---------------------------------------------------
Just thought I'd throw this out there since I couldn't find any good info on it when I was trying to do it. This is how to use DCEF - specifically the branches 2623 and above (because it's not supported earlier) with dynamically set runtime proxies. I believe this only works if you don't pass in proxy settings on the command line.
What I did was open the guiclient demo and drop a combobox on Panel1:
- Code: Select all
object cefProxy: TComboBox
Left = 718
Top = 1
Width = 145
Height = 21
Align = alRight
Style = csDropDownList
ItemHeight = 13
TabOrder = 1
OnChange = cefProxyChange
Items.Strings = (
'system'
'direct'
'auto_detect'
'fixed_servers'
'pac_script')
end
With this event handler:
- Code: Select all
procedure TMainForm.cefProxyChange(Sender: TObject);
var
err: ustring;
proxy: ICefValue;
val: ICefValue;
begin
proxy := crm.Browser.Host.RequestContext.GetPreference('proxy');
val := TCefValueRef.New;
val.SetString(cefProxy.Items[cefProxy.ItemIndex]);
proxy.GetDictionary.SetValue('mode', val);
if cefProxy.Items[cefProxy.ItemIndex] = 'fixed_servers' then
begin
proxy.GetDictionary.SetString('server', 'http://127.0.0.1:8888'); // format [scheme://]hostname[:port];etc.
proxy.GetDictionary.SetString('bypass_list', ''); // example: 'address1;address2'
end
else if cefProxy.Items[cefProxy.ItemIndex] = 'pac_script' then
proxy.GetDictionary.SetString('pac_url', 'http://localhost/test/pacscript.js');
crm.Browser.Host.RequestContext.SetPreference('proxy', proxy, err);
end;
And in the FormCreate, I'm doing this to initialize the combobox:
- Code: Select all
cefProxy.ItemIndex := cefProxy.Items.IndexOf(crm.Browser.Host.RequestContext.
GetPreference('proxy').GetDictionary.GetValue('mode').GetString);
Of course, it will always be "system" but I think it's instructive.
Note that you don't want to call crm.Browser before you first load a page because it will be nil. You could probably put this proxy code into OnBeforeBrowse if that worked better for your setup.
I've tested it with direct, system, fixed_server and pac_script. Haven't verified it with auto_detect simply because that's a bit more work to set up (our network doesn't have an auto-detect proxy).
Hope this helps someone else!