diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 9f77657037c..72e7dc4a7b3 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -162,7 +162,6 @@ #include "nsIURIWithPrincipal.h" #include "nsIURL.h" #include "nsIWebNavigation.h" -#include "nsIWindowMediator.h" #include "nsIWordBreaker.h" #include "nsIXPConnect.h" #include "nsJSUtils.h" @@ -5168,23 +5167,6 @@ nsContentUtils::GetWindowProviderForContentProcess() return ContentChild::GetSingleton(); } -/* static */ -already_AddRefed -nsContentUtils::GetMostRecentNonPBWindow() -{ - nsCOMPtr windowMediator = - do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); - nsCOMPtr wm = do_QueryInterface(windowMediator); - - nsCOMPtr window; - wm->GetMostRecentNonPBWindow(MOZ_UTF16("navigator:browser"), - getter_AddRefs(window)); - nsCOMPtr pwindow; - pwindow = do_QueryInterface(window); - - return pwindow.forget(); -} - /* static */ void nsContentUtils::WarnScriptWasIgnored(nsIDocument* aDocument) diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 6d043af5620..18b79bcb23b 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -1666,11 +1666,6 @@ public: static nsIWindowProvider* GetWindowProviderForContentProcess(); - // Returns the browser window with the most recent time stamp that is - // not in private browsing mode. - static already_AddRefed - GetMostRecentNonPBWindow(); - /** * Call this function if !IsSafeToRunScript() and we fail to run the script * (rather than using AddScriptRunner as we usually do). |aDocument| is diff --git a/dom/bindings/test/test_exception_options_from_jsimplemented.html b/dom/bindings/test/test_exception_options_from_jsimplemented.html index 1e77718a8e9..32bf6ca31c8 100644 --- a/dom/bindings/test/test_exception_options_from_jsimplemented.html +++ b/dom/bindings/test/test_exception_options_from_jsimplemented.html @@ -18,7 +18,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1107592 var file = location.href; var asyncFrame; /* Async parent frames from pushPrefEnv don't show up in e10s. */ - var isE10S = !SpecialPowers.isMainProcess(); + var isE10S = !SpecialPowers.Services.wm.getMostRecentWindow("navigator:browser"); if (!isE10S && SpecialPowers.getBoolPref("javascript.options.asyncstack")) { asyncFrame = `Async*@${file}:153:1 `; diff --git a/dom/bindings/test/test_promise_rejections_from_jsimplemented.html b/dom/bindings/test/test_promise_rejections_from_jsimplemented.html index daad0190432..6c9b5f22b2a 100644 --- a/dom/bindings/test/test_promise_rejections_from_jsimplemented.html +++ b/dom/bindings/test/test_promise_rejections_from_jsimplemented.html @@ -38,7 +38,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1107592 function doTest() { var t = new TestInterfaceJS(); /* Async parent frames from pushPrefEnv don't show up in e10s. */ - var isE10S = !SpecialPowers.isMainProcess(); + var isE10S = !SpecialPowers.Services.wm.getMostRecentWindow("navigator:browser"); var asyncStack = SpecialPowers.getBoolPref("javascript.options.asyncstack"); var ourFile = location.href; var parentFrame = (asyncStack && !isE10S) ? `Async*@${ourFile}:121:1 diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 11237fcf163..9fa9b32cc63 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -148,6 +148,7 @@ #include "nsISystemMessagesInternal.h" #include "nsITimer.h" #include "nsIURIFixup.h" +#include "nsIWindowMediator.h" #include "nsIDocShellTreeOwner.h" #include "nsIXULWindow.h" #include "nsIDOMChromeWindow.h" @@ -5388,6 +5389,34 @@ ContentParent::DeallocPWebBrowserPersistDocumentParent(PWebBrowserPersistDocumen return true; } +static already_AddRefed +FindMostRecentOpenWindow() +{ + nsCOMPtr windowMediator = + do_GetService(NS_WINDOWMEDIATOR_CONTRACTID); + nsCOMPtr windowEnumerator; + windowMediator->GetEnumerator(MOZ_UTF16("navigator:browser"), + getter_AddRefs(windowEnumerator)); + + nsCOMPtr latest; + + bool hasMore = false; + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->HasMoreElements(&hasMore))); + while (hasMore) { + nsCOMPtr item; + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->GetNext(getter_AddRefs(item)))); + nsCOMPtr window = do_QueryInterface(item); + + if (window && !window->Closed()) { + latest = window; + } + + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(windowEnumerator->HasMoreElements(&hasMore))); + } + + return latest.forget(); +} + bool ContentParent::RecvCreateWindow(PBrowserParent* aThisTab, PBrowserParent* aNewTab, @@ -5461,7 +5490,7 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab, // If we haven't found a chrome window to open in, just use the most recently // opened one. if (!parent) { - parent = nsContentUtils::GetMostRecentNonPBWindow(); + parent = FindMostRecentOpenWindow(); if (NS_WARN_IF(!parent)) { *aResult = NS_ERROR_FAILURE; return true; diff --git a/dom/workers/ServiceWorkerClients.cpp b/dom/workers/ServiceWorkerClients.cpp index 1b267bb3099..b3f23217932 100644 --- a/dom/workers/ServiceWorkerClients.cpp +++ b/dom/workers/ServiceWorkerClients.cpp @@ -615,9 +615,10 @@ private: } // Find the most recent browser window and open a new tab in it. - nsCOMPtr browserWindow = - nsContentUtils::GetMostRecentNonPBWindow(); - if (!browserWindow) { + nsCOMPtr browserWindow; + rv = wm->GetMostRecentWindow(MOZ_UTF16("navigator:browser"), + getter_AddRefs(browserWindow)); + if (NS_WARN_IF(NS_FAILED(rv)) || !browserWindow) { // It is possible to be running without a browser window on Mac OS, so // we need to open a new chrome window. // TODO(catalinb): open new chrome window. Bug 1218080 diff --git a/xpfe/appshell/nsIWindowMediator.idl b/xpfe/appshell/nsIWindowMediator.idl index 55de09e4e0b..d5c1946b650 100644 --- a/xpfe/appshell/nsIWindowMediator.idl +++ b/xpfe/appshell/nsIWindowMediator.idl @@ -191,15 +191,3 @@ interface nsIWindowMediator: nsISupports */ void removeListener(in nsIWindowMediatorListener aListener); }; - -// XXXcatalinb: This should be merged to nsIWindowMediator. Using this -// to avoid UUID change in aurora. -[scriptable, uuid(88b54988-7f3c-40d2-a625-7e42a9c196c2)] -interface nsIWindowMediator_44 : nsIWindowMediator -{ - /** - * Same as getMostRecentWindow, but ignores private browsing - * windows. - */ - nsIDOMWindow getMostRecentNonPBWindow(in wstring aWindowType); -}; diff --git a/xpfe/appshell/nsWindowMediator.cpp b/xpfe/appshell/nsWindowMediator.cpp index 5eaa38c4c92..26364167210 100644 --- a/xpfe/appshell/nsWindowMediator.cpp +++ b/xpfe/appshell/nsWindowMediator.cpp @@ -275,7 +275,7 @@ nsWindowMediator::GetMostRecentWindow(const char16_t* inType, nsIDOMWindow** out // Find the most window with the highest time stamp that matches // the requested type - nsWindowInfo* info = MostRecentWindowInfo(inType, false); + nsWindowInfo *info = MostRecentWindowInfo(inType); if (info && info->mWindow) { nsCOMPtr DOMWindow; if (NS_SUCCEEDED(GetDOMWindow(info->mWindow, DOMWindow))) { @@ -289,66 +289,31 @@ nsWindowMediator::GetMostRecentWindow(const char16_t* inType, nsIDOMWindow** out return NS_OK; } -NS_IMETHODIMP -nsWindowMediator::GetMostRecentNonPBWindow(const char16_t* aType, nsIDOMWindow** aWindow) -{ - MOZ_RELEASE_ASSERT(NS_IsMainThread()); - NS_ENSURE_ARG_POINTER(aWindow); - *aWindow = nullptr; - - nsWindowInfo *info = MostRecentWindowInfo(aType, true); - nsCOMPtr domWindow; - if (info && info->mWindow) { - GetDOMWindow(info->mWindow, domWindow); - } - - if (!domWindow) { - return NS_ERROR_FAILURE; - } - - domWindow.forget(aWindow); - return NS_OK; -} - nsWindowInfo* -nsWindowMediator::MostRecentWindowInfo(const char16_t* inType, bool aSkipPrivateBrowsing) +nsWindowMediator::MostRecentWindowInfo(const char16_t* inType) { - MOZ_ASSERT(XRE_IsParentProcess()); - int32_t lastTimeStamp = -1; nsAutoString typeString(inType); bool allWindows = !inType || typeString.IsEmpty(); - // Find the most recent window with the highest time stamp that matches - // the requested type and has the correct browsing mode. - nsWindowInfo* searchInfo = mOldestWindow; - nsWindowInfo* listEnd = nullptr; - nsWindowInfo* foundInfo = nullptr; - for (; searchInfo != listEnd; searchInfo = searchInfo->mYounger) { + // Find the most window with the highest time stamp that matches + // the requested type + nsWindowInfo *searchInfo, + *listEnd, + *foundInfo = nullptr; + + searchInfo = mOldestWindow; + listEnd = nullptr; + while (searchInfo != listEnd) { + if ((allWindows || searchInfo->TypeEquals(typeString)) && + searchInfo->mTimeStamp >= lastTimeStamp) { + + foundInfo = searchInfo; + lastTimeStamp = searchInfo->mTimeStamp; + } + searchInfo = searchInfo->mYounger; listEnd = mOldestWindow; - - if (!allWindows && !searchInfo->TypeEquals(typeString)) { - continue; - } - if (searchInfo->mTimeStamp < lastTimeStamp) { - continue; - } - if (!searchInfo->mWindow) { - continue; - } - if (aSkipPrivateBrowsing) { - nsCOMPtr docShell; - searchInfo->mWindow->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr loadContext = do_QueryInterface(docShell); - if (!loadContext || loadContext->UsePrivateBrowsing()) { - continue; - } - } - - foundInfo = searchInfo; - lastTimeStamp = searchInfo->mTimeStamp; } - return foundInfo; } @@ -776,7 +741,6 @@ nsWindowMediator::SortZOrderBackToFront() } NS_IMPL_ISUPPORTS(nsWindowMediator, - nsIWindowMediator_44, nsIWindowMediator, nsIObserver, nsISupportsWeakReference) diff --git a/xpfe/appshell/nsWindowMediator.h b/xpfe/appshell/nsWindowMediator.h index 6b2e4858a34..88f90a00ab4 100644 --- a/xpfe/appshell/nsWindowMediator.h +++ b/xpfe/appshell/nsWindowMediator.h @@ -25,7 +25,7 @@ class nsIWindowMediatorListener; struct nsWindowInfo; class nsWindowMediator : - public nsIWindowMediator_44, + public nsIWindowMediator, public nsIObserver, public nsSupportsWeakReference { @@ -47,7 +47,6 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIWINDOWMEDIATOR - NS_DECL_NSIWINDOWMEDIATOR_44 NS_DECL_NSIOBSERVER static nsresult GetDOMWindow(nsIXULWindow* inWindow, @@ -56,8 +55,7 @@ public: private: int32_t AddEnumerator(nsAppShellWindowEnumerator* inEnumerator); int32_t RemoveEnumerator(nsAppShellWindowEnumerator* inEnumerator); - nsWindowInfo* MostRecentWindowInfo(const char16_t* inType, - bool aSkipPrivateBrowsing = false); + nsWindowInfo *MostRecentWindowInfo(const char16_t* inType); nsresult UnregisterWindow(nsWindowInfo *inInfo); nsWindowInfo *GetInfoFor(nsIXULWindow *aWindow);