From 227dafc55c39ffb34515a586396d8c8e003d2b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Sat, 30 Dec 2017 15:42:29 +0100 Subject: [PATCH] Added TChromium.ProxyScheme property --- demos/MiniBrowser/uMiniBrowser.pas | 38 ++++++++---------------------- demos/MiniBrowser/uPreferences.dfm | 6 ++--- source/uCEFChromium.pas | 21 ++++++++++++++++- source/uCEFTypes.pas | 2 ++ 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/demos/MiniBrowser/uMiniBrowser.pas b/demos/MiniBrowser/uMiniBrowser.pas index 666ca3e8..aeccaeb6 100644 --- a/demos/MiniBrowser/uMiniBrowser.pas +++ b/demos/MiniBrowser/uMiniBrowser.pas @@ -688,34 +688,15 @@ begin end; procedure TMiniBrowserFrm.Preferences1Click(Sender: TObject); -var - TempScheme, TempServer : string; - i : integer; begin - i := pos('://', Chromium1.ProxyServer); - - if (i <= 0) then - begin - PreferencesFrm.ProxySchemeCb.ItemIndex := 0; - TempServer := Chromium1.ProxyServer; - end - else - begin - TempScheme := copy(Chromium1.ProxyServer, 1, pred(i)); - TempServer := copy(Chromium1.ProxyServer, i + 3, length(Chromium1.ProxyServer)); - - if (CompareText(TempScheme, 'socks') = 0) or - (CompareText(TempScheme, 'socks5') = 0) then - PreferencesFrm.ProxySchemeCb.ItemIndex := 2 - else - if (CompareText(TempScheme, 'socks4') = 0) then - PreferencesFrm.ProxySchemeCb.ItemIndex := 1 - else - PreferencesFrm.ProxySchemeCb.ItemIndex := 0; - end; + case Chromium1.ProxyScheme of + psSOCKS4 : PreferencesFrm.ProxySchemeCb.ItemIndex := 1; + psSOCKS5 : PreferencesFrm.ProxySchemeCb.ItemIndex := 2; + else PreferencesFrm.ProxySchemeCb.ItemIndex := 0; + end; PreferencesFrm.ProxyTypeCbx.ItemIndex := Chromium1.ProxyType; - PreferencesFrm.ProxyServerEdt.Text := TempServer; + PreferencesFrm.ProxyServerEdt.Text := Chromium1.ProxyServer; PreferencesFrm.ProxyPortEdt.Text := inttostr(Chromium1.ProxyPort); PreferencesFrm.ProxyUsernameEdt.Text := Chromium1.ProxyUsername; PreferencesFrm.ProxyPasswordEdt.Text := Chromium1.ProxyPassword; @@ -727,6 +708,7 @@ begin if (PreferencesFrm.ShowModal = mrOk) then begin Chromium1.ProxyType := PreferencesFrm.ProxyTypeCbx.ItemIndex; + Chromium1.ProxyServer := PreferencesFrm.ProxyServerEdt.Text; Chromium1.ProxyPort := strtoint(PreferencesFrm.ProxyPortEdt.Text); Chromium1.ProxyUsername := PreferencesFrm.ProxyUsernameEdt.Text; Chromium1.ProxyPassword := PreferencesFrm.ProxyPasswordEdt.Text; @@ -736,9 +718,9 @@ begin Chromium1.CustomHeaderValue := PreferencesFrm.HeaderValueEdt.Text; case PreferencesFrm.ProxySchemeCb.ItemIndex of - 1 : Chromium1.ProxyServer := 'socks4://' + PreferencesFrm.ProxyServerEdt.Text; - 2 : Chromium1.ProxyServer := 'socks5://' + PreferencesFrm.ProxyServerEdt.Text; - else Chromium1.ProxyServer := PreferencesFrm.ProxyServerEdt.Text; + 1 : Chromium1.ProxyScheme := psSOCKS4; + 2 : Chromium1.ProxyScheme := psSOCKS5; + else Chromium1.ProxyScheme := psHTTP; end; Chromium1.UpdatePreferences; diff --git a/demos/MiniBrowser/uPreferences.dfm b/demos/MiniBrowser/uPreferences.dfm index 812404b0..3520fb8c 100644 --- a/demos/MiniBrowser/uPreferences.dfm +++ b/demos/MiniBrowser/uPreferences.dfm @@ -108,9 +108,9 @@ object PreferencesFrm: TPreferencesFrm 'PAC script') end object ProxyServerEdt: TEdit - Left = 176 + Left = 184 Top = 53 - Width = 224 + Width = 216 Height = 21 TabOrder = 2 end @@ -156,7 +156,7 @@ object PreferencesFrm: TPreferencesFrm object ProxySchemeCb: TComboBox Left = 108 Top = 53 - Width = 62 + Width = 70 Height = 21 Style = csDropDownList ItemIndex = 0 diff --git a/source/uCEFChromium.pas b/source/uCEFChromium.pas index ab6cc070..a8e98abb 100644 --- a/source/uCEFChromium.pas +++ b/source/uCEFChromium.pas @@ -75,6 +75,7 @@ type FPDFPrintOptions : TPDFPrintOptions; FDefaultEncoding : ustring; FProxyType : integer; + FProxyScheme : TCefProxyScheme; FProxyServer : string; FProxyPort : integer; FProxyUsername : string; @@ -244,6 +245,7 @@ type procedure SetCookiePrefs(aValue : integer); procedure SetImagesPrefs(aValue : integer); procedure SetProxyType(aValue : integer); + procedure SetProxyScheme(aValue : TCefProxyScheme); procedure SetProxyServer(const aValue : string); procedure SetProxyPort(aValue : integer); procedure SetProxyUsername(const aValue : string); @@ -570,6 +572,7 @@ type property WebRTCNonproxiedUDP : TCefState read FWebRTCNonProxiedUDP write SetWebRTCNonProxiedUDP; property ProxyType : integer read FProxyType write SetProxyType; + property ProxyScheme : TCefProxyScheme read FProxyScheme write SetProxyScheme; property ProxyServer : string read FProxyServer write SetProxyServer; property ProxyPort : integer read FProxyPort write SetProxyPort; property ProxyUsername : string read FProxyUsername write SetProxyUsername; @@ -736,6 +739,7 @@ begin FWebRTCNonProxiedUDP := STATE_DEFAULT; FProxyType := CEF_PROXYTYPE_DIRECT; + FProxyScheme := psHTTP; FProxyServer := ''; FProxyPort := 80; FProxyUsername := ''; @@ -1810,6 +1814,15 @@ begin end; end; +procedure TChromium.SetProxyScheme(aValue : TCefProxyScheme); +begin + if (FProxyScheme <> aValue) then + begin + FProxyScheme := aValue; + FUpdatePreferences := True; + end; +end; + procedure TChromium.SetProxyServer(const aValue : string); begin if (FProxyServer <> aValue) then @@ -2227,7 +2240,13 @@ begin begin TempValue.SetString('fixed_servers'); TempDict.SetValue('mode', TempValue); - TempDict.SetString('server', FProxyServer + ':' + inttostr(FProxyPort)); + + case FProxyScheme of + psSOCKS4 : TempDict.SetString('server', 'socks4://' + FProxyServer + ':' + inttostr(FProxyPort)); + psSOCKS5 : TempDict.SetString('server', 'socks5://' + FProxyServer + ':' + inttostr(FProxyPort)); + else TempDict.SetString('server', FProxyServer + ':' + inttostr(FProxyPort)); + end; + if (length(FProxyByPassList) > 0) then TempDict.SetString('bypass_list', FProxyByPassList); end; diff --git a/source/uCEFTypes.pas b/source/uCEFTypes.pas index b6dae3fb..30b6234c 100644 --- a/source/uCEFTypes.pas +++ b/source/uCEFTypes.pas @@ -299,6 +299,8 @@ type asErrorInitializingLibrary, asErrorExecutingProcess); + TCefProxyScheme = (psHTTP, psSOCKS4, psSOCKS5); + TCefWebRTCHandlingPolicy = ( hpDefault, hpDefaultPublicAndPrivateInterfaces,