Bug 890570 - PRemoteOpenFile Constructor doesn't need PBrowser r=jduell
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 10 Aug 2013 11:18:12 -0400
changeset 142179 cc6bfc5b2b1f6e02f06e2501ba9456c2e6b6719c
parent 142178 ae82c97dfa0852e7342f49182f84fdf878049667
child 142180 f99521bfd19727096e41f0f63d6f7ede7d8f3335
push id25084
push usercbook@mozilla.com
push dateMon, 12 Aug 2013 09:28:56 +0000
treeherdermozilla-central@f057fca09627 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjduell
bugs890570
milestone26.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 890570 - PRemoteOpenFile Constructor doesn't need PBrowser r=jduell
netwerk/ipc/NeckoChild.cpp
netwerk/ipc/NeckoChild.h
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
netwerk/ipc/PNecko.ipdl
netwerk/ipc/RemoteOpenFileChild.cpp
--- a/netwerk/ipc/NeckoChild.cpp
+++ b/netwerk/ipc/NeckoChild.cpp
@@ -184,17 +184,17 @@ bool
 NeckoChild::DeallocPTCPServerSocketChild(PTCPServerSocketChild* child)
 {
   TCPServerSocketChild* p = static_cast<TCPServerSocketChild*>(child);
   p->ReleaseIPDLReference();
   return true;
 }
 
 PRemoteOpenFileChild*
-NeckoChild::AllocPRemoteOpenFileChild(const URIParams&, PBrowserChild*)
+NeckoChild::AllocPRemoteOpenFileChild(const URIParams&)
 {
   // We don't allocate here: instead we always use IPDL constructor that takes
   // an existing RemoteOpenFileChild
   NS_NOTREACHED("AllocPRemoteOpenFileChild should not be called on child");
   return nullptr;
 }
 
 bool
--- a/netwerk/ipc/NeckoChild.h
+++ b/netwerk/ipc/NeckoChild.h
@@ -42,18 +42,17 @@ protected:
   virtual PWebSocketChild* AllocPWebSocketChild(PBrowserChild*, const SerializedLoadContext&);
   virtual bool DeallocPWebSocketChild(PWebSocketChild*);
   virtual PTCPSocketChild* AllocPTCPSocketChild();
   virtual bool DeallocPTCPSocketChild(PTCPSocketChild*);
   virtual PTCPServerSocketChild* AllocPTCPServerSocketChild(const uint16_t& aLocalPort,
                                                        const uint16_t& aBacklog,
                                                        const nsString& aBinaryType);
   virtual bool DeallocPTCPServerSocketChild(PTCPServerSocketChild*);
-  virtual PRemoteOpenFileChild* AllocPRemoteOpenFileChild(const URIParams&,
-                                                          PBrowserChild*);
+  virtual PRemoteOpenFileChild* AllocPRemoteOpenFileChild(const URIParams&);
   virtual bool DeallocPRemoteOpenFileChild(PRemoteOpenFileChild*);
 };
 
 /**
  * Reference to the PNecko Child protocol.
  * Null if this is not a content process.
  */
 extern PNeckoChild *gNeckoChild;
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -380,51 +380,57 @@ bool
 NeckoParent::DeallocPTCPServerSocketParent(PTCPServerSocketParent* actor)
 {
   TCPServerSocketParent* p = static_cast<TCPServerSocketParent*>(actor);
    p->ReleaseIPDLReference();
   return true;
 }
 
 PRemoteOpenFileParent*
-NeckoParent::AllocPRemoteOpenFileParent(const URIParams& aURI,
-                                        PBrowserParent* aBrowser)
+NeckoParent::AllocPRemoteOpenFileParent(const URIParams& aURI)
 {
   nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
   nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri);
   if (!fileURL) {
     return nullptr;
   }
 
   // security checks
   if (UsingNeckoIPCSecurity()) {
-    if (!aBrowser) {
-      printf_stderr("NeckoParent::AllocPRemoteOpenFile: "
-                    "FATAL error: missing TabParent: KILLING CHILD PROCESS\n");
-      return nullptr;
-    }
-    nsRefPtr<TabParent> tabParent = static_cast<TabParent*>(aBrowser);
-    uint32_t appId = tabParent->OwnOrContainingAppId();
     nsCOMPtr<nsIAppsService> appsService =
       do_GetService(APPS_SERVICE_CONTRACTID);
     if (!appsService) {
       return nullptr;
     }
-    nsCOMPtr<mozIDOMApplication> domApp;
-    nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(domApp));
-    if (!domApp) {
-      return nullptr;
+    bool haveValidBrowser = false;
+    bool hasManage = false;
+    nsCOMPtr<mozIApplication> mozApp;
+    for (uint32_t i = 0; i < Manager()->ManagedPBrowserParent().Length(); i++) {
+      nsRefPtr<TabParent> tabParent =
+        static_cast<TabParent*>(Manager()->ManagedPBrowserParent()[i]);
+      uint32_t appId = tabParent->OwnOrContainingAppId();
+      nsCOMPtr<mozIDOMApplication> domApp;
+      nsresult rv = appsService->GetAppByLocalId(appId, getter_AddRefs(domApp));
+      if (!domApp) {
+        continue;
+      }
+      mozApp = do_QueryInterface(domApp);
+      if (!mozApp) {
+        continue;
+      }
+      hasManage = false;
+      rv = mozApp->HasPermission("webapps-manage", &hasManage);
+      if (NS_FAILED(rv)) {
+        continue;
+      }
+      haveValidBrowser = true;
+      break;
     }
-    nsCOMPtr<mozIApplication> mozApp = do_QueryInterface(domApp);
-    if (!mozApp) {
-      return nullptr;
-    }
-    bool hasManage = false;
-    rv = mozApp->HasPermission("webapps-manage", &hasManage);
-    if (NS_FAILED(rv)) {
+
+    if (!haveValidBrowser) {
       return nullptr;
     }
 
     nsAutoCString requestedPath;
     fileURL->GetPath(requestedPath);
     NS_UnescapeURL(requestedPath);
 
     if (hasManage) {
@@ -457,17 +463,17 @@ NeckoParent::AllocPRemoteOpenFileParent(
         printf_stderr("NeckoParent::AllocPRemoteOpenFile: "
                       "FATAL error: requested file URI '%s' contains '/../' "
                       "KILLING CHILD PROCESS\n", requestedPath.get());
         return nullptr;
       }
     } else {
       // regular packaged apps can only access their own application.zip file
       nsAutoString basePath;
-      rv = mozApp->GetBasePath(basePath);
+      nsresult rv = mozApp->GetBasePath(basePath);
       if (NS_FAILED(rv)) {
         return nullptr;
       }
       nsAutoString uuid;
       rv = mozApp->GetId(uuid);
       if (NS_FAILED(rv)) {
         return nullptr;
       }
@@ -486,18 +492,17 @@ NeckoParent::AllocPRemoteOpenFileParent(
   }
 
   RemoteOpenFileParent* parent = new RemoteOpenFileParent(fileURL);
   return parent;
 }
 
 bool
 NeckoParent::RecvPRemoteOpenFileConstructor(PRemoteOpenFileParent* aActor,
-                                            const URIParams& aFileURI,
-                                            PBrowserParent* aBrowser)
+                                            const URIParams& aFileURI)
 {
   return static_cast<RemoteOpenFileParent*>(aActor)->OpenSendCloseDelete();
 }
 
 bool
 NeckoParent::DeallocPRemoteOpenFileParent(PRemoteOpenFileParent* actor)
 {
   delete actor;
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -83,22 +83,20 @@ protected:
                       const SerializedLoadContext& aSerialized,
                       const FTPChannelCreationArgs& aOpenArgs);
   virtual bool DeallocPFTPChannelParent(PFTPChannelParent*);
   virtual PWebSocketParent* AllocPWebSocketParent(PBrowserParent* browser,
                                                   const SerializedLoadContext& aSerialized);
   virtual bool DeallocPWebSocketParent(PWebSocketParent*);
   virtual PTCPSocketParent* AllocPTCPSocketParent();
 
-  virtual PRemoteOpenFileParent* AllocPRemoteOpenFileParent(const URIParams& aFileURI,
-                                                            PBrowserParent* aBrowser)
+  virtual PRemoteOpenFileParent* AllocPRemoteOpenFileParent(const URIParams& aFileURI)
                                                             MOZ_OVERRIDE;
   virtual bool RecvPRemoteOpenFileConstructor(PRemoteOpenFileParent* aActor,
-                                              const URIParams& aFileURI,
-                                              PBrowserParent* aBrowser)
+                                              const URIParams& aFileURI)
                                               MOZ_OVERRIDE;
   virtual bool DeallocPRemoteOpenFileParent(PRemoteOpenFileParent* aActor)
                                             MOZ_OVERRIDE;
 
   virtual bool DeallocPTCPSocketParent(PTCPSocketParent*);
   virtual PTCPServerSocketParent* AllocPTCPServerSocketParent(const uint16_t& aLocalPort,
                                                         const uint16_t& aBacklog,
                                                         const nsString& aBinaryType);
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -49,17 +49,17 @@ parent:
                SerializedLoadContext loadContext,
                HttpChannelCreationArgs args);
   PWyciwygChannel();
   PFTPChannel(PBrowser browser, SerializedLoadContext loadContext,
               FTPChannelCreationArgs args);
 
   PWebSocket(PBrowser browser, SerializedLoadContext loadContext);
   PTCPServerSocket(uint16_t localPort, uint16_t backlog, nsString binaryType);
-  PRemoteOpenFile(URIParams fileuri, nullable PBrowser browser);
+  PRemoteOpenFile(URIParams fileuri);
 
   HTMLDNSPrefetch(nsString hostname, uint16_t flags);
   CancelHTMLDNSPrefetch(nsString hostname, uint16_t flags, nsresult reason);
 
 both:
   PTCPSocket();
 };
 
--- a/netwerk/ipc/RemoteOpenFileChild.cpp
+++ b/netwerk/ipc/RemoteOpenFileChild.cpp
@@ -179,17 +179,17 @@ RemoteOpenFileChild::AsyncRemoteFileOpen
       // will be called with it.
       return NS_OK;
     }
   }
 
   URIParams uri;
   SerializeURI(mURI, uri);
 
-  gNeckoChild->SendPRemoteOpenFileConstructor(this, uri, mTabChild);
+  gNeckoChild->SendPRemoteOpenFileConstructor(this, uri);
 
   // The chrome process now has a logical ref to us until it calls Send__delete.
   AddIPDLReference();
 
   mListener = aListener;
   mAsyncOpenCalled = true;
   return NS_OK;
 #endif