1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Fix for issue #265 made by Matthias Kretschmar

Added TChromium.AcceptCookies and TChormium.Block3rdPartyCookies
This commit is contained in:
Salvador Díaz Fau 2020-03-04 09:42:32 +01:00
parent 5649b6e661
commit f4dd3e69a3
5 changed files with 51 additions and 10 deletions

View File

@ -167,6 +167,7 @@ uses
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.cache := 'cache';
//GlobalCEFApp.LogFile := 'cef.log';
//GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
end;
@ -181,7 +182,6 @@ procedure TCookieVisitorFrm.BrowserCreatedMsg(var aMessage : TMessage);
begin
CEFWindowParent1.UpdateSize;
AddressBarPnl.Enabled := True;
GoBtn.Click;
end;
procedure TCookieVisitorFrm.BrowserDestroyMsg(var aMessage : TMessage);
@ -319,10 +319,10 @@ begin
'/',
True,
True,
False,
now,
True,
now,
now,
now + 1,
False);
end;
end;
@ -384,6 +384,8 @@ procedure TCookieVisitorFrm.FormCreate(Sender: TObject);
begin
FCanClose := False;
FClosing := False;
Chromium1.DefaultURL := Edit1.Text;
end;
procedure TCookieVisitorFrm.FormShow(Sender: TObject);

View File

@ -126,6 +126,8 @@ type
FWebRTCMultipleRoutes : TCefState;
FWebRTCNonProxiedUDP : TCefState;
FAcceptLanguageList : ustring;
FAcceptCookies : TCefCookiePref;
FBlock3rdPartyCookies : boolean;
{$IFDEF MSWINDOWS}
FOldBrowserCompWndPrc : TFNWndProc;
@ -328,6 +330,8 @@ type
procedure SetYouTubeRestrict(aValue : integer);
procedure SetPrintingEnabled(aValue : boolean);
procedure SetAcceptLanguageList(const aValue : ustring);
procedure SetAcceptCookies(const aValue : TCefCookiePref);
procedure SetBlock3rdPartyCookies(const aValue : boolean);
procedure SetOnRequestContextInitialized(const aValue : TOnRequestContextInitialized);
procedure SetOnBeforePluginLoad(const aValue : TOnBeforePluginLoad);
@ -738,6 +742,8 @@ type
property YouTubeRestrict : integer read FYouTubeRestrict write SetYouTubeRestrict;
property PrintingEnabled : boolean read FPrintingEnabled write SetPrintingEnabled;
property AcceptLanguageList : ustring read FAcceptLanguageList write SetAcceptLanguageList;
property AcceptCookies : TCefCookiePref read FAcceptCookies write SetAcceptCookies;
property Block3rdPartyCookies : boolean read FBlock3rdPartyCookies write SetBlock3rdPartyCookies;
property WebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy read FWebRTCIPHandlingPolicy write SetWebRTCIPHandlingPolicy;
property WebRTCMultipleRoutes : TCefState read FWebRTCMultipleRoutes write SetWebRTCMultipleRoutes;
@ -965,6 +971,8 @@ begin
FYouTubeRestrict := YOUTUBE_RESTRICT_OFF;
FPrintingEnabled := True;
FAcceptLanguageList := '';
FAcceptCookies := cpAllow;
FBlock3rdPartyCookies := False;
{$IFDEF MSWINDOWS}
FOldBrowserCompWndPrc := nil;
@ -2552,6 +2560,24 @@ begin
end;
end;
procedure TChromiumCore.SetAcceptCookies(const aValue : TCefCookiePref);
begin
if (FAcceptCookies <> aValue) then
begin
FAcceptCookies := aValue;
FUpdatePreferences := True;
end;
end;
procedure TChromiumCore.SetBlock3rdPartyCookies(const aValue : boolean);
begin
if (FBlock3rdPartyCookies <> aValue) then
begin
FBlock3rdPartyCookies := aValue;
FUpdatePreferences := True;
end;
end;
procedure TChromiumCore.SetOnRequestContextInitialized(const aValue : TOnRequestContextInitialized);
begin
FOnRequestContextInitialized := aValue;
@ -3188,6 +3214,15 @@ begin
UpdatePreference(aBrowser, 'printing.enabled', FPrintingEnabled);
UpdatePreference(aBrowser, 'intl.accept_languages', FAcceptLanguageList);
case FAcceptCookies of
cpAllow : UpdatePreference(aBrowser, 'profile.default_content_setting_values.cookies', CEF_COOKIE_PREF_ALLOW);
cpBlock : UpdatePreference(aBrowser, 'profile.default_content_setting_values.cookies', CEF_COOKIE_PREF_BLOCK);
else UpdatePreference(aBrowser, 'profile.default_content_setting_values.cookies', CEF_COOKIE_PREF_DEFAULT);
end;
UpdatePreference(aBrowser, 'profile.managed_default_content_settings.cookies', CEF_COOKIE_PREF_DEFAULT);
UpdatePreference(aBrowser, 'profile.block_third_party_cookies', FBlock3rdPartyCookies);
if (FMaxConnectionsPerProxy <> CEF_MAX_CONNECTIONS_PER_PROXY_DEFAULT_VALUE) then
UpdatePreference(aBrowser, 'net.max_connections_per_proxy', FMaxConnectionsPerProxy);
@ -4648,13 +4683,10 @@ function TChromiumCore.doOnGetAuthCredentials(const browser : ICefBrowser;
begin
Result := False;
if isProxy then
if isProxy and (FProxyType = CEF_PROXYTYPE_FIXED_SERVERS) and (callback <> nil) then
begin
if (FProxyType = CEF_PROXYTYPE_FIXED_SERVERS) and (callback <> nil) then
begin
Result := True;
callback.cont(FProxyUsername, FProxyPassword);
end;
Result := True;
callback.cont(FProxyUsername, FProxyPassword);
end
else
if Assigned(FOnGetAuthCredentials) then

View File

@ -548,6 +548,10 @@ const
CEF_MAX_CONNECTIONS_PER_PROXY_MIN_VALUE = 7;
CEF_MAX_CONNECTIONS_PER_PROXY_MAX_VALUE = 99;
CEF_COOKIE_PREF_DEFAULT = 0;
CEF_COOKIE_PREF_ALLOW = 1;
CEF_COOKIE_PREF_BLOCK = 2;
// https://chromium.googlesource.com/chromium/src/+/refs/tags/77.0.3865.90/chrome/common/net/safe_search_util.h (YouTubeRestrictMode)
// https://www.chromium.org/administrators/policy-list-3#ForceYouTubeRestrict
YOUTUBE_RESTRICT_OFF = 0;

View File

@ -385,6 +385,9 @@ type
TCefProcessType = (ptBrowser, ptRenderer, ptZygote, ptGPU, ptUtility, ptOther);
// Used in TChromium preferences to allow or block cookies.
TCefCookiePref = (cpDefault, cpAllow, cpBlock);
TCefAplicationStatus = (asLoading,
asLoaded,
asInitialized,

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 104,
"InternalVersion" : 105,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "80.0.4.0"
}