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;
}
without the listener, SetWebBrowser() is called only once at startup.
with the listener, SetWebBrowser() is called every time i click a
link.
You hold a reference to |chrome| somewhere else, right?
-Boris
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;
};
i am only getting this on gecko 1.9 :(
1.8.1.x seems to be fine...
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
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
Maybe something like this would be better:
nsCOMPtr<nsIURIContentListener> uriContentListener =
do_QueryInterface(chrome);
webBrowser->SetParentURIContentListener(uriContentListener);
-Pelle
will try it out in the next day or 2 and let you know how it goes...
-amitabh