Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

nsIURIContentListener exception?

1 view
Skip to first unread message

poopdawg

unread,
Jun 13, 2008, 9:08:41 AM6/13/08
to
im trying to extend pelle's win32 sample code by adding a URI
listener.

i inherited & stubbed nsIURIContentListener in webbrowserchrome.

i added this line after baseWindow->Create():

//rv returns 0
rv = webBrowser-
>SetParentURIContentListener((nsIURIContentListener*)(chrome.get()) );

i get a unhandled exception (0×0041b025) when i click on a link. here
is the stack:

nsCOMPtr_base::assign_with_AddRef()
nsCOMPtr::operator=(nsIWebBrowser * rhs=0×025371d0)
WebBrowserChrome::SetWebBrowser(nsIWebBrowser *
aWebBrowser=0×025371d0)

im new to mozilla stuff - am i creating the listener correctly? do i
need to replace the assignment with some sort of addref?

thanks
amitabh

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

NS_IMETHODIMP WebBrowserChrome::SetWebBrowser(nsIWebBrowser *
aWebBrowser)
{
mWebBrowser = aWebBrowser;
return NS_OK;
}

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

nsresult MozEmbed::CreateBrowser(void* aNativeWindow, PRInt32 x,
PRInt32 y, PRInt32 width, PRInt32 height)
{
nativeWindow = aNativeWindow;

nsresult rv;

nsCOMPtr<nsIBaseWindow> baseWindow;
webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
printf("do_CreateInstance webBrowser\n");
}
baseWindow = do_QueryInterface(webBrowser);
rv = baseWindow->InitWindow(nativeWindow, 0, x, y, width, height);
if (NS_FAILED(rv)) {
printf("InitWindow\n");
}

nsIWebBrowserChrome **aNewWindow = getter_AddRefs(chrome);
CallQueryInterface(static_cast<nsIWebBrowserChrome*>(new
WebBrowserChrome(this)), aNewWindow);
rv = webBrowser->SetContainerWindow(chrome.get());
chrome->SetWebBrowser(webBrowser);

rv = baseWindow->Create();
if (NS_FAILED(rv)) {
printf("Create\n");
}

//*** AG - listener code ***
rv = webBrowser-
>SetParentURIContentListener((nsIURIContentListener*)(chrome.get()) );

rv =baseWindow->SetVisibility(PR_TRUE);
if (NS_FAILED(rv)) {
printf("SetVisibility\n");
}

webNavigation = do_QueryInterface(webBrowser);

SetFocus(true);

return 0;
}

poopdawg

unread,
Jun 13, 2008, 9:45:44 AM6/13/08
to
just a note:

without the listener, SetWebBrowser() is called only once at startup.

with the listener, SetWebBrowser() is called every time i click a
link.


Boris Zbarsky

unread,
Jun 13, 2008, 2:09:24 PM6/13/08
to
poopdawg wrote:
> rv = webBrowser-
>> SetParentURIContentListener((nsIURIContentListener*)(chrome.get()) );

You hold a reference to |chrome| somewhere else, right?

-Boris

poopdawg

unread,
Jun 16, 2008, 2:19:41 AM6/16/08
to
> You hold a reference to |chrome| somewhere else, right?

not sure what you mean by "hold a reference", but if youre asking if
its defined somewhere, yes, its defined in the .h. all other
references to |chrome| are in the MozEmbed::CreateBrowser() method
shown above.

//mozembed.h
class MozEmbed
{
...
private:
nsCOMPtr<nsIWebBrowserChrome> chrome;
};

poopdawg

unread,
Jun 18, 2008, 7:45:57 AM6/18/08
to
ran some tests...

i am only getting this on gecko 1.9 :(

1.8.1.x seems to be fine...

Pelle Johnsen

unread,
Jun 18, 2008, 7:57:44 AM6/18/08
to
Hi,

I had a quick look and got it working using this:

nsIURIContentListener* uriContentListener;
chrome->QueryInterface(nsIURIContentListener::GetIID(),
(void**)&uriContentListener);
rv = webBrowser->SetParentURIContentListener(uriContentListener);

However you also need to make WebBrowserChrome support weak references
or you will get assertions. This is done by:

in WebBrowserChrome.h:

#include "nsWeakReference.h"

also inherit WebBrowserChrome from nsSupportsWeakReference

and in WebBrowserChrome.cpp:

add NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) to the interface map

Hope this helps,

-Pelle

Boris Zbarsky

unread,
Jun 18, 2008, 11:41:04 AM6/18/08
to
Pelle Johnsen wrote:
> chrome->QueryInterface(nsIURIContentListener::GetIID(),
> (void**)&uriContentListener);
> rv = webBrowser->SetParentURIContentListener(uriContentListener);

That looks like a leak to me, but does make it look like the reason things
didn't work before is because the object went away...

-Boris

Pelle Johnsen

unread,
Jun 18, 2008, 3:41:50 PM6/18/08
to
Hmmm ... it doesn't leak, but I agree it doesn't really look that nice :)

Maybe something like this would be better:

nsCOMPtr<nsIURIContentListener> uriContentListener =
do_QueryInterface(chrome);
webBrowser->SetParentURIContentListener(uriContentListener);

-Pelle

poopdawg

unread,
Jun 22, 2008, 2:58:25 PM6/22/08
to
hey thanks a lot pelle/boris.

will try it out in the next day or 2 and let you know how it goes...

-amitabh

poopdawg

unread,
Jun 22, 2008, 4:08:28 PM6/22/08
to
perfect.
0 new messages