Bug 1597175. Fix nsExternalHelperAppService::DoContent to work with non-docshell content contexts. r=mattwoodrow
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 18 Nov 2019 06:14:57 +0000
changeset 502375 eb5f05b67d5684795a3043d90ef99cc9f17c504a
parent 502374 cbe5a080a2ada0308ff3a8eae088ddd44b79af6d
child 502376 34f0f8db631a206ab5115baa73c13bcd7c2f36ea
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1597175
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1597175. Fix nsExternalHelperAppService::DoContent to work with non-docshell content contexts. r=mattwoodrow Some consumers of this code have an aContentContext implemented in JS. Differential Revision: https://phabricator.services.mozilla.com/D53385
uriloader/exthandler/nsExternalHelperAppService.cpp
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -804,18 +804,29 @@ NS_IMETHODIMP nsExternalHelperAppService
   return NS_OK;
 }
 
 NS_IMETHODIMP nsExternalHelperAppService::DoContent(
     const nsACString& aMimeContentType, nsIRequest* aRequest,
     nsIInterfaceRequestor* aContentContext, bool aForceSave,
     nsIInterfaceRequestor* aWindowContext,
     nsIStreamListener** aStreamListener) {
-  nsCOMPtr<nsPIDOMWindowOuter> window = do_GetInterface(aContentContext);
-  RefPtr<BrowsingContext> bc = window ? window->GetBrowsingContext() : nullptr;
+  // Scripted interface requestors cannot return an instance of the
+  // (non-scriptable) nsPIDOMWindowOuter or nsPIDOMWindowInner interfaces, so
+  // get to the window via `nsIDOMWindow`.  Unfortunately, at that point we
+  // don't know whether the thing we got is an inner or outer window, so have to
+  // work with either one.
+  RefPtr<BrowsingContext> bc;
+  nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(aContentContext);
+  if (nsCOMPtr<nsPIDOMWindowOuter> outerWindow = do_QueryInterface(domWindow)) {
+    bc = outerWindow->GetBrowsingContext();
+  } else if (nsCOMPtr<nsPIDOMWindowInner> innerWindow =
+                 do_QueryInterface(domWindow)) {
+    bc = innerWindow->GetBrowsingContext();
+  }
 
   if (XRE_IsContentProcess()) {
     return DoContentContentProcessHelper(aMimeContentType, aRequest, bc,
                                          aForceSave, aWindowContext,
                                          aStreamListener);
   }
 
   RefPtr<nsExternalAppHandler> handler;