Bug 1301406 - replace SerializedLoadContext with NeckoOriginAttributes. r=smaug, ehsan, jduell
authorYoshi Huang <allstars.chh@mozilla.com>
Fri, 09 Sep 2016 18:26:14 +0800
changeset 314444 f9fc3453e993
parent 314443 3f26b3f32f99
child 314445 008c6f3dc239
push id81895
push useryhuang@mozilla.com
push dateTue, 20 Sep 2016 06:24:47 +0000
treeherdermozilla-inbound@f9fc3453e993 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, ehsan, jduell
bugs1301406
milestone52.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 1301406 - replace SerializedLoadContext with NeckoOriginAttributes. r=smaug, ehsan, jduell SerializedLoadContext carries the origin attributes of the docshell to parent process. However document could have different origin attributes than the docshell's. And the origin attributes of the document comes from the LoadInfo of the channel. So we replace SerializedLoadContext with NeckoOriginAttributes, which is from the loadInfo of the channel, therefore parent can get the correct origin attributes from the document.
netwerk/cookie/CookieServiceChild.cpp
netwerk/cookie/CookieServiceParent.cpp
netwerk/cookie/CookieServiceParent.h
netwerk/cookie/PCookieService.ipdl
--- a/netwerk/cookie/CookieServiceChild.cpp
+++ b/netwerk/cookie/CookieServiceChild.cpp
@@ -1,21 +1,23 @@
 /* -*- 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/LoadInfo.h"
+#include "mozilla/BasePrincipal.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/net/NeckoChild.h"
+#include "nsIChannel.h"
 #include "nsIURI.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsServiceManagerUtils.h"
-#include "SerializedLoadContext.h"
 
 using namespace mozilla::ipc;
 
 namespace mozilla {
 namespace net {
 
 // Pref string constants
 static const char kPrefCookieBehavior[] = "network.cookie.cookieBehavior";
@@ -117,20 +119,27 @@ 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);
 
+  mozilla::NeckoOriginAttributes attrs;
+  if (aChannel) {
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+    if (loadInfo) {
+      attrs = loadInfo->GetOriginAttributes();
+    }
+  }
+
   // Synchronously call the parent.
   nsAutoCString result;
-  SendGetCookieString(uriParams, !!isForeign, aFromHttp,
-                      IPC::SerializedLoadContext(aChannel), &result);
+  SendGetCookieString(uriParams, !!isForeign, aFromHttp, attrs, &result);
   if (!result.IsEmpty())
     *aCookieString = ToNewCString(result);
 
   return NS_OK;
 }
 
 nsresult
 CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI,
@@ -157,19 +166,27 @@ CookieServiceChild::SetCookieStringInter
   nsDependentCString cookieString(aCookieString);
   nsDependentCString serverTime;
   if (aServerTime)
     serverTime.Rebind(aServerTime);
 
   URIParams uriParams;
   SerializeURI(aHostURI, uriParams);
 
+  mozilla::NeckoOriginAttributes attrs;
+  if (aChannel) {
+    nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
+    if (loadInfo) {
+      attrs = loadInfo->GetOriginAttributes();
+    }
+  }
+
   // Synchronously call the parent.
   SendSetCookieString(uriParams, !!isForeign, cookieString, serverTime,
-                      aFromHttp, IPC::SerializedLoadContext(aChannel));
+                      aFromHttp, attrs);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 CookieServiceChild::Observe(nsISupports     *aSubject,
                             const char      *aTopic,
                             const char16_t *aData)
 {
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -10,17 +10,16 @@
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "nsCookieService.h"
 #include "nsIChannel.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIPrivateBrowsingChannel.h"
 #include "nsNetCID.h"
 #include "nsPrintfCString.h"
-#include "SerializedLoadContext.h"
 
 using namespace mozilla::ipc;
 using mozilla::BasePrincipal;
 using mozilla::NeckoOriginAttributes;
 using mozilla::PrincipalOriginAttributes;
 using mozilla::dom::PContentParent;
 using mozilla::net::NeckoParent;
 
@@ -65,43 +64,16 @@ CreateDummyChannel(nsIURI* aHostURI, Nec
   return;
 }
 
 }
 
 namespace mozilla {
 namespace net {
 
-MOZ_MUST_USE
-bool
-CookieServiceParent::GetOriginAttributesFromParams(const IPC::SerializedLoadContext &aLoadContext,
-                                                   NeckoOriginAttributes& aAttrs,
-                                                   bool& aIsPrivate)
-{
-  aIsPrivate = false;
-
-  DocShellOriginAttributes docShellAttrs;
-  const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext,
-                                                       Manager()->Manager(),
-                                                       docShellAttrs);
-  if (error) {
-    NS_WARNING(nsPrintfCString("CookieServiceParent: GetOriginAttributesFromParams: "
-                               "FATAL error: %s: KILLING CHILD PROCESS\n",
-                               error).get());
-    return false;
-  }
-
-  if (aLoadContext.IsPrivateBitValid()) {
-    aIsPrivate = aLoadContext.mOriginAttributes.mPrivateBrowsingId > 0;
-  }
-
-  aAttrs.InheritFromDocShellToNecko(docShellAttrs);
-  return true;
-}
-
 CookieServiceParent::CookieServiceParent()
 {
   // Instantiate the cookieservice via the service manager, so it sticks around
   // until shutdown.
   nsCOMPtr<nsICookieService> cs = do_GetService(NS_COOKIESERVICE_CONTRACTID);
 
   // Get the nsCookieService instance directly, so we can call internal methods.
   mCookieService =
@@ -119,80 +91,68 @@ CookieServiceParent::ActorDestroy(ActorD
   // Nothing needed here. Called right before destructor since this is a
   // non-refcounted class.
 }
 
 bool
 CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const bool& aFromHttp,
-                                         const IPC::SerializedLoadContext&
-                                               aLoadContext,
+                                         const NeckoOriginAttributes& aAttrs,
                                          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;
 
-  NeckoOriginAttributes attrs;
-  bool isPrivate;
-  bool valid = GetOriginAttributesFromParams(aLoadContext, attrs, isPrivate);
-  if (!valid) {
-    return false;
-  }
-
-  mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, attrs,
+  bool isPrivate = aAttrs.mPrivateBrowsingId > 0;
+  mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, aAttrs,
                                           isPrivate, *aResult);
   return true;
 }
 
 bool
 CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
                                          const bool& aIsForeign,
                                          const nsCString& aCookieString,
                                          const nsCString& aServerTime,
                                          const bool& aFromHttp,
-                                         const IPC::SerializedLoadContext&
-                                               aLoadContext)
+                                         const NeckoOriginAttributes& aAttrs)
 {
   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;
 
-  NeckoOriginAttributes attrs;
-  bool isPrivate;
-  bool valid = GetOriginAttributesFromParams(aLoadContext, attrs, isPrivate);
-  if (!valid) {
-    return false;
-  }
+  bool isPrivate = aAttrs.mPrivateBrowsingId > 0;
 
   // This is a gross hack. We've already computed everything we need to know
   // for whether to set this cookie or not, but we need to communicate all of
   // this information through to nsICookiePermission, which indirectly
   // computes the information from the channel. We only care about the
   // aIsPrivate argument as nsCookieService::SetCookieStringInternal deals
   // with aIsForeign before we have to worry about nsCookiePermission trying
   // to use the channel to inspect it.
   nsCOMPtr<nsIChannel> dummyChannel;
-  CreateDummyChannel(hostURI, attrs, isPrivate, getter_AddRefs(dummyChannel));
+  CreateDummyChannel(hostURI, const_cast<NeckoOriginAttributes&>(aAttrs),
+                     isPrivate, getter_AddRefs(dummyChannel));
 
   // NB: dummyChannel could be null if something failed in CreateDummyChannel.
   nsDependentCString cookieString(aCookieString, 0);
   mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString,
-                                          aServerTime, aFromHttp, attrs,
+                                          aServerTime, aFromHttp, aAttrs,
                                           isPrivate, dummyChannel);
   return true;
 }
 
 mozilla::ipc::IProtocol*
 CookieServiceParent::CloneProtocol(Channel* aChannel,
                                    mozilla::ipc::ProtocolCloneContext* aCtx)
 {
--- a/netwerk/cookie/CookieServiceParent.h
+++ b/netwerk/cookie/CookieServiceParent.h
@@ -2,52 +2,44 @@
 /* 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/. */
 
 #ifndef mozilla_net_CookieServiceParent_h
 #define mozilla_net_CookieServiceParent_h
 
 #include "mozilla/net/PCookieServiceParent.h"
-#include "SerializedLoadContext.h"
 
 class nsCookieService;
 namespace mozilla { class NeckoOriginAttributes; }
 
 namespace mozilla {
 namespace net {
 
 class CookieServiceParent : public PCookieServiceParent
 {
 public:
   CookieServiceParent();
   virtual ~CookieServiceParent();
 
 protected:
-  MOZ_MUST_USE bool
-  GetOriginAttributesFromParams(const IPC::SerializedLoadContext &aLoadContext,
-                                NeckoOriginAttributes& aAttrs,
-                                bool& aIsPrivate);
-
   virtual void ActorDestroy(ActorDestroyReason aWhy) override;
 
   virtual bool RecvGetCookieString(const URIParams& aHost,
                                    const bool& aIsForeign,
                                    const bool& aFromHttp,
-                                   const IPC::SerializedLoadContext&
-                                         loadContext,
+                                   const NeckoOriginAttributes& aAttrs,
                                    nsCString* aResult) override;
 
   virtual bool RecvSetCookieString(const URIParams& aHost,
                                    const bool& aIsForeign,
                                    const nsCString& aCookieString,
                                    const nsCString& aServerTime,
                                    const bool& aFromHttp,
-                                   const IPC::SerializedLoadContext&
-                                         loadContext) override;
+                                   const NeckoOriginAttributes& aAttrs) override;
 
   virtual mozilla::ipc::IProtocol*
   CloneProtocol(Channel* aChannel,
                 mozilla::ipc::ProtocolCloneContext* aCtx) override;
 
   RefPtr<nsCookieService> mCookieService;
 };
 
--- a/netwerk/cookie/PCookieService.ipdl
+++ b/netwerk/cookie/PCookieService.ipdl
@@ -3,18 +3,17 @@
 
 /* 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 URIParams;
 
-
-using class IPC::SerializedLoadContext from "SerializedLoadContext.h";
+using mozilla::NeckoOriginAttributes from "mozilla/ipc/BackgroundUtils.h";
 
 namespace mozilla {
 namespace net {
 
 /**
  * PCookieService
  *
  * Provides IPDL methods for setting and getting cookies. These are stored on
@@ -45,30 +44,30 @@ parent:
    *        access to cookies. This should be obtained from
    *        mozIThirdPartyUtil.isThirdPartyChannel. Third party requests may be
    *        rejected depending on user preferences; if those checks are
    *        disabled, this parameter is ignored.
    * @param fromHttp
    *        Whether the result is for an HTTP request header. This should be
    *        true for nsICookieService.getCookieStringFromHttp calls, false
    *        otherwise.
-   * @param loadContext
-   *        The loadContext from the HTTP channel or document that the cookie is
-   *        being set on.
+   * @param attrs
+   *        The origin attributes from the HTTP channel or document that the
+   *        cookie is being set on.
    *
    * @see nsICookieService.getCookieString
    * @see nsICookieService.getCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    *
    * @return the resulting cookie string.
    */
   prio(urgent) sync GetCookieString(URIParams host,
                                     bool isForeign,
                                     bool fromHttp,
-                                    SerializedLoadContext loadContext)
+                                    NeckoOriginAttributes attrs)
        returns (nsCString result);
 
   /*
    * Set a cookie string.
    *
    * @param host
    *        Same as the 'aURI' argument to nsICookieService.setCookieString.
    * @param isForeign
@@ -82,29 +81,29 @@ parent:
    * @param serverTime
    *        Same as the 'aServerTime' argument to
    *        nsICookieService.setCookieStringFromHttp. If the string is empty or
    *        null (e.g. for non-HTTP requests), the current local time is used.
    * @param fromHttp
    *        Whether the result is for an HTTP request header. This should be
    *        true for nsICookieService.setCookieStringFromHttp calls, false
    *        otherwise.
-   * @param loadContext
-   *        The loadContext from the HTTP channel or document that the cookie is
-   *        being set on.
+   * @param attrs
+   *        The origin attributes from the HTTP channel or document that the
+   *        cookie is being set on.
    *
    * @see nsICookieService.setCookieString
    * @see nsICookieService.setCookieStringFromHttp
    * @see mozIThirdPartyUtil.isThirdPartyChannel
    */
   prio(urgent) async SetCookieString(URIParams host,
                                      bool isForeign,
                                      nsCString cookieString,
                                      nsCString serverTime,
                                      bool fromHttp,
-                                     SerializedLoadContext loadContext);
+                                     NeckoOriginAttributes attrs);
 
   async __delete__();
 };
 
 }
 }