Bug 1334080 - If a plugin is associated with a window that has no nsIWebNavigation, don't crash, r=qdot a=gchang
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 10 Feb 2017 11:27:08 -0500
changeset 376172 c682c0d49f8c006cbb7ab706357c7303e6228c35
parent 376171 d0ba912fe2c8098a284b39d08a03d09c4c799cbe
child 376173 85ae3b00692108495df1d7c54cc5fd3d70e74137
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot, gchang
bugs1334080
milestone53.0a2
Bug 1334080 - If a plugin is associated with a window that has no nsIWebNavigation, don't crash, r=qdot a=gchang MozReview-Commit-ID: CZLne2N498d
dom/plugins/base/nsPluginStreamListenerPeer.cpp
--- a/dom/plugins/base/nsPluginStreamListenerPeer.cpp
+++ b/dom/plugins/base/nsPluginStreamListenerPeer.cpp
@@ -1286,29 +1286,38 @@ nsPluginStreamListenerPeer::VisitHeader(
 nsresult
 nsPluginStreamListenerPeer::GetInterfaceGlobal(const nsIID& aIID, void** result)
 {
   if (!mPluginInstance) {
     return NS_ERROR_FAILURE;
   }
 
   RefPtr<nsPluginInstanceOwner> owner = mPluginInstance->GetOwner();
-  if (owner) {
-    nsCOMPtr<nsIDocument> doc;
-    nsresult rv = owner->GetDocument(getter_AddRefs(doc));
-    if (NS_SUCCEEDED(rv) && doc) {
-      if  (nsPIDOMWindowOuter *window = doc->GetWindow()) {
-        nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
-        nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(webNav);
-        return ir->GetInterface(aIID, result);
-      }
-    }
+  if (!owner) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsIDocument> doc;
+  nsresult rv = owner->GetDocument(getter_AddRefs(doc));
+  if (NS_FAILED(rv) || !doc) {
+    return NS_ERROR_FAILURE;
   }
 
-  return NS_ERROR_FAILURE;
+  nsPIDOMWindowOuter *window = doc->GetWindow();
+  if (!window) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
+  nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(webNav);
+  if (!ir) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return ir->GetInterface(aIID, result);
 }
 
 NS_IMETHODIMP
 nsPluginStreamListenerPeer::GetInterface(const nsIID& aIID, void** result)
 {
   // Provide nsIChannelEventSink ourselves, otherwise let our document's
   // script global object owner provide the interface.
   if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {