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

poopdawg wrote:
> 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;
> }
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to