Bug 890570 - PCookieService doesn't need PBrowser r=jduell
authorDavid Zbarsky <dzbarsky@gmail.com>
Sat, 10 Aug 2013 11:18:11 -0400
changeset 156004 38657fcd2d1aa0e63041cfec4876271320a4a4b0
parent 156003 260786f8fef0850e0a556c3ac29b05b5fac76f65
child 156005 ae82c97dfa0852e7342f49182f84fdf878049667
push id407
push userlsblakk@mozilla.com
push dateTue, 03 Dec 2013 03:32:50 +0000
treeherdermozilla-release@babf8c9ebc52 [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 - PCookieService doesn't need PBrowser r=jduell
netwerk/cookie/CookieServiceChild.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/CookieServiceParent.h
netwerk/cookie/PCookieService.ipdl
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
--- a/netwerk/cookie/CookieServiceChild.cpp
+++ b/netwerk/cookie/CookieServiceChild.cpp
@@ -1,21 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/net/CookieServiceChild.h"
-#include "mozilla/dom/TabChild.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/net/NeckoChild.h"
 #include "nsIURI.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
-#include "nsITabChild.h"
 #include "nsNetUtil.h"
 
 using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace net {
 
 // Behavior pref constants
@@ -113,32 +111,20 @@ CookieServiceChild::GetCookieStringInter
   // Determine whether the request is foreign. Failure is acceptable.
   bool isForeign = true;
   if (RequireThirdPartyCheck())
     mThirdPartyUtil->IsThirdPartyChannel(aChannel, aHostURI, &isForeign);
 
   URIParams uriParams;
   SerializeURI(aHostURI, uriParams);
 
-  nsCOMPtr<nsITabChild> iTabChild;
-  mozilla::dom::TabChild* tabChild = nullptr;
-  if (aChannel) {
-    NS_QueryNotificationCallbacks(aChannel, iTabChild);
-    if (iTabChild) {
-      tabChild = static_cast<mozilla::dom::TabChild*>(iTabChild.get());
-    }
-    if (MissingRequiredTabChild(tabChild, "cookie")) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-  }
-
   // Synchronously call the parent.
   nsAutoCString result;
   SendGetCookieString(uriParams, !!isForeign, aFromHttp,
-                      IPC::SerializedLoadContext(aChannel), tabChild, &result);
+                      IPC::SerializedLoadContext(aChannel), &result);
   if (!result.IsEmpty())
     *aCookieString = ToNewCString(result);
 
   return NS_OK;
 }
 
 nsresult
 CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
@@ -158,31 +144,19 @@ CookieServiceChild::SetCookieStringInter
   nsDependentCString cookieString(aCookieString);
   nsDependentCString serverTime;
   if (aServerTime)
     serverTime.Rebind(aServerTime);
 
   URIParams uriParams;
   SerializeURI(aHostURI, uriParams);
 
-  nsCOMPtr<nsITabChild> iTabChild;
-  mozilla::dom::TabChild* tabChild = nullptr;
-  if (aChannel) {
-    NS_QueryNotificationCallbacks(aChannel, iTabChild);
-    if (iTabChild) {
-      tabChild = static_cast<mozilla::dom::TabChild*>(iTabChild.get());
-    }
-    if (MissingRequiredTabChild(tabChild, "cookie")) {
-      return NS_ERROR_ILLEGAL_VALUE;
-    }
-  }
-
   // Synchronously call the parent.
   SendSetCookieString(uriParams, !!isForeign, cookieString, serverTime,
-                      aFromHttp, IPC::SerializedLoadContext(aChannel), tabChild);
+                      aFromHttp, IPC::SerializedLoadContext(aChannel));
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CookieServiceChild::Observe(nsISupports     *aSubject,
                             const char      *aTopic,
                             const PRUnichar *aData)
 {
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -1,42 +1,42 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/net/CookieServiceParent.h"
-#include "mozilla/dom/PBrowserParent.h"
+#include "mozilla/dom/PContentParent.h"
 #include "mozilla/net/NeckoParent.h"
 
 #include "mozilla/ipc/URIUtils.h"
 #include "nsCookieService.h"
 #include "nsNetUtil.h"
 #include "nsPrintfCString.h"
 
 using namespace mozilla::ipc;
-using mozilla::dom::PBrowserParent;
+using mozilla::dom::PContentParent;
 using mozilla::net::NeckoParent;
 
 namespace mozilla {
 namespace net {
 
 MOZ_WARN_UNUSED_RESULT
-static bool
-GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
-                     PBrowserParent* aBrowser,
-                     uint32_t& aAppId,
-                     bool& aIsInBrowserElement,
-                     bool& aIsPrivate)
+bool
+CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
+                                          uint32_t& aAppId,
+                                          bool& aIsInBrowserElement,
+                                          bool& aIsPrivate)
 {
   aAppId = NECKO_NO_APP_ID;
   aIsInBrowserElement = false;
   aIsPrivate = false;
 
-  const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext, aBrowser,
+  const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext,
+                                                       Manager()->Manager(),
                                                        &aAppId,
                                                        &aIsInBrowserElement);
   if (error) {
     NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: "
                                "FATAL error: %s: KILLING CHILD PROCESS\n",
                                error).get());
     return false;
   }
@@ -64,31 +64,30 @@ CookieServiceParent::~CookieServiceParen
 }
 
 bool
 CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const bool& aFromHttp,
                                          const IPC::SerializedLoadContext&
                                                aLoadContext,
-                                         PBrowserParent* aBrowser,
                                          nsCString* aResult)
 {
   if (!mCookieService)
     return true;
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
   if (!hostURI)
     return false;
 
   uint32_t appId;
   bool isInBrowserElement, isPrivate;
-  bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId,
+  bool valid = GetAppInfoFromParams(aLoadContext, appId,
                                     isInBrowserElement, isPrivate);
   if (!valid) {
     return false;
   }
 
   mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId,
                                           isInBrowserElement, isPrivate, *aResult);
   return true;
@@ -96,31 +95,30 @@ CookieServiceParent::RecvGetCookieString
 
 bool
 CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const nsCString& aCookieString,
                                          const nsCString& aServerTime,
                                          const bool& aFromHttp,
                                          const IPC::SerializedLoadContext&
-                                               aLoadContext,
-                                         PBrowserParent* aBrowser)
+                                               aLoadContext)
 {
   if (!mCookieService)
     return true;
 
   // Deserialize URI. Having a host URI is mandatory and should always be
   // provided by the child; thus we consider failure fatal.
   nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost);
   if (!hostURI)
     return false;
 
   uint32_t appId;
   bool isInBrowserElement, isPrivate;
-  bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId,
+  bool valid = GetAppInfoFromParams(aLoadContext, appId,
                                     isInBrowserElement, isPrivate);
   if (!valid) {
     return false;
   }
 
   nsDependentCString cookieString(aCookieString, 0);
   //TODO: bug 812475, pass a real channel object
   mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
--- a/netwerk/cookie/CookieServiceParent.h
+++ b/netwerk/cookie/CookieServiceParent.h
@@ -8,44 +8,45 @@
 
 #include "mozilla/net/PCookieServiceParent.h"
 #include "SerializedLoadContext.h"
 
 class nsCookieService;
 class nsIIOService;
 
 namespace mozilla {
-namespace dom {
-  class PBrowserParent;
-}
 namespace net {
 
 class CookieServiceParent : public PCookieServiceParent
 {
 public:
   CookieServiceParent();
   virtual ~CookieServiceParent();
 
 protected:
-  virtual bool RecvGetCookieString(const URIParams& aHost,
+  MOZ_WARN_UNUSED_RESULT bool
+  GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
+                       uint32_t& aAppId,
+                       bool& aIsInBrowserElement,
+                       bool& aIsPrivate);
+
+   virtual bool RecvGetCookieString(const URIParams& aHost,
                                    const bool& aIsForeign,
                                    const bool& aFromHttp,
                                    const IPC::SerializedLoadContext&
                                          loadContext,
-                                   mozilla::dom::PBrowserParent* aBrowser,
-                                   nsCString* aResult);
+                                   nsCString* aResult) MOZ_OVERRIDE;
 
   virtual bool RecvSetCookieString(const URIParams& aHost,
                                    const bool& aIsForeign,
                                    const nsCString& aCookieString,
                                    const nsCString& aServerTime,
                                    const bool& aFromHttp,
                                    const IPC::SerializedLoadContext&
-                                         loadContext,
-                                   mozilla::dom::PBrowserParent* aBrowser);
+                                         loadContext) MOZ_OVERRIDE;
 
   nsRefPtr<nsCookieService> mCookieService;
 };
 
 }
 }
 
 #endif // mozilla_net_CookieServiceParent_h
--- a/netwerk/cookie/PCookieService.ipdl
+++ b/netwerk/cookie/PCookieService.ipdl
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
 
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PNecko;
-include protocol PBrowser;
 include URIParams;
 
 include "SerializedLoadContext.h";
 
 using IPC::SerializedLoadContext;
 
 namespace mozilla {
 namespace net {
@@ -60,18 +59,17 @@ parent:
    * @see nsICookieService.getCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    *
    * @return the resulting cookie string.
    */
   sync GetCookieString(URIParams host,
                        bool isForeign,
                        bool fromHttp,
-                       SerializedLoadContext loadContext,
-                       nullable PBrowser browser)
+                       SerializedLoadContext loadContext)
        returns (nsCString result);
 
   /*
    * Set a cookie string.
    *
    * @param host
    *        Same as the 'aURI' argument to nsICookieService.setCookieString.
    * @param isForeign
@@ -98,17 +96,16 @@ parent:
    * @see nsICookieService.setCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    */
   SetCookieString(URIParams host,
                   bool isForeign,
                   nsCString cookieString,
                   nsCString serverTime,
                   bool fromHttp,
-                  SerializedLoadContext loadContext,
-                  nullable PBrowser browser);
+                  SerializedLoadContext loadContext);
 
   __delete__();
 };
 
 }
 }
 
--- a/netwerk/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -8,28 +8,30 @@
 #include "nsHttp.h"
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/net/HttpChannelParent.h"
 #include "mozilla/net/CookieServiceParent.h"
 #include "mozilla/net/WyciwygChannelParent.h"
 #include "mozilla/net/FTPChannelParent.h"
 #include "mozilla/net/WebSocketChannelParent.h"
 #include "mozilla/net/RemoteOpenFileParent.h"
+#include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/network/TCPSocketParent.h"
 #include "mozilla/dom/network/TCPServerSocketParent.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/LoadContext.h"
 #include "mozilla/AppProcessChecker.h"
 #include "nsPrintfCString.h"
 #include "nsHTMLDNSPrefetch.h"
 #include "nsIAppsService.h"
 #include "nsEscape.h"
 #include "RemoteOpenFileParent.h"
 
+using mozilla::dom::ContentParent;
 using mozilla::dom::TabParent;
 using mozilla::net::PTCPSocketParent;
 using mozilla::dom::TCPSocketParent;
 using mozilla::net::PTCPServerSocketParent;
 using mozilla::dom::TCPServerSocketParent;
 using IPC::SerializedLoadContext;
 
 namespace mozilla {
@@ -72,16 +74,57 @@ PBOverrideStatusFromLoadContext(const Se
       kPBOverride_Private :
       kPBOverride_NotPrivate;
   }
   return kPBOverride_Unset;
 }
 
 const char*
 NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
+                                 PContentParent* aContent,
+                                 uint32_t* aAppId,
+                                 bool* aInBrowserElement)
+{
+  *aAppId = NECKO_UNKNOWN_APP_ID;
+  *aInBrowserElement = false;
+
+  if (UsingNeckoIPCSecurity()) {
+    if (!aSerialized.IsNotNull()) {
+      return "SerializedLoadContext from child is null";
+    }
+  }
+
+  const InfallibleTArray<PBrowserParent*>& browsers = aContent->ManagedPBrowserParent();
+  for (uint32_t i = 0; i < browsers.Length(); i++) {
+    // GetValidatedAppInfo returning null means we passed security checks.
+    if (!GetValidatedAppInfo(aSerialized, browsers[i], aAppId, aInBrowserElement)) {
+      return nullptr;
+    }
+  }
+
+  if (browsers.Length() == 0) {
+    if (UsingNeckoIPCSecurity()) {
+      return "ContentParent does not have any PBrowsers";
+    }
+    if (aSerialized.IsNotNull()) {
+      *aAppId = aSerialized.mAppId;
+      *aInBrowserElement = aSerialized.mIsInBrowserElement;
+    } else {
+      *aAppId = NECKO_NO_APP_ID;
+    }
+    return nullptr;
+  }
+
+  // If we reached this point, we failed the security check.
+  // Try to return a reasonable error message.
+  return GetValidatedAppInfo(aSerialized, browsers[0], aAppId, aInBrowserElement);
+}
+
+const char*
+NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
                                  PBrowserParent* aBrowser,
                                  uint32_t* aAppId,
                                  bool* aInBrowserElement)
 {
   if (UsingNeckoIPCSecurity()) {
     if (!aBrowser) {
       return "missing required PBrowser argument";
     }
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -31,16 +31,23 @@ public:
 
   MOZ_WARN_UNUSED_RESULT
   static const char *
   GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
                       PBrowserParent* aBrowser,
                       uint32_t* aAppId,
                       bool* aInBrowserElement);
 
+  MOZ_WARN_UNUSED_RESULT
+  static const char *
+  GetValidatedAppInfo(const SerializedLoadContext& aSerialized,
+                      PContentParent* aBrowser,
+                      uint32_t* aAppId,
+                      bool* aInBrowserElement);
+
   /*
    * Creates LoadContext for parent-side of an e10s channel.
    *
    * Values from PBrowserParent are more secure, and override those set in
    * SerializedLoadContext.
    *
    * Returns null if successful, or an error string if failed.
    */