Bug 1186920 - Fix b2g applications that use cookies. r=gwagner
authorBlake Kaplan <mrbkap@gmail.com>
Thu, 23 Jul 2015 19:00:49 -0700
changeset 287750 6c2d68d7625d2bf88cc9eef30a1d1873745e7295
parent 287749 09878dde0cc89f979c98a4ac00ad3d7053b8702f
child 287751 51afd4c6a44ed0c7513193800ea595e4a6ceac3b
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs1186920
milestone42.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 1186920 - Fix b2g applications that use cookies. r=gwagner
netwerk/cookie/CookieServiceParent.cpp
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -16,37 +16,49 @@
 #include "SerializedLoadContext.h"
 
 using namespace mozilla::ipc;
 using mozilla::dom::PContentParent;
 using mozilla::net::NeckoParent;
 
 namespace {
 
-bool
-CreateDummyChannel(nsIURI* aHostURI, bool aIsPrivate, nsIChannel **aChannel)
+// Ignore failures from this function, as they only affect whether we do or
+// don't show a dialog box in private browsing mode if the user sets a pref.
+void
+CreateDummyChannel(nsIURI* aHostURI, uint32_t aAppId, bool aInMozBrowser,
+                   bool aIsPrivate, nsIChannel **aChannel)
 {
+  MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
+
   nsCOMPtr<nsIPrincipal> principal;
   nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
-  nsresult rv = ssm->GetNoAppCodebasePrincipal(aHostURI, getter_AddRefs(principal));
+  nsresult rv = ssm->GetAppCodebasePrincipal(aHostURI, aAppId, aInMozBrowser,
+                                             getter_AddRefs(principal));
   if (NS_FAILED(rv)) {
-    return false;
+    return;
+  }
+
+  nsCOMPtr<nsIURI> dummyURI;
+  rv = NS_NewURI(getter_AddRefs(dummyURI), "about:blank");
+  if (NS_FAILED(rv)) {
+      return;
   }
 
   nsCOMPtr<nsIChannel> dummyChannel;
-  NS_NewChannel(getter_AddRefs(dummyChannel), aHostURI, principal,
+  NS_NewChannel(getter_AddRefs(dummyChannel), dummyURI, principal,
                 nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_INVALID);
   nsCOMPtr<nsIPrivateBrowsingChannel> pbChannel = do_QueryInterface(dummyChannel);
   if (!pbChannel) {
-    return false;
+    return;
   }
 
   pbChannel->SetPrivate(aIsPrivate);
   dummyChannel.forget(aChannel);
-  return true;
+  return;
 }
 
 }
 
 namespace mozilla {
 namespace net {
 
 MOZ_WARN_UNUSED_RESULT
@@ -158,20 +170,20 @@ CookieServiceParent::RecvSetCookieString
   // 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;
-  if (!CreateDummyChannel(hostURI, isPrivate, getter_AddRefs(dummyChannel))) {
-    return false;
-  }
+  CreateDummyChannel(hostURI, appId, isInBrowserElement,
+                     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, appId,
                                           isInBrowserElement, isPrivate, dummyChannel);
   return true;
 }
 
 mozilla::ipc::IProtocol*