2017-09-19 19:18:52 +02:00
|
|
|
unit uCEFExtension;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-09-19 19:18:52 +02:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-09-19 19:18:52 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
|
|
|
|
|
|
|
|
type
|
|
|
|
TCefExtensionRef = class(TCefBaseRefCountedRef, ICefExtension)
|
|
|
|
protected
|
2017-10-26 13:23:13 +02:00
|
|
|
function GetIdentifier : ustring;
|
|
|
|
function GetPath : ustring;
|
|
|
|
function GetManifest : ICefDictionaryValue;
|
|
|
|
function IsSame(const that : ICefExtension) : boolean;
|
|
|
|
function GetHandler : ICefExtensionHandler;
|
|
|
|
function GetLoaderContext: ICefRequestContext;
|
|
|
|
function IsLoaded : boolean;
|
2017-09-19 19:18:52 +02:00
|
|
|
procedure unload;
|
2020-08-04 17:52:09 +02:00
|
|
|
function GetPopup(const aParent : ustring) : ustring;
|
|
|
|
function GetIcon(const aParent : ustring) : ustring;
|
|
|
|
function GetBrowserActionPopup : ustring;
|
|
|
|
function GetBrowserActionIcon : ustring;
|
|
|
|
function GetPageActionPopup : ustring;
|
|
|
|
function GetPageActionIcon : ustring;
|
|
|
|
function GetOptionsPage : ustring;
|
|
|
|
function GetOptionsUIPage : ustring;
|
|
|
|
function GetBackgroundPage : ustring;
|
|
|
|
function GetURL : ustring;
|
2017-09-19 19:18:52 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
class function UnWrap(data: Pointer): ICefExtension;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2020-08-04 17:52:09 +02:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFDictionaryValue, uCEFRequestContext,
|
|
|
|
uCEFExtensionHandler, uCEFJson;
|
2017-09-19 19:18:52 +02:00
|
|
|
|
|
|
|
function TCefExtensionRef.GetIdentifier : ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefExtension(FData)^.get_identifier(PCefExtension(FData)));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetPath : ustring;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := CefStringFreeAndGet(PCefExtension(FData)^.get_path(PCefExtension(FData)));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetManifest : ICefDictionaryValue;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TCefDictionaryValueRef.UnWrap(PCefExtension(FData)^.get_manifest(PCefExtension(FData)));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.IsSame(const that : ICefExtension) : boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result:= PCefExtension(FData)^.is_same(PCefExtension(FData), PCefExtension(CefGetData(that))) <> 0;
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetHandler : ICefExtensionHandler;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TCefExtensionHandlerRef.UnWrap(PCefExtension(FData)^.get_handler(PCefExtension(FData)));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetLoaderContext: ICefRequestContext;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := TCefRequestContextRef.UnWrap(PCefExtension(FData)^.get_loader_context(PCefExtension(FData)));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.IsLoaded : boolean;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
Result := PCefExtension(FData)^.is_loaded(PCefExtension(FData)) <> 0;
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCefExtensionRef.unload;
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefExtension(FData)^.unload(PCefExtension(FData));
|
2017-09-19 19:18:52 +02:00
|
|
|
end;
|
|
|
|
|
2020-08-04 17:52:09 +02:00
|
|
|
function TCefExtensionRef.GetPopup(const aParent : ustring) : ustring;
|
|
|
|
var
|
|
|
|
TempManifest, TempBrowserAction : ICefDictionaryValue;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
TempManifest := GetManifest;
|
|
|
|
|
|
|
|
if (TempManifest <> nil) and
|
|
|
|
TCEFJson.ReadDictionary(TempManifest, aParent, TempBrowserAction) then
|
|
|
|
TCEFJson.ReadString(TempBrowserAction, 'default_popup', Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetIcon(const aParent : ustring) : ustring;
|
|
|
|
var
|
|
|
|
TempManifest, TempBrowserAction, TempDefIcon : ICefDictionaryValue;
|
|
|
|
TempResult : ustring;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
TempManifest := GetManifest;
|
|
|
|
|
|
|
|
if (TempManifest <> nil) and
|
|
|
|
TCEFJson.ReadDictionary(TempManifest, aParent, TempBrowserAction) then
|
|
|
|
begin
|
|
|
|
if TCEFJson.ReadString(TempBrowserAction, 'default_icon', TempResult) then
|
|
|
|
Result := TempResult
|
|
|
|
else
|
|
|
|
if TCEFJson.ReadDictionary(TempManifest, 'default_icon', TempDefIcon) and
|
|
|
|
(TCEFJson.ReadString(TempDefIcon, '128', TempResult) or
|
|
|
|
TCEFJson.ReadString(TempDefIcon, '48', TempResult) or
|
|
|
|
TCEFJson.ReadString(TempDefIcon, '32', TempResult) or
|
|
|
|
TCEFJson.ReadString(TempDefIcon, '16', TempResult)) then
|
|
|
|
Result := TempResult
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetBrowserActionPopup : ustring;
|
|
|
|
begin
|
|
|
|
Result := GetPopup('browser_action');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetBrowserActionIcon : ustring;
|
|
|
|
begin
|
|
|
|
Result := GetIcon('browser_action');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetPageActionPopup : ustring;
|
|
|
|
begin
|
|
|
|
Result := GetPopup('page_action');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetPageActionIcon : ustring;
|
|
|
|
begin
|
|
|
|
Result := GetIcon('page_action');
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetOptionsPage : ustring;
|
|
|
|
var
|
|
|
|
TempManifest : ICefDictionaryValue;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
TempManifest := GetManifest;
|
|
|
|
|
|
|
|
if (TempManifest <> nil) then
|
|
|
|
TCEFJson.ReadString(TempManifest, 'options_page', Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetOptionsUIPage : ustring;
|
|
|
|
var
|
|
|
|
TempManifest, TempOptions : ICefDictionaryValue;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
TempManifest := GetManifest;
|
|
|
|
|
|
|
|
if (TempManifest <> nil) and
|
|
|
|
TCEFJson.ReadDictionary(TempManifest, 'options_ui', TempOptions) then
|
|
|
|
TCEFJson.ReadString(TempOptions, 'page', Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetBackgroundPage : ustring;
|
|
|
|
var
|
|
|
|
TempManifest, TempBackground : ICefDictionaryValue;
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
TempManifest := GetManifest;
|
|
|
|
|
|
|
|
if (TempManifest <> nil) and
|
|
|
|
TCEFJson.ReadDictionary(TempManifest, 'background', TempBackground) then
|
|
|
|
TCEFJson.ReadString(TempBackground, 'page', Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCefExtensionRef.GetURL : ustring;
|
|
|
|
begin
|
|
|
|
Result := 'chrome-extension://' + GetIdentifier + '/';
|
|
|
|
end;
|
|
|
|
|
2017-09-19 19:18:52 +02:00
|
|
|
class function TCefExtensionRef.UnWrap(data: Pointer): ICefExtension;
|
|
|
|
begin
|
|
|
|
if (data <> nil) then
|
|
|
|
Result := Create(data) as ICefExtension
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|