monkeyxu / dcef3

Automatically exported from code.google.com/p/dcef3
0 stars 0 forks source link

CefRegisterExtension always false #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Any example of using CefRegisterExtension not work
CefRegisterExtension always return false and extension not work

Original issue reported on code.google.com by vGhost2...@gmail.com on 8 Jul 2013 at 9:32

GoogleCodeExporter commented 9 years ago
verified

Original comment by lmf1...@gmail.com on 6 Aug 2013 at 1:14

GoogleCodeExporter commented 9 years ago
Strangely, BUT this code work fine:

// .....
type

  TMyExtension = class(TThread) // or just class, (extension code execute in thread)
    class function call(const arg1, arg2: ICefv8Value): string;
  end;

  TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn)
  protected
    procedure OnWebKitInitialized; override;
  end;

implementation

// .....

procedure TCustomRenderProcessHandler.OnWebKitInitialized;
begin
  {In webPage <script> alert( MyEXT.call('arg1', 'arg2') ); <script>}
  TCefRTTIExtension.Register('MyEXT', TMyExtension);
end;

class function TMyExtension.call;
begin
  // some code
  result := 'result from Delphi XE2: ' + arg1.GetStringValue;
end

initialization
  CefRenderProcessHandler := TCustomRenderProcessHandler.Create;
end.

-------------------------------------------

To add MyEXT.SomeAnotherFunc() in js, just add
class function TMyExtension.SomeAnotherFunc;

Original comment by vGhost2...@gmail.com on 6 Aug 2013 at 5:36

GoogleCodeExporter commented 9 years ago
And I think this is more scalable than using CefRegisterExtension.
The issue may be closed.

Original comment by vGhost2...@gmail.com on 6 Aug 2013 at 5:47

GoogleCodeExporter commented 9 years ago
class function hello: ICefv8value;

  ret := TCefv8ValueRef.NewArray(2);
  ret.SetValueByIndex(0,TCefv8ValueRef.NewString('qwe'));
  ret.SetValueByIndex(1,TCefv8ValueRef.NewString('asd'));
  result := TCefv8ValueRef.NewObject(nil);
  result.SetUserData(ret);

on return empty object

Original comment by amphilim...@gmail.com on 21 Aug 2014 at 4:53