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

nsIDOMAbstractView is always null

1 view
Skip to first unread message

Ranjitha Kumar

unread,
Feb 21, 2009, 4:54:13 AM2/21/09
to
Hi,

I am embedding XULRunner 1.9.0.6 in my C++ app. I want to get at the
computed styles for elements in the DOM tree. All the code I found on
the web to do this follows the same basic format:

nsCOMPtr<nsIDOMDocumentView> domView = do_QueryInterface
(domDocument,&rv);
if(NS_FAILED(rv) || !domView) printf("domView failed %08X\n", rv);

nsCOMPtr<nsIDOMAbstractView> abstractView;
rv = domView->GetDefaultView(getter_AddRefs(abstractView));
if(NS_FAILED(rv) || !abstractView) printf("abstractView failed %08X
\n", rv);

nsCOMPtr<nsIDOMViewCSS> viewCSS;
viewCSS = do_QueryInterface(abstractView, &rv);
if(NS_FAILED(rv) || !viewCSS) printf("viewCSS failed %08X\n", rv);
...
...
...
nsCOMPtr<nsIDOMCSSStyleDeclaration> style;
rv = viewCSS->GetComputedStyle(DOMelement.get(), EmptyString(),
style.get());
if(NS_FAILED(rv) || !style) printf("style failed %08X\n", rv);

The problem is that when I run this code, abstractView is always NULL.
I can't figure out what is causing GetDefaultView to return an
invalid nsIDOMAbstractView? This code is being executed in the
OnStateChange callback in nsIWebProgressListener, when STATE_STOP and
STATE_IS_DOCUMENT (page has been fully loaded). Both domDocument and
domView appear to be valid; I can traverse the DOM tree just fine.

Any help would be greatly appreciated!!

Boris Zbarsky

unread,
Feb 23, 2009, 12:35:21 PM2/23/09
to
Ranjitha Kumar wrote:
> The problem is that when I run this code, abstractView is always NULL.
> I can't figure out what is causing GetDefaultView to return an
> invalid nsIDOMAbstractView? This code is being executed in the
> OnStateChange callback in nsIWebProgressListener, when STATE_STOP and
> STATE_IS_DOCUMENT (page has been fully loaded).

Is this a document being loaded in a window? Or via some other means?

-Boris

Ranju

unread,
Feb 23, 2009, 5:20:39 PM2/23/09
to

It is being loaded in a window. This is the code that I call in main.
One odd thing is that I was never able to get a valid domDocument from
the webBrowser; when I tried, I got a NO_INTERFACE error; so I had to
get the domDocument from the webNavigation. That's why I store a
webNavigation object in the webProgressListener. I don't really get
what the NO_INTERFACE error means? Thanks!

GtkWidget *window;
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsILocalFile> libxul;
nsCOMPtr<nsIWebNavigation> webNavigation;

nsDynamicFunctionLoad nsFuncs[] = { {"XRE_InitEmbedding",
(NSFuncPtr*)&XRE_InitEmbedding}, {"XRE_TermEmbedding",(NSFuncPtr*)
&XRE_TermEmbedding},{0, 0}};
nsresult rv;

gtk_init (&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);

rv = XPCOMGlueStartup("/usr/lib/xulrunner-1.9.0.6/libxpcom.so");
if (NS_FAILED(rv)) printf("XPCOMGlueStartup\n");

rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv)) printf("XPCOMGlueLoadXULFunctions\n");

rv = NS_NewNativeLocalFile(nsEmbedCString("/usr/lib/
xulrunner-1.9.0.6/"),PR_FALSE,getter_AddRefs(libxul));
if (NS_FAILED(rv)) printf("NS_NewNativeLocalFile\n");

rv = XRE_InitEmbedding(libxul, 0, 0, 0, 0);
if (NS_FAILED(rv)) printf("XRE_InitEmbedding\n");

webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv)) printf("do_CreateInstance webBrowser\n");

baseWindow = do_QueryInterface(webBrowser);
rv = baseWindow->InitWindow(window, 0, 0, 0, 300, 400);
if (NS_FAILED(rv)) printf("InitWindow\n");

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

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

nsWebProgressListener* myWebProgressListener = new
nsWebProgressListener();
nsCOMPtr<nsIWebProgressListener> webProgressListener =
myWebProgressListener;

nsCOMPtr<nsIWeakReference> weakWebProgressListener
(do_GetWeakReference(webProgressListener));
rv = webBrowser->AddWebBrowserListener(weakWebProgressListener,
NS_GET_IID(nsIWebProgressListener));
if (NS_FAILED(rv)) printf("AddWebBroswerListener = %08X\n",rv);

webNavigation = do_QueryInterface(webBrowser);
rv = webNavigation->LoadURI(NS_ConvertASCIItoUTF16("http://
www.google.com").get(),nsIWebNavigation::LOAD_FLAGS_NONE,0,0,0);
if (NS_FAILED(rv)) printf("LoadURI failed rv = %08X\n", rv);

myWebProgressListener->setWebNavigation(webNavigation);

g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK
(delete_event), 0);

gtk_main();
printf("exit...\n");

XRE_TermEmbedding();
XPCOMGlueShutdown();

return 0;

Boris Zbarsky

unread,
Feb 23, 2009, 10:44:12 PM2/23/09
to
Ranju wrote:
> It is being loaded in a window. This is the code that I call in main.
> One odd thing is that I was never able to get a valid domDocument from
> the webBrowser; when I tried, I got a NO_INTERFACE error; so I had to
> get the domDocument from the webNavigation. That's why I store a
> webNavigation object in the webProgressListener. I don't really get
> what the NO_INTERFACE error means? Thanks!

Hmm. Have you tried stepping into the GetDefaultView call? What's the
documentURI of the document you're making that call on?

-Boris

0 new messages