RuidSiel / chromiumembedded

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

OnJSBinding handler executed twice per page #359

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently OnJSBinding handler executed twice per page, it happens 'cause it 
executed from didClearWindowObject.
As i understood that didClearWindowObject used to prepare window object and 
clear window object when page is unloaded, or something else.

In fact it executed in this order:
OnJSBinding
OnLoadStart
OnJSBinding
...look as html parser works...
OnLoadEnd

But second page load (navigating by url, etc...) have little other order:

OnLoadStart
OnJSBinding
OnJSBinding
...look as html parser works...
OnLoadEnd

Original issue reported on code.google.com by fdd...@gmail.com on 1 Oct 2011 at 8:57

GoogleCodeExporter commented 9 years ago
Is it related to the following piece of code in 
V8DOMWindowShell::initContextIfNeeded()?

    // FIXME: This is wrong. We should actually do this for the proper world once
    // we do isolated worlds the WebCore way.
    m_frame->loader()->dispatchDidClearWindowObjectInWorld(0);

Original comment by emerick on 18 Nov 2011 at 9:23

GoogleCodeExporter commented 9 years ago
Based on the comment for this function, maybe this is a better delegate to 
implement for this purpose:

    // Notifies that a new script context has been created for this frame.
    // This is similar to didClearWindowObject but only called once per
    // frame context.
    virtual void didCreateScriptContext(WebFrame*) { }

It seems to imply that didClearWindowObject can be called multiple times per 
frame whereas this delegate is called only once.

Original comment by emerick on 21 Nov 2011 at 8:27

GoogleCodeExporter commented 9 years ago
I'm in the process of eliminating didClearWindowObject usage in favor of 
didCreateScriptContext. Changes to land this afternoon.

Original comment by magreenb...@gmail.com on 21 Nov 2011 at 8:45

GoogleCodeExporter commented 9 years ago
Fantastic, thanks!

Original comment by emerick on 21 Nov 2011 at 8:47

GoogleCodeExporter commented 9 years ago
Revision 392 replaces JSBindingHandler with a new V8ContextHandler interface 
that contains callbacks for V8 context creation and release.

Old code:

virtual void OnJSBinding(CefRefPtr<CefBrowser> browser,
                         CefRefPtr<CefFrame> frame,
                         CefRefPtr<CefV8Value> object) OVERRIDE
{
  // ...
}

New code:

virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
                              CefRefPtr<CefFrame> frame,
                              CefRefPtr<CefV8Context> context) OVERRIDE
{
  // Retrieve the 'window' object.
  CefRefPtr<CefV8Value> object = context->GetGlobal();

  // ...
}

Original comment by magreenb...@gmail.com on 21 Nov 2011 at 9:27