From dceb2299e35c869b4f132ebc2544a202d3e9ed88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Fri, 17 Jul 2020 12:56:43 +0200 Subject: [PATCH] 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 --- demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas | 17 +- source/uCEFChromiumCore.pas | 269 +------------------- source/uCEFDevToolsMessageObserver.pas | 8 +- source/uCEFJson.pas | 209 ++++++++++++++- source/uCEFMiscFunctions.pas | 59 ----- source/uCEFOAuth2Helper.pas | 6 +- update_CEF4Delphi.json | 2 +- 7 files changed, 231 insertions(+), 339 deletions(-) diff --git a/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas b/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas index bafca0cb..1c2873dd 100644 --- a/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas +++ b/demos/Delphi_VCL/DOMVisitor/uDOMVisitor.pas @@ -212,7 +212,7 @@ implementation // TChromium.OnConsoleMessage event and we identify the right message thanks to // 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 // TChromium.ExecuteDevToolsMethod function and the results are received in the // TChromium.OnDevToolsMethodResult event. @@ -288,14 +288,19 @@ procedure SimpleNodeSearch(const aDocument: ICefDomDocument; const aFrame : ICef // known preamble that will be used to identify the message in the // TChromium.OnConsoleMessage event. - // CEF has some known issues with ICefDomNode.GetValue and ICefDomNode.SetValue - // Use JavaScript if you need to get or set the value of HTML elements. + // NOTE : In case you try to read or write node values using the CEF API + // 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 // to get the value of the search box in our forum you would have to // execute this JavaScript code : // console.log("DOMVISITOR" + document.getElementById("keywords").value); - TempMessage := 'name:' + quotedstr(TempNode.Name); + TempMessage := 'name:' + TempNode.Name; TempJSCode := 'console.log("' + CONSOLE_MSG_PREAMBLE + TempMessage + '");'; aFrame.ExecuteJavaScript(TempJSCode, 'about:blank', 0); end; @@ -531,9 +536,9 @@ procedure TDOMVisitorFrm.Chromium1ConsoleMessage(Sender: TObject; MsgContents := copy(message, succ(length(CONSOLE_MSG_PREAMBLE)), length(message)); if (length(MsgContents) = 0) then - MsgContents := 'The INPUT node has no value' + MsgContents := 'There was an error reading the search box information' else - MsgContents := 'INPUT node value : ' + quotedstr(MsgContents); + MsgContents := 'Search box information: ' + quotedstr(MsgContents); PostMessage(Handle, MINIBROWSER_SHOWMESSAGE, 0, 0); end; diff --git a/source/uCEFChromiumCore.pas b/source/uCEFChromiumCore.pas index 78c8b1c6..57c42037 100644 --- a/source/uCEFChromiumCore.pas +++ b/source/uCEFChromiumCore.pas @@ -406,16 +406,6 @@ TChromiumCore = class(TComponent, IChromiumEvents) function UpdatePreference(const aBrowser: ICefBrowser; const aName : ustring; const aValue : TStringList) : boolean; overload; 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 ExecuteUpdateZoomPctTask(aInc : boolean) : boolean; function ExecuteReadZoomTask : boolean; @@ -1104,7 +1094,7 @@ implementation uCEFDownloadImageCallBack, uCEFCookieManager, uCEFRequestContextHandler, uCEFCookieVisitor, uCEFSetCookieCallback, uCEFResourceRequestHandler, uCEFMediaObserver, uCEFMediaRouteCreateCallback ,uCEFDevToolsMessageObserver, - uCEFMediaSinkDeviceInfoCallback; + uCEFMediaSinkDeviceInfoCallback, uCEFJson; constructor TChromiumCore.Create(AOwner: TComponent); begin @@ -4099,262 +4089,13 @@ function TChromiumCore.UpdateStringListPref(const aBrowser: ICefBrowser; const a 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; -{$IFDEF MSWINDOWS} -var - TempDict : ICefDictionaryValue; - TempPrefs : TStringList; -{$ENDIF} begin - Result := False; - {$IFDEF MSWINDOWS} - TempPrefs := nil; + Result := Initialized and + TCEFJson.SaveToFile(Browser.Host.RequestContext.GetAllPreferences(True), FPrefsFileName); - try - try - 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; + {$IFDEF MSWINDOWS} + SendCompMessage(CEF_PREFERENCES_SAVED, Ord(Result)); {$ENDIF} end; diff --git a/source/uCEFDevToolsMessageObserver.pas b/source/uCEFDevToolsMessageObserver.pas index 80c6a7c0..eba7bd61 100644 --- a/source/uCEFDevToolsMessageObserver.pas +++ b/source/uCEFDevToolsMessageObserver.pas @@ -87,7 +87,7 @@ implementation {$ELSE} SysUtils, {$ENDIF} - uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser; + uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFJson; // ************************************************************ @@ -108,7 +108,7 @@ function cef_on_dev_tools_message( self : PCefDevToolsMessageObserv if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then try - TempValue := CefParseJson(message_, message_size); + TempValue := TCEFJson.Parse(message_, message_size); TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMessage(TCefBrowserRef.UnWrap(browser), TempValue, TempHandled); @@ -133,7 +133,7 @@ procedure cef_on_dev_tools_method_result( self : PCefDevToolsMessage if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then try - TempValue := CefParseJson(result, result_size); + TempValue := TCEFJson.Parse(result, result_size); TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsMethodResult(TCefBrowserRef.UnWrap(browser), message_id, success <> 0, @@ -156,7 +156,7 @@ procedure cef_on_dev_tools_event( self : PCefDevToolsMessageObserver if (TempObject <> nil) and (TempObject is TCEFDevToolsMessageObserverOwn) then try - TempValue := CefParseJson(params, params_size); + TempValue := TCEFJson.Parse(params, params_size); TCEFDevToolsMessageObserverOwn(TempObject).OnDevToolsEvent(TCefBrowserRef.UnWrap(browser), CefString(method), TempValue); diff --git a/source/uCEFJson.pas b/source/uCEFJson.pas index f726b02e..dd1a615c 100644 --- a/source/uCEFJson.pas +++ b/source/uCEFJson.pas @@ -37,10 +37,24 @@ unit uCEFJson; +{$IFDEF FPC} + {$MODE OBJFPC}{$H+} +{$ENDIF} + +{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF} +{$MINENUMSIZE 4} + +{$I cef.inc} + interface uses - uCEFInterfaces; + {$IFDEF DELPHI16_UP} + System.Classes, System.SysUtils, + {$ELSE} + Classes, SysUtils, + {$ENDIF} + uCEFInterfaces, uCEFTypes, uCEFConstants; type TCEFJson = class @@ -53,12 +67,23 @@ TCEFJson = class 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 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; implementation uses - uCEFTypes; + uCEFLibFunctions, uCEFApplicationCore, uCEFMiscFunctions, uCEFValue; class function TCEFJson.ReadValue(const aDictionary : ICefDictionaryValue; const aKey : string; var aValue : ICefValue) : boolean; begin @@ -177,4 +202,184 @@ class function TCEFJson.ReadList(const aDictionary : ICefDictionaryValue; const 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. diff --git a/source/uCEFMiscFunctions.pas b/source/uCEFMiscFunctions.pas index a5c7fcb2..a30d7faf 100644 --- a/source/uCEFMiscFunctions.pas +++ b/source/uCEFMiscFunctions.pas @@ -245,14 +245,6 @@ function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRule: 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 CefGetTempDirectory(out tempDir: ustring): Boolean; function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean; @@ -1805,49 +1797,6 @@ function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRule: Result := ''; 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; var TempPath : TCefString; @@ -1863,14 +1812,6 @@ function CefGetPath(const aPathKey : TCefPathKey) : ustring; Result := ''; 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; var TempPath : TCefString; diff --git a/source/uCEFOAuth2Helper.pas b/source/uCEFOAuth2Helper.pas index 69dbc2f3..fd5515ae 100644 --- a/source/uCEFOAuth2Helper.pas +++ b/source/uCEFOAuth2Helper.pas @@ -156,7 +156,7 @@ implementation uses {$IFDEF DELPHI22_UP}System.Hash,{$ENDIF} {$IFDEF FPC}DCPSha256,{$ENDIF} - uCEFMiscFunctions; + uCEFMiscFunctions, uCEFJson; constructor TCEFOAuth2Helper.Create; begin @@ -391,7 +391,7 @@ function TCEFOAuth2Helper.ParseTokenExchangeResponse(const aResponse : ustring) try if (length(aResponse) > 0) then begin - TempRoot := CefParseJson(aResponse, JSON_PARSER_RFC); + TempRoot := TCEFJson.Parse(aResponse); if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then begin @@ -432,7 +432,7 @@ function TCEFOAuth2Helper.ParseRefreshTokenResponse(const aResponse : ustring) : try if (length(aResponse) > 0) then begin - TempRoot := CefParseJson(aResponse, JSON_PARSER_RFC); + TempRoot := TCEFJson.Parse(aResponse); if (TempRoot <> nil) and (TempRoot.GetType = VTYPE_DICTIONARY) then begin diff --git a/update_CEF4Delphi.json b/update_CEF4Delphi.json index 83570ef2..90e8ddd7 100644 --- a/update_CEF4Delphi.json +++ b/update_CEF4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 163, + "InternalVersion" : 164, "Name" : "cef4delphi_lazarus.lpk", "Version" : "83.5.0.0" }