From 9888fe3e464be220f309f32dd8d17518d13c172e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Tue, 2 Jan 2018 16:52:35 +0100 Subject: [PATCH] Bug fix #85 : Adding overloaded ExecuteJavaScript to select individual frames --- source/uCEFChromium.pas | 43 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/source/uCEFChromium.pas b/source/uCEFChromium.pas index a8e98abb..1c30c4ff 100644 --- a/source/uCEFChromium.pas +++ b/source/uCEFChromium.pas @@ -468,7 +468,9 @@ type procedure RetrieveText(const aFrameIdentifier : int64); overload; function GetFrameNames(var aFrameNames : TStrings) : boolean; function GetFrameIdentifiers(var aFrameCount : NativeUInt; var aFrameIdentifierArray : TCefFrameIdentifierArray) : boolean; - procedure ExecuteJavaScript(const aCode, aScriptURL : ustring; aStartLine : integer = 0); + procedure ExecuteJavaScript(const aCode, aScriptURL : ustring; const aFrameName : ustring = ''; aStartLine : integer = 0); overload; + procedure ExecuteJavaScript(const aCode, aScriptURL : ustring; const aFrame : ICefFrame; aStartLine : integer = 0); overload; + procedure ExecuteJavaScript(const aCode, aScriptURL : ustring; const aFrameIdentifier : int64; aStartLine : integer = 0); overload; procedure UpdatePreferences; procedure SavePreferences(const aFileName : string); function SetNewBrowserParent(aNewParentHwnd : HWND) : boolean; @@ -2753,14 +2755,49 @@ begin if assigned(FOnTextResultAvailable) then FOnTextResultAvailable(self, aText); end; -procedure TChromium.ExecuteJavaScript(const aCode, aScriptURL : ustring; aStartLine : integer); +procedure TChromium.ExecuteJavaScript(const aCode, aScriptURL, aFrameName : ustring; aStartLine : integer); var TempFrame : ICefFrame; begin try if Initialized then begin - TempFrame := FBrowser.MainFrame; + if (length(aFrameName) > 0) then + TempFrame := FBrowser.GetFrame(aFrameName) + else + TempFrame := FBrowser.MainFrame; + + if (TempFrame <> nil) then + TempFrame.ExecuteJavaScript(aCode, aScriptURL, aStartLine); + end; + except + on e : exception do + if CustomExceptionHandler('TChromium.ExecuteJavaScript', e) then raise; + end; +end; + +procedure TChromium.ExecuteJavaScript(const aCode, aScriptURL : ustring; const aFrame : ICefFrame; aStartLine : integer); +begin + try + if Initialized and (aFrame <> nil) then + aFrame.ExecuteJavaScript(aCode, aScriptURL, aStartLine); + except + on e : exception do + if CustomExceptionHandler('TChromium.ExecuteJavaScript', e) then raise; + end; +end; + +procedure TChromium.ExecuteJavaScript(const aCode, aScriptURL : ustring; const aFrameIdentifier : int64; aStartLine : integer = 0); +var + TempFrame : ICefFrame; +begin + try + if Initialized then + begin + if (aFrameIdentifier <> 0) then + TempFrame := FBrowser.GetFrameByident(aFrameIdentifier) + else + TempFrame := FBrowser.MainFrame; if (TempFrame <> nil) then TempFrame.ExecuteJavaScript(aCode, aScriptURL, aStartLine);