public nsIWebBrowserChrome CreateChromeWindow(nsIWebBrowserChrome parent, uint chromeFlags)
{
// for chrome windows, we can use the AppShellService to create the window using some built-in xulrunner code
GeckoWindowFlags flags = (GeckoWindowFlags)chromeFlags;
if ((flags & GeckoWindowFlags.OpenAsChrome) != 0)
{
// obtain the services we need
nsIAppShellService appShellService = Xpcom.GetService<nsIAppShellService>("@mozilla.org/appshell/appShellService;1");
System.IntPtr ptr = (IntPtr)Xpcom.GetService(new Guid("2d96b3df-c051-11d1-a827-0040959a28c9"));
nsIAppShell appShell = (nsIAppShell)Marshal.GetObjectForIUnknown(ptr);
// create the child window
nsIXULWindow xulChild = appShellService.CreateTopLevelWindow(null, null, chromeFlags, -1, -1, appShell);
// this little gem allows the GeckoWebBrowser to be properly activated when it gains the focus again
if (parent is GeckoWebBrowser && (flags & GeckoWindowFlags.OpenAsDialog) != 0)
{
EventHandler gotFocus = null;
gotFocus = delegate (object sender, EventArgs e)
{
(sender as GeckoWebBrowser).GotFocus -= gotFocus;
(sender as GeckoWebBrowser).WebBrowserFocus.Activate();
};
(parent as GeckoWebBrowser).GotFocus += gotFocus;
}
// return the chrome
return Xpcom.QueryInterface<nsIWebBrowserChrome>(xulChild);
}
GeckoWebBrowser browser = parent as GeckoWebBrowser;
if (browser != null)
{
GeckoCreateWindowEventArgs e = new GeckoCreateWindowEventArgs((GeckoWindowFlags)chromeFlags);
browser.OnCreateWindow(e);
if (e.WebBrowser != null)
{
// set flags
((nsIWebBrowserChrome)e.WebBrowser).SetChromeFlagsAttribute(chromeFlags);
return e.WebBrowser;
}
nsIAppShellService appShellService = Xpcom.GetService<nsIAppShellService>("@mozilla.org/appshell/appShellService;1");
System.IntPtr ptr = (IntPtr)Xpcom.GetService(new Guid("2d96b3df-c051-11d1-a827-0040959a28c9"));
nsIAppShell appShell = (nsIAppShell)Marshal.GetObjectForIUnknown(ptr);
nsIXULWindow xulChild = appShellService.CreateTopLevelWindow(null, null, chromeFlags, -1, -1, appShell);
return Xpcom.QueryInterface<nsIWebBrowserChrome>(xulChild);
}
return null;
}