mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-04-17 06:57:13 +02:00
Moved all JSON functions to the TCEFJson class
- Added TCEFJson.SaveToFile and TCEFJson.LoadFromFile functions - Added more code comments to DOMVisitor - Replaced all the code to save the browser preferences in TChromiumCore with the new TCEFJson functions
This commit is contained in:
parent
2b963f06ba
commit
dceb2299e3
@ -212,7 +212,7 @@ uses
|
|||||||
// TChromium.OnConsoleMessage event and we identify the right message thanks to
|
// TChromium.OnConsoleMessage event and we identify the right message thanks to
|
||||||
// the preamble in the message.
|
// the preamble in the message.
|
||||||
|
|
||||||
// This demos also uses DevTool methods to change the "value" attribute of an
|
// This demo also uses DevTool methods to change the "value" attribute of an
|
||||||
// INPUT HTML element. Each method is called using the
|
// INPUT HTML element. Each method is called using the
|
||||||
// TChromium.ExecuteDevToolsMethod function and the results are received in the
|
// TChromium.ExecuteDevToolsMethod function and the results are received in the
|
||||||
// TChromium.OnDevToolsMethodResult event.
|
// TChromium.OnDevToolsMethodResult event.
|
||||||
@ -288,14 +288,19 @@ begin
|
|||||||
// known preamble that will be used to identify the message in the
|
// known preamble that will be used to identify the message in the
|
||||||
// TChromium.OnConsoleMessage event.
|
// TChromium.OnConsoleMessage event.
|
||||||
|
|
||||||
// CEF has some known issues with ICefDomNode.GetValue and ICefDomNode.SetValue
|
// NOTE : In case you try to read or write node values using the CEF API
|
||||||
// Use JavaScript if you need to get or set the value of HTML elements.
|
// you should know that ICefDomNode.GetValue and ICefDomNode.SetValue
|
||||||
|
// only work in text nodes. ICefDomNode.GetElementAttribute returns
|
||||||
|
// the attribute value specified in the HTML and not the current value.
|
||||||
|
|
||||||
|
// It's recommended that you use JavaScript or DevTools methods if
|
||||||
|
// you need to get or set the value of HTML elements.
|
||||||
// For example, if you want to use the "console trick" and you want
|
// For example, if you want to use the "console trick" and you want
|
||||||
// to get the value of the search box in our forum you would have to
|
// to get the value of the search box in our forum you would have to
|
||||||
// execute this JavaScript code :
|
// execute this JavaScript code :
|
||||||
// console.log("DOMVISITOR" + document.getElementById("keywords").value);
|
// console.log("DOMVISITOR" + document.getElementById("keywords").value);
|
||||||
|
|
||||||
TempMessage := 'name:' + quotedstr(TempNode.Name);
|
TempMessage := 'name:' + TempNode.Name;
|
||||||
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + TempMessage + '");';
|
TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + TempMessage + '");';
|
||||||
aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
|
aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0);
|
||||||
end;
|
end;
|
||||||
@ -531,9 +536,9 @@ begin
|
|||||||
MsgContents := copy(message, succ(length(CONSOLE_MSG_PREAMBLE)), length(message));
|
MsgContents := copy(message, succ(length(CONSOLE_MSG_PREAMBLE)), length(message));
|
||||||
|
|
||||||
if (length(MsgContents) = 0) then
|
if (length(MsgContents) = 0) then
|
||||||
MsgContents := 'The INPUT node has no value'
|
MsgContents := 'There was an error reading the search box information'
|
||||||
else
|
else
|
||||||
MsgContents := 'INPUT node value : ' + quotedstr(MsgContents);
|
MsgContents := 'Search box information: ' + quotedstr(MsgContents);
|
||||||
|
|
||||||
PostMessage(Handle, MINIBROWSER_SHOWMESSAGE, 0, 0);
|
PostMessage(Handle, MINIBROWSER_SHOWMESSAGE, 0, 0);
|
||||||
end;
|
end;
|
||||||
|
@ -406,16 +406,6 @@ type
|
|||||||
function UpdatePreference(const aBrowser: ICefBrowser; const aName : ustring; const aValue : TStringList) : boolean; overload;
|
function UpdatePreference(const aBrowser: ICefBrowser; const aName : ustring; const aValue : TStringList) : boolean; overload;
|
||||||
function UpdateStringListPref(const aBrowser: ICefBrowser; const aName, aValue : ustring) : boolean;
|
function UpdateStringListPref(const aBrowser: ICefBrowser; const aName, aValue : ustring) : boolean;
|
||||||
|
|
||||||
procedure HandleDictionary(const aDict : ICefDictionaryValue; var aResultSL : TStringList; const aRoot : string);
|
|
||||||
procedure HandleNull(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleBool(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleInteger(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleDouble(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleString(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleBinary(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleList(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
procedure HandleInvalid(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
|
|
||||||
function ExecuteUpdateZoomStepTask(aInc : boolean) : boolean;
|
function ExecuteUpdateZoomStepTask(aInc : boolean) : boolean;
|
||||||
function ExecuteUpdateZoomPctTask(aInc : boolean) : boolean;
|
function ExecuteUpdateZoomPctTask(aInc : boolean) : boolean;
|
||||||
function ExecuteReadZoomTask : boolean;
|
function ExecuteReadZoomTask : boolean;
|
||||||
@ -1104,7 +1094,7 @@ uses
|
|||||||
uCEFDownloadImageCallBack, uCEFCookieManager, uCEFRequestContextHandler,
|
uCEFDownloadImageCallBack, uCEFCookieManager, uCEFRequestContextHandler,
|
||||||
uCEFCookieVisitor, uCEFSetCookieCallback, uCEFResourceRequestHandler,
|
uCEFCookieVisitor, uCEFSetCookieCallback, uCEFResourceRequestHandler,
|
||||||
uCEFMediaObserver, uCEFMediaRouteCreateCallback ,uCEFDevToolsMessageObserver,
|
uCEFMediaObserver, uCEFMediaRouteCreateCallback ,uCEFDevToolsMessageObserver,
|
||||||
uCEFMediaSinkDeviceInfoCallback;
|
uCEFMediaSinkDeviceInfoCallback, uCEFJson;
|
||||||
|
|
||||||
constructor TChromiumCore.Create(AOwner: TComponent);
|
constructor TChromiumCore.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
@ -4099,262 +4089,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChromiumCore.HandleNull(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : -null-')
|
|
||||||
else
|
|
||||||
aResultSL.Add('-null-');
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleBool(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : ' + BoolToStr(aValue.GetBool, true))
|
|
||||||
else
|
|
||||||
aResultSL.Add(BoolToStr(aValue.GetBool, true));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleInteger(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : ' + IntToStr(aValue.GetInt))
|
|
||||||
else
|
|
||||||
aResultSL.Add(IntToStr(aValue.GetInt));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleDouble(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : ' + FloatToStr(aValue.GetDouble))
|
|
||||||
else
|
|
||||||
aResultSL.Add(FloatToStr(aValue.GetDouble));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleString(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : ' + aValue.GetString)
|
|
||||||
else
|
|
||||||
aResultSL.Add(aValue.GetString);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleBinary(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : -binary-')
|
|
||||||
else
|
|
||||||
aResultSL.Add('-binary-');
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleList(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey, TempResult : string;
|
|
||||||
i, j : integer;
|
|
||||||
TempList : ICefListValue;
|
|
||||||
TempValue : ICefValue;
|
|
||||||
TempSL : TStringList;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
TempList := aValue.GetList;
|
|
||||||
TempSL := TStringList.Create;
|
|
||||||
|
|
||||||
i := 0;
|
|
||||||
j := TempList.GetSize;
|
|
||||||
|
|
||||||
TempResult := '(' + inttostr(j) + '){';
|
|
||||||
|
|
||||||
while (i < j) do
|
|
||||||
begin
|
|
||||||
TempValue := TempList.GetValue(i);
|
|
||||||
|
|
||||||
case TempValue.GetType of
|
|
||||||
VTYPE_NULL : TempResult := TempResult + '-null-,';
|
|
||||||
VTYPE_BOOL : TempResult := TempResult + BoolToStr(TempValue.GetBool, true) + ',';
|
|
||||||
VTYPE_INT : TempResult := TempResult + IntToStr(TempValue.GetInt) + ',';
|
|
||||||
VTYPE_DOUBLE : TempResult := TempResult + FloatToStr(TempValue.GetDouble) + ',';
|
|
||||||
VTYPE_STRING : TempResult := TempResult + TempValue.GetString + ',';
|
|
||||||
VTYPE_BINARY : TempResult := TempResult + '-binary-,';
|
|
||||||
VTYPE_DICTIONARY :
|
|
||||||
begin
|
|
||||||
TempSL.Clear;
|
|
||||||
HandleDictionary(TempValue.GetDictionary, TempSL, '');
|
|
||||||
TempResult := TempResult + TempSL.CommaText + ',';
|
|
||||||
end;
|
|
||||||
|
|
||||||
VTYPE_LIST :
|
|
||||||
begin
|
|
||||||
TempSL.Clear;
|
|
||||||
HandleList(TempValue, TempSL, '', '');
|
|
||||||
TempResult := TempResult + TempSL.CommaText + ',';
|
|
||||||
end;
|
|
||||||
|
|
||||||
else TempResult := TempResult + '-invalid-,';
|
|
||||||
end;
|
|
||||||
|
|
||||||
inc(i);
|
|
||||||
end;
|
|
||||||
|
|
||||||
i := length(TempResult);
|
|
||||||
if (i > 0) and (TempResult[i] = ',') then TempResult := copy(TempResult, 1, pred(i));
|
|
||||||
TempResult := TempResult + '}';
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : ' + TempResult)
|
|
||||||
else
|
|
||||||
aResultSL.Add(TempResult);
|
|
||||||
|
|
||||||
TempSL.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleInvalid(const aValue : ICefValue; var aResultSL : TStringList; const aRoot, aKey : string);
|
|
||||||
var
|
|
||||||
TempKey : string;
|
|
||||||
begin
|
|
||||||
if (aRoot <> '') then
|
|
||||||
TempKey := aRoot + '.' + aKey
|
|
||||||
else
|
|
||||||
TempKey := aKey;
|
|
||||||
|
|
||||||
if (length(TempKey) > 0) then
|
|
||||||
aResultSL.Add(TempKey + ' : -invalid-')
|
|
||||||
else
|
|
||||||
aResultSL.Add('-invalid-');
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TChromiumCore.HandleDictionary(const aDict : ICefDictionaryValue; var aResultSL : TStringList; const aRoot : string);
|
|
||||||
var
|
|
||||||
TempKeys : TStringList;
|
|
||||||
i, j : integer;
|
|
||||||
TempValue : ICefValue;
|
|
||||||
TempNewKey : string;
|
|
||||||
begin
|
|
||||||
TempKeys := nil;
|
|
||||||
|
|
||||||
try
|
|
||||||
try
|
|
||||||
if (aDict <> nil) then
|
|
||||||
begin
|
|
||||||
TempKeys := TStringList.Create;
|
|
||||||
aDict.GetKeys(TempKeys);
|
|
||||||
|
|
||||||
i := 0;
|
|
||||||
j := TempKeys.Count;
|
|
||||||
|
|
||||||
while (i < j) do
|
|
||||||
begin
|
|
||||||
TempValue := aDict.GetValue(TempKeys[i]);
|
|
||||||
|
|
||||||
case TempValue.GetType of
|
|
||||||
VTYPE_NULL : HandleNull(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_BOOL : HandleBool(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_INT : HandleInteger(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_DOUBLE : HandleDouble(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_STRING : HandleString(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_BINARY : HandleBinary(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_LIST : HandleList(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
VTYPE_DICTIONARY :
|
|
||||||
begin
|
|
||||||
if (length(aRoot) > 0) then
|
|
||||||
TempNewKey := aRoot + '.' + TempKeys[i]
|
|
||||||
else
|
|
||||||
TempNewKey := TempKeys[i];
|
|
||||||
|
|
||||||
HandleDictionary(TempValue.GetDictionary, aResultSL, TempNewKey);
|
|
||||||
end;
|
|
||||||
|
|
||||||
else
|
|
||||||
HandleInvalid(TempValue, aResultSL, aRoot, TempKeys[i]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
inc(i);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
on e : exception do
|
|
||||||
if CustomExceptionHandler('TChromiumCore.HandleDictionary', e) then raise;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
if (TempKeys <> nil) then TempKeys.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TChromiumCore.doSavePreferences : boolean;
|
function TChromiumCore.doSavePreferences : boolean;
|
||||||
{$IFDEF MSWINDOWS}
|
|
||||||
var
|
|
||||||
TempDict : ICefDictionaryValue;
|
|
||||||
TempPrefs : TStringList;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := Initialized and
|
||||||
{$IFDEF MSWINDOWS}
|
TCEFJson.SaveToFile(Browser.Host.RequestContext.GetAllPreferences(True), FPrefsFileName);
|
||||||
TempPrefs := nil;
|
|
||||||
|
|
||||||
try
|
{$IFDEF MSWINDOWS}
|
||||||
try
|
SendCompMessage(CEF_PREFERENCES_SAVED, Ord(Result));
|
||||||
if Initialized then
|
|
||||||
begin
|
|
||||||
TempPrefs := TStringList.Create;
|
|
||||||
TempDict := Browser.Host.RequestContext.GetAllPreferences(True);
|
|
||||||
HandleDictionary(TempDict, TempPrefs, '');
|
|
||||||
TempPrefs.SaveToFile(FPrefsFileName);
|
|
||||||
Result := True;
|
|
||||||
end;
|
|
||||||
except
|
|
||||||
on e : exception do
|
|
||||||
if CustomExceptionHandler('TChromiumCore.Internal_SavePreferences', e) then raise;
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
SendCompMessage(CEF_PREFERENCES_SAVED, Ord(Result));
|
|
||||||
if (TempPrefs <> nil) then FreeAndNil(TempPrefs);
|
|
||||||
end;
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ uses
|
|||||||
{$ELSE}
|
{$ELSE}
|
||||||
SysUtils,
|
SysUtils,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser;
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFJson;
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
@ -108,7 +108,7 @@ begin
|
|||||||
|
|
||||||
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
||||||
try
|
try
|
||||||
TempValue := CefParseJson(message_, message_size);
|
TempValue := TCEFJson.Parse(message_, message_size);
|
||||||
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMessage(TCefBrowserRef.UnWrap(browser),
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMessage(TCefBrowserRef.UnWrap(browser),
|
||||||
TempValue,
|
TempValue,
|
||||||
TempHandled);
|
TempHandled);
|
||||||
@ -133,7 +133,7 @@ begin
|
|||||||
|
|
||||||
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
||||||
try
|
try
|
||||||
TempValue := CefParseJson(result, result_size);
|
TempValue := TCEFJson.Parse(result, result_size);
|
||||||
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMethodResult(TCefBrowserRef.UnWrap(browser),
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMethodResult(TCefBrowserRef.UnWrap(browser),
|
||||||
message_id,
|
message_id,
|
||||||
success <> 0,
|
success <> 0,
|
||||||
@ -156,7 +156,7 @@ begin
|
|||||||
|
|
||||||
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then
|
||||||
try
|
try
|
||||||
TempValue := CefParseJson(params, params_size);
|
TempValue := TCEFJson.Parse(params, params_size);
|
||||||
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(TCefBrowserRef.UnWrap(browser),
|
TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(TCefBrowserRef.UnWrap(browser),
|
||||||
CefString(method),
|
CefString(method),
|
||||||
TempValue);
|
TempValue);
|
||||||
|
@ -37,10 +37,24 @@
|
|||||||
|
|
||||||
unit uCEFJson;
|
unit uCEFJson;
|
||||||
|
|
||||||
|
{$IFDEF FPC}
|
||||||
|
{$MODE OBJFPC}{$H+}
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
||||||
|
{$MINENUMSIZE 4}
|
||||||
|
|
||||||
|
{$I cef.inc}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
uCEFInterfaces;
|
{$IFDEF DELPHI16_UP}
|
||||||
|
System.Classes, System.SysUtils,
|
||||||
|
{$ELSE}
|
||||||
|
Classes, SysUtils,
|
||||||
|
{$ENDIF}
|
||||||
|
uCEFInterfaces, uCEFTypes, uCEFConstants;
|
||||||
|
|
||||||
type
|
type
|
||||||
TCEFJson = class
|
TCEFJson = class
|
||||||
@ -53,12 +67,23 @@ type
|
|||||||
class function ReadBinary(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefBinaryValue) : boolean;
|
class function ReadBinary(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefBinaryValue) : boolean;
|
||||||
class function ReadDictionary(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefDictionaryValue) : boolean;
|
class function ReadDictionary(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefDictionaryValue) : boolean;
|
||||||
class function ReadList(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefListValue) : boolean;
|
class function ReadList(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefListValue) : boolean;
|
||||||
|
|
||||||
|
class function Parse(const jsonString: ustring; options: TCefJsonParserOptions = JSON_PARSER_RFC): ICefValue; overload;
|
||||||
|
class function Parse(const json: Pointer; json_size: NativeUInt; options: TCefJsonParserOptions = JSON_PARSER_RFC): ICefValue; overload;
|
||||||
|
class function ParseAndReturnError(const jsonString: ustring; options: TCefJsonParserOptions; out errorCodeOut: TCefJsonParserError; out errorMsgOut: ustring): ICefValue;
|
||||||
|
class function Write(const node: ICefValue; options: TCefJsonWriterOptions = JSON_WRITER_DEFAULT): ustring; overload;
|
||||||
|
class function Write(const node: ICefDictionaryValue; options: TCefJsonWriterOptions = JSON_WRITER_DEFAULT): ustring; overload;
|
||||||
|
class function Write(const node: ICefValue; var aRsltStrings: TStringList): boolean; overload;
|
||||||
|
class function Write(const node: ICefDictionaryValue; var aRsltStrings: TStringList): boolean; overload;
|
||||||
|
class function SaveToFile(const node: ICefValue; const aFileName: ustring): boolean; overload;
|
||||||
|
class function SaveToFile(const node: ICefDictionaryValue; const aFileName: ustring): boolean; overload;
|
||||||
|
class function LoadFromFile(const aFileName: ustring; var aRsltNode: ICefValue; encoding: TEncoding = nil; options: TCefJsonParserOptions = JSON_PARSER_RFC): boolean;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
uCEFTypes;
|
uCEFLibFunctions, uCEFApplicationCore, uCEFMiscFunctions, uCEFValue;
|
||||||
|
|
||||||
class function TCEFJson.ReadValue(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefValue) : boolean;
|
class function TCEFJson.ReadValue(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefValue) : boolean;
|
||||||
begin
|
begin
|
||||||
@ -177,4 +202,184 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.Parse(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
|
||||||
|
var
|
||||||
|
TempJSON : TCefString;
|
||||||
|
begin
|
||||||
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
||||||
|
begin
|
||||||
|
TempJSON := CefString(jsonString);
|
||||||
|
Result := TCefValueRef.UnWrap(cef_parse_json(@TempJSON, options));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// json must be a pointer to a UTF8 string
|
||||||
|
class function TCEFJson.Parse(const json: Pointer; json_size: NativeUInt; options: TCefJsonParserOptions): ICefValue;
|
||||||
|
begin
|
||||||
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded and (json <> nil) and (json_size > 0) then
|
||||||
|
Result := TCefValueRef.UnWrap(cef_parse_json_buffer(json, json_size, options))
|
||||||
|
else
|
||||||
|
Result := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.ParseAndReturnError(const jsonString : ustring;
|
||||||
|
options : TCefJsonParserOptions;
|
||||||
|
out errorCodeOut : TCefJsonParserError;
|
||||||
|
out errorMsgOut : ustring): ICefValue;
|
||||||
|
var
|
||||||
|
TempJSON, TempError : TCefString;
|
||||||
|
begin
|
||||||
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
||||||
|
begin
|
||||||
|
CefStringInitialize(@TempError);
|
||||||
|
TempJSON := CefString(jsonString);
|
||||||
|
Result := TCefValueRef.UnWrap(cef_parse_jsonand_return_error(@TempJSON, options, @errorCodeOut, @TempError));
|
||||||
|
errorMsgOut := CefStringClearAndGet(@TempError);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
errorCodeOut := JSON_NO_ERROR;
|
||||||
|
Result := nil;
|
||||||
|
errorMsgOut := '';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.Write(const node: ICefValue; options: TCefJsonWriterOptions): ustring;
|
||||||
|
begin
|
||||||
|
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded and (node <> nil) then
|
||||||
|
Result := CefStringFreeAndGet(cef_write_json(CefGetData(node), options))
|
||||||
|
else
|
||||||
|
Result := '';
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.Write(const node: ICefDictionaryValue; options: TCefJsonWriterOptions): ustring;
|
||||||
|
var
|
||||||
|
TempValue : ICefValue;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
|
||||||
|
if (node = nil) then exit;
|
||||||
|
|
||||||
|
try
|
||||||
|
TempValue := TCefValueRef.New;
|
||||||
|
TempValue.SetDictionary(node);
|
||||||
|
Result := Write(TempValue, options);
|
||||||
|
finally
|
||||||
|
TempValue := nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.Write(const node: ICefValue; var aRsltStrings: TStringList): boolean;
|
||||||
|
var
|
||||||
|
TempJSON : ustring;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if (aRsltStrings <> nil) then
|
||||||
|
begin
|
||||||
|
TempJSON := Write(node, JSON_WRITER_PRETTY_PRINT);
|
||||||
|
|
||||||
|
if (length(TempJSON) > 0) then
|
||||||
|
begin
|
||||||
|
aRsltStrings.SetText(@TempJSON[1]);
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.Write(const node: ICefDictionaryValue; var aRsltStrings: TStringList): boolean;
|
||||||
|
var
|
||||||
|
TempJSON : ustring;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if (aRsltStrings <> nil) then
|
||||||
|
begin
|
||||||
|
TempJSON := Write(node, JSON_WRITER_PRETTY_PRINT);
|
||||||
|
|
||||||
|
if (length(TempJSON) > 0) then
|
||||||
|
begin
|
||||||
|
aRsltStrings.SetText(@TempJSON[1]);
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.SaveToFile(const node: ICefValue; const aFileName: ustring): boolean;
|
||||||
|
var
|
||||||
|
TempJSON : TStringList;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
TempJSON := nil;
|
||||||
|
|
||||||
|
try
|
||||||
|
try
|
||||||
|
TempJSON := TStringList.Create;
|
||||||
|
|
||||||
|
if Write(node, TempJSON) then
|
||||||
|
begin
|
||||||
|
TempJSON.SaveToFile(aFileName);
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCEFJson.SaveToFile', e) then raise;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
if (TempJSON <> nil) then FreeAndNil(TempJSON);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.SaveToFile(const node: ICefDictionaryValue; const aFileName: ustring): boolean;
|
||||||
|
var
|
||||||
|
TempJSON : TStringList;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
TempJSON := nil;
|
||||||
|
|
||||||
|
try
|
||||||
|
try
|
||||||
|
TempJSON := TStringList.Create;
|
||||||
|
|
||||||
|
if Write(node, TempJSON) then
|
||||||
|
begin
|
||||||
|
TempJSON.SaveToFile(aFileName);
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCEFJson.SaveToFile', e) then raise;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
if (TempJSON <> nil) then FreeAndNil(TempJSON);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCEFJson.LoadFromFile(const aFileName: ustring; var aRsltNode: ICefValue; encoding: TEncoding; options: TCefJsonParserOptions): boolean;
|
||||||
|
var
|
||||||
|
TempJSON : TStringList;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
TempJSON := nil;
|
||||||
|
|
||||||
|
try
|
||||||
|
try
|
||||||
|
if (length(aFileName) > 0) and FileExists(aFileName) then
|
||||||
|
begin
|
||||||
|
TempJSON := TStringList.Create;
|
||||||
|
TempJSON.LoadFromFile(aFileName, encoding);
|
||||||
|
aRsltNode := Parse(TempJSON.Text, options);
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
on e : exception do
|
||||||
|
if CustomExceptionHandler('TCEFJson.LoadFromFile', e) then raise;
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
if (TempJSON <> nil) then FreeAndNil(TempJSON);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -245,14 +245,6 @@ function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRule:
|
|||||||
|
|
||||||
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
||||||
|
|
||||||
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions = JSON_PARSER_RFC): ICefValue; overload;
|
|
||||||
function CefParseJson(const json: Pointer; json_size: NativeUInt; options: TCefJsonParserOptions = JSON_PARSER_RFC): ICefValue; overload;
|
|
||||||
function CefParseJsonAndReturnError(const jsonString : ustring;
|
|
||||||
options : TCefJsonParserOptions;
|
|
||||||
out errorCodeOut : TCefJsonParserError;
|
|
||||||
out errorMsgOut : ustring): ICefValue;
|
|
||||||
function CefWriteJson(const node: ICefValue; options: TCefJsonWriterOptions): ustring;
|
|
||||||
|
|
||||||
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
||||||
function CefGetTempDirectory(out tempDir: ustring): Boolean;
|
function CefGetTempDirectory(out tempDir: ustring): Boolean;
|
||||||
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
|
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
|
||||||
@ -1805,49 +1797,6 @@ begin
|
|||||||
Result := '';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
|
|
||||||
var
|
|
||||||
TempJSON : TCefString;
|
|
||||||
begin
|
|
||||||
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
||||||
begin
|
|
||||||
TempJSON := CefString(jsonString);
|
|
||||||
Result := TCefValueRef.UnWrap(cef_parse_json(@TempJSON, options));
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CefParseJson(const json: Pointer; json_size: NativeUInt; options: TCefJsonParserOptions): ICefValue;
|
|
||||||
begin
|
|
||||||
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded and (json <> nil) and (json_size > 0) then
|
|
||||||
Result := TCefValueRef.UnWrap(cef_parse_json_buffer(json, json_size, options))
|
|
||||||
else
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CefParseJsonAndReturnError(const jsonString : ustring;
|
|
||||||
options : TCefJsonParserOptions;
|
|
||||||
out errorCodeOut : TCefJsonParserError;
|
|
||||||
out errorMsgOut : ustring): ICefValue;
|
|
||||||
var
|
|
||||||
TempJSON, TempError : TCefString;
|
|
||||||
begin
|
|
||||||
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
||||||
begin
|
|
||||||
CefStringInitialize(@TempError);
|
|
||||||
TempJSON := CefString(jsonString);
|
|
||||||
Result := TCefValueRef.UnWrap(cef_parse_jsonand_return_error(@TempJSON, options, @errorCodeOut, @TempError));
|
|
||||||
errorMsgOut := CefStringClearAndGet(@TempError);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
errorCodeOut := JSON_NO_ERROR;
|
|
||||||
Result := nil;
|
|
||||||
errorMsgOut := '';
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
function CefGetPath(const aPathKey : TCefPathKey) : ustring;
|
||||||
var
|
var
|
||||||
TempPath : TCefString;
|
TempPath : TCefString;
|
||||||
@ -1863,14 +1812,6 @@ begin
|
|||||||
Result := '';
|
Result := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CefWriteJson(const node: ICefValue; options: TCefJsonWriterOptions): ustring;
|
|
||||||
begin
|
|
||||||
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
|
|
||||||
Result := CefStringFreeAndGet(cef_write_json(CefGetData(node), options))
|
|
||||||
else
|
|
||||||
Result := '';
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
function CefCreateDirectory(const fullPath: ustring): Boolean;
|
||||||
var
|
var
|
||||||
TempPath : TCefString;
|
TempPath : TCefString;
|
||||||
|
@ -156,7 +156,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
{$IFDEF DELPHI22_UP}System.Hash,{$ENDIF}
|
{$IFDEF DELPHI22_UP}System.Hash,{$ENDIF}
|
||||||
{$IFDEF FPC}DCPSha256,{$ENDIF}
|
{$IFDEF FPC}DCPSha256,{$ENDIF}
|
||||||
uCEFMiscFunctions;
|
uCEFMiscFunctions, uCEFJson;
|
||||||
|
|
||||||
constructor TCEFOAuth2Helper.Create;
|
constructor TCEFOAuth2Helper.Create;
|
||||||
begin
|
begin
|
||||||
@ -391,7 +391,7 @@ begin
|
|||||||
try
|
try
|
||||||
if (length(aResponse) > 0) then
|
if (length(aResponse) > 0) then
|
||||||
begin
|
begin
|
||||||
TempRoot := CefParseJson(aResponse, JSON_PARSER_RFC);
|
TempRoot := TCEFJson.Parse(aResponse);
|
||||||
|
|
||||||
if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then
|
if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then
|
||||||
begin
|
begin
|
||||||
@ -432,7 +432,7 @@ begin
|
|||||||
try
|
try
|
||||||
if (length(aResponse) > 0) then
|
if (length(aResponse) > 0) then
|
||||||
begin
|
begin
|
||||||
TempRoot := CefParseJson(aResponse, JSON_PARSER_RFC);
|
TempRoot := TCEFJson.Parse(aResponse);
|
||||||
|
|
||||||
if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then
|
if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then
|
||||||
begin
|
begin
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 163,
|
"InternalVersion" : 164,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "83.5.0.0"
|
"Version" : "83.5.0.0"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user