Can I list Tabs of a "MozillaWindowClass" HWND via XPCOM?

668 Views Asked by At

IE provides easy access to a IWebBrowser2 and IHtmlDocument2 from a HWND of a IE Frame. So you EnumWindows and EnumChildWindows and then you test the class and once you find the right ones, you can easily interact with them.

If there a way to list all open Mozilla Firefox tabs in a "MozillaWindowClass" (having its HWND), via XPCOM and C++?

I've googled long and strong but can't find much on the subject. I don't want to develop an extension / add-on but want to control the browser externally from an unrelated EXE, not from an extension DLL. Or at least some read-only access to it.

1

There are 1 best solutions below

0
On BEST ANSWER

You can not use C++/XPCOM with Firefox externally like you use COM with IE, you can only use C++/XPCOM from within a binary component of your extension. So you won't be able to do it without writing an extension, and at that point it's easier to listen on tab events from JS and notify your binary component.

Note that supporting binary components in a FF is a PITA so I don't suggest you take that road without a good reason.

However, once you have an extension and a binary component the way to get a HWND from a tab is this (hope it still works, we stopped supporting FF many versions back):

static HWND GetWndHandle(nsIXULWindow * window) {
    HWND hwnd = NULL;

    nsCOMPtr<nsIDocShell> docshell;
    nsresult res = window->GetDocShell(getter_AddRefs(docshell));

    if(NS_SUCCEEDED(res)) {
        nsCOMPtr<nsIBaseWindow> basewnd(do_QueryInterface(docshell));

        if(basewnd) {
            res = basewnd->GetParentNativeWindow((nativeWindow*)&hwnd);
            if(NS_FAILED(res)) hwnd = NULL;
        }
    }

    return hwnd;
}

With this and the notifications from the JS your binary component could provide a look up to find a tab by HWND and do stuff with it.