2017-01-27 16:37:51 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
|
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2018-01-06 15:25:32 +01:00
|
|
|
|
// Copyright <20> 2018 Salvador D<>az Fau. All rights reserved.
|
2017-01-27 16:37:51 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
|
*
|
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
|
*
|
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFFrame;
|
|
|
|
|
|
|
|
|
|
{$IFNDEF CPUX64}
|
|
|
|
|
{$ALIGN ON}
|
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-03-16 19:09:42 +01:00
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
|
TCefFrameRef = class(TCefBaseRefCountedRef, ICefFrame)
|
2017-01-27 16:37:51 +01:00
|
|
|
|
public
|
|
|
|
|
function IsValid: Boolean;
|
|
|
|
|
procedure Undo;
|
|
|
|
|
procedure Redo;
|
|
|
|
|
procedure Cut;
|
|
|
|
|
procedure Copy;
|
|
|
|
|
procedure Paste;
|
|
|
|
|
procedure Del;
|
|
|
|
|
procedure SelectAll;
|
|
|
|
|
procedure ViewSource;
|
|
|
|
|
procedure GetSource(const visitor: ICefStringVisitor);
|
|
|
|
|
procedure GetSourceProc(const proc: TCefStringVisitorProc);
|
|
|
|
|
procedure GetText(const visitor: ICefStringVisitor);
|
|
|
|
|
procedure GetTextProc(const proc: TCefStringVisitorProc);
|
|
|
|
|
procedure LoadRequest(const request: ICefRequest);
|
|
|
|
|
procedure LoadUrl(const url: ustring);
|
|
|
|
|
procedure LoadString(const str, url: ustring);
|
|
|
|
|
procedure ExecuteJavaScript(const code, scriptUrl: ustring; startLine: Integer);
|
|
|
|
|
function IsMain: Boolean;
|
|
|
|
|
function IsFocused: Boolean;
|
|
|
|
|
function GetName: ustring;
|
|
|
|
|
function GetIdentifier: Int64;
|
|
|
|
|
function GetParent: ICefFrame;
|
|
|
|
|
function GetUrl: ustring;
|
|
|
|
|
function GetBrowser: ICefBrowser;
|
|
|
|
|
function GetV8Context: ICefv8Context;
|
|
|
|
|
procedure VisitDom(const visitor: ICefDomVisitor);
|
|
|
|
|
procedure VisitDomProc(const proc: TCefDomVisitorProc);
|
|
|
|
|
|
|
|
|
|
class function UnWrap(data: Pointer): ICefFrame;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFStringVisitor, uCEFv8Context, uCEFDomVisitor;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.IsValid: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefFrame(FData)^.is_valid(PCefFrame(FData)) <> 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Copy;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.copy(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Cut;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.cut(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Del;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.del(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.ExecuteJavaScript(const code, scriptUrl: ustring;
|
|
|
|
|
startLine: Integer);
|
|
|
|
|
var
|
|
|
|
|
j, s: TCefString;
|
|
|
|
|
begin
|
|
|
|
|
j := CefString(code);
|
|
|
|
|
s := CefString(scriptUrl);
|
|
|
|
|
PCefFrame(FData)^.execute_java_script(PCefFrame(FData), @j, @s, startline);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetBrowser: ICefBrowser;
|
|
|
|
|
begin
|
|
|
|
|
Result := TCefBrowserRef.UnWrap(PCefFrame(FData)^.get_browser(PCefFrame(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetIdentifier: Int64;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefFrame(FData)^.get_identifier(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetName: ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefFrame(FData)^.get_name(PCefFrame(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetParent: ICefFrame;
|
|
|
|
|
begin
|
|
|
|
|
Result := TCefFrameRef.UnWrap(PCefFrame(FData)^.get_parent(PCefFrame(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.GetSource(const visitor: ICefStringVisitor);
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.get_source(PCefFrame(FData), CefGetData(visitor));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.GetSourceProc(const proc: TCefStringVisitorProc);
|
|
|
|
|
begin
|
|
|
|
|
GetSource(TCefFastStringVisitor.Create(proc));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.getText(const visitor: ICefStringVisitor);
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.get_text(PCefFrame(FData), CefGetData(visitor));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.GetTextProc(const proc: TCefStringVisitorProc);
|
|
|
|
|
begin
|
|
|
|
|
GetText(TCefFastStringVisitor.Create(proc));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetUrl: ustring;
|
|
|
|
|
begin
|
|
|
|
|
Result := CefStringFreeAndGet(PCefFrame(FData)^.get_url(PCefFrame(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.GetV8Context: ICefv8Context;
|
|
|
|
|
begin
|
|
|
|
|
Result := TCefv8ContextRef.UnWrap(PCefFrame(FData)^.get_v8context(PCefFrame(FData)));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.IsFocused: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefFrame(FData)^.is_focused(PCefFrame(FData)) <> 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCefFrameRef.IsMain: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := PCefFrame(FData)^.is_main(PCefFrame(FData)) <> 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.LoadRequest(const request: ICefRequest);
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.load_request(PCefFrame(FData), CefGetData(request));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.LoadString(const str, url: ustring);
|
|
|
|
|
var
|
|
|
|
|
s, u: TCefString;
|
|
|
|
|
begin
|
|
|
|
|
s := CefString(str);
|
|
|
|
|
u := CefString(url);
|
|
|
|
|
PCefFrame(FData)^.load_string(PCefFrame(FData), @s, @u);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.LoadUrl(const url: ustring);
|
|
|
|
|
var
|
|
|
|
|
u: TCefString;
|
|
|
|
|
begin
|
|
|
|
|
u := CefString(url);
|
|
|
|
|
PCefFrame(FData)^.load_url(PCefFrame(FData), @u);
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Paste;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.paste(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Redo;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.redo(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.SelectAll;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.select_all(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.Undo;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.undo(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.ViewSource;
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.view_source(PCefFrame(FData));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.VisitDom(const visitor: ICefDomVisitor);
|
|
|
|
|
begin
|
|
|
|
|
PCefFrame(FData)^.visit_dom(PCefFrame(FData), CefGetData(visitor));
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCefFrameRef.VisitDomProc(const proc: TCefDomVisitorProc);
|
|
|
|
|
begin
|
|
|
|
|
VisitDom(TCefFastDomVisitor.Create(proc) as ICefDomVisitor);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
class function TCefFrameRef.UnWrap(data: Pointer): ICefFrame;
|
|
|
|
|
begin
|
|
|
|
|
if data <> nil then
|
|
|
|
|
Result := Create(data) as ICefFrame else
|
|
|
|
|
Result := nil;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|