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 "nsWebShellWindow.h"
|
|
|
|
|
1999-05-16 14:02:19 +04:00
|
|
|
#include "nsLayoutCID.h"
|
2001-02-22 06:01:34 +03:00
|
|
|
#include "nsContentCID.h"
|
2018-12-26 05:35:30 +03:00
|
|
|
#include "nsContentList.h"
|
1999-08-13 02:08:17 +04:00
|
|
|
#include "nsIWeakReference.h"
|
2011-10-15 11:33:26 +04:00
|
|
|
#include "nsIContentViewer.h"
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1998-12-30 03:03:52 +03:00
|
|
|
#include "nsIServiceManager.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 07:29:44 +04:00
|
|
|
#include "nsIURL.h"
|
2001-04-10 10:01:08 +04:00
|
|
|
#include "nsNetCID.h"
|
2000-09-01 09:54:59 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
#include "nsContentUtils.h"
|
1999-05-28 00:36:15 +04:00
|
|
|
#include "nsEscape.h"
|
2000-01-27 01:48:16 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2000-03-16 05:20:26 +03:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-04-07 07:33:56 +04:00
|
|
|
#include "nsIWindowWatcher.h"
|
1999-04-20 02:05:49 +04:00
|
|
|
|
2013-10-22 17:27:34 +04:00
|
|
|
#include "nsWidgetInitData.h"
|
1998-12-03 04:35:53 +03:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIWidget.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsIWidgetListener.h"
|
1998-12-30 03:03:52 +03:00
|
|
|
|
2018-01-31 23:18:10 +03:00
|
|
|
#include "nsINodeList.h"
|
1999-01-26 18:58:58 +03:00
|
|
|
|
2000-02-23 23:07:31 +03:00
|
|
|
#include "nsITimer.h"
|
2007-11-28 23:18:11 +03:00
|
|
|
#include "nsXULPopupManager.h"
|
1999-01-27 13:51:28 +03:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2000-02-12 02:50:15 +03:00
|
|
|
|
2000-12-15 02:27:59 +03:00
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2000-01-29 09:48:38 +03:00
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
1999-06-09 00:59:41 +04:00
|
|
|
#include "nsIObserverService.h"
|
1999-02-22 00:04:21 +03:00
|
|
|
|
2010-10-08 22:51:50 +04:00
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
#include "nsIScreen.h"
|
|
|
|
|
1999-02-22 00:04:21 +03:00
|
|
|
#include "nsIContent.h" // for menus
|
2012-09-18 14:16:05 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
1998-12-30 03:03:52 +03:00
|
|
|
|
1999-02-12 18:56:54 +03:00
|
|
|
// For calculating size
|
|
|
|
#include "nsIPresShell.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1999-02-12 18:56:54 +03:00
|
|
|
|
1999-12-18 02:43:47 +03:00
|
|
|
#include "nsIBaseWindow.h"
|
2000-01-26 05:21:42 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "nsDocShell.h"
|
2000-01-26 05:21:42 +03:00
|
|
|
|
2012-07-24 01:28:06 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-17 21:53:03 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2017-08-06 20:28:52 +03:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2000-02-08 18:55:46 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2019-01-11 14:43:39 +03:00
|
|
|
#include "mozilla/dom/LoadURIOptionsBinding.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
|
2015-03-31 23:39:02 +03:00
|
|
|
#include "nsPIWindowRoot.h"
|
|
|
|
|
2017-04-04 17:22:00 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
#ifdef XP_MACOSX
|
2019-01-18 12:16:18 +03:00
|
|
|
# include "nsINativeMenuService.h"
|
|
|
|
# define USE_NATIVE_MENUS
|
2002-06-27 03:32:09 +04:00
|
|
|
#endif
|
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
using namespace mozilla;
|
2013-04-22 05:25:28 +04:00
|
|
|
using namespace mozilla::dom;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
|
2000-02-23 23:07:31 +03:00
|
|
|
#define SIZE_PERSISTENCE_TIMEOUT 500 // msec
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWebShellWindow::nsWebShellWindow(uint32_t aChromeFlags)
|
2009-08-14 15:00:44 +04:00
|
|
|
: nsXULWindow(aChromeFlags),
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
mSPTimerLock("nsWebShellWindow.mSPTimerLock"),
|
2018-01-10 14:04:43 +03:00
|
|
|
mWidgetListenerDelegate(this) {}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
nsWebShellWindow::~nsWebShellWindow() {
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
|
|
|
if (mSPTimer) mSPTimer->Cancel();
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
2005-01-04 01:51:17 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsWebShellWindow, nsXULWindow)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsWebShellWindow, nsXULWindow)
|
1998-12-30 03:03:52 +03:00
|
|
|
|
1999-11-24 13:04:13 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsWebShellWindow)
|
2005-02-20 01:42:01 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
2005-01-04 01:51:17 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsXULWindow)
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2000-02-29 03:20:55 +03:00
|
|
|
nsresult nsWebShellWindow::Initialize(
|
2009-09-29 06:20:46 +04:00
|
|
|
nsIXULWindow* aParent, nsIXULWindow* aOpener, nsIURI* aUrl,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aInitialWidth, int32_t aInitialHeight, bool aIsHiddenWindow,
|
2016-10-07 21:59:59 +03:00
|
|
|
nsITabParent* aOpeningTab, mozIDOMWindowProxy* aOpenerWindow,
|
2005-02-20 01:42:01 +03:00
|
|
|
nsWidgetInitData& widgetInitData) {
|
1998-12-03 04:35:53 +03:00
|
|
|
nsresult rv;
|
1999-08-19 18:44:31 +04:00
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
1999-07-20 18:40:55 +04:00
|
|
|
|
2001-04-12 03:04:28 +04:00
|
|
|
mIsHiddenWindow = aIsHiddenWindow;
|
2009-09-29 06:20:46 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t initialX = 0, initialY = 0;
|
2009-09-29 06:20:46 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aOpener));
|
|
|
|
if (base) {
|
2018-01-10 19:15:22 +03:00
|
|
|
int32_t x, y, width, height;
|
|
|
|
rv = base->GetPositionAndSize(&x, &y, &width, &height);
|
2009-09-29 06:20:46 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-04-19 07:07:23 +04:00
|
|
|
mOpenerScreenRect.SetEmpty();
|
2010-10-08 22:51:50 +04:00
|
|
|
} else {
|
2012-10-16 23:41:19 +04:00
|
|
|
double scale;
|
|
|
|
if (NS_SUCCEEDED(base->GetUnscaledDevicePixelsPerCSSPixel(&scale))) {
|
2018-01-10 19:15:22 +03:00
|
|
|
mOpenerScreenRect.SetRect(
|
|
|
|
NSToIntRound(x / scale), NSToIntRound(y / scale),
|
|
|
|
NSToIntRound(width / scale), NSToIntRound(height / scale));
|
|
|
|
} else {
|
|
|
|
mOpenerScreenRect.SetRect(x, y, width, height);
|
2012-10-16 23:41:19 +04:00
|
|
|
}
|
2018-01-10 19:15:22 +03:00
|
|
|
initialX = mOpenerScreenRect.X();
|
|
|
|
initialY = mOpenerScreenRect.Y();
|
2010-10-08 22:51:50 +04:00
|
|
|
ConstrainToOpenerScreen(&initialX, &initialY);
|
2009-09-29 06:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
// XXX: need to get the default window size from prefs...
|
1999-07-20 18:40:55 +04:00
|
|
|
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
2016-01-13 10:32:55 +03:00
|
|
|
DesktopIntRect deskRect(initialX, initialY, aInitialWidth, aInitialHeight);
|
2015-11-26 07:55:36 +03:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
// Create top level window
|
2017-04-04 17:22:00 +03:00
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
mWindow = nsIWidget::CreateHeadlessWidget();
|
|
|
|
} else {
|
2018-08-20 16:47:00 +03:00
|
|
|
mWindow = nsIWidget::CreateTopLevelWindow();
|
|
|
|
}
|
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
1999-08-13 02:08:17 +04:00
|
|
|
/* This next bit is troublesome. We carry two different versions of a pointer
|
|
|
|
to our parent window. One is the parent window's widget, which is passed
|
|
|
|
to our own widget. The other is a weak reference we keep here to our
|
|
|
|
parent WebShellWindow. The former is useful to the widget, and we can't
|
|
|
|
trust its treatment of the parent reference because they're platform-
|
|
|
|
specific. The latter is useful to this class.
|
|
|
|
A better implementation would be one in which the parent keeps strong
|
|
|
|
references to its children and closes them before it allows itself
|
|
|
|
to be closed. This would mimic the behaviour of OSes that support
|
|
|
|
top-level child windows in OSes that do not. Later.
|
|
|
|
*/
|
2000-02-29 03:20:55 +03:00
|
|
|
nsCOMPtr<nsIBaseWindow> parentAsWin(do_QueryInterface(aParent));
|
|
|
|
if (parentAsWin) {
|
|
|
|
parentAsWin->GetMainWidget(getter_AddRefs(parentWidget));
|
2003-07-25 23:06:59 +04:00
|
|
|
mParentWindow = do_GetWeakReference(aParent);
|
1999-08-13 02:08:17 +04:00
|
|
|
}
|
|
|
|
|
2018-01-10 14:04:43 +03:00
|
|
|
mWindow->SetWidgetListener(&mWidgetListenerDelegate);
|
2016-08-19 02:03:17 +03:00
|
|
|
rv = mWindow->Create((nsIWidget*)parentWidget, // Parent nsIWidget
|
|
|
|
nullptr, // Native parent widget
|
|
|
|
deskRect, // Widget dimensions
|
|
|
|
&widgetInitData); // Widget initialization data
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-01-13 10:32:55 +03:00
|
|
|
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect r = mWindow->GetClientBounds();
|
2010-09-08 19:21:56 +04:00
|
|
|
// Match the default background color of content. Important on windows
|
|
|
|
// since we no longer use content child widgets.
|
|
|
|
mWindow->SetBackgroundColor(NS_RGB(255, 255, 255));
|
1998-12-03 04:35:53 +03:00
|
|
|
|
|
|
|
// Create web shell
|
2018-11-27 12:59:44 +03:00
|
|
|
RefPtr<BrowsingContext> openerContext =
|
|
|
|
aOpenerWindow
|
|
|
|
? nsPIDOMWindowOuter::From(aOpenerWindow)->GetBrowsingContext()
|
|
|
|
: nullptr;
|
2018-11-05 15:43:10 +03:00
|
|
|
RefPtr<BrowsingContext> browsingContext =
|
2018-11-27 12:59:44 +03:00
|
|
|
BrowsingContext::Create(/* aParent */ nullptr, openerContext,
|
|
|
|
EmptyString(), BrowsingContext::Type::Chrome);
|
2018-11-05 15:43:10 +03:00
|
|
|
mDocShell = nsDocShell::Create(browsingContext);
|
2000-03-11 04:25:54 +03:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
// XXX(nika): This is used to handle propagating opener across remote tab
|
|
|
|
// creation. We should come up with a better system for doing this (probably
|
|
|
|
// based on BrowsingContext).
|
2014-06-06 06:51:14 +04:00
|
|
|
mDocShell->SetOpener(aOpeningTab);
|
|
|
|
|
2005-09-16 19:51:14 +04:00
|
|
|
// Make sure to set the item type on the docshell _before_ calling
|
|
|
|
// Create() so it knows what type it is.
|
2018-10-02 00:38:01 +03:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(mDocShell);
|
2005-09-16 19:51:14 +04:00
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
docShellAsItem->SetTreeOwner(mChromeTreeOwner);
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2018-01-10 19:15:22 +03:00
|
|
|
r.MoveTo(0, 0);
|
2000-03-11 04:25:54 +03:00
|
|
|
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_ENSURE_SUCCESS(docShellAsWin->InitWindow(nullptr, mWindow, r.X(), r.Y(),
|
2018-01-10 19:15:22 +03:00
|
|
|
r.Width(), r.Height()),
|
|
|
|
NS_ERROR_FAILURE);
|
2000-03-11 04:25:54 +03:00
|
|
|
NS_ENSURE_SUCCESS(docShellAsWin->Create(), NS_ERROR_FAILURE);
|
2000-12-15 02:27:59 +03:00
|
|
|
|
|
|
|
// Attach a WebProgress listener.during initialization...
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
|
|
|
|
if (webProgress) {
|
2002-05-17 00:57:37 +04:00
|
|
|
webProgress->AddProgressListener(this,
|
|
|
|
nsIWebProgress::NOTIFY_STATE_NETWORK);
|
2000-12-15 02:27:59 +03:00
|
|
|
}
|
1999-03-16 10:25:43 +03:00
|
|
|
|
2016-10-07 21:59:59 +03:00
|
|
|
if (aOpenerWindow) {
|
|
|
|
nsPIDOMWindowOuter* window = mDocShell->GetWindow();
|
|
|
|
MOZ_ASSERT(window);
|
|
|
|
window->SetOpenerWindow(nsPIDOMWindowOuter::From(aOpenerWindow), true);
|
|
|
|
}
|
|
|
|
|
2012-09-18 14:16:05 +04:00
|
|
|
// Eagerly create an about:blank content viewer with the right principal here,
|
|
|
|
// rather than letting it happening in the upcoming call to
|
|
|
|
// SetInitialPrincipalToSubject. 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. Note that we don't accept
|
2016-09-08 02:30:36 +03:00
|
|
|
// expanded principals here, similar to SetInitialPrincipalToSubject.
|
2014-05-07 02:43:03 +04:00
|
|
|
if (nsContentUtils::IsInitialized()) { // Sometimes this happens really early
|
|
|
|
// See bug 793370.
|
2016-09-08 02:30:36 +03:00
|
|
|
MOZ_ASSERT(mDocShell->ItemType() == nsIDocShellTreeItem::typeChrome);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller();
|
|
|
|
if (nsContentUtils::IsExpandedPrincipal(principal)) {
|
|
|
|
principal = nullptr;
|
|
|
|
}
|
|
|
|
rv = mDocShell->CreateAboutBlankContentViewer(principal);
|
2012-09-30 23:10:37 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> doc = mDocShell->GetDocument();
|
2012-09-30 23:10:37 +04:00
|
|
|
NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);
|
|
|
|
doc->SetIsInitialDocument(true);
|
2012-09-18 14:16:05 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aUrl) {
|
2009-08-14 15:00:44 +04:00
|
|
|
nsCString tmpStr;
|
1999-05-28 00:36:15 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = aUrl->GetSpec(tmpStr);
|
1999-11-30 07:50:42 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF8toUTF16 urlString(tmpStr);
|
2000-03-16 05:20:26 +03:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
|
|
|
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
|
2019-01-11 14:43:39 +03:00
|
|
|
|
|
|
|
LoadURIOptions loadURIOptions;
|
|
|
|
loadURIOptions.mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal();
|
|
|
|
|
|
|
|
rv = webNav->LoadURI(urlString, loadURIOptions);
|
2003-04-10 22:17:57 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-02-10 19:32:55 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
1998-12-03 04:35:53 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
nsIPresShell* nsWebShellWindow::GetPresShell() {
|
|
|
|
if (!mDocShell) return nullptr;
|
|
|
|
|
2012-12-29 05:56:42 +04:00
|
|
|
return mDocShell->GetPresShell();
|
2012-08-15 22:52:42 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool nsWebShellWindow::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) {
|
2012-08-15 22:52:42 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window =
|
2014-01-10 06:03:47 +04:00
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 22:52:42 +04:00
|
|
|
pm->AdjustPopupsOnWindowChange(window);
|
|
|
|
}
|
1998-12-03 04:35:53 +03:00
|
|
|
|
2015-03-31 23:39:02 +03:00
|
|
|
// Notify all tabs that the widget moved.
|
|
|
|
if (mDocShell && mDocShell->GetWindow()) {
|
|
|
|
nsCOMPtr<EventTarget> eventTarget =
|
|
|
|
mDocShell->GetWindow()->GetTopWindowRoot();
|
|
|
|
nsContentUtils::DispatchChromeEvent(mDocShell->GetDocument(), eventTarget,
|
|
|
|
NS_LITERAL_STRING("MozUpdateWindowPos"),
|
2018-06-25 19:23:50 +03:00
|
|
|
CanBubble::eNo, Cancelable::eNo,
|
|
|
|
nullptr);
|
2015-03-31 23:39:02 +03:00
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
// Persist position, but not immediately, in case this OS is firing
|
|
|
|
// repeated move events as the user drags the window
|
|
|
|
SetPersistenceTimer(PAD_POSITION);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
bool nsWebShellWindow::WindowResized(nsIWidget* aWidget, int32_t aWidth,
|
|
|
|
int32_t aHeight) {
|
2012-08-15 22:52:42 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
|
2012-08-16 04:54:18 +04:00
|
|
|
if (shellAsWin) {
|
2016-05-12 03:07:45 +03:00
|
|
|
shellAsWin->SetPositionAndSize(0, 0, aWidth, aHeight, 0);
|
2012-08-16 04:54:18 +04:00
|
|
|
}
|
2012-08-15 22:52:42 +04:00
|
|
|
// Persist size, but not immediately, in case this OS is firing
|
|
|
|
// repeated size events as the user drags the sizing handle
|
|
|
|
if (!IsLocked()) SetPersistenceTimer(PAD_POSITION | PAD_SIZE | PAD_MISC);
|
|
|
|
return true;
|
2001-11-27 04:47:41 +03:00
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
bool nsWebShellWindow::RequestWindowClose(nsIWidget* aWidget) {
|
|
|
|
// Maintain a reference to this as it is about to get destroyed.
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window(mDocShell ? mDocShell->GetWindow()
|
|
|
|
: nullptr);
|
2013-04-22 05:25:28 +04:00
|
|
|
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(window);
|
2012-08-15 22:52:42 +04:00
|
|
|
|
2012-12-29 05:56:42 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = mDocShell->GetPresShell();
|
2013-05-16 22:34:34 +04:00
|
|
|
if (!presShell) {
|
2013-12-17 21:53:03 +04:00
|
|
|
mozilla::DebugOnly<bool> dying;
|
2013-05-16 22:34:34 +04:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mDocShell->IsBeingDestroyed(&dying)) && dying,
|
|
|
|
"No presShell, but window is not being destroyed");
|
|
|
|
} else if (eventTarget) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext = presShell->GetPresContext();
|
2012-08-15 22:52:42 +04:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2017-07-12 00:49:24 +03:00
|
|
|
WidgetMouseEvent event(true, eClose, nullptr, WidgetMouseEvent::eReal);
|
2017-08-06 20:28:52 +03:00
|
|
|
if (NS_SUCCEEDED(EventDispatcher::Dispatch(eventTarget, presContext, &event,
|
|
|
|
nullptr, &status)) &&
|
2012-08-15 22:52:42 +04:00
|
|
|
status == nsEventStatus_eConsumeNoDefault)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::SizeModeChanged(nsSizeMode sizeMode) {
|
|
|
|
// An alwaysRaised (or higher) window will hide any newly opened normal
|
|
|
|
// browser windows, so here we just drop a raised window to the normal
|
|
|
|
// zlevel if it's maximized. We make no provision for automatically
|
|
|
|
// re-raising it when restored.
|
|
|
|
if (sizeMode == nsSizeMode_Maximized || sizeMode == nsSizeMode_Fullscreen) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t zLevel;
|
2012-08-15 22:52:42 +04:00
|
|
|
GetZLevel(&zLevel);
|
|
|
|
if (zLevel > nsIXULWindow::normalZ) SetZLevel(nsIXULWindow::normalZ);
|
|
|
|
}
|
|
|
|
mWindow->SetSizeMode(sizeMode);
|
|
|
|
|
|
|
|
// Persist mode, but not immediately, because in many (all?)
|
|
|
|
// cases this will merge with the similar call in NS_SIZE and
|
|
|
|
// write the attribute values only once.
|
|
|
|
SetPersistenceTimer(PAD_MISC);
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> ourWindow =
|
2014-01-10 06:03:47 +04:00
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 22:52:42 +04:00
|
|
|
if (ourWindow) {
|
2015-06-10 14:13:12 +03:00
|
|
|
// Ensure that the fullscreen state is synchronized between
|
|
|
|
// the widget and the outer window object.
|
2012-08-15 22:52:42 +04:00
|
|
|
if (sizeMode == nsSizeMode_Fullscreen) {
|
|
|
|
ourWindow->SetFullScreen(true);
|
|
|
|
} else if (sizeMode != nsSizeMode_Minimized) {
|
2016-01-20 01:56:52 +03:00
|
|
|
if (ourWindow->GetFullScreen()) {
|
|
|
|
// The first SetFullscreenInternal call below ensures that we do
|
|
|
|
// not trigger any fullscreen transition even if the window was
|
|
|
|
// put in fullscreen only for the Fullscreen API. The second
|
|
|
|
// SetFullScreen call ensures that the window really exit from
|
|
|
|
// fullscreen even if it entered fullscreen for both Fullscreen
|
|
|
|
// Mode and Fullscreen API.
|
2016-01-30 20:05:36 +03:00
|
|
|
ourWindow->SetFullscreenInternal(
|
|
|
|
FullscreenReason::ForForceExitFullscreen, false);
|
2016-01-20 01:56:52 +03:00
|
|
|
ourWindow->SetFullScreen(false);
|
|
|
|
}
|
2012-08-15 22:52:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// And always fire a user-defined sizemodechange event on the window
|
2014-06-29 19:31:13 +04:00
|
|
|
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("sizemodechange"));
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 19:10:00 +03:00
|
|
|
nsIPresShell* presShell;
|
|
|
|
if ((presShell = GetPresShell())) {
|
|
|
|
presShell->GetPresContext()->SizeModeChanged(sizeMode);
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
// Note the current implementation of SetSizeMode just stores
|
|
|
|
// the new state; it doesn't actually resize. So here we store
|
|
|
|
// the state and pass the event on to the OS. The day is coming
|
|
|
|
// when we'll handle the event here, and the return result will
|
|
|
|
// then need to be different.
|
|
|
|
}
|
2001-01-04 03:05:42 +03:00
|
|
|
|
2016-03-17 15:53:31 +03:00
|
|
|
void nsWebShellWindow::UIResolutionChanged() {
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> ourWindow =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
|
|
|
if (ourWindow) {
|
|
|
|
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("resolutionchange"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 04:50:47 +03:00
|
|
|
void nsWebShellWindow::FullscreenWillChange(bool aInFullscreen) {
|
|
|
|
if (mDocShell) {
|
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> ourWindow = mDocShell->GetWindow()) {
|
|
|
|
ourWindow->FullscreenWillChange(aInFullscreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 14:13:12 +03:00
|
|
|
void nsWebShellWindow::FullscreenChanged(bool aInFullscreen) {
|
|
|
|
if (mDocShell) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> ourWindow = mDocShell->GetWindow()) {
|
2015-06-10 14:13:12 +03:00
|
|
|
ourWindow->FinishFullscreenChange(aInFullscreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-26 13:09:34 +03:00
|
|
|
void nsWebShellWindow::OcclusionStateChanged(bool aIsFullyOccluded) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> ourWindow =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
|
|
|
if (ourWindow) {
|
|
|
|
// And always fire a user-defined occlusionstatechange event on the window
|
|
|
|
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("occlusionstatechange"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
void nsWebShellWindow::OSToolbarButtonPressed() {
|
|
|
|
// Keep a reference as setting the chrome flags can fire events.
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
|
|
|
// rjc: don't use "nsIWebBrowserChrome::CHROME_EXTRA"
|
|
|
|
// due to components with multiple sidebar components
|
|
|
|
// (such as Mail/News, Addressbook, etc)... and frankly,
|
|
|
|
// Mac IE, OmniWeb, and other Mac OS X apps all work this way
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t chromeMask = (nsIWebBrowserChrome::CHROME_TOOLBAR |
|
2012-08-15 22:52:42 +04:00
|
|
|
nsIWebBrowserChrome::CHROME_LOCATIONBAR |
|
|
|
|
nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowserChrome> wbc(do_GetInterface(xulWindow));
|
|
|
|
if (!wbc) return;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t chromeFlags, newChromeFlags = 0;
|
2012-08-15 22:52:42 +04:00
|
|
|
wbc->GetChromeFlags(&chromeFlags);
|
|
|
|
newChromeFlags = chromeFlags & chromeMask;
|
|
|
|
if (!newChromeFlags)
|
|
|
|
chromeFlags |= chromeMask;
|
|
|
|
else
|
|
|
|
chromeFlags &= (~newChromeFlags);
|
|
|
|
wbc->SetChromeFlags(chromeFlags);
|
|
|
|
}
|
1999-05-29 23:36:55 +04:00
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
bool nsWebShellWindow::ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
|
|
|
|
nsIWidget* aRequestBelow,
|
|
|
|
nsIWidget** aActualBelow) {
|
|
|
|
if (aActualBelow) *aActualBelow = nullptr;
|
|
|
|
|
|
|
|
return ConstrainToZLevel(aImmediate, aPlacement, aRequestBelow, aActualBelow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WindowActivated() {
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
|
|
|
// focusing the window could cause it to close, so keep a reference to it
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2018-09-10 16:03:04 +03:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
2012-08-15 22:52:42 +04:00
|
|
|
if (fm && window) fm->WindowRaised(window);
|
|
|
|
|
|
|
|
if (mChromeLoaded) {
|
2015-10-14 04:33:51 +03:00
|
|
|
PersistentAttributesDirty(PAD_POSITION | PAD_SIZE | PAD_MISC);
|
|
|
|
SavePersistentAttributes();
|
2012-08-15 22:52:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WindowDeactivated() {
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window =
|
2014-01-10 06:03:47 +04:00
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2018-09-10 16:03:04 +03:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm && window && !fm->IsTestMode()) fm->WindowLowered(window);
|
1998-12-03 04:35:53 +03:00
|
|
|
}
|
1999-01-21 10:24:01 +03:00
|
|
|
|
2006-02-21 22:07:14 +03:00
|
|
|
#ifdef USE_NATIVE_MENUS
|
2019-01-02 16:05:23 +03:00
|
|
|
static void LoadNativeMenus(Document* aDoc, nsIWidget* aParentWindow) {
|
2017-07-04 01:33:16 +03:00
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-18 18:34:00 +03:00
|
|
|
nsCOMPtr<nsINativeMenuService> nms =
|
|
|
|
do_GetService("@mozilla.org/widget/nativemenuservice;1");
|
|
|
|
if (!nms) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-20 01:42:01 +03:00
|
|
|
// Find the menubar tag (if there is more than one, we ignore all but
|
|
|
|
// the first).
|
2018-01-31 23:18:10 +03:00
|
|
|
nsCOMPtr<nsINodeList> menubarElements = aDoc->GetElementsByTagNameNS(
|
|
|
|
NS_LITERAL_STRING(
|
|
|
|
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"),
|
|
|
|
NS_LITERAL_STRING("menubar"));
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2018-01-31 23:18:10 +03:00
|
|
|
nsCOMPtr<nsINode> menubarNode;
|
|
|
|
if (menubarElements) {
|
|
|
|
menubarNode = menubarElements->Item(0);
|
|
|
|
}
|
1999-04-19 12:23:18 +04:00
|
|
|
|
2015-02-18 18:34:00 +03:00
|
|
|
if (menubarNode) {
|
2017-12-05 20:05:51 +03:00
|
|
|
nsCOMPtr<Element> menubarContent(do_QueryInterface(menubarNode));
|
2008-06-28 11:55:30 +04:00
|
|
|
nms->CreateNativeMenuBar(aParentWindow, menubarContent);
|
2015-02-18 18:34:00 +03:00
|
|
|
} else {
|
|
|
|
nms->CreateNativeMenuBar(aParentWindow, nullptr);
|
|
|
|
}
|
1999-03-20 07:13:09 +03:00
|
|
|
}
|
2006-02-21 22:07:14 +03:00
|
|
|
#endif
|
1999-03-20 07:13:09 +03:00
|
|
|
|
2012-07-23 18:40:36 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class WebShellWindowTimerCallback final : public nsITimerCallback,
|
2017-07-26 21:18:20 +03:00
|
|
|
public nsINamed {
|
2012-07-23 18:40:36 +04:00
|
|
|
public:
|
2014-09-03 02:24:24 +04:00
|
|
|
explicit WebShellWindowTimerCallback(nsWebShellWindow* aWindow)
|
2012-07-23 18:40:36 +04:00
|
|
|
: mWindow(aWindow) {}
|
|
|
|
|
2013-07-19 06:31:36 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-23 18:40:36 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Notify(nsITimer* aTimer) override {
|
2012-07-23 18:40:36 +04:00
|
|
|
// Although this object participates in a refcount cycle (this -> mWindow
|
|
|
|
// -> mSPTimer -> this), mSPTimer is a one-shot timer and releases this
|
|
|
|
// after it fires. So we don't need to release mWindow here.
|
|
|
|
|
|
|
|
mWindow->FirePersistenceTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_IMETHOD GetName(nsACString& aName) override {
|
|
|
|
aName.AssignLiteral("WebShellWindowTimerCallback");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-23 18:40:36 +04:00
|
|
|
private:
|
2014-06-24 20:36:45 +04:00
|
|
|
~WebShellWindowTimerCallback() {}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWebShellWindow> mWindow;
|
2012-07-23 18:40:36 +04:00
|
|
|
};
|
|
|
|
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_IMPL_ISUPPORTS(WebShellWindowTimerCallback, nsITimerCallback, nsINamed)
|
2012-07-23 18:40:36 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsWebShellWindow::SetPersistenceTimer(uint32_t aDirtyFlags) {
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
2009-02-03 17:42:21 +03:00
|
|
|
if (!mSPTimer) {
|
2017-09-25 05:57:48 +03:00
|
|
|
mSPTimer = NS_NewTimer();
|
2012-07-23 18:40:36 +04:00
|
|
|
if (!mSPTimer) {
|
|
|
|
NS_WARNING("Couldn't create @mozilla.org/timer;1 instance?");
|
|
|
|
return;
|
2000-05-17 06:49:35 +04:00
|
|
|
}
|
2000-02-25 00:16:16 +03:00
|
|
|
}
|
2012-07-23 18:40:36 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<WebShellWindowTimerCallback> callback =
|
2012-07-23 18:40:36 +04:00
|
|
|
new WebShellWindowTimerCallback(this);
|
|
|
|
mSPTimer->InitWithCallback(callback, SIZE_PERSISTENCE_TIMEOUT,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
|
2015-10-14 04:33:51 +03:00
|
|
|
PersistentAttributesDirty(aDirtyFlags);
|
2000-02-23 23:07:31 +03:00
|
|
|
}
|
|
|
|
|
2012-07-23 18:40:36 +04:00
|
|
|
void nsWebShellWindow::FirePersistenceTimer() {
|
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
2015-10-14 04:33:51 +03:00
|
|
|
SavePersistentAttributes();
|
2000-02-23 23:07:31 +03:00
|
|
|
}
|
1999-03-20 07:13:09 +03:00
|
|
|
|
1999-01-26 18:58:58 +03:00
|
|
|
//----------------------------------------
|
2000-12-15 02:27:59 +03:00
|
|
|
// nsIWebProgessListener implementation
|
1999-01-26 18:58:58 +03:00
|
|
|
//----------------------------------------
|
1999-03-29 13:21:01 +04:00
|
|
|
NS_IMETHODIMP
|
2000-12-15 02:27:59 +03:00
|
|
|
nsWebShellWindow::OnProgressChange(nsIWebProgress* aProgress,
|
|
|
|
nsIRequest* aRequest,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
1999-03-29 13:21:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-12-15 02:27:59 +03:00
|
|
|
nsWebShellWindow::OnStateChange(nsIWebProgress* aProgress, nsIRequest* aRequest,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStateFlags, nsresult aStatus) {
|
2000-12-15 02:27:59 +03:00
|
|
|
// If the notification is not about a document finishing, then just
|
|
|
|
// ignore it...
|
2017-07-06 15:00:35 +03:00
|
|
|
if (!(aStateFlags & nsIWebProgressListener::STATE_STOP) ||
|
2000-12-15 02:27:59 +03:00
|
|
|
!(aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
if (mChromeLoaded) return NS_OK;
|
1999-04-07 01:01:51 +04:00
|
|
|
|
2000-12-15 02:27:59 +03:00
|
|
|
// If this document notification is for a frame then ignore it...
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> eventWin;
|
2001-05-22 06:02:08 +04:00
|
|
|
aProgress->GetDOMWindow(getter_AddRefs(eventWin));
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* eventPWin = nsPIDOMWindowOuter::From(eventWin);
|
2001-05-22 06:02:08 +04:00
|
|
|
if (eventPWin) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* rootPWin = eventPWin->GetPrivateRoot();
|
2001-05-22 06:02:08 +04:00
|
|
|
if (eventPWin != rootPWin) return NS_OK;
|
2000-11-01 04:20:59 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mChromeLoaded = true;
|
|
|
|
mLockedUntilChromeLoad = false;
|
1999-05-05 03:36:42 +04:00
|
|
|
|
2000-03-11 06:08:04 +03:00
|
|
|
#ifdef USE_NATIVE_MENUS
|
1999-04-07 01:01:51 +04:00
|
|
|
///////////////////////////////
|
|
|
|
// Find the Menubar DOM and Load the menus, hooking them up to the loaded
|
|
|
|
// commands
|
|
|
|
///////////////////////////////
|
2011-10-14 17:06:41 +04:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> menubarDoc = cv->GetDocument();
|
2018-01-31 23:18:10 +03:00
|
|
|
if (menubarDoc) LoadNativeMenus(menubarDoc, mWindow);
|
2011-10-14 17:06:41 +04:00
|
|
|
}
|
2000-03-11 06:08:04 +03:00
|
|
|
#endif // USE_NATIVE_MENUS
|
1999-04-07 01:01:51 +04:00
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
OnChromeLoaded();
|
1999-04-07 01:01:51 +04:00
|
|
|
|
1999-03-29 13:21:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-12-15 02:27:59 +03:00
|
|
|
nsWebShellWindow::OnLocationChange(nsIWebProgress* aProgress,
|
|
|
|
nsIRequest* aRequest, nsIURI* aURI,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
1999-03-29 13:21:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
NS_IMETHODIMP
|
2000-12-15 02:27:59 +03:00
|
|
|
nsWebShellWindow::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest, nsresult aStatus,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aMessage) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
1999-03-29 13:21:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-12-15 02:27:59 +03:00
|
|
|
nsWebShellWindow::OnSecurityChange(nsIWebProgress* aWebProgress,
|
2018-11-29 18:46:08 +03:00
|
|
|
nsIRequest* aRequest, uint32_t state) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("notification excluded in AddProgressListener(...)");
|
1999-03-29 13:21:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-02 01:38:06 +03:00
|
|
|
/**
|
|
|
|
* ExecuteCloseHandler - Run the close handler, if any.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @return true iff we found a close handler to run.
|
1999-12-02 01:38:06 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsWebShellWindow::ExecuteCloseHandler() {
|
1999-12-02 01:38:06 +03:00
|
|
|
/* If the event handler closes this window -- a likely scenario --
|
|
|
|
things get deleted out of order without this death grip.
|
|
|
|
(The problem may be the death grip in nsWindow::windowProc,
|
|
|
|
which forces this window's widget to remain alive longer
|
|
|
|
than it otherwise would.) */
|
2005-02-20 01:42:01 +03:00
|
|
|
nsCOMPtr<nsIXULWindow> kungFuDeathGrip(this);
|
1999-12-02 01:38:06 +03:00
|
|
|
|
2014-01-10 06:03:47 +04:00
|
|
|
nsCOMPtr<EventTarget> eventTarget;
|
|
|
|
if (mDocShell) {
|
|
|
|
eventTarget = do_QueryInterface(mDocShell->GetWindow());
|
|
|
|
}
|
1999-12-02 01:38:06 +03:00
|
|
|
|
2007-02-16 02:04:33 +03:00
|
|
|
if (eventTarget) {
|
2004-02-11 09:09:51 +03:00
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2011-10-15 11:33:26 +04:00
|
|
|
if (contentViewer) {
|
2018-11-20 04:17:53 +03:00
|
|
|
RefPtr<nsPresContext> presContext = contentViewer->GetPresContext();
|
2004-02-11 09:09:51 +03:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2017-07-12 00:49:24 +03:00
|
|
|
WidgetMouseEvent event(true, eClose, nullptr, WidgetMouseEvent::eReal);
|
2004-02-11 09:09:51 +03:00
|
|
|
|
2017-08-06 20:28:52 +03:00
|
|
|
nsresult rv = EventDispatcher::Dispatch(eventTarget, presContext, &event,
|
|
|
|
nullptr, &status);
|
2004-02-11 09:09:51 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
|
|
|
// else fall through and return false
|
1999-12-02 01:38:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1999-12-02 01:38:06 +03:00
|
|
|
} // ExecuteCloseHandler
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsWebShellWindow::ConstrainToOpenerScreen(int32_t* aX, int32_t* aY) {
|
2010-10-08 22:51:50 +04:00
|
|
|
if (mOpenerScreenRect.IsEmpty()) {
|
|
|
|
*aX = *aY = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t left, top, width, height;
|
2010-10-08 22:51:50 +04:00
|
|
|
// Constrain initial positions to the same screen as opener
|
|
|
|
nsCOMPtr<nsIScreenManager> screenmgr =
|
|
|
|
do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
if (screenmgr) {
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
2018-01-10 19:15:22 +03:00
|
|
|
screenmgr->ScreenForRect(
|
|
|
|
mOpenerScreenRect.X(), mOpenerScreenRect.Y(), mOpenerScreenRect.Width(),
|
|
|
|
mOpenerScreenRect.Height(), getter_AddRefs(screen));
|
2010-10-08 22:51:50 +04:00
|
|
|
if (screen) {
|
2012-10-16 23:41:19 +04:00
|
|
|
screen->GetAvailRectDisplayPix(&left, &top, &width, &height);
|
2011-05-11 01:26:48 +04:00
|
|
|
if (*aX < left || *aX > left + width) {
|
2010-10-08 22:51:50 +04:00
|
|
|
*aX = left;
|
|
|
|
}
|
|
|
|
if (*aY < top || *aY > top + height) {
|
|
|
|
*aY = top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-12 03:52:50 +04:00
|
|
|
// nsIBaseWindow
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::Destroy() {
|
2000-12-15 02:27:59 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->RemoveProgressListener(this);
|
|
|
|
}
|
|
|
|
|
2005-02-20 01:42:01 +03:00
|
|
|
nsCOMPtr<nsIXULWindow> kungFuDeathGrip(this);
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
|
|
|
if (mSPTimer) {
|
|
|
|
mSPTimer->Cancel();
|
2015-10-14 04:33:51 +03:00
|
|
|
SavePersistentAttributes();
|
2012-07-30 18:20:58 +04:00
|
|
|
mSPTimer = nullptr;
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
}
|
2003-11-25 05:47:48 +03:00
|
|
|
}
|
2001-05-01 05:25:49 +04:00
|
|
|
return nsXULWindow::Destroy();
|
2000-04-12 03:52:50 +04:00
|
|
|
}
|
2018-01-10 14:04:43 +03:00
|
|
|
|
|
|
|
nsIXULWindow* nsWebShellWindow::WidgetListenerDelegate::GetXULWindow() {
|
|
|
|
return mWebShellWindow->GetXULWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell* nsWebShellWindow::WidgetListenerDelegate::GetPresShell() {
|
|
|
|
return mWebShellWindow->GetPresShell();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsWebShellWindow::WidgetListenerDelegate::WindowMoved(nsIWidget* aWidget,
|
|
|
|
int32_t aX,
|
|
|
|
int32_t aY) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
return holder->WindowMoved(aWidget, aX, aY);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsWebShellWindow::WidgetListenerDelegate::WindowResized(nsIWidget* aWidget,
|
|
|
|
int32_t aWidth,
|
|
|
|
int32_t aHeight) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
return holder->WindowResized(aWidget, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsWebShellWindow::WidgetListenerDelegate::RequestWindowClose(
|
|
|
|
nsIWidget* aWidget) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
return holder->RequestWindowClose(aWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::SizeModeChanged(
|
|
|
|
nsSizeMode aSizeMode) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->SizeModeChanged(aSizeMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::UIResolutionChanged() {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->UIResolutionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::FullscreenWillChange(
|
|
|
|
bool aInFullscreen) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->FullscreenWillChange(aInFullscreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::FullscreenChanged(
|
|
|
|
bool aInFullscreen) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->FullscreenChanged(aInFullscreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::OcclusionStateChanged(
|
|
|
|
bool aIsFullyOccluded) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->OcclusionStateChanged(aIsFullyOccluded);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::OSToolbarButtonPressed() {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->OSToolbarButtonPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsWebShellWindow::WidgetListenerDelegate::ZLevelChanged(
|
|
|
|
bool aImmediate, nsWindowZ* aPlacement, nsIWidget* aRequestBelow,
|
|
|
|
nsIWidget** aActualBelow) {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
return holder->ZLevelChanged(aImmediate, aPlacement, aRequestBelow,
|
|
|
|
aActualBelow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::WindowActivated() {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->WindowActivated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsWebShellWindow::WidgetListenerDelegate::WindowDeactivated() {
|
|
|
|
RefPtr<nsWebShellWindow> holder = mWebShellWindow;
|
|
|
|
holder->WindowDeactivated();
|
|
|
|
}
|