admin';?>

首页 / Development & communication

nsIDOMWindow <==> nsIWebBrowserChrome

By admin •  2019-03-25 14:04:09 •  63次点击
As we all known, if you get nsIWebBrowserChrome*, then you can do too many things,but how can I get nsIWebBrowserChrome?
this code snippet copy from MozUtil.cpp:

already_AddRefed<nsIWebBrowserChrome>
CMozUtil::GetWebBrowserChromeFromDOMWindow(nsIDOMWindow* domWindow)
{
	do {
		nsresult rv = NS_OK;
		if (!domWindow) break;

		nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(domWindow);
		if (!webNav) break;

		nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webNav));
		if (!docShell) break;

		nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
		rv = docShell->GetTreeOwner(getter_AddRefs(treeOwner));
		if (!treeOwner) break;

		nsCOMPtr<nsIWebBrowserChrome> webBrowserChrome(do_GetInterface(treeOwner));
		if (!webBrowserChrome) break;

		return webBrowserChrome.forget();
	} while (0);

	return nullptr;
}

you can call it as following:
nsCOMPtr<mozIDOMWindowProxy> domWindow;

nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1");

nsCOMPtr<nsIWebBrowserChrome> chrome;
wwatch->GetChromeForWindow(domWindow, getter_AddRefs(chrome));
if(!chrome){
	nsCOMPtr<nsIDOMWindow> domWin;
	domWin = do_QueryInterface(domWindow);
	chrome = CMozUtil::GetWebBrowserChromeFromDOMWindow(domWin);
}
 

If you want get nsIDomWindow from nsIWebBroserChrome,then:
nsIWebBrowserChrome  ==> nsIDOMWindow
//and you can get nsIDOMWindow from nsIWebBrowserChrome:
nsCOMPtr<nsIWebBrowser> webBrowser;
rv = chrome->GetWebBrowser(getter_AddRefs(webBrowser));
nsCOMPtr<mozIDOMWindowProxy> domChildWindowProxy;
webBrowser->GetContentDOMWindow(getter_AddRefs(domChildWindowProxy));
nsCOMPtr<nsIDOMWindow> contentWin = do_QueryInterface(domChildWindowProxy);




0 回复 | 直到2019-06-26 16:04添加回复

回复

登录发表 or 还没有账号?去注册

他山跨平台混合应用开发框架

现在注册 已注册请 登入
Development & communication

节点列表