Skip to content

Commit

Permalink
Bug 1165267 - Part 1: Replace appId and inBrowser by originAttributes…
Browse files Browse the repository at this point in the history
… v2. r=honzab
  • Loading branch information
ethantseng committed Sep 3, 2015
1 parent 583b700 commit bb095c0
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 142 deletions.
2 changes: 1 addition & 1 deletion extensions/cookie/test/unit/test_cookies_sync_failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// c) Schema 3: the 'creationTime' column already exists; or the
// 'moz_uniqueid' index already exists.

var COOKIE_DATABASE_SCHEMA_CURRENT = 5;
var COOKIE_DATABASE_SCHEMA_CURRENT = 6;

var test_generator = do_run_test();

Expand Down
51 changes: 20 additions & 31 deletions netwerk/cookie/CookieServiceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ namespace {
// 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)
CreateDummyChannel(nsIURI* aHostURI, OriginAttributes &aAttrs, bool aIsPrivate,
nsIChannel **aChannel)
{
MOZ_ASSERT(aAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);
MOZ_ASSERT(aAttrs.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID);

// TODO: Bug 1165267 - Use OriginAttributes for nsCookieService
OriginAttributes attrs(aAppId, aInMozBrowser);
nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateCodebasePrincipal(aHostURI, attrs);
BasePrincipal::CreateCodebasePrincipal(aHostURI, aAttrs);
if (!principal) {
return;
}
Expand Down Expand Up @@ -66,28 +64,22 @@ namespace net {

MOZ_WARN_UNUSED_RESULT
bool
CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
uint32_t& aAppId,
bool& aIsInBrowserElement,
bool& aIsPrivate)
CookieServiceParent::GetOriginAttributesFromParams(const IPC::SerializedLoadContext &aLoadContext,
OriginAttributes& aAttrs,
bool& aIsPrivate)
{
aAppId = NECKO_NO_APP_ID;
aIsInBrowserElement = false;
aIsPrivate = false;

OriginAttributes attrs;
const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext,
Manager()->Manager(),
attrs);
aAttrs);
if (error) {
NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: "
NS_WARNING(nsPrintfCString("CookieServiceParent: GetOriginAttributesFromParams: "
"FATAL error: %s: KILLING CHILD PROCESS\n",
error).get());
return false;
}

aAppId = attrs.mAppId;
aIsInBrowserElement = attrs.mInBrowser;
if (aLoadContext.IsPrivateBitValid()) {
aIsPrivate = aLoadContext.mUsePrivateBrowsing;
}
Expand Down Expand Up @@ -133,16 +125,15 @@ CookieServiceParent::RecvGetCookieString(const URIParams& aHost,
if (!hostURI)
return false;

uint32_t appId;
bool isInBrowserElement, isPrivate;
bool valid = GetAppInfoFromParams(aLoadContext, appId,
isInBrowserElement, isPrivate);
OriginAttributes attrs;
bool isPrivate;
bool valid = GetOriginAttributesFromParams(aLoadContext, attrs, isPrivate);
if (!valid) {
return false;
}

mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId,
isInBrowserElement, isPrivate, *aResult);
mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, attrs,
isPrivate, *aResult);
return true;
}

Expand All @@ -164,10 +155,9 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
if (!hostURI)
return false;

uint32_t appId;
bool isInBrowserElement, isPrivate;
bool valid = GetAppInfoFromParams(aLoadContext, appId,
isInBrowserElement, isPrivate);
OriginAttributes attrs;
bool isPrivate;
bool valid = GetOriginAttributesFromParams(aLoadContext, attrs, isPrivate);
if (!valid) {
return false;
}
Expand All @@ -180,14 +170,13 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
// with aIsForeign before we have to worry about nsCookiePermission trying
// to use the channel to inspect it.
nsCOMPtr<nsIChannel> dummyChannel;
CreateDummyChannel(hostURI, appId, isInBrowserElement,
isPrivate, getter_AddRefs(dummyChannel));
CreateDummyChannel(hostURI, attrs, 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);
aServerTime, aFromHttp, attrs,
isPrivate, dummyChannel);
return true;
}

Expand Down
8 changes: 4 additions & 4 deletions netwerk/cookie/CookieServiceParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "SerializedLoadContext.h"

class nsCookieService;
namespace mozilla { class OriginAttributes; }

namespace mozilla {
namespace net {
Expand All @@ -22,10 +23,9 @@ class CookieServiceParent : public PCookieServiceParent

protected:
MOZ_WARN_UNUSED_RESULT bool
GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext,
uint32_t& aAppId,
bool& aIsInBrowserElement,
bool& aIsPrivate);
GetOriginAttributesFromParams(const IPC::SerializedLoadContext &aLoadContext,
OriginAttributes& aAttrs,
bool& aIsPrivate);

virtual void ActorDestroy(ActorDestroyReason aWhy) override;

Expand Down
Loading

0 comments on commit bb095c0

Please sign in to comment.