Bug 1578070 - Use nsWindowWatcher::GetBrowsingContextByName in GeckoViewOpenWindow, r=farre

This also removes LaunchObserver, which was only needed for Fennec.

Differential Revision: https://phabricator.services.mozilla.com/D65401

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kashav Madan 2020-03-10 20:27:24 +00:00
Родитель 5f18b14d6d
Коммит 41ed32b21b
2 изменённых файлов: 16 добавлений и 70 удалений

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsPIDOMWindow.h"
#include "nsPIWindowWatcher.h"
#include "nsPrintfCString.h"
#include "nsWindowWatcher.h"
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/BrowsingContext.h"
@ -354,22 +355,18 @@ void GeckoViewOpenWindow(const ClientOpenWindowArgs& aArgs,
return rv;
}
// Retrieve the window by using the GeckoSession ID. The window is named
// the same as the ID of the GeckoSession it is associated with.
nsCOMPtr<mozIDOMWindowProxy> domWindow;
wwatch->GetWindowByName(sessionId, nullptr, getter_AddRefs(domWindow));
if (!domWindow) {
// Retrieve the browsing context by using the GeckoSession ID. The
// window is named the same as the ID of the GeckoSession it is
// associated with.
RefPtr<BrowsingContext> browsingContext =
static_cast<nsWindowWatcher*>(wwatch.get())
->GetBrowsingContextByName(sessionId, false, nullptr);
if (NS_WARN_IF(!browsingContext)) {
promise->Reject(NS_ERROR_FAILURE, __func__);
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsPIDOMWindowOuter> outerWindow = do_QueryInterface(domWindow);
if (NS_WARN_IF(!outerWindow)) {
promise->Reject(NS_ERROR_FAILURE, __func__);
return NS_ERROR_FAILURE;
}
WaitForLoad(aArgs, outerWindow->GetBrowsingContext(), promise);
WaitForLoad(aArgs, browsingContext, promise);
return NS_OK;
},
[promise](nsString aResult) {
@ -377,57 +374,6 @@ void GeckoViewOpenWindow(const ClientOpenWindowArgs& aArgs,
});
}
class LaunchObserver final : public nsIObserver {
RefPtr<GenericPromise::Private> mPromise;
LaunchObserver() : mPromise(new GenericPromise::Private(__func__)) {}
~LaunchObserver() = default;
NS_IMETHOD
Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData) override {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
os->RemoveObserver(this, "BrowserChrome:Ready");
}
mPromise->Resolve(true, __func__);
return NS_OK;
}
public:
static already_AddRefed<LaunchObserver> Create() {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (NS_WARN_IF(!os)) {
return nullptr;
}
RefPtr<LaunchObserver> ref = new LaunchObserver();
nsresult rv =
os->AddObserver(ref, "BrowserChrome:Ready", /* weakRef */ false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
return ref.forget();
}
void Cancel() {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
os->RemoveObserver(this, "BrowserChrome:Ready");
}
mPromise->Reject(NS_ERROR_ABORT, __func__);
}
GenericPromise* Promise() { return mPromise; }
NS_DECL_ISUPPORTS
};
NS_IMPL_ISUPPORTS(LaunchObserver, nsIObserver);
#endif // MOZ_WIDGET_ANDROID
} // anonymous namespace

Просмотреть файл

@ -56,6 +56,13 @@ class nsWindowWatcher : public nsIWindowWatcher,
bool aPositionSpecified,
bool aSizeSpecified);
// Will first look for a caller on the JS stack, and then fall back on
// aCurrentContext if it can't find one.
// It also knows to not look for things if aForceNoOpener is set.
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContextByName(
const nsAString& aName, bool aForceNoOpener,
mozilla::dom::BrowsingContext* aCurrentContext);
protected:
virtual ~nsWindowWatcher();
@ -66,13 +73,6 @@ class nsWindowWatcher : public nsIWindowWatcher,
nsWatcherWindowEntry* FindWindowEntry(mozIDOMWindowProxy* aWindow);
nsresult RemoveWindow(nsWatcherWindowEntry* aInfo);
// Will first look for a caller on the JS stack, and then fall back on
// aCurrentContext if it can't find one.
// It also knows to not look for things if aForceNoOpener is set.
already_AddRefed<mozilla::dom::BrowsingContext> GetBrowsingContextByName(
const nsAString& aName, bool aForceNoOpener,
mozilla::dom::BrowsingContext* aCurrentContext);
// Just like OpenWindowJS, but knows whether it got called via OpenWindowJS
// (which means called from script) or called via OpenWindow.
nsresult OpenWindowInternal(mozIDOMWindowProxy* aParent, const char* aUrl,