Skip to content

Commit

Permalink
only override specific calls to IsCookieAccessAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Jan 19, 2021
1 parent 54d02cc commit 64e699d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ bool ShouldUseEphemeralStorage(
if (!top_frame_origin || url::Origin::Create(url) == top_frame_origin)
return false;

bool block_3p = !cookie_settings->IsChromiumCookieAccessAllowed(
bool block_3p = !cookie_settings->IsCookieAccessAllowed(
url, site_for_cookies, top_frame_origin);
bool block_1p = !cookie_settings->IsChromiumCookieAccessAllowed(
bool block_1p = !cookie_settings->IsCookieAccessAllowed(
url, url, url::Origin::Create(url));

// only use ephemeral storage for block 3p
Expand All @@ -171,19 +171,31 @@ bool ShouldUseEphemeralStorage(

} // namespace

bool CookieSettingsBase::IsCookieAccessAllowed(
bool CookieSettingsBase::IsEphemeralCookieAccessAllowed(
const GURL& url, const GURL& first_party_url) const {
return IsCookieAccessAllowed(url, first_party_url, base::nullopt);
return IsEphemeralCookieAccessAllowed(url, first_party_url, base::nullopt);
}

bool CookieSettingsBase::IsCookieAccessAllowed(
bool CookieSettingsBase::IsEphemeralCookieAccessAllowed(
const GURL& url,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) const {

if (ShouldUseEphemeralStorage(url, site_for_cookies, top_frame_origin, this))
return true;

return IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
}

bool CookieSettingsBase::IsCookieAccessAllowed(
const GURL& url, const GURL& first_party_url) const {
return IsCookieAccessAllowed(url, first_party_url, base::nullopt);
}

bool CookieSettingsBase::IsCookieAccessAllowed(
const GURL& url,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) const {
// Get content settings only - do not consider default 3rd-party blocking.
ContentSetting setting;
GetCookieSettingInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_

#define BRAVE_COOKIE_SETTINGS_BASE_H \
bool IsEphemeralCookieAccessAllowed(const GURL& url, \
const GURL& first_party_url) const; \
bool IsEphemeralCookieAccessAllowed( \
const GURL& url, const GURL& site_for_cookies, \
const base::Optional<url::Origin>& top_frame_origin) const; \
bool IsChromiumCookieAccessAllowed(const GURL& url, \
const GURL& first_party_url) const; \
bool IsChromiumCookieAccessAllowed( \
const GURL& url, \
const GURL& site_for_cookies, \
const GURL& url, const GURL& site_for_cookies, \
const base::Optional<url::Origin>& top_frame_origin) const;

#include "../../../../../../components/content_settings/core/common/cookie_settings_base.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* Copyright 2021 The Brave Authors. All rights reserved.
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* 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 "components/content_settings/browser/content_settings_manager_impl.h"
#include "services/network/network_service_network_delegate.h"

#include "components/content_settings/core/common/cookie_settings_base.h"

#define IsCookieAccessAllowed IsChromiumCookieAccessAllowed
#include "../../../../../components/content_settings/browser/content_settings_manager_impl.cc"
#define IsCookieAccessAllowed IsEphemeralCookieAccessAllowed
#include "../../../../../services/network/network_service_network_delegate.cc"
#undef IsCookieAccessAllowed
7 changes: 5 additions & 2 deletions chromium_src/services/network/restricted_cookie_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "services/network/restricted_cookie_manager.h"

#include "base/feature_list.h"
#include "components/content_settings/core/common/cookie_settings_base.h"
#include "net/base/features.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/site_for_cookies.h"
Expand All @@ -25,9 +26,9 @@ bool ShouldUseEphemeralStorage(
if (url::Origin::Create(url) == top_frame_origin)
return false;

bool block_3p = !cookie_settings->IsChromiumCookieAccessAllowed(
bool block_3p = !cookie_settings->IsCookieAccessAllowed(
url, site_for_cookies.RepresentativeUrl(), top_frame_origin);
bool block_1p = !cookie_settings->IsChromiumCookieAccessAllowed(
bool block_1p = !cookie_settings->IsCookieAccessAllowed(
url, url, url::Origin::Create(url));

// only use ephemeral storage for block 3p
Expand Down Expand Up @@ -67,4 +68,6 @@ bool ShouldUseEphemeralStorage(
return; \
}

#define IsCookieAccessAllowed IsEphemeralCookieAccessAllowed
#include "../../../../../services/network/restricted_cookie_manager.cc"
#undef IsCookieAccessAllowed

0 comments on commit 64e699d

Please sign in to comment.