2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
#include "nsIAppShellService.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-10-22 01:36:25 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIObserver.h"
|
2014-09-10 22:53:55 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2004-10-29 23:28:38 +04:00
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
#include "nsPIWindowWatcher.h"
|
2012-09-05 22:32:06 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2019-11-05 20:56:28 +03:00
|
|
|
#include "AppWindow.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2023-01-24 02:58:41 +03:00
|
|
|
#include "mozilla/widget/InitData.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsWidgetsCID.h"
|
2013-10-22 17:27:34 +04:00
|
|
|
#include "nsIWidget.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2019-03-20 22:35:59 +03:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2000-02-05 08:38:13 +03:00
|
|
|
#include "nsAppShellService.h"
|
2016-01-16 06:23:09 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-03-20 22:35:59 +03:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2016-01-16 06:23:09 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2012-10-10 19:28:42 +04:00
|
|
|
#include "nsILoadContext.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
2016-01-16 06:23:09 +03:00
|
|
|
#include "nsIWindowlessBrowser.h"
|
2000-02-05 08:38:13 +03:00
|
|
|
|
2013-04-19 05:07:00 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-06-20 07:00:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-04-29 21:31:06 +04:00
|
|
|
#include "mozilla/Services.h"
|
2011-11-18 11:54:27 +04:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2022-09-22 03:26:17 +03:00
|
|
|
#include "mozilla/StaticPrefs_browser.h"
|
2019-08-16 10:35:29 +03:00
|
|
|
#include "mozilla/StaticPrefs_fission.h"
|
2023-09-28 23:46:07 +03:00
|
|
|
#include "mozilla/Try.h"
|
2017-03-14 22:35:06 +03:00
|
|
|
#include "mozilla/intl/LocaleService.h"
|
2019-10-23 22:39:00 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2023-01-24 02:58:41 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2011-06-20 07:00:16 +04:00
|
|
|
|
2013-04-04 17:24:32 +04:00
|
|
|
#include "nsEmbedCID.h"
|
|
|
|
#include "nsIWebBrowser.h"
|
|
|
|
#include "nsIDocShell.h"
|
2017-04-05 18:20:00 +03:00
|
|
|
#include "gfxPlatform.h"
|
2013-04-04 17:24:32 +04:00
|
|
|
|
2018-11-09 00:58:58 +03:00
|
|
|
#include "nsWebBrowser.h"
|
2020-04-08 00:39:19 +03:00
|
|
|
#include "nsDocShell.h"
|
|
|
|
#include "nsDocShellLoadState.h"
|
2018-11-09 00:58:58 +03:00
|
|
|
|
2014-02-12 19:33:43 +04:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
2014-02-11 18:24:47 +04:00
|
|
|
# include "EventTracer.h"
|
2014-02-12 19:33:43 +04:00
|
|
|
#endif
|
2014-02-11 18:24:47 +04:00
|
|
|
|
2011-06-20 07:00:16 +04:00
|
|
|
using namespace mozilla;
|
2019-03-14 21:50:45 +03:00
|
|
|
using mozilla::dom::BrowsingContext;
|
2017-03-14 22:35:06 +03:00
|
|
|
using mozilla::intl::LocaleService;
|
2011-06-20 07:00:16 +04:00
|
|
|
|
2007-04-21 01:23:35 +04:00
|
|
|
// Default URL for the hidden window, can be overridden by a pref on Mac
|
2009-10-12 23:31:50 +04:00
|
|
|
#define DEFAULT_HIDDENWINDOW_URL "resource://gre-resources/hiddenWindow.html"
|
2007-04-21 01:23:35 +04:00
|
|
|
|
2004-10-29 23:28:38 +04:00
|
|
|
class nsIAppShell;
|
2001-07-10 12:01:55 +04:00
|
|
|
|
2015-04-29 12:25:26 +03:00
|
|
|
nsAppShellService::nsAppShellService()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mXPCOMWillShutDown(false),
|
|
|
|
mXPCOMShuttingDown(false),
|
2007-08-24 01:30:29 +04:00
|
|
|
mModalWindowCount(0),
|
2015-04-29 12:25:26 +03:00
|
|
|
mApplicationProvidedHiddenWindow(false),
|
|
|
|
mScreenId(0) {
|
2014-04-29 21:31:06 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
2004-10-29 23:28:38 +04:00
|
|
|
|
2009-11-21 01:25:11 +03:00
|
|
|
if (obs) {
|
2011-10-17 18:59:28 +04:00
|
|
|
obs->AddObserver(this, "xpcom-will-shutdown", false);
|
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
2009-11-21 01:25:11 +03:00
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShellService::~nsAppShellService() {}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implement the nsISupports methods...
|
|
|
|
*/
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAppShellService, nsIAppShellService, nsIObserver)
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2015-04-29 12:25:26 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::SetScreenId(uint32_t aScreenId) {
|
|
|
|
mScreenId = aScreenId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-05 23:18:25 +03:00
|
|
|
void nsAppShellService::EnsureHiddenWindow() {
|
|
|
|
if (!mHiddenWindow) {
|
2019-10-30 18:35:31 +03:00
|
|
|
(void)CreateHiddenWindow();
|
2013-01-07 06:16:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-30 18:35:31 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::CreateHiddenWindow() {
|
2019-03-05 23:18:25 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2019-03-20 22:35:59 +03:00
|
|
|
if (mXPCOMShuttingDown) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2021-12-16 21:59:42 +03:00
|
|
|
if (mHiddenWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-03-20 22:35:59 +03:00
|
|
|
nsCOMPtr<nsIFile> profileDir;
|
|
|
|
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
getter_AddRefs(profileDir));
|
|
|
|
if (!profileDir) {
|
|
|
|
// This is too early on startup to create the hidden window
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-07-20 18:40:55 +04:00
|
|
|
nsresult rv;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t initialHeight = 100, initialWidth = 100;
|
2012-10-09 13:56:58 +04:00
|
|
|
|
2006-11-16 06:25:55 +03:00
|
|
|
#ifdef XP_MACOSX
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t chromeMask = 0;
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString prefVal;
|
|
|
|
rv = Preferences::GetCString("browser.hiddenWindowChromeURL", prefVal);
|
|
|
|
const char* hiddenWindowURL =
|
|
|
|
NS_SUCCEEDED(rv) ? prefVal.get() : DEFAULT_HIDDENWINDOW_URL;
|
2019-10-30 18:35:31 +03:00
|
|
|
mApplicationProvidedHiddenWindow = prefVal.get() ? true : false;
|
1999-10-08 07:31:41 +04:00
|
|
|
#else
|
2007-04-21 01:23:35 +04:00
|
|
|
static const char hiddenWindowURL[] = DEFAULT_HIDDENWINDOW_URL;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t chromeMask = nsIWebBrowserChrome::CHROME_ALL;
|
2000-05-10 04:37:05 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> url;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(url), hiddenWindowURL);
|
2005-02-20 01:42:01 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
RefPtr<AppWindow> newWindow;
|
2020-04-08 00:39:32 +03:00
|
|
|
rv = JustCreateTopWindow(nullptr, url, chromeMask, initialWidth,
|
|
|
|
initialHeight, true, getter_AddRefs(newWindow));
|
2017-05-26 20:49:51 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-12-11 08:49:17 +04:00
|
|
|
|
2017-05-26 20:49:51 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
newWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
if (docShell) {
|
2020-12-11 18:43:19 +03:00
|
|
|
Unused << docShell->GetBrowsingContext()->SetExplicitActive(
|
|
|
|
dom::ExplicitActiveStatus::Inactive);
|
2017-05-26 20:49:51 +03:00
|
|
|
}
|
2013-01-22 22:06:30 +04:00
|
|
|
|
2019-10-30 18:35:31 +03:00
|
|
|
mHiddenWindow.swap(newWindow);
|
2012-12-11 08:49:17 +04:00
|
|
|
|
2005-02-20 01:42:01 +03:00
|
|
|
return NS_OK;
|
1999-07-20 18:40:55 +04:00
|
|
|
}
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHODIMP
|
2004-10-29 23:28:38 +04:00
|
|
|
nsAppShellService::DestroyHiddenWindow() {
|
|
|
|
if (mHiddenWindow) {
|
2005-02-20 01:42:01 +03:00
|
|
|
mHiddenWindow->Destroy();
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mHiddenWindow = nullptr;
|
1999-11-11 08:51:22 +03:00
|
|
|
}
|
|
|
|
|
2004-10-29 23:28:38 +04:00
|
|
|
return NS_OK;
|
1999-09-17 03:42:49 +04:00
|
|
|
}
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
/*
|
|
|
|
* Create a new top level window and display the given URL within it...
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2020-04-08 00:39:32 +03:00
|
|
|
nsAppShellService::CreateTopLevelWindow(nsIAppWindow* aParent, nsIURI* aUrl,
|
|
|
|
uint32_t aChromeMask,
|
|
|
|
int32_t aInitialWidth,
|
|
|
|
int32_t aInitialHeight,
|
|
|
|
nsIAppWindow** aResult) {
|
1998-12-03 04:35:53 +03:00
|
|
|
nsresult rv;
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2011-11-18 11:54:27 +04:00
|
|
|
StartupTimeline::RecordOnce(StartupTimeline::CREATE_TOP_LEVEL_WINDOW);
|
2011-09-23 16:30:49 +04:00
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
RefPtr<AppWindow> newWindow;
|
2005-02-20 01:42:01 +03:00
|
|
|
rv = JustCreateTopWindow(aParent, aUrl, aChromeMask, aInitialWidth,
|
2020-04-08 00:39:32 +03:00
|
|
|
aInitialHeight, false, getter_AddRefs(newWindow));
|
2016-10-07 21:59:59 +03:00
|
|
|
newWindow.forget(aResult);
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2003-10-07 05:20:05 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-07-20 18:40:55 +04:00
|
|
|
// the addref resulting from this is the owning addref for this window
|
|
|
|
RegisterTopLevelWindow(*aResult);
|
2019-11-05 20:56:28 +03:00
|
|
|
nsCOMPtr<nsIAppWindow> parent;
|
2009-09-29 06:20:46 +04:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT) parent = aParent;
|
|
|
|
(*aResult)->SetZLevel(CalculateWindowZLevel(parent, aChromeMask));
|
2003-10-07 05:20:05 +04:00
|
|
|
}
|
1999-07-20 18:40:55 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-04-04 17:24:32 +04:00
|
|
|
/*
|
2019-12-04 16:50:01 +03:00
|
|
|
* This class provides a stub implementation of nsIWebBrowserChrome, as needed
|
2013-04-04 17:24:32 +04:00
|
|
|
* by nsAppShellService::CreateWindowlessBrowser
|
|
|
|
*/
|
2019-12-04 16:50:01 +03:00
|
|
|
class WebBrowserChrome2Stub final : public nsIWebBrowserChrome,
|
2018-11-27 12:59:44 +03:00
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsSupportsWeakReference {
|
2014-06-24 20:36:45 +04:00
|
|
|
protected:
|
2017-04-04 17:22:00 +03:00
|
|
|
nsCOMPtr<nsIWebBrowser> mBrowser;
|
2022-12-16 02:13:00 +03:00
|
|
|
virtual ~WebBrowserChrome2Stub() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-24 20:36:45 +04:00
|
|
|
public:
|
2018-11-27 12:59:44 +03:00
|
|
|
void SetBrowser(nsIWebBrowser* aBrowser) { mBrowser = aBrowser; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-04-04 17:24:32 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIWEBBROWSERCHROME
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(WebBrowserChrome2Stub)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
2013-04-11 11:09:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2013-04-04 17:24:32 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(WebBrowserChrome2Stub)
|
|
|
|
NS_IMPL_RELEASE(WebBrowserChrome2Stub)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebBrowserChrome2Stub::GetChromeFlags(uint32_t* aChromeFlags) {
|
|
|
|
*aChromeFlags = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebBrowserChrome2Stub::SetChromeFlags(uint32_t aChromeFlags) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"WebBrowserChrome2Stub::SetChromeFlags is "
|
|
|
|
"not supported");
|
2013-04-04 17:24:32 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebBrowserChrome2Stub::ShowAsModal() {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("WebBrowserChrome2Stub::ShowAsModal is not supported");
|
2013-04-04 17:24:32 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebBrowserChrome2Stub::IsWindowModal(bool* aResult) {
|
|
|
|
*aResult = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-12-05 13:36:12 +03:00
|
|
|
WebBrowserChrome2Stub::SetLinkStatus(const nsAString& aStatusText) {
|
2013-04-04 17:24:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-10-22 21:40:00 +03:00
|
|
|
WebBrowserChrome2Stub::GetInterface(const nsIID& aIID, void** aSink) {
|
2013-04-04 17:24:32 +04:00
|
|
|
return QueryInterface(aIID, aSink);
|
|
|
|
}
|
|
|
|
|
2015-10-22 21:40:00 +03:00
|
|
|
NS_IMETHODIMP
|
2022-12-16 02:13:00 +03:00
|
|
|
WebBrowserChrome2Stub::GetDimensions(DimensionKind aDimensionKind, int32_t* aX,
|
|
|
|
int32_t* aY, int32_t* aCX, int32_t* aCY) {
|
|
|
|
if (aX) {
|
|
|
|
*aX = 0;
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
2022-12-16 02:13:00 +03:00
|
|
|
if (aY) {
|
|
|
|
*aY = 0;
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
2022-12-16 02:13:00 +03:00
|
|
|
if (aCX) {
|
|
|
|
*aCX = 0;
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
2022-12-16 02:13:00 +03:00
|
|
|
if (aCY) {
|
|
|
|
*aCY = 0;
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
2017-04-04 17:22:00 +03:00
|
|
|
return NS_OK;
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2022-12-16 02:13:00 +03:00
|
|
|
WebBrowserChrome2Stub::SetDimensions(DimensionRequest&& aRequest) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> window(do_QueryInterface(mBrowser));
|
|
|
|
NS_ENSURE_STATE(window);
|
|
|
|
// Inner and outer dimensions are equal.
|
|
|
|
aRequest.mDimensionKind = DimensionKind::Outer;
|
|
|
|
MOZ_TRY(aRequest.SupplementFrom(window));
|
|
|
|
return aRequest.ApplyOuterTo(window);
|
2015-10-22 21:40:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WebBrowserChrome2Stub::Blur() { return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class BrowserDestroyer final : public Runnable {
|
2016-01-16 06:23:09 +03:00
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
BrowserDestroyer(nsIWebBrowser* aBrowser, nsISupports* aContainer)
|
|
|
|
: mozilla::Runnable("BrowserDestroyer"),
|
|
|
|
mBrowser(aBrowser),
|
|
|
|
mContainer(aContainer) {}
|
2016-01-16 06:23:09 +03:00
|
|
|
|
2020-02-06 22:07:56 +03:00
|
|
|
static nsresult Destroy(nsIWebBrowser* aBrowser) {
|
|
|
|
nsCOMPtr<nsIBaseWindow> window(do_QueryInterface(aBrowser));
|
2020-08-31 21:51:45 +03:00
|
|
|
return window->Destroy();
|
2020-02-06 22:07:56 +03:00
|
|
|
}
|
|
|
|
|
2016-01-16 06:23:09 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
Run() override {
|
|
|
|
// Explicitly destroy the browser, in case this isn't the last reference.
|
2020-02-06 22:07:56 +03:00
|
|
|
return Destroy(mBrowser);
|
2016-01-16 06:23:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~BrowserDestroyer() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWebBrowser> mBrowser;
|
|
|
|
nsCOMPtr<nsISupports> mContainer;
|
|
|
|
};
|
|
|
|
|
2013-04-11 11:09:13 +04:00
|
|
|
// This is the "stub" we return from CreateWindowlessBrowser - it exists
|
2016-01-16 06:23:09 +03:00
|
|
|
// to manage the lifetimes of the nsIWebBrowser and container window.
|
|
|
|
// In particular, it keeps a strong reference to both, to prevent them from
|
|
|
|
// being collected while this object remains alive, and ensures that they
|
|
|
|
// aren't destroyed when it's not safe to run scripts.
|
|
|
|
class WindowlessBrowser final : public nsIWindowlessBrowser,
|
|
|
|
public nsIInterfaceRequestor {
|
2013-04-11 11:09:13 +04:00
|
|
|
public:
|
2016-01-16 06:23:09 +03:00
|
|
|
WindowlessBrowser(nsIWebBrowser* aBrowser, nsISupports* aContainer)
|
|
|
|
: mBrowser(aBrowser), mContainer(aContainer), mClosed(false) {
|
2013-04-11 11:09:13 +04:00
|
|
|
mWebNavigation = do_QueryInterface(aBrowser);
|
|
|
|
mInterfaceRequestor = do_QueryInterface(aBrowser);
|
|
|
|
}
|
|
|
|
NS_DECL_ISUPPORTS
|
2018-08-03 03:05:07 +03:00
|
|
|
NS_DECL_NSIWINDOWLESSBROWSER
|
2016-01-16 06:23:09 +03:00
|
|
|
NS_FORWARD_SAFE_NSIWEBNAVIGATION(mWebNavigation)
|
|
|
|
NS_FORWARD_SAFE_NSIINTERFACEREQUESTOR(mInterfaceRequestor)
|
|
|
|
|
2020-02-06 22:07:56 +03:00
|
|
|
private:
|
|
|
|
~WindowlessBrowser() {
|
2016-01-16 06:23:09 +03:00
|
|
|
if (mClosed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Windowless browser was not closed prior to destruction");
|
|
|
|
|
|
|
|
// The docshell destructor needs to dispatch events, and can only run
|
|
|
|
// when it's safe to run scripts. If this was triggered by GC, it may
|
|
|
|
// not always be safe to run scripts, in which cases we need to delay
|
|
|
|
// destruction until it is.
|
2020-02-06 22:07:56 +03:00
|
|
|
auto runnable = MakeRefPtr<BrowserDestroyer>(mBrowser, mContainer);
|
|
|
|
nsContentUtils::AddScriptRunner(runnable.forget());
|
2016-01-16 06:23:09 +03:00
|
|
|
}
|
|
|
|
|
2013-04-11 11:09:13 +04:00
|
|
|
nsCOMPtr<nsIWebBrowser> mBrowser;
|
|
|
|
nsCOMPtr<nsIWebNavigation> mWebNavigation;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mInterfaceRequestor;
|
|
|
|
// we don't use the container but just hold a reference to it.
|
|
|
|
nsCOMPtr<nsISupports> mContainer;
|
|
|
|
|
2016-01-16 06:23:09 +03:00
|
|
|
bool mClosed;
|
|
|
|
};
|
2013-04-11 11:09:13 +04:00
|
|
|
|
2016-01-16 06:23:09 +03:00
|
|
|
NS_IMPL_ISUPPORTS(WindowlessBrowser, nsIWindowlessBrowser, nsIWebNavigation,
|
|
|
|
nsIInterfaceRequestor)
|
2013-04-11 11:09:13 +04:00
|
|
|
|
2018-08-03 03:05:07 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WindowlessBrowser::Close() {
|
|
|
|
NS_ENSURE_TRUE(!mClosed, NS_ERROR_UNEXPECTED);
|
|
|
|
NS_ASSERTION(nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"WindowlessBrowser::Close called when not safe to run scripts");
|
|
|
|
|
|
|
|
mClosed = true;
|
|
|
|
|
|
|
|
mWebNavigation = nullptr;
|
|
|
|
mInterfaceRequestor = nullptr;
|
2020-02-06 22:07:56 +03:00
|
|
|
return BrowserDestroyer::Destroy(mBrowser);
|
2018-08-03 03:05:07 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 06:28:44 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WindowlessBrowser::GetBrowsingContext(BrowsingContext** aBrowsingContext) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = do_QueryInterface(mBrowser);
|
|
|
|
if (!docShellTreeItem) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
return docShellTreeItem->GetBrowsingContextXPCOM(aBrowsingContext);
|
|
|
|
}
|
|
|
|
|
2018-08-03 03:05:07 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
WindowlessBrowser::GetDocShell(nsIDocShell** aDocShell) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mInterfaceRequestor);
|
|
|
|
if (!docShell) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
docShell.forget(aDocShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-04 17:24:32 +04:00
|
|
|
NS_IMETHODIMP
|
2020-07-10 16:40:51 +03:00
|
|
|
nsAppShellService::CreateWindowlessBrowser(bool aIsChrome, uint32_t aChromeMask,
|
2016-01-16 06:23:09 +03:00
|
|
|
nsIWindowlessBrowser** aResult) {
|
2020-07-10 16:40:51 +03:00
|
|
|
if (aChromeMask) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aIsChrome, "Got chrome flags for non-chrome browser");
|
|
|
|
if (aChromeMask & ~(nsIWebBrowserChrome::CHROME_REMOTE_WINDOW |
|
|
|
|
nsIWebBrowserChrome::CHROME_FISSION_WINDOW |
|
|
|
|
nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW)) {
|
|
|
|
NS_ERROR("Received unexpected chrome flags");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:59:44 +03:00
|
|
|
/* First, we set the container window for our instance of nsWebBrowser. Since
|
2013-04-04 17:24:32 +04:00
|
|
|
* we don't actually have a window, we instead set the container window to be
|
|
|
|
* an instance of WebBrowserChrome2Stub, which provides a stub implementation
|
2019-12-04 16:50:01 +03:00
|
|
|
* of nsIWebBrowserChrome.
|
2013-04-04 17:24:32 +04:00
|
|
|
*/
|
2018-11-27 12:59:44 +03:00
|
|
|
RefPtr<WebBrowserChrome2Stub> stub = new WebBrowserChrome2Stub();
|
2013-04-04 17:24:32 +04:00
|
|
|
|
|
|
|
/* A windowless web browser doesn't have an associated OS level window. To
|
|
|
|
* accomplish this, we initialize the window associated with our instance of
|
2017-04-05 18:20:00 +03:00
|
|
|
* nsWebBrowser with an instance of HeadlessWidget/PuppetWidget, which provide
|
|
|
|
* a stub implementation of nsIWidget.
|
2013-04-04 17:24:32 +04:00
|
|
|
*/
|
2017-04-05 18:20:00 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
widget = nsIWidget::CreateHeadlessWidget();
|
|
|
|
} else {
|
|
|
|
widget = nsIWidget::CreatePuppetWidget(nullptr);
|
|
|
|
}
|
2013-04-04 17:24:32 +04:00
|
|
|
if (!widget) {
|
2017-04-05 18:20:00 +03:00
|
|
|
NS_ERROR("Couldn't create instance of stub widget");
|
2013-04-04 17:24:32 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2018-11-27 12:59:44 +03:00
|
|
|
|
2016-08-19 02:03:17 +03:00
|
|
|
nsresult rv =
|
|
|
|
widget->Create(nullptr, 0, LayoutDeviceIntRect(0, 0, 0, 0), nullptr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2018-11-27 12:59:44 +03:00
|
|
|
|
2019-03-14 21:50:45 +03:00
|
|
|
// Create a BrowsingContext for our windowless browser.
|
2020-04-24 21:33:01 +03:00
|
|
|
RefPtr<BrowsingContext> browsingContext = BrowsingContext::CreateIndependent(
|
2020-02-06 22:08:06 +03:00
|
|
|
aIsChrome ? BrowsingContext::Type::Chrome
|
|
|
|
: BrowsingContext::Type::Content);
|
2019-03-14 21:50:45 +03:00
|
|
|
|
2020-07-10 16:40:51 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW) {
|
|
|
|
browsingContext->SetRemoteTabs(true);
|
|
|
|
}
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_FISSION_WINDOW) {
|
|
|
|
browsingContext->SetRemoteSubframes(true);
|
|
|
|
}
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW) {
|
|
|
|
browsingContext->SetPrivateBrowsing(true);
|
|
|
|
}
|
|
|
|
|
2018-11-27 12:59:44 +03:00
|
|
|
/* Next, we create an instance of nsWebBrowser. Instances of this class have
|
|
|
|
* an associated doc shell, which is what we're interested in.
|
|
|
|
*/
|
2019-08-08 19:07:12 +03:00
|
|
|
nsCOMPtr<nsIWebBrowser> browser = nsWebBrowser::Create(
|
2020-05-08 06:28:44 +03:00
|
|
|
stub, widget, browsingContext, nullptr /* initialWindowChild */);
|
2018-11-27 12:59:44 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!browser)) {
|
|
|
|
NS_ERROR("Couldn't create instance of nsWebBrowser!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the container window owns the the nsWebBrowser instance.
|
|
|
|
stub->SetBrowser(browser);
|
2013-04-04 17:24:32 +04:00
|
|
|
|
2019-12-04 16:50:01 +03:00
|
|
|
nsISupports* isstub = NS_ISUPPORTS_CAST(nsIWebBrowserChrome*, stub);
|
2016-01-16 06:23:09 +03:00
|
|
|
RefPtr<nsIWindowlessBrowser> result = new WindowlessBrowser(browser, isstub);
|
2013-10-16 17:18:42 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(result);
|
|
|
|
docshell->SetInvisible(true);
|
|
|
|
|
2013-04-11 11:09:13 +04:00
|
|
|
result.forget(aResult);
|
2013-04-04 17:24:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
uint32_t nsAppShellService::CalculateWindowZLevel(nsIAppWindow* aParent,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aChromeMask) {
|
|
|
|
uint32_t zLevel;
|
2003-10-07 05:20:05 +04:00
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
zLevel = nsIAppWindow::normalZ;
|
2003-10-07 05:20:05 +04:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RAISED)
|
2019-11-05 20:56:28 +03:00
|
|
|
zLevel = nsIAppWindow::raisedZ;
|
2003-10-07 05:20:05 +04:00
|
|
|
else if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_LOWERED)
|
2019-11-05 20:56:28 +03:00
|
|
|
zLevel = nsIAppWindow::loweredZ;
|
2003-10-07 05:20:05 +04:00
|
|
|
|
2006-11-16 06:25:55 +03:00
|
|
|
#ifdef XP_MACOSX
|
2003-10-07 05:20:05 +04:00
|
|
|
/* 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 19:56:38 +04:00
|
|
|
uint32_t modalDepMask =
|
2003-10-07 05:20:05 +04:00
|
|
|
nsIWebBrowserChrome::CHROME_MODAL | nsIWebBrowserChrome::CHROME_DEPENDENT;
|
|
|
|
if (aParent && (aChromeMask & modalDepMask)) {
|
2004-10-24 21:36:11 +04:00
|
|
|
aParent->GetZLevel(&zLevel);
|
2003-10-07 05:20:05 +04:00
|
|
|
}
|
|
|
|
#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;
|
|
|
|
}
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2010-12-04 13:06:53 +03:00
|
|
|
#ifdef XP_WIN
|
2010-08-27 08:44:01 +04:00
|
|
|
/*
|
|
|
|
* Checks to see if any existing window is currently in fullscreen mode.
|
|
|
|
*/
|
|
|
|
static bool CheckForFullscreenWindow() {
|
|
|
|
nsCOMPtr<nsIWindowMediator> wm(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!wm) return false;
|
2010-08-27 08:44:01 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowList;
|
2019-11-05 20:56:28 +03:00
|
|
|
wm->GetAppWindowEnumerator(nullptr, getter_AddRefs(windowList));
|
2010-08-27 08:44:01 +04:00
|
|
|
if (!windowList) return false;
|
|
|
|
|
|
|
|
for (;;) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool more = false;
|
2010-08-27 08:44:01 +04:00
|
|
|
windowList->HasMoreElements(&more);
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!more) return false;
|
2010-08-27 08:44:01 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supportsWindow;
|
|
|
|
windowList->GetNext(getter_AddRefs(supportsWindow));
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWin(do_QueryInterface(supportsWindow));
|
|
|
|
if (baseWin) {
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
baseWin->GetMainWidget(getter_AddRefs(widget));
|
2013-04-26 10:49:47 +04:00
|
|
|
if (widget && widget->SizeMode() == nsSizeMode_Fullscreen) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-08-27 08:44:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-12-04 13:06:53 +03:00
|
|
|
#endif
|
2010-08-27 08:44:01 +04:00
|
|
|
|
1999-07-20 18:40:55 +04:00
|
|
|
/*
|
|
|
|
* Just do the window-making part of CreateTopLevelWindow
|
|
|
|
*/
|
2000-02-29 03:20:55 +03:00
|
|
|
nsresult nsAppShellService::JustCreateTopWindow(
|
2019-11-05 20:56:28 +03:00
|
|
|
nsIAppWindow* aParent, nsIURI* aUrl, uint32_t aChromeMask,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aInitialWidth, int32_t aInitialHeight, bool aIsHiddenWindow,
|
2019-11-05 20:56:28 +03:00
|
|
|
AppWindow** aResult) {
|
2023-01-24 02:58:41 +03:00
|
|
|
using BorderStyle = widget::BorderStyle;
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2009-11-21 01:25:11 +03:00
|
|
|
NS_ENSURE_STATE(!mXPCOMWillShutDown);
|
1999-07-27 10:34:25 +04:00
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
nsCOMPtr<nsIAppWindow> parent;
|
2009-09-29 06:20:46 +04:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEPENDENT) parent = aParent;
|
|
|
|
|
2019-11-05 20:56:28 +03:00
|
|
|
RefPtr<AppWindow> window = new AppWindow(aChromeMask);
|
1999-07-27 10:34:25 +04:00
|
|
|
|
2010-08-27 08:44:01 +04: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()) window->IgnoreXULSizeMode(true);
|
|
|
|
#endif
|
|
|
|
|
2023-01-24 02:58:41 +03:00
|
|
|
widget::InitData widgetInitData;
|
2005-02-20 01:42:01 +03:00
|
|
|
|
|
|
|
if (aIsHiddenWindow)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mWindowType = widget::WindowType::Invisible;
|
2005-02-20 01:42:01 +03:00
|
|
|
else
|
|
|
|
widgetInitData.mWindowType =
|
|
|
|
aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG
|
2023-01-24 02:58:41 +03:00
|
|
|
? widget::WindowType::Dialog
|
|
|
|
: widget::WindowType::TopLevel;
|
2005-02-20 01:42:01 +03:00
|
|
|
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_POPUP)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mWindowType = widget::WindowType::Popup;
|
2002-03-22 22:22:05 +03:00
|
|
|
|
2017-02-04 00:04:33 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_SUPPRESS_ANIMATION)
|
2012-02-17 07:47:39 +04:00
|
|
|
widgetInitData.mIsAnimationSuppressed = true;
|
|
|
|
|
2019-01-16 01:29:59 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_ALWAYS_ON_TOP)
|
|
|
|
widgetInitData.mAlwaysOnTop = true;
|
|
|
|
|
2021-09-18 00:42:15 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_REMOTE_WINDOW)
|
|
|
|
widgetInitData.mHasRemoteContent = true;
|
|
|
|
|
2023-03-21 17:36:19 +03:00
|
|
|
#if defined(MOZ_WIDGET_GTK) || defined(XP_WIN)
|
|
|
|
// Windows/Gtk PIP window support. It's Chrome dialog window, always on top
|
2019-09-28 09:55:41 +03:00
|
|
|
// and without any bar.
|
|
|
|
uint32_t pipMask = nsIWebBrowserChrome::CHROME_ALWAYS_ON_TOP |
|
2023-02-16 17:50:23 +03:00
|
|
|
nsIWebBrowserChrome::CHROME_OPENAS_CHROME |
|
|
|
|
nsIWebBrowserChrome::CHROME_WINDOW_RESIZE;
|
2019-09-28 09:55:41 +03:00
|
|
|
uint32_t barMask = nsIWebBrowserChrome::CHROME_MENUBAR |
|
|
|
|
nsIWebBrowserChrome::CHROME_TOOLBAR |
|
|
|
|
nsIWebBrowserChrome::CHROME_LOCATIONBAR |
|
2023-03-21 17:36:19 +03:00
|
|
|
nsIWebBrowserChrome::CHROME_TITLEBAR |
|
2020-06-09 16:35:52 +03:00
|
|
|
nsIWebBrowserChrome::CHROME_STATUSBAR;
|
2023-01-24 02:58:41 +03:00
|
|
|
if (widgetInitData.mWindowType == widget::WindowType::Dialog &&
|
2020-06-09 16:35:52 +03:00
|
|
|
((aChromeMask & pipMask) == pipMask) && !(aChromeMask & barMask)) {
|
|
|
|
widgetInitData.mPIPWindow = true;
|
|
|
|
}
|
2019-09-28 09:55:41 +03:00
|
|
|
#endif
|
|
|
|
|
2004-11-12 19:42:58 +03:00
|
|
|
#ifdef XP_MACOSX
|
2005-02-20 01:42:01 +03:00
|
|
|
// Mac OS X sheet support
|
2008-03-24 01:30:56 +03: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 19:56:38 +04:00
|
|
|
uint32_t sheetMask = nsIWebBrowserChrome::CHROME_OPENAS_DIALOG |
|
2008-03-24 01:30:56 +03:00
|
|
|
nsIWebBrowserChrome::CHROME_MODAL |
|
|
|
|
nsIWebBrowserChrome::CHROME_OPENAS_CHROME;
|
2019-10-30 18:35:31 +03:00
|
|
|
if (parent && (parent != mHiddenWindow) &&
|
2014-01-18 15:49:47 +04:00
|
|
|
((aChromeMask & sheetMask) == sheetMask)) {
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mWindowType = widget::WindowType::Sheet;
|
2014-01-18 15:49:47 +04:00
|
|
|
}
|
2004-11-12 19:42:58 +03:00
|
|
|
#endif
|
|
|
|
|
2010-06-26 02:50:36 +04:00
|
|
|
#if defined(XP_WIN)
|
2023-01-24 02:58:41 +03:00
|
|
|
if (widgetInitData.mWindowType == widget::WindowType::TopLevel ||
|
|
|
|
widgetInitData.mWindowType == widget::WindowType::Dialog)
|
2022-06-03 13:23:00 +03:00
|
|
|
widgetInitData.mClipChildren = true;
|
2010-06-26 02:50:36 +04:00
|
|
|
#endif
|
|
|
|
|
2005-02-20 01:42:01 +03:00
|
|
|
// note default chrome overrides other OS chrome settings, but
|
|
|
|
// not internal chrome
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_DEFAULT)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle = BorderStyle::Default;
|
2005-02-20 01:42:01 +03:00
|
|
|
else if ((aChromeMask & nsIWebBrowserChrome::CHROME_ALL) ==
|
|
|
|
nsIWebBrowserChrome::CHROME_ALL)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle = BorderStyle::All;
|
2005-02-20 01:42:01 +03:00
|
|
|
else {
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle = BorderStyle::None; // assumes none == 0x00
|
2005-02-20 01:42:01 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_BORDERS)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Border;
|
2005-02-20 01:42:01 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Title;
|
2005-02-20 01:42:01 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_CLOSE)
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Close;
|
2005-02-20 01:42:01 +03:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) {
|
2020-06-05 20:09:58 +03:00
|
|
|
widgetInitData.mResizable = true;
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::ResizeH;
|
2005-02-20 01:42:01 +03:00
|
|
|
// only resizable windows get the maximize button (but not dialogs)
|
2002-02-10 10:12:16 +03:00
|
|
|
if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Maximize;
|
1999-07-28 02:42:34 +04:00
|
|
|
}
|
2005-02-20 01:42:01 +03:00
|
|
|
// all windows (except dialogs) get minimize buttons and the system menu
|
|
|
|
if (!(aChromeMask & nsIWebBrowserChrome::CHROME_OPENAS_DIALOG))
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Minimize | BorderStyle::Menu;
|
2005-02-20 01:42:01 +03:00
|
|
|
// but anyone can explicitly ask for a minimize button
|
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_WINDOW_MIN) {
|
2023-01-24 02:58:41 +03:00
|
|
|
widgetInitData.mBorderStyle |= BorderStyle::Minimize;
|
2017-02-04 00:04:33 +03:00
|
|
|
}
|
2005-02-20 01:42:01 +03:00
|
|
|
}
|
1999-07-01 06:50:53 +04:00
|
|
|
|
2005-02-20 01:42:01 +03:00
|
|
|
if (aInitialWidth == nsIAppShellService::SIZE_TO_CONTENT ||
|
|
|
|
aInitialHeight == nsIAppShellService::SIZE_TO_CONTENT) {
|
|
|
|
aInitialWidth = 1;
|
|
|
|
aInitialHeight = 1;
|
2011-10-17 18:59:28 +04:00
|
|
|
window->SetIntrinsicallySized(true);
|
2005-02-20 01:42:01 +03:00
|
|
|
}
|
1999-07-04 08:09:54 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool center = aChromeMask & nsIWebBrowserChrome::CHROME_CENTER_SCREEN;
|
2009-09-29 06:20:46 +04:00
|
|
|
|
2017-03-14 22:35:06 +03:00
|
|
|
widgetInitData.mRTL = LocaleService::GetInstance()->IsAppLocaleRTL();
|
2009-12-21 13:22:09 +03:00
|
|
|
|
2012-10-17 02:06:38 +04:00
|
|
|
// Enforce the Private Browsing autoStart pref first.
|
|
|
|
bool isPrivateBrowsingWindow =
|
2022-09-22 03:26:17 +03:00
|
|
|
StaticPrefs::browser_privatebrowsing_autostart();
|
2012-12-11 08:49:17 +04:00
|
|
|
if (aChromeMask & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW) {
|
|
|
|
// Caller requested a private window
|
|
|
|
isPrivateBrowsingWindow = true;
|
|
|
|
}
|
2023-02-03 06:28:06 +03:00
|
|
|
widgetInitData.mIsPrivate = isPrivateBrowsingWindow;
|
|
|
|
|
2023-02-03 21:10:09 +03:00
|
|
|
nsresult rv =
|
|
|
|
window->Initialize(parent, center ? aParent : nullptr, aInitialWidth,
|
|
|
|
aInitialHeight, aIsHiddenWindow, widgetInitData);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWin = do_GetInterface(aParent);
|
2014-06-20 22:07:47 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(domWin);
|
|
|
|
nsCOMPtr<nsILoadContext> parentContext = do_QueryInterface(webNav);
|
2017-12-04 23:06:26 +03:00
|
|
|
|
2014-06-20 22:07:47 +04:00
|
|
|
if (!isPrivateBrowsingWindow && parentContext) {
|
2012-10-17 02:06:38 +04:00
|
|
|
// Ensure that we propagate any existing private browsing status
|
|
|
|
// from the parent, even if it will not actually be used
|
|
|
|
// as a parent value.
|
2017-12-04 23:06:26 +03:00
|
|
|
isPrivateBrowsingWindow = parentContext->UsePrivateBrowsing();
|
2014-06-20 22:07:47 +04:00
|
|
|
}
|
|
|
|
|
2023-08-01 15:09:36 +03:00
|
|
|
if (RefPtr<nsDocShell> docShell = window->GetDocShell()) {
|
2020-04-15 16:42:40 +03:00
|
|
|
MOZ_ASSERT(docShell->GetBrowsingContext()->IsChrome());
|
2020-04-08 00:39:19 +03:00
|
|
|
|
|
|
|
docShell->SetPrivateBrowsing(isPrivateBrowsingWindow);
|
|
|
|
docShell->SetRemoteTabs(aChromeMask &
|
|
|
|
nsIWebBrowserChrome::CHROME_REMOTE_WINDOW);
|
|
|
|
docShell->SetRemoteSubframes(aChromeMask &
|
|
|
|
nsIWebBrowserChrome::CHROME_FISSION_WINDOW);
|
|
|
|
|
|
|
|
// Eagerly create an about:blank content viewer with the right principal
|
2022-09-21 02:29:06 +03:00
|
|
|
// here, rather than letting it happen in the upcoming call to
|
|
|
|
// SetInitialPrincipal. This avoids creating the about:blank document and
|
|
|
|
// then blowing it away with a second one, which can cause problems for the
|
|
|
|
// top-level chrome window case. See bug 789773.
|
|
|
|
// Toplevel chrome windows always have a system principal, so ensure the
|
|
|
|
// initial window is created with that principal.
|
|
|
|
// We need to do this even when creating a chrome window to load a content
|
|
|
|
// window, see bug 799348 comment 13 for details about what previously
|
|
|
|
// happened here due to it using the subject principal.
|
2020-04-08 00:39:19 +03:00
|
|
|
if (nsContentUtils::IsInitialized()) { // Sometimes this happens really
|
|
|
|
// early. See bug 793370.
|
2022-09-21 02:29:06 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
nsContentUtils::LegacyIsCallerChromeOrNativeCode(),
|
|
|
|
"Previously, this method would use the subject principal rather than "
|
|
|
|
"hardcoding the system principal");
|
|
|
|
// Use the system principal as the storage principal too until the new
|
|
|
|
// window finishes navigating and gets a real storage principal.
|
2023-11-24 00:35:21 +03:00
|
|
|
rv = docShell->CreateAboutBlankDocumentViewer(
|
2022-09-21 02:29:06 +03:00
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
|
|
|
/* aCsp = */ nullptr, /* aBaseURI = */ nullptr,
|
2021-07-14 18:51:20 +03:00
|
|
|
/* aIsInitialDocument = */ true);
|
2020-04-08 00:39:19 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2023-01-24 02:58:41 +03:00
|
|
|
RefPtr<dom::Document> doc = docShell->GetDocument();
|
2020-04-08 00:39:19 +03:00
|
|
|
NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);
|
2021-07-14 18:51:20 +03:00
|
|
|
MOZ_ASSERT(doc->IsInitialDocument(),
|
|
|
|
"Document should be an initial document");
|
2020-04-08 00:39:19 +03:00
|
|
|
}
|
2014-06-20 22:07:47 +04:00
|
|
|
|
2020-04-08 00:39:19 +03:00
|
|
|
// Begin loading the URL provided.
|
|
|
|
if (aUrl) {
|
|
|
|
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aUrl);
|
|
|
|
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
|
|
|
|
loadState->SetFirstParty(true);
|
|
|
|
rv = docShell->LoadURI(loadState, /* aSetNavigating */ true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2012-10-10 19:28:42 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 01:19:00 +03:00
|
|
|
window.forget(aResult);
|
2009-09-29 06:20:46 +04:00
|
|
|
if (parent) parent->AddChildWindow(*aResult);
|
2000-04-14 00:32:30 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (center) rv = (*aResult)->Center(parent, parent ? false : true, false);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-20 18:40:55 +04:00
|
|
|
NS_IMETHODIMP
|
2019-11-05 20:56:28 +03:00
|
|
|
nsAppShellService::GetHiddenWindow(nsIAppWindow** aWindow) {
|
2000-02-29 03:20:55 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2019-03-05 23:18:25 +03:00
|
|
|
EnsureHiddenWindow();
|
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
*aWindow = mHiddenWindow;
|
|
|
|
NS_IF_ADDREF(*aWindow);
|
|
|
|
return *aWindow ? NS_OK : NS_ERROR_FAILURE;
|
1999-07-20 18:40:55 +04:00
|
|
|
}
|
|
|
|
|
2000-05-25 04:44:10 +04:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsAppShellService::GetHiddenDOMWindow(mozIDOMWindowProxy** aWindow) {
|
2019-03-05 23:18:25 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
|
|
|
EnsureHiddenWindow();
|
|
|
|
|
2000-05-25 04:44:10 +04:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
2002-01-28 21:52:24 +03:00
|
|
|
NS_ENSURE_TRUE(mHiddenWindow, NS_ERROR_FAILURE);
|
|
|
|
|
2000-05-25 04:44:10 +04:00
|
|
|
rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell));
|
2004-10-29 23:28:38 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-01-10 06:03:47 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
2012-10-09 13:56:58 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> hiddenDOMWindow(docShell->GetWindow());
|
2014-01-10 06:03:47 +04:00
|
|
|
hiddenDOMWindow.forget(aWindow);
|
|
|
|
return *aWindow ? NS_OK : NS_ERROR_FAILURE;
|
2000-05-25 04:44:10 +04:00
|
|
|
}
|
|
|
|
|
2019-03-05 23:18:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::GetHasHiddenWindow(bool* aHasHiddenWindow) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aHasHiddenWindow);
|
|
|
|
|
|
|
|
*aHasHiddenWindow = !!mHiddenWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-24 01:30:29 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsAppShellService::GetApplicationProvidedHiddenWindow(bool* aAPHW) {
|
2007-08-24 01:30:29 +04:00
|
|
|
*aAPHW = mApplicationProvidedHiddenWindow;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
/*
|
|
|
|
* Register a new top level window (created elsewhere)
|
|
|
|
*/
|
1998-12-03 04:35:53 +03:00
|
|
|
NS_IMETHODIMP
|
2019-11-05 20:56:28 +03:00
|
|
|
nsAppShellService::RegisterTopLevelWindow(nsIAppWindow* aWindow) {
|
2012-10-09 13:56:58 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
2012-09-05 22:32:06 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
aWindow->GetDocShell(getter_AddRefs(docShell));
|
2014-01-10 06:03:47 +04:00
|
|
|
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow(docShell->GetWindow());
|
2012-10-09 13:56:58 +04:00
|
|
|
NS_ENSURE_TRUE(domWindow, NS_ERROR_FAILURE);
|
2022-09-21 02:29:06 +03:00
|
|
|
|
|
|
|
// Toplevel chrome windows always have a system principal, so ensure the
|
|
|
|
// initial window is created with that principal.
|
|
|
|
// We need to do this even when creating a chrome window to load a content
|
|
|
|
// window, see bug 799348 comment 13 for details about what previously
|
|
|
|
// happened here due to it using the subject principal.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
nsContentUtils::LegacyIsCallerChromeOrNativeCode(),
|
|
|
|
"Previously, this method would use the subject principal rather than "
|
|
|
|
"hardcoding the system principal");
|
|
|
|
domWindow->SetInitialPrincipal(nsContentUtils::GetSystemPrincipal(), nullptr,
|
|
|
|
Nothing());
|
2012-09-05 22:32:06 +04:00
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
// tell the window mediator about the new window
|
2004-10-29 23:28:38 +04:00
|
|
|
nsCOMPtr<nsIWindowMediator> mediator(
|
|
|
|
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
NS_ASSERTION(mediator, "Couldn't get window mediator.");
|
|
|
|
|
|
|
|
if (mediator) mediator->RegisterWindow(aWindow);
|
2001-09-08 03:37:16 +04:00
|
|
|
|
|
|
|
// tell the window watcher about the new window
|
2004-10-29 23:28:38 +04:00
|
|
|
nsCOMPtr<nsPIWindowWatcher> wwatcher(
|
|
|
|
do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
|
|
|
NS_ASSERTION(wwatcher, "No windowwatcher?");
|
2012-09-05 22:32:06 +04:00
|
|
|
if (wwatcher && domWindow) {
|
|
|
|
wwatcher->AddWindow(domWindow, 0);
|
2001-09-08 03:37:16 +04:00
|
|
|
}
|
2001-09-07 23:29:43 +04:00
|
|
|
|
2002-08-30 03:55:37 +04:00
|
|
|
// an ongoing attempt to quit is stopped by a newly opened window
|
2014-04-29 21:31:06 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obssvc = services::GetObserverService();
|
2004-10-29 23:28:38 +04:00
|
|
|
NS_ASSERTION(obssvc, "Couldn't get observer service.");
|
|
|
|
|
2016-06-02 20:28:28 +03:00
|
|
|
if (obssvc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
obssvc->NotifyObservers(aWindow, "xul-window-registered", nullptr);
|
2019-11-05 20:56:28 +03:00
|
|
|
AppWindow* appWindow = static_cast<AppWindow*>(aWindow);
|
|
|
|
appWindow->WasRegistered();
|
2016-06-02 20:28:28 +03:00
|
|
|
}
|
2002-08-30 03:55:37 +04:00
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
return NS_OK;
|
1999-02-15 08:38:15 +03:00
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
1999-02-15 08:38:15 +03:00
|
|
|
NS_IMETHODIMP
|
2019-11-05 20:56:28 +03:00
|
|
|
nsAppShellService::UnregisterTopLevelWindow(nsIAppWindow* aWindow) {
|
2004-06-20 07:42:50 +04:00
|
|
|
if (mXPCOMShuttingDown) {
|
2001-09-08 03:37:16 +04:00
|
|
|
/* 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
|
2005-02-20 01:42:01 +03:00
|
|
|
mHiddenWindow->Destroy() in our destructor)
|
2001-09-08 03:37:16 +04:00
|
|
|
*/
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2012-10-09 13:56:58 +04:00
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aWindow);
|
|
|
|
|
2006-11-16 06:25:55 +03:00
|
|
|
if (aWindow == mHiddenWindow) {
|
|
|
|
// CreateHiddenWindow() does not register the window, so we're done.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
// tell the window mediator
|
2004-10-29 23:28:38 +04:00
|
|
|
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 13:56:58 +04:00
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
// tell the window watcher
|
2004-10-29 23:28:38 +04:00
|
|
|
nsCOMPtr<nsPIWindowWatcher> wwatcher(
|
|
|
|
do_GetService(NS_WINDOWWATCHER_CONTRACTID));
|
|
|
|
NS_ASSERTION(wwatcher, "Couldn't get windowwatcher, doing xpcom shutdown?");
|
|
|
|
if (wwatcher) {
|
2001-09-08 03:37:16 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
aWindow->GetDocShell(getter_AddRefs(docShell));
|
|
|
|
if (docShell) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow(docShell->GetWindow());
|
2004-10-29 23:28:38 +04:00
|
|
|
if (domWindow) wwatcher->RemoveWindow(domWindow);
|
2001-09-08 03:37:16 +04:00
|
|
|
}
|
|
|
|
}
|
2000-02-29 03:20:55 +03:00
|
|
|
|
2001-09-08 03:37:16 +04:00
|
|
|
return NS_OK;
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
2001-06-20 10:49:22 +04:00
|
|
|
NS_IMETHODIMP
|
2004-10-29 23:28:38 +04:00
|
|
|
nsAppShellService::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData) {
|
2009-11-21 01:25:11 +03:00
|
|
|
if (!strcmp(aTopic, "xpcom-will-shutdown")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mXPCOMWillShutDown = true;
|
2009-11-21 01:25:11 +03:00
|
|
|
} else if (!strcmp(aTopic, "xpcom-shutdown")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mXPCOMShuttingDown = true;
|
2009-11-21 01:25:11 +03:00
|
|
|
if (mHiddenWindow) {
|
|
|
|
mHiddenWindow->Destroy();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Unexpected observer topic!");
|
2003-01-22 09:13:39 +03:00
|
|
|
}
|
|
|
|
|
1999-10-22 01:36:25 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-02-11 18:24:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::StartEventLoopLagTracking(bool* aResult) {
|
2014-02-12 19:33:43 +04:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
2014-02-11 18:24:47 +04:00
|
|
|
*aResult = mozilla::InitEventTracing(true);
|
2014-02-12 19:33:43 +04:00
|
|
|
#endif
|
2014-02-11 18:24:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAppShellService::StopEventLoopLagTracking() {
|
2014-02-12 19:33:43 +04:00
|
|
|
#ifdef MOZ_INSTRUMENT_EVENT_LOOP
|
2014-02-11 18:24:47 +04:00
|
|
|
mozilla::ShutdownEventTracing();
|
2014-02-12 19:33:43 +04:00
|
|
|
#endif
|
2014-02-11 18:24:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|