diff --git a/netwerk/cookie/CookieServiceParent.cpp b/netwerk/cookie/CookieServiceParent.cpp index 4a929b5ca2e3..467eeba8cf98 100644 --- a/netwerk/cookie/CookieServiceParent.cpp +++ b/netwerk/cookie/CookieServiceParent.cpp @@ -21,27 +21,39 @@ 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 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 dummyURI; + rv = NS_NewURI(getter_AddRefs(dummyURI), "about:blank"); + if (NS_FAILED(rv)) { + return; } nsCOMPtr dummyChannel; - NS_NewChannel(getter_AddRefs(dummyChannel), aHostURI, principal, + NS_NewChannel(getter_AddRefs(dummyChannel), dummyURI, principal, nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_INVALID); nsCOMPtr pbChannel = do_QueryInterface(dummyChannel); if (!pbChannel) { - return false; + return; } pbChannel->SetPrivate(aIsPrivate); dummyChannel.forget(aChannel); - return true; + return; } } @@ -163,10 +175,10 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost, // with aIsForeign before we have to worry about nsCookiePermission trying // to use the channel to inspect it. nsCOMPtr 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,