2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
#include "nsPIWindowWatcher.h"
|
2011-07-15 03:31:34 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2012-09-05 11:32:06 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsWebShellWindow.h"
|
|
|
|
|
|
|
|
#include "nsIEnumerator.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIRequestObserver.h"
|
|
|
|
|
|
|
|
/* For implementing GetHiddenWindowAndJSContext */
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
#include "nsAppShellService.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIPlatformCharset.h"
|
|
|
|
#include "nsICharsetConverterManager.h"
|
|
|
|
#include "nsIUnicodeDecoder.h"
|
2009-12-21 02:22:09 -08:00
|
|
|
#include "nsIChromeRegistry.h"
|
2012-10-10 08:28:42 -07:00
|
|
|
#include "nsILoadContext.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-19 20:00:16 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-11-17 23:54:27 -08:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2011-06-19 20:00:16 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-04-20 14:23:35 -07:00
|
|
|
// Default URL for the hidden window, can be overridden by a pref on Mac
|
2009-10-12 12:31:50 -07:00
|
|
|
#define DEFAULT_HIDDENWINDOW_URL "resource://gre-resources/hiddenWindow.html"
|
2007-04-20 14:23:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIAppShell;
|
|
|
|
|
|
|
|
nsAppShellService::nsAppShellService() :
|
2011-10-17 07:59:28 -07:00
|
|
|
mXPCOMWillShutDown(false),
|
|
|
|
mXPCOMShuttingDown(false),
|
2007-08-23 14:30:29 -07:00
|
|
|
mModalWindowCount(0),
|
2011-10-17 07:59:28 -07:00
|
|
|
mApplicationProvidedHiddenWindow(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs
|
|
|
|
(do_GetService("@mozilla.org/observer-service;1"));
|
|
|
|
|
2009-11-20 14:25:11 -08:00
|
|
|
if (obs) {
|
2011-10-17 07:59:28 -07:00
|
|
|
obs->AddObserver(this, "xpcom-will-shutdown", false);
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
2009-11-20 14:25:11 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShellService::~nsAppShellService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement the nsISupports methods...
|
|
|
|
*/
|
|
|
|
NS_IMPL_ISUPPORTS2(nsAppShellService,
|
|
|
|
nsIAppShellService,
|
|
|
|
nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-10-14 06:06:39 -07:00
|
|
|
nsAppShellService::CreateHiddenWindow()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t initialHeight = 100, initialWidth = 100;
|
2012-10-09 02:56:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t chromeMask = 0;
|
2011-06-19 20:00:16 -07:00
|
|
|
nsAdoptingCString prefVal =
|
|
|
|
Preferences::GetCString("browser.hiddenWindowChromeURL");
|
2012-04-19 00:39:52 -07:00
|
|
|
const char* hiddenWindowURL = prefVal.get() ? prefVal.get() : DEFAULT_HIDDENWINDOW_URL;
|
2013-01-08 09:02:55 -08:00
|
|
|
mApplicationProvidedHiddenWindow = prefVal.get() ? true : false;
|
2007-03-22 10:30:00 -07:00
|
|
|
#else
|
2007-04-20 14:23:35 -07:00
|
|
|
static const char hiddenWindowURL[] = DEFAULT_HIDDENWINDOW_URL;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t chromeMask = nsIWebBrowserChrome::CHROME_ALL;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), hiddenWindowURL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsRefPtr<nsWebShellWindow> newWindow;
|
2013-01-08 09:02:55 -08:00
|
|
|
rv = JustCreateTopWindow(nullptr, url,
|
|
|
|
chromeMask, initialWidth, initialHeight,
|
|
|
|
true, getter_AddRefs(newWindow));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mHiddenWindow.swap(newWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-10 20:49:17 -08:00
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
2013-01-08 09:02:55 -08:00
|
|
|
// Create the hidden private window
|
|
|
|
chromeMask |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
|
2012-12-10 20:49:17 -08:00
|
|
|
|
2013-01-08 09:02:55 -08:00
|
|
|
rv = JustCreateTopWindow(nullptr, url,
|
|
|
|
chromeMask, initialWidth, initialHeight,
|
|
|
|
true, getter_AddRefs(newWindow));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-12-10 20:49:17 -08:00
|
|
|
|
2013-01-08 09:02:55 -08:00
|
|
|
mHiddenPrivateWindow.swap(newWindow);
|
2012-12-10 20:49:17 -08:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// RegisterTopLevelWindow(newWindow); -- Mac only
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::DestroyHiddenWindow()
|
|
|
|
{
|
|
|
|
if (mHiddenWindow) {
|
|
|
|
mHiddenWindow->Destroy();
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mHiddenWindow = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-12-10 20:49:17 -08:00
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
if (mHiddenPrivateWindow) {
|
|
|
|
mHiddenPrivateWindow->Destroy();
|
|
|
|
|
|
|
|
mHiddenPrivateWindow = nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new top level window and display the given URL within it...
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent,
|
|
|
|
nsIURI *aUrl,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aChromeMask,
|
|
|
|
int32_t aInitialWidth,
|
|
|
|
int32_t aInitialHeight,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIXULWindow **aResult)
|
|
|
|
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-11-17 23:54:27 -08:00
|
|
|
StartupTimeline::RecordOnce(StartupTimeline::CREATE_TOP_LEVEL_WINDOW);
|
2011-09-23 05:30:49 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsWebShellWindow *newWindow = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = JustCreateTopWindow(aParent, aUrl,
|
|
|
|
aChromeMask, aInitialWidth, aInitialHeight,
|
2011-10-17 07:59:28 -07:00
|
|
|
false, &newWindow); // addrefs
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
*aResult = newWindow; // transfer ref
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// the addref resulting from this is the owning addref for this window
|
|
|
|
RegisterTopLevelWindow(*aResult);
|
2009-09-28 19:20:46 -07:00
|
|
|
nsCOMPtr<nsIXULWindow> parent;
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT)
|
|
|
|
parent = aParent;
|
|
|
|
(*aResult)->SetZLevel(CalculateWindowZLevel(parent, aChromeMask));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAppShellService::CalculateWindowZLevel(nsIXULWindow *aParent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aChromeMask)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t zLevel;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
zLevel = nsIXULWindow::normalZ;
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RAISED)
|
|
|
|
zLevel = nsIXULWindow::raisedZ;
|
|
|
|
else if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_LOWERED)
|
|
|
|
zLevel = nsIXULWindow::loweredZ;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
/* Platforms on which modal windows are always application-modal, not
|
|
|
|
window-modal (that's just the Mac, right?) want modal windows to
|
|
|
|
be stacked on top of everyone else.
|
|
|
|
|
|
|
|
On Mac OS X, bind modality to parent window instead of app (ala Mac OS 9)
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t modalDepMask = nsIWebBrowserChrome::CHROME_MODAL |
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWebBrowserChrome::CHROME_DEPENDENT;
|
|
|
|
if (aParent && (aChromeMask & modalDepMask)) {
|
|
|
|
aParent->GetZLevel(&zLevel);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Platforms with native support for dependent windows (that's everyone
|
|
|
|
but pre-Mac OS X, right?) know how to stack dependent windows. On these
|
|
|
|
platforms, give the dependent window the same level as its parent,
|
|
|
|
so we won't try to override the normal platform behaviour. */
|
|
|
|
if ((aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT) && aParent)
|
|
|
|
aParent->GetZLevel(&zLevel);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return zLevel;
|
|
|
|
}
|
|
|
|
|
2010-12-04 02:06:53 -08:00
|
|
|
#ifdef XP_WIN
|
2010-08-26 21:44:01 -07:00
|
|
|
/*
|
|
|
|
* Checks to see if any existing window is currently in fullscreen mode.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-08-26 21:44:01 -07:00
|
|
|
CheckForFullscreenWindow()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWindowMediator> wm(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
if (!wm)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-26 21:44:01 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowList;
|
2012-07-30 07:20:58 -07:00
|
|
|
wm->GetXULWindowEnumerator(nullptr, getter_AddRefs(windowList));
|
2010-08-26 21:44:01 -07:00
|
|
|
if (!windowList)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-26 21:44:01 -07:00
|
|
|
|
|
|
|
for (;;) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool more = false;
|
2010-08-26 21:44:01 -07:00
|
|
|
windowList->HasMoreElements(&more);
|
|
|
|
if (!more)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-26 21:44:01 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supportsWindow;
|
|
|
|
windowList->GetNext(getter_AddRefs(supportsWindow));
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(supportsWindow));
|
|
|
|
if (baseWin) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t sizeMode;
|
2010-08-26 21:44:01 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
baseWin->GetMainWidget(getter_AddRefs(widget));
|
|
|
|
if (widget && NS_SUCCEEDED(widget->GetSizeMode(&sizeMode)) &&
|
|
|
|
sizeMode == nsSizeMode_Fullscreen) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-26 21:44:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-26 21:44:01 -07:00
|
|
|
}
|
2010-12-04 02:06:53 -08:00
|
|
|
#endif
|
2010-08-26 21:44:01 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Just do the window-making part of CreateTopLevelWindow
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent,
|
|
|
|
nsIURI *aUrl,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aChromeMask,
|
|
|
|
int32_t aInitialWidth,
|
|
|
|
int32_t aInitialHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsHiddenWindow,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWebShellWindow **aResult)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2009-11-20 14:25:11 -08:00
|
|
|
NS_ENSURE_STATE(!mXPCOMWillShutDown);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-28 19:20:46 -07:00
|
|
|
nsCOMPtr<nsIXULWindow> parent;
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT)
|
|
|
|
parent = aParent;
|
|
|
|
|
2009-08-14 04:00:44 -07:00
|
|
|
nsRefPtr<nsWebShellWindow> window = new nsWebShellWindow(aChromeMask);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2010-08-26 21:44:01 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// If the parent is currently fullscreen, tell the child to ignore persisted
|
|
|
|
// full screen states. This way new browser windows open on top of fullscreen
|
|
|
|
// windows normally.
|
|
|
|
if (window && CheckForFullscreenWindow())
|
2011-10-17 07:59:28 -07:00
|
|
|
window->IgnoreXULSizeMode(true);
|
2010-08-26 21:44:01 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWidgetInitData widgetInitData;
|
|
|
|
|
|
|
|
if (aIsHiddenWindow)
|
|
|
|
widgetInitData.mWindowType = eWindowType_invisible;
|
|
|
|
else
|
|
|
|
widgetInitData.mWindowType = aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG ?
|
|
|
|
eWindowType_dialog : eWindowType_toplevel;
|
|
|
|
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_POPUP)
|
|
|
|
widgetInitData.mWindowType = eWindowType_popup;
|
|
|
|
|
2012-02-16 19:47:39 -08:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_MAC_SUPPRESS_ANIMATION)
|
|
|
|
widgetInitData.mIsAnimationSuppressed = true;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Mac OS X sheet support
|
2008-03-23 15:30:56 -07:00
|
|
|
// Adding CHROME_OPENAS_CHROME to sheetMask makes modal windows opened from
|
|
|
|
// nsGlobalWindow::ShowModalDialog() be dialogs (not sheets), while modal
|
|
|
|
// windows opened from nsPromptService::DoDialog() still are sheets. This
|
|
|
|
// fixes bmo bug 395465 (see nsCocoaWindow::StandardCreate() and
|
|
|
|
// nsCocoaWindow::SetModal()).
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t sheetMask = nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
|
2008-03-23 15:30:56 -07:00
|
|
|
nsIWebBrowserChrome::CHROME_MODAL |
|
|
|
|
nsIWebBrowserChrome::CHROME_OPENAS_CHROME;
|
2009-09-28 19:20:46 -07:00
|
|
|
if (parent && ((aChromeMask & sheetMask) == sheetMask))
|
2007-03-22 10:30:00 -07:00
|
|
|
widgetInitData.mWindowType = eWindowType_sheet;
|
|
|
|
#endif
|
|
|
|
|
2010-06-25 15:50:36 -07:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
if (widgetInitData.mWindowType == eWindowType_toplevel ||
|
|
|
|
widgetInitData.mWindowType == eWindowType_dialog)
|
2011-10-17 07:59:28 -07:00
|
|
|
widgetInitData.clipChildren = true;
|
2010-06-25 15:50:36 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// note default chrome overrides other OS chrome settings, but
|
|
|
|
// not internal chrome
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEFAULT)
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_default;
|
|
|
|
else if ((aChromeMask & nsIWebBrowserChrome::CHROME_ALL) == nsIWebBrowserChrome::CHROME_ALL)
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_all;
|
|
|
|
else {
|
|
|
|
widgetInitData.mBorderStyle = eBorderStyle_none; // assumes none == 0x00
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_BORDERS)
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_border);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR)
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_title);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_close);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) {
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_resizeh);
|
2007-03-22 10:30:00 -07:00
|
|
|
// only resizable windows get the maximize button (but not dialogs)
|
|
|
|
if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_maximize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// all windows (except dialogs) get minimize buttons and the system menu
|
|
|
|
if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_minimize | eBorderStyle_menu);
|
2007-03-22 10:30:00 -07:00
|
|
|
// but anyone can explicitly ask for a minimize button
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_MIN) {
|
2007-07-08 00:08:04 -07:00
|
|
|
widgetInitData.mBorderStyle = static_cast<enum nsBorderStyle>(widgetInitData.mBorderStyle | eBorderStyle_minimize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aInitialWidth == nsIAppShellService::SIZE_TO_CONTENT ||
|
|
|
|
aInitialHeight == nsIAppShellService::SIZE_TO_CONTENT) {
|
|
|
|
aInitialWidth = 1;
|
|
|
|
aInitialHeight = 1;
|
2011-10-17 07:59:28 -07:00
|
|
|
window->SetIntrinsicallySized(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool center = aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN;
|
2009-09-28 19:20:46 -07:00
|
|
|
|
2009-12-21 02:22:09 -08:00
|
|
|
nsCOMPtr<nsIXULChromeRegistry> reg =
|
2010-05-14 02:24:41 -07:00
|
|
|
mozilla::services::GetXULChromeRegistryService();
|
2009-12-21 02:22:09 -08:00
|
|
|
if (reg) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString package;
|
2009-12-21 02:22:09 -08:00
|
|
|
package.AssignLiteral("global");
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isRTL = false;
|
2009-12-21 02:22:09 -08:00
|
|
|
reg->IsLocaleRTL(package, &isRTL);
|
|
|
|
widgetInitData.mRTL = isRTL;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsresult rv = window->Initialize(parent, center ? aParent : nullptr,
|
2011-10-14 06:06:39 -07:00
|
|
|
aUrl, aInitialWidth, aInitialHeight,
|
2007-03-22 10:30:00 -07:00
|
|
|
aIsHiddenWindow, widgetInitData);
|
2012-10-09 02:56:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-10-16 15:06:38 -07:00
|
|
|
// Enforce the Private Browsing autoStart pref first.
|
|
|
|
bool isPrivateBrowsingWindow =
|
|
|
|
Preferences::GetBool("browser.privatebrowsing.autostart");
|
2012-12-10 20:49:17 -08:00
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW) {
|
|
|
|
// Caller requested a private window
|
|
|
|
isPrivateBrowsingWindow = true;
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-16 15:06:38 -07:00
|
|
|
if (!isPrivateBrowsingWindow) {
|
|
|
|
// Ensure that we propagate any existing private browsing status
|
|
|
|
// from the parent, even if it will not actually be used
|
|
|
|
// as a parent value.
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(aParent);
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(domWin);
|
|
|
|
nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(webNav);
|
|
|
|
if (parentContext) {
|
|
|
|
isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
|
|
|
|
}
|
|
|
|
}
|
2012-10-10 08:28:42 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> newDomWin =
|
|
|
|
do_GetInterface(NS_ISUPPORTS_CAST(nsIBaseWindow*, window));
|
|
|
|
nsCOMPtr<nsIWebNavigation> newWebNav = do_GetInterface(newDomWin);
|
|
|
|
nsCOMPtr<nsILoadContext> thisContext = do_GetInterface(newWebNav);
|
2012-10-16 15:06:38 -07:00
|
|
|
if (thisContext) {
|
2012-10-30 21:15:24 -07:00
|
|
|
thisContext->SetPrivateBrowsing(isPrivateBrowsingWindow);
|
2012-10-10 08:28:42 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
window.swap(*aResult); // transfer reference
|
2009-09-28 19:20:46 -07:00
|
|
|
if (parent)
|
|
|
|
parent->AddChildWindow(*aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-28 19:20:46 -07:00
|
|
|
if (center)
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = (*aResult)->Center(parent, parent ? false : true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetHiddenWindow(nsIXULWindow **aWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
|
|
|
*aWindow = mHiddenWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return *aWindow ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-07-15 03:31:34 -07:00
|
|
|
nsAppShellService::GetHiddenDOMWindow(nsIDOMWindow **aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_ENSURE_TRUE(mHiddenWindow, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-10-09 02:56:58 -07:00
|
|
|
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> hiddenDOMWindow(do_GetInterface(docShell, &rv));
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aWindow = hiddenDOMWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-10 20:49:17 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetHiddenPrivateWindow(nsIXULWindow **aWindow)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
|
|
|
*aWindow = mHiddenPrivateWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return *aWindow ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetHiddenPrivateDOMWindow(nsIDOMWindow **aWindow)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
NS_ENSURE_TRUE(mHiddenPrivateWindow, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
rv = mHiddenPrivateWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> hiddenPrivateDOMWindow(do_GetInterface(docShell, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aWindow = hiddenPrivateDOMWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return NS_OK;
|
|
|
|
#else
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-07-15 03:31:34 -07:00
|
|
|
nsAppShellService::GetHiddenWindowAndJSContext(nsIDOMWindow **aWindow,
|
2007-03-22 10:30:00 -07:00
|
|
|
JSContext **aJSContext)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if ( aWindow && aJSContext ) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aWindow = nullptr;
|
|
|
|
*aJSContext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if ( mHiddenWindow ) {
|
2011-07-15 03:31:34 -07:00
|
|
|
// Convert hidden window to nsIDOMWindow and extract its JSContext.
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
// 1. Get doc for hidden window.
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
if (NS_FAILED(rv)) break;
|
|
|
|
|
2011-07-15 03:31:34 -07:00
|
|
|
// 2. Convert that to an nsIDOMWindow.
|
|
|
|
nsCOMPtr<nsIDOMWindow> hiddenDOMWindow(do_GetInterface(docShell));
|
2007-03-22 10:30:00 -07:00
|
|
|
if(!hiddenDOMWindow) break;
|
|
|
|
|
|
|
|
// 3. Get script global object for the window.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
sgo = do_QueryInterface( hiddenDOMWindow );
|
|
|
|
if (!sgo) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// 4. Get script context from that.
|
|
|
|
nsIScriptContext *scriptContext = sgo->GetContext();
|
|
|
|
if (!scriptContext) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// 5. Get JSContext from the script context.
|
2011-09-18 02:22:17 -07:00
|
|
|
JSContext *jsContext = scriptContext->GetNativeContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!jsContext) { rv = NS_ERROR_FAILURE; break; }
|
|
|
|
|
|
|
|
// Now, give results to caller.
|
|
|
|
*aWindow = hiddenDOMWindow.get();
|
|
|
|
NS_IF_ADDREF( *aWindow );
|
|
|
|
*aJSContext = jsContext;
|
|
|
|
} while (0);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-08-23 14:30:29 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsAppShellService::GetApplicationProvidedHiddenWindow(bool* aAPHW)
|
2007-08-23 14:30:29 -07:00
|
|
|
{
|
|
|
|
*aAPHW = mApplicationProvidedHiddenWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/*
|
|
|
|
* Register a new top level window (created elsewhere)
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow)
|
|
|
|
{
|
2012-10-09 02:56:58 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
2012-09-05 11:32:06 -07:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
aWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(docShell));
|
2012-10-09 02:56:58 -07:00
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
2012-09-05 11:32:06 -07:00
|
|
|
domWindow->SetInitialPrincipalToSubject();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// tell the window mediator about the new window
|
|
|
|
nsCOMPtr<nsIWindowMediator> mediator
|
|
|
|
( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) );
|
|
|
|
NS_ASSERTION(mediator, "Couldn't get window mediator.");
|
|
|
|
|
|
|
|
if (mediator)
|
|
|
|
mediator->RegisterWindow(aWindow);
|
|
|
|
|
|
|
|
// tell the window watcher about the new window
|
|
|
|
nsCOMPtr<nsPIWindowWatcher> wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) );
|
|
|
|
NS_ASSERTION(wwatcher, "No windowwatcher?");
|
2012-09-05 11:32:06 -07:00
|
|
|
if (wwatcher && domWindow) {
|
|
|
|
wwatcher->AddWindow(domWindow, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// an ongoing attempt to quit is stopped by a newly opened window
|
|
|
|
nsCOMPtr<nsIObserverService> obssvc =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
NS_ASSERTION(obssvc, "Couldn't get observer service.");
|
|
|
|
|
|
|
|
if (obssvc)
|
2012-07-30 07:20:58 -07:00
|
|
|
obssvc->NotifyObservers(aWindow, "xul-window-registered", nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow)
|
|
|
|
{
|
|
|
|
if (mXPCOMShuttingDown) {
|
|
|
|
/* return an error code in order to:
|
|
|
|
- avoid doing anything with other member variables while we are in
|
|
|
|
the destructor
|
|
|
|
- notify the caller not to release the AppShellService after
|
|
|
|
unregistering the window
|
|
|
|
(we don't want to be deleted twice consecutively to
|
|
|
|
mHiddenWindow->Destroy() in our destructor)
|
|
|
|
*/
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-10-09 02:56:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
|
|
|
if (aWindow == mHiddenWindow) {
|
|
|
|
// CreateHiddenWindow() does not register the window, so we're done.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-10 20:49:17 -08:00
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
if (aWindow == mHiddenPrivateWindow) {
|
|
|
|
// CreateHiddenWindow() does not register the window, so we're done.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// tell the window mediator
|
|
|
|
nsCOMPtr<nsIWindowMediator> mediator
|
|
|
|
( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) );
|
|
|
|
NS_ASSERTION(mediator, "Couldn't get window mediator. Doing xpcom shutdown?");
|
|
|
|
|
|
|
|
if (mediator)
|
|
|
|
mediator->UnregisterWindow(aWindow);
|
2012-10-09 02:56:58 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// tell the window watcher
|
|
|
|
nsCOMPtr<nsPIWindowWatcher> wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) );
|
|
|
|
NS_ASSERTION(wwatcher, "Couldn't get windowwatcher, doing xpcom shutdown?");
|
|
|
|
if (wwatcher) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
aWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(docShell));
|
|
|
|
if (domWindow)
|
|
|
|
wwatcher->RemoveWindow(domWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::Observe(nsISupports* aSubject, const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
2009-11-20 14:25:11 -08:00
|
|
|
if (!strcmp(aTopic, "xpcom-will-shutdown")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mXPCOMWillShutDown = true;
|
2009-11-20 14:25:11 -08:00
|
|
|
} else if (!strcmp(aTopic, "xpcom-shutdown")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mXPCOMShuttingDown = true;
|
2009-11-20 14:25:11 -08:00
|
|
|
if (mHiddenWindow) {
|
|
|
|
mHiddenWindow->Destroy();
|
|
|
|
}
|
2012-12-10 20:49:17 -08:00
|
|
|
#ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
|
|
|
|
if (mHiddenPrivateWindow) {
|
|
|
|
mHiddenPrivateWindow->Destroy();
|
|
|
|
}
|
|
|
|
#endif
|
2009-11-20 14:25:11 -08:00
|
|
|
} else {
|
|
|
|
NS_ERROR("Unexpected observer topic!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|