2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsWebShellWindow.h"
|
|
|
|
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "nsIWeakReference.h"
|
2011-10-15 00:33:26 -07:00
|
|
|
#include "nsIContentViewer.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
|
2014-05-06 15:43:03 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
|
2013-10-22 06:27:34 -07:00
|
|
|
#include "nsWidgetInitData.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIWidget.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIDOMCharacterData.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
|
|
|
|
#include "nsITimer.h"
|
2007-11-28 12:18:11 -08:00
|
|
|
#include "nsXULPopupManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
|
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 11:00:39 -07:00
|
|
|
#include "nsFocusManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIWebProgress.h"
|
|
|
|
#include "nsIWebProgressListener.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDocumentLoaderFactory.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
|
2010-10-08 11:51:50 -07:00
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
#include "nsIScreen.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h" // for menus
|
2012-09-18 03:16:05 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// For calculating size
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
|
2012-07-23 14:28:06 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-17 09:53:03 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsINativeMenuService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#define USE_NATIVE_MENUS
|
|
|
|
#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-03-31 21:29:02 -07:00
|
|
|
using namespace mozilla;
|
2013-04-21 18:25:28 -07: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-03-31 21:29:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* Define Class IDs */
|
|
|
|
static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID);
|
|
|
|
|
|
|
|
#define SIZE_PERSISTENCE_TIMEOUT 500 // msec
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWebShellWindow::nsWebShellWindow(uint32_t aChromeFlags)
|
2009-08-14 04:00:44 -07: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-03-31 21:29:02 -07:00
|
|
|
, mSPTimerLock("nsWebShellWindow.mSPTimerLock")
|
2007-03-22 10:30:00 -07: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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
|
|
|
if (mSPTimer)
|
|
|
|
mSPTimer->Cancel();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsWebShellWindow, nsXULWindow)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsWebShellWindow, nsXULWindow)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsWebShellWindow)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsXULWindow)
|
|
|
|
|
|
|
|
nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
|
2009-09-28 19:20:46 -07:00
|
|
|
nsIXULWindow* aOpener,
|
2011-10-14 06:06:39 -07:00
|
|
|
nsIURI* aUrl,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aInitialWidth,
|
|
|
|
int32_t aInitialHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsHiddenWindow,
|
2014-06-05 19:51:14 -07:00
|
|
|
nsITabParent *aOpeningTab,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWidgetInitData& widgetInitData)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWidget> parentWidget;
|
|
|
|
|
|
|
|
mIsHiddenWindow = aIsHiddenWindow;
|
2009-09-28 19:20:46 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t initialX = 0, initialY = 0;
|
2009-09-28 19:20:46 -07:00
|
|
|
nsCOMPtr<nsIBaseWindow> base(do_QueryInterface(aOpener));
|
|
|
|
if (base) {
|
|
|
|
rv = base->GetPositionAndSize(&mOpenerScreenRect.x,
|
|
|
|
&mOpenerScreenRect.y,
|
|
|
|
&mOpenerScreenRect.width,
|
|
|
|
&mOpenerScreenRect.height);
|
|
|
|
if (NS_FAILED(rv)) {
|
2011-04-18 20:07:23 -07:00
|
|
|
mOpenerScreenRect.SetEmpty();
|
2010-10-08 11:51:50 -07:00
|
|
|
} else {
|
2012-10-16 12:41:19 -07:00
|
|
|
double scale;
|
|
|
|
if (NS_SUCCEEDED(base->GetUnscaledDevicePixelsPerCSSPixel(&scale))) {
|
|
|
|
mOpenerScreenRect.x = NSToIntRound(mOpenerScreenRect.x / scale);
|
|
|
|
mOpenerScreenRect.y = NSToIntRound(mOpenerScreenRect.y / scale);
|
|
|
|
mOpenerScreenRect.width = NSToIntRound(mOpenerScreenRect.width / scale);
|
|
|
|
mOpenerScreenRect.height = NSToIntRound(mOpenerScreenRect.height / scale);
|
|
|
|
}
|
2010-10-08 11:51:50 -07:00
|
|
|
initialX = mOpenerScreenRect.x;
|
|
|
|
initialY = mOpenerScreenRect.y;
|
|
|
|
ConstrainToOpenerScreen(&initialX, &initialY);
|
2009-09-28 19:20:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX: need to get the default window size from prefs...
|
|
|
|
// Doesn't come from prefs... will come from CSS/XUL/RDF
|
2010-10-08 11:51:50 -07:00
|
|
|
nsIntRect r(initialX, initialY, aInitialWidth, aInitialHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create top level window
|
|
|
|
mWindow = do_CreateInstance(kWindowCID, &rv);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIBaseWindow> parentAsWin(do_QueryInterface(aParent));
|
|
|
|
if (parentAsWin) {
|
|
|
|
parentAsWin->GetMainWidget(getter_AddRefs(parentWidget));
|
|
|
|
mParentWindow = do_GetWeakReference(aParent);
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
mWindow->SetWidgetListener(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
|
2012-08-15 11:52:42 -07:00
|
|
|
nullptr, // Native parent widget
|
2007-03-22 10:30:00 -07:00
|
|
|
r, // Widget dimensions
|
2012-08-15 11:52:42 -07:00
|
|
|
nullptr, // Device context
|
2007-03-22 10:30:00 -07:00
|
|
|
&widgetInitData); // Widget initialization data
|
|
|
|
mWindow->GetClientBounds(r);
|
2010-09-08 08:21:56 -07: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));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Create web shell
|
2009-05-07 12:21:53 -07:00
|
|
|
mDocShell = do_CreateInstance("@mozilla.org/docshell;1");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
|
|
|
|
|
2014-06-05 19:51:14 -07:00
|
|
|
mDocShell->SetOpener(aOpeningTab);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure to set the item type on the docshell _before_ calling
|
|
|
|
// Create() so it knows what type it is.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
docShellAsItem->SetTreeOwner(mChromeTreeOwner);
|
|
|
|
docShellAsItem->SetItemType(nsIDocShellTreeItem::typeChrome);
|
|
|
|
|
|
|
|
r.x = r.y = 0;
|
|
|
|
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell));
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_SUCCESS(docShellAsWin->InitWindow(nullptr, mWindow,
|
2007-03-22 10:30:00 -07:00
|
|
|
r.x, r.y, r.width, r.height), NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_SUCCESS(docShellAsWin->Create(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Attach a WebProgress listener.during initialization...
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK);
|
|
|
|
}
|
|
|
|
|
2012-09-18 03:16:05 -07: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.
|
2014-05-06 15:43:03 -07:00
|
|
|
if (nsContentUtils::IsInitialized()) { // Sometimes this happens really early See bug 793370.
|
2014-05-13 02:58:00 -07:00
|
|
|
rv = mDocShell->CreateAboutBlankContentViewer(nsContentUtils::SubjectPrincipal());
|
2012-09-30 12:10:37 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsIDocument> doc = mDocShell ? mDocShell->GetDocument() : nullptr;
|
2012-09-30 12:10:37 -07:00
|
|
|
NS_ENSURE_TRUE(!!doc, NS_ERROR_FAILURE);
|
|
|
|
doc->SetIsInitialDocument(true);
|
2012-09-18 03:16:05 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != aUrl) {
|
2009-08-14 04:00:44 -07:00
|
|
|
nsCString tmpStr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
rv = aUrl->GetSpec(tmpStr);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
NS_ConvertUTF8toUTF16 urlString(tmpStr);
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
|
|
|
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
|
|
|
|
rv = webNav->LoadURI(urlString.get(),
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIPresShell*
|
|
|
|
nsWebShellWindow::GetPresShell()
|
|
|
|
{
|
|
|
|
if (!mDocShell)
|
|
|
|
return nullptr;
|
|
|
|
|
2012-12-28 17:56:42 -08:00
|
|
|
return mDocShell->GetPresShell();
|
2012-08-15 11:52:42 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWebShellWindow::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y)
|
2012-08-15 11:52:42 -07:00
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 11:52:42 -07:00
|
|
|
pm->AdjustPopupsOnWindowChange(window);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-15 11:52:42 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWebShellWindow::WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
|
2012-08-15 17:54:18 -07:00
|
|
|
if (shellAsWin) {
|
|
|
|
shellAsWin->SetPositionAndSize(0, 0, aWidth, aHeight, false);
|
|
|
|
}
|
2012-08-15 11:52:42 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
bool
|
|
|
|
nsWebShellWindow::RequestWindowClose(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
// Maintain a reference to this as it is about to get destroyed.
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocShell ? mDocShell->GetWindow() : nullptr);
|
2013-04-21 18:25:28 -07:00
|
|
|
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(window);
|
2012-08-15 11:52:42 -07:00
|
|
|
|
2012-12-28 17:56:42 -08:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = mDocShell->GetPresShell();
|
2013-05-16 11:34:34 -07:00
|
|
|
if (!presShell) {
|
2013-12-17 09:53:03 -08:00
|
|
|
mozilla::DebugOnly<bool> dying;
|
2013-05-16 11:34:34 -07:00
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(mDocShell->IsBeingDestroyed(&dying)) && dying,
|
|
|
|
"No presShell, but window is not being destroyed");
|
|
|
|
} else if (eventTarget) {
|
2012-08-15 11:52:42 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext = presShell->GetPresContext();
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, NS_XUL_CLOSE, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
2012-08-15 11:52:42 -07:00
|
|
|
if (NS_SUCCEEDED(eventTarget->DispatchDOMEvent(&event, nullptr, presContext, &status)) &&
|
|
|
|
status == nsEventStatus_eConsumeNoDefault)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWebShellWindow::SizeModeChanged(nsSizeMode sizeMode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
// 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 08:56:38 -07:00
|
|
|
uint32_t zLevel;
|
2012-08-15 11:52:42 -07: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);
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 11:52:42 -07:00
|
|
|
if (ourWindow) {
|
2014-06-29 08:31:13 -07:00
|
|
|
MOZ_ASSERT(ourWindow->IsOuterWindow());
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
// Let the application know if it's in fullscreen mode so it
|
|
|
|
// can update its UI.
|
|
|
|
if (sizeMode == nsSizeMode_Fullscreen) {
|
|
|
|
ourWindow->SetFullScreen(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-15 11:52:42 -07:00
|
|
|
else if (sizeMode != nsSizeMode_Minimized) {
|
|
|
|
ourWindow->SetFullScreen(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And always fire a user-defined sizemodechange event on the window
|
2014-06-29 08:31:13 -07:00
|
|
|
ourWindow->DispatchCustomEvent(NS_LITERAL_STRING("sizemodechange"));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07: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.
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-15 11:52:42 -07: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 08:56:38 -07:00
|
|
|
uint32_t chromeMask = (nsIWebBrowserChrome::CHROME_TOOLBAR |
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIWebBrowserChrome::CHROME_LOCATIONBAR |
|
|
|
|
nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowserChrome> wbc(do_GetInterface(xulWindow));
|
|
|
|
if (!wbc)
|
|
|
|
return;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t chromeFlags, newChromeFlags = 0;
|
2012-08-15 11:52:42 -07:00
|
|
|
wbc->GetChromeFlags(&chromeFlags);
|
|
|
|
newChromeFlags = chromeFlags & chromeMask;
|
|
|
|
if (!newChromeFlags) chromeFlags |= chromeMask;
|
|
|
|
else chromeFlags &= (~newChromeFlags);
|
|
|
|
wbc->SetChromeFlags(chromeFlags);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-15 11:52:42 -07: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
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 11:52:42 -07:00
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
|
|
|
if (fm && window)
|
|
|
|
fm->WindowRaised(window);
|
|
|
|
|
|
|
|
if (mChromeLoaded) {
|
|
|
|
PersistentAttributesDirty(PAD_POSITION | PAD_SIZE | PAD_MISC);
|
|
|
|
SavePersistentAttributes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWebShellWindow::WindowDeactivated()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXULWindow> xulWindow(this);
|
|
|
|
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window =
|
|
|
|
mDocShell ? mDocShell->GetWindow() : nullptr;
|
2012-08-15 11:52:42 -07:00
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
|
|
|
if (fm && window)
|
|
|
|
fm->WindowLowered(window);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef USE_NATIVE_MENUS
|
2007-09-17 08:06:59 -07:00
|
|
|
static void LoadNativeMenus(nsIDOMDocument *aDOMDoc, nsIWidget *aParentWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Find the menubar tag (if there is more than one, we ignore all but
|
|
|
|
// the first).
|
|
|
|
nsCOMPtr<nsIDOMNodeList> menubarElements;
|
|
|
|
aDOMDoc->GetElementsByTagNameNS(NS_LITERAL_STRING("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"),
|
|
|
|
NS_LITERAL_STRING("menubar"),
|
|
|
|
getter_AddRefs(menubarElements));
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> menubarNode;
|
|
|
|
if (menubarElements)
|
|
|
|
menubarElements->Item(0, getter_AddRefs(menubarNode));
|
|
|
|
if (!menubarNode)
|
|
|
|
return;
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsCOMPtr<nsINativeMenuService> nms = do_GetService("@mozilla.org/widget/nativemenuservice;1");
|
|
|
|
nsCOMPtr<nsIContent> menubarContent(do_QueryInterface(menubarNode));
|
|
|
|
if (nms && menubarContent)
|
|
|
|
nms->CreateNativeMenuBar(aParentWindow, menubarContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-23 07:40:36 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2012-07-23 14:28:06 -07:00
|
|
|
class WebShellWindowTimerCallback MOZ_FINAL : public nsITimerCallback
|
2012-07-23 07:40:36 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
WebShellWindowTimerCallback(nsWebShellWindow* aWindow)
|
|
|
|
: mWindow(aWindow)
|
|
|
|
{}
|
|
|
|
|
2013-07-18 19:31:36 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-07-23 07:40:36 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-24 09:36:45 -07:00
|
|
|
~WebShellWindowTimerCallback() {}
|
|
|
|
|
2012-07-23 07:40:36 -07:00
|
|
|
nsRefPtr<nsWebShellWindow> mWindow;
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(WebShellWindowTimerCallback, nsITimerCallback)
|
2012-07-23 07:40:36 -07:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsWebShellWindow::SetPersistenceTimer(uint32_t aDirtyFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
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-03-31 21:29:02 -07:00
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
2009-02-03 06:42:21 -08:00
|
|
|
if (!mSPTimer) {
|
2012-07-23 07:40:36 -07:00
|
|
|
mSPTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (!mSPTimer) {
|
|
|
|
NS_WARNING("Couldn't create @mozilla.org/timer;1 instance?");
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-23 07:40:36 -07:00
|
|
|
|
|
|
|
nsRefPtr<WebShellWindowTimerCallback> callback =
|
|
|
|
new WebShellWindowTimerCallback(this);
|
|
|
|
mSPTimer->InitWithCallback(callback, SIZE_PERSISTENCE_TIMEOUT,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
|
2009-02-03 06:42:21 -08:00
|
|
|
PersistentAttributesDirty(aDirtyFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-07-23 07:40:36 -07:00
|
|
|
nsWebShellWindow::FirePersistenceTimer()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-23 07:40:36 -07:00
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
|
|
|
SavePersistentAttributes();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// nsIWebProgessListener implementation
|
|
|
|
//----------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::OnProgressChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aCurSelfProgress,
|
|
|
|
int32_t aMaxSelfProgress,
|
|
|
|
int32_t aCurTotalProgress,
|
|
|
|
int32_t aMaxTotalProgress)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::OnStateChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aStateFlags,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
// If the notification is not about a document finishing, then just
|
|
|
|
// ignore it...
|
|
|
|
if (!(aStateFlags & nsIWebProgressListener::STATE_STOP) ||
|
|
|
|
!(aStateFlags & nsIWebProgressListener::STATE_IS_NETWORK)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mChromeLoaded)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// If this document notification is for a frame then ignore it...
|
|
|
|
nsCOMPtr<nsIDOMWindow> eventWin;
|
|
|
|
aProgress->GetDOMWindow(getter_AddRefs(eventWin));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> eventPWin(do_QueryInterface(eventWin));
|
|
|
|
if (eventPWin) {
|
|
|
|
nsPIDOMWindow *rootPWin = eventPWin->GetPrivateRoot();
|
|
|
|
if (eventPWin != rootPWin)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mChromeLoaded = true;
|
|
|
|
mLockedUntilChromeLoad = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef USE_NATIVE_MENUS
|
|
|
|
///////////////////////////////
|
|
|
|
// Find the Menubar DOM and Load the menus, hooking them up to the loaded commands
|
|
|
|
///////////////////////////////
|
2011-10-14 06:06:41 -07:00
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if (cv) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> menubarDOMDoc(do_QueryInterface(cv->GetDocument()));
|
|
|
|
if (menubarDOMDoc)
|
|
|
|
LoadNativeMenus(menubarDOMDoc, mWindow);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // USE_NATIVE_MENUS
|
|
|
|
|
|
|
|
OnChromeLoaded();
|
|
|
|
LoadContentAreas();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::OnLocationChange(nsIWebProgress *aProgress,
|
|
|
|
nsIRequest *aRequest,
|
2011-11-10 06:01:11 -08:00
|
|
|
nsIURI *aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::OnStatusChange(nsIWebProgress* aWebProgress,
|
|
|
|
nsIRequest* aRequest,
|
|
|
|
nsresult aStatus,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aMessage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWebShellWindow::OnSecurityChange(nsIWebProgress *aWebProgress,
|
|
|
|
nsIRequest *aRequest,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t state)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// if the main document URL specified URLs for any content areas, start them loading
|
|
|
|
void nsWebShellWindow::LoadContentAreas() {
|
|
|
|
|
|
|
|
nsAutoString searchSpec;
|
|
|
|
|
|
|
|
// fetch the chrome document URL
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
// yes, it's possible for the docshell to be null even this early
|
|
|
|
// see bug 57514.
|
|
|
|
if (mDocShell)
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (contentViewer) {
|
2010-01-23 03:41:41 -08:00
|
|
|
nsIDocument* doc = contentViewer->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsIURI* mainURL = doc->GetDocumentURI();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(mainURL);
|
|
|
|
if (url) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString search;
|
2007-03-22 10:30:00 -07:00
|
|
|
url->GetQuery(search);
|
|
|
|
|
|
|
|
AppendUTF8toUTF16(search, searchSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// content URLs are specified in the search part of the URL
|
|
|
|
// as <contentareaID>=<escapedURL>[;(repeat)]
|
|
|
|
if (!searchSpec.IsEmpty()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t begPos,
|
2007-03-22 10:30:00 -07:00
|
|
|
eqPos,
|
|
|
|
endPos;
|
|
|
|
nsString contentAreaID,
|
|
|
|
contentURL;
|
|
|
|
char *urlChar;
|
|
|
|
nsresult rv;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (endPos = 0; endPos < (int32_t)searchSpec.Length(); ) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// extract contentAreaID and URL substrings
|
|
|
|
begPos = endPos;
|
|
|
|
eqPos = searchSpec.FindChar('=', begPos);
|
|
|
|
if (eqPos < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
endPos = searchSpec.FindChar(';', eqPos);
|
|
|
|
if (endPos < 0)
|
|
|
|
endPos = searchSpec.Length();
|
|
|
|
searchSpec.Mid(contentAreaID, begPos, eqPos-begPos);
|
|
|
|
searchSpec.Mid(contentURL, eqPos+1, endPos-eqPos-1);
|
|
|
|
endPos++;
|
|
|
|
|
|
|
|
// see if we have a docshell with a matching contentAreaID
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> content;
|
|
|
|
rv = GetContentShellById(contentAreaID.get(), getter_AddRefs(content));
|
|
|
|
if (NS_SUCCEEDED(rv) && content) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(content));
|
|
|
|
if (webNav) {
|
|
|
|
urlChar = ToNewCString(contentURL);
|
|
|
|
if (urlChar) {
|
|
|
|
nsUnescape(urlChar);
|
|
|
|
contentURL.AssignWithConversion(urlChar);
|
|
|
|
webNav->LoadURI(contentURL.get(),
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMemory::Free(urlChar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ExecuteCloseHandler - Run the close handler, if any.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true iff we found a close handler to run.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsWebShellWindow::ExecuteCloseHandler()
|
2007-03-22 10:30:00 -07: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.) */
|
|
|
|
nsCOMPtr<nsIXULWindow> kungFuDeathGrip(this);
|
|
|
|
|
2014-01-09 18:03:47 -08:00
|
|
|
nsCOMPtr<EventTarget> eventTarget;
|
|
|
|
if (mDocShell) {
|
|
|
|
eventTarget = do_QueryInterface(mDocShell->GetWindow());
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (eventTarget) {
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
|
2011-10-15 00:33:26 -07:00
|
|
|
if (contentViewer) {
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2011-10-15 00:33:26 -07:00
|
|
|
contentViewer->GetPresContext(getter_AddRefs(presContext));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2013-10-01 23:38:27 -07:00
|
|
|
WidgetMouseEvent event(true, NS_XUL_CLOSE, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv =
|
2012-07-30 07:20:58 -07:00
|
|
|
eventTarget->DispatchDOMEvent(&event, nullptr, presContext, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv) && status == nsEventStatus_eConsumeNoDefault)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
|
|
|
// else fall through and return false
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} // ExecuteCloseHandler
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsWebShellWindow::ConstrainToOpenerScreen(int32_t* aX, int32_t* aY)
|
2010-10-08 11:51:50 -07:00
|
|
|
{
|
|
|
|
if (mOpenerScreenRect.IsEmpty()) {
|
|
|
|
*aX = *aY = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t left, top, width, height;
|
2010-10-08 11:51:50 -07: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;
|
|
|
|
screenmgr->ScreenForRect(mOpenerScreenRect.x, mOpenerScreenRect.y,
|
|
|
|
mOpenerScreenRect.width, mOpenerScreenRect.height,
|
|
|
|
getter_AddRefs(screen));
|
|
|
|
if (screen) {
|
2012-10-16 12:41:19 -07:00
|
|
|
screen->GetAvailRectDisplayPix(&left, &top, &width, &height);
|
2011-05-10 14:26:48 -07:00
|
|
|
if (*aX < left || *aX > left + width) {
|
2010-10-08 11:51:50 -07:00
|
|
|
*aX = left;
|
|
|
|
}
|
|
|
|
if (*aY < top || *aY > top + height) {
|
|
|
|
*aY = top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIBaseWindow
|
|
|
|
NS_IMETHODIMP nsWebShellWindow::Destroy()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv));
|
|
|
|
if (webProgress) {
|
|
|
|
webProgress->RemoveProgressListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-31 21:29:02 -07:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mSPTimerLock);
|
|
|
|
if (mSPTimer) {
|
|
|
|
mSPTimer->Cancel();
|
|
|
|
SavePersistentAttributes();
|
2012-07-30 07:20:58 -07: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-03-31 21:29:02 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return nsXULWindow::Destroy();
|
|
|
|
}
|