We have a C++ application that calls a JS based XPCOM component and passes it a nsIDOMWindow object. But we have trouble registering event handlers for the DOM window.

// based on mozembed / https://wiki.mozilla.org/Embedding/NewApi

 nsCOMPtr<nsIWebBrowser> mWebBrowser;

..

NS_IMETHODIMP WebBrowserChrome::OnStateChange(
        nsIWebProgress  *aWebProgress,
        nsIRequest *aRequest,
        PRUint32 aStateFlags, nsresult aStatus)
{
   nsCOMPtr<nsIDOMWindow> contentWin;
   nsresult rv_contentWin =
      mWebBrowser->GetContentDOMWindow(getter_AddRefs(contentWin));

   // m_c is the our component
   nsresult rv = m_c->SetBrowserWindow(contentWin);

}

Inside the component we want to register events on the passed window object.


// the component's interface

[scriptable, uuid(1b0946b6-0e2d-4848-ae6b-299052d7a19d)]
interface OurComponent : nsISupports
{
    void setBrowserWindow(in nsIDOMWindow win);
    // other methods
};


// The implementation looks like this:

  setBrowserWindow : function (browserWindow) {
     browserWindow.document.location = "http://foo.com/";;
     browserWindow.addEventListener("DOMContentLoaded",
                                      function() {
                                          dump("Called\n");
                                      }, false);
  }

The code executes without errors, however the registered events are not triggered.

It looks like registering for events on the document (browserWindow.document) object itself works just fine (such as mouseover).

Is it possible that we have missed some security restrictions that prevents registering events on the window object events?

Any hints appreciated. Thanks.

/ Adam
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to