From 45ef6c8aba3c88aaf8b457a91e0220339035d2ae Mon Sep 17 00:00:00 2001 From: Aleksey Khoroshilov Date: Mon, 26 Apr 2021 17:39:24 +0700 Subject: [PATCH] Unify ephemeral storage trigger logic to use net::CookieOptions. --- .../ephemeral_storage_browsertest.cc | 12 ++- .../components/content_settings/browser/DEPS | 5 ++ .../browser/content_settings_manager_impl.cc | 23 ++++++ .../browser/content_settings_manager_impl.h | 24 ++++++ .../common/content_settings_manager.mojom | 15 ++++ .../core/common/cookie_settings_base.cc | 34 ++++++++- .../core/common/cookie_settings_base.h | 29 +++++++- .../net/cookies/cookie_access_delegate.cc | 26 +++++++ .../net/cookies/cookie_access_delegate.h | 25 +++++++ chromium_src/net/cookies/cookie_monster.cc | 62 +++++++++++----- chromium_src/net/cookies/cookie_monster.h | 16 ++-- chromium_src/net/cookies/cookie_options.cc | 47 ++++++++++++ chromium_src/net/cookies/cookie_options.h | 73 +++++++++++++++++++ .../net/url_request/url_request_http_job.cc | 28 +++++++ .../net/url_request/url_request_http_job.h | 26 +++++++ .../network/cookie_access_delegate_impl.cc | 26 +++++++ .../network/cookie_access_delegate_impl.h | 22 ++++++ .../network_service_network_delegate.cc | 43 +++++++++++ .../network_service_network_delegate.h | 22 ++++++ chromium_src/services/network/public/cpp/DEPS | 6 ++ .../public/cpp/cookie_manager_mojom_traits.cc | 40 ++++++++++ .../public/cpp/cookie_manager_mojom_traits.h | 45 ++++++++++++ .../network/public/mojom/cookie_manager.mojom | 10 +++ .../network/restricted_cookie_manager.cc | 69 ++++++++---------- .../network/restricted_cookie_manager.h | 35 +++++++++ .../brave_content_settings_agent_impl.cc | 45 ++++-------- .../brave_content_settings_agent_impl.h | 1 - ...ettings_agent_impl_autoplay_browsertest.cc | 8 ++ ...network-restricted_cookie_manager.cc.patch | 20 ----- 29 files changed, 714 insertions(+), 123 deletions(-) create mode 100644 chromium_src/components/content_settings/browser/DEPS create mode 100644 chromium_src/components/content_settings/browser/content_settings_manager_impl.cc create mode 100644 chromium_src/components/content_settings/browser/content_settings_manager_impl.h create mode 100644 chromium_src/components/content_settings/common/content_settings_manager.mojom create mode 100644 chromium_src/net/cookies/cookie_access_delegate.cc create mode 100644 chromium_src/net/cookies/cookie_access_delegate.h create mode 100644 chromium_src/net/cookies/cookie_options.cc create mode 100644 chromium_src/net/cookies/cookie_options.h create mode 100644 chromium_src/net/url_request/url_request_http_job.cc create mode 100644 chromium_src/net/url_request/url_request_http_job.h create mode 100644 chromium_src/services/network/cookie_access_delegate_impl.cc create mode 100644 chromium_src/services/network/cookie_access_delegate_impl.h create mode 100644 chromium_src/services/network/network_service_network_delegate.cc create mode 100644 chromium_src/services/network/network_service_network_delegate.h create mode 100644 chromium_src/services/network/public/cpp/DEPS create mode 100644 chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.cc create mode 100644 chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.h create mode 100644 chromium_src/services/network/restricted_cookie_manager.h delete mode 100644 patches/services-network-restricted_cookie_manager.cc.patch diff --git a/browser/ephemeral_storage/ephemeral_storage_browsertest.cc b/browser/ephemeral_storage/ephemeral_storage_browsertest.cc index c20722c21a28..4624dc744d70 100644 --- a/browser/ephemeral_storage/ephemeral_storage_browsertest.cc +++ b/browser/ephemeral_storage/ephemeral_storage_browsertest.cc @@ -470,7 +470,7 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, } IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, - DISABLED_NavigationCookiesArePartitioned) { + NavigationCookiesArePartitioned) { GURL a_site_set_cookie_url = https_server_.GetURL( "a.com", "/set-cookie?name=acom;path=/;SameSite=None;Secure"); GURL b_site_set_cookie_url = https_server_.GetURL( @@ -510,8 +510,16 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, b_cookie = content::GetCookies(browser()->profile(), GURL("https://b.com/")); EXPECT_EQ("name=bcom", b_cookie); - // Navigating to a new TLD should clear all ephemeral cookies. + // Navigating to a new TLD should clear all ephemeral cookies after keep-alive + // timeout. ui_test_utils::NavigateToURL(browser(), b_site_ephemeral_storage_url_); + + base::RunLoop run_loop; + base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( + FROM_HERE, run_loop.QuitClosure(), + base::TimeDelta::FromSeconds(kKeepAliveInterval)); + run_loop.Run(); + ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_); ValuesFromFrames values_after = GetValuesFromFrames(web_contents); diff --git a/chromium_src/components/content_settings/browser/DEPS b/chromium_src/components/content_settings/browser/DEPS new file mode 100644 index 000000000000..2cfec7e9b891 --- /dev/null +++ b/chromium_src/components/content_settings/browser/DEPS @@ -0,0 +1,5 @@ +include_rules = [ + "+../../../../../components/content_settings/browser", + "+components/content_settings/browser", + "+components/content_settings/common", +] diff --git a/chromium_src/components/content_settings/browser/content_settings_manager_impl.cc b/chromium_src/components/content_settings/browser/content_settings_manager_impl.cc new file mode 100644 index 000000000000..a9e6b909890e --- /dev/null +++ b/chromium_src/components/content_settings/browser/content_settings_manager_impl.cc @@ -0,0 +1,23 @@ +/* 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 "../../../../../components/content_settings/browser/content_settings_manager_impl.cc" + +namespace content_settings { + +void ContentSettingsManagerImpl::AllowEphemeralStorageAccess( + int32_t render_frame_id, + StorageType storage_type, + const url::Origin& origin, + const GURL& site_for_cookies, + const url::Origin& top_frame_origin, + base::OnceCallback callback) { + std::move(callback).Run(cookie_settings_->ShouldUseEphemeralStorage( + origin.GetURL(), site_for_cookies, top_frame_origin)); +} + +} // namespace content_settings diff --git a/chromium_src/components/content_settings/browser/content_settings_manager_impl.h b/chromium_src/components/content_settings/browser/content_settings_manager_impl.h new file mode 100644 index 000000000000..3594fef03061 --- /dev/null +++ b/chromium_src/components/content_settings/browser/content_settings_manager_impl.h @@ -0,0 +1,24 @@ +/* Copyright 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_BROWSER_CONTENT_SETTINGS_MANAGER_IMPL_H_ +#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_BROWSER_CONTENT_SETTINGS_MANAGER_IMPL_H_ + +#include "components/content_settings/common/content_settings_manager.mojom.h" + +#define OnContentBlocked \ + NotUsed() {} \ + void AllowEphemeralStorageAccess( \ + int32_t render_frame_id, StorageType storage_type, \ + const url::Origin& origin, const GURL& site_for_cookies, \ + const url::Origin& top_frame_origin, \ + base::OnceCallback callback) override; \ + void OnContentBlocked + +#include "../../../../../components/content_settings/browser/content_settings_manager_impl.h" + +#undef OnContentBlocked + +#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_BROWSER_CONTENT_SETTINGS_MANAGER_IMPL_H_ diff --git a/chromium_src/components/content_settings/common/content_settings_manager.mojom b/chromium_src/components/content_settings/common/content_settings_manager.mojom new file mode 100644 index 000000000000..ac2ef8f5605e --- /dev/null +++ b/chromium_src/components/content_settings/common/content_settings_manager.mojom @@ -0,0 +1,15 @@ +module content_settings.mojom; + +import "url/mojom/origin.mojom"; +import "url/mojom/url.mojom"; + +[BraveExtend] +interface ContentSettingsManager { + [Sync] + AllowEphemeralStorageAccess( + int32 render_frame_id, + StorageType storage_type, + url.mojom.Origin origin, + url.mojom.Url site_for_cookies, + url.mojom.Origin top_frame_origin) => (bool ephemeral_storage_allowed); +}; diff --git a/chromium_src/components/content_settings/core/common/cookie_settings_base.cc b/chromium_src/components/content_settings/core/common/cookie_settings_base.cc index 1b727f96bef5..2ee3895a097a 100644 --- a/chromium_src/components/content_settings/core/common/cookie_settings_base.cc +++ b/chromium_src/components/content_settings/core/common/cookie_settings_base.cc @@ -78,6 +78,7 @@ GURL GetFirstPartyURL(const GURL& site_for_cookies, const base::Optional& top_frame_origin) { return top_frame_origin ? top_frame_origin->GetURL() : site_for_cookies; } + bool IsFirstPartyAccessAllowed( const GURL& first_party_url, const CookieSettingsBase* const cookie_settings) { @@ -88,6 +89,15 @@ bool IsFirstPartyAccessAllowed( } // namespace +ScopedEphemeralStorageAwareness::ScopedEphemeralStorageAwareness( + bool* ephemeral_storage_aware) + : ephemeral_storage_aware_auto_reset_(ephemeral_storage_aware, true) {} +ScopedEphemeralStorageAwareness::~ScopedEphemeralStorageAwareness() = default; +ScopedEphemeralStorageAwareness::ScopedEphemeralStorageAwareness( + ScopedEphemeralStorageAwareness&& rhs) = default; +ScopedEphemeralStorageAwareness& ScopedEphemeralStorageAwareness::operator=( + ScopedEphemeralStorageAwareness&& rhs) = default; + bool CookieSettingsBase::ShouldUseEphemeralStorage( const GURL& url, const GURL& site_for_cookies, @@ -107,13 +117,18 @@ bool CookieSettingsBase::ShouldUseEphemeralStorage( return false; bool allow_3p = - IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); + IsCookieAccessAllowedImpl(url, site_for_cookies, top_frame_origin); bool allow_1p = IsFirstPartyAccessAllowed(first_party_url, this); // only use ephemeral storage for block 3p return allow_1p && !allow_3p; } +ScopedEphemeralStorageAwareness +CookieSettingsBase::CreateScopedEphemeralStorageAwareness() const { + return ScopedEphemeralStorageAwareness(&ephemeral_storage_aware_); +} + bool CookieSettingsBase::IsEphemeralCookieAccessAllowed( const GURL& url, const GURL& first_party_url) const { @@ -124,9 +139,8 @@ bool CookieSettingsBase::IsEphemeralCookieAccessAllowed( const GURL& url, const GURL& site_for_cookies, const base::Optional& top_frame_origin) const { - if (ShouldUseEphemeralStorage(url, site_for_cookies, top_frame_origin)) - return true; - + auto scoped_ephemeral_storage_awareness = + CreateScopedEphemeralStorageAwareness(); return IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); } @@ -140,6 +154,18 @@ bool CookieSettingsBase::IsCookieAccessAllowed( const GURL& url, const GURL& site_for_cookies, const base::Optional& top_frame_origin) const { + if (ephemeral_storage_aware_ && + ShouldUseEphemeralStorage(url, site_for_cookies, top_frame_origin)) { + return true; + } + + return IsCookieAccessAllowedImpl(url, site_for_cookies, top_frame_origin); +} + +bool CookieSettingsBase::IsCookieAccessAllowedImpl( + const GURL& url, + const GURL& site_for_cookies, + const base::Optional& top_frame_origin) const { bool allow = IsChromiumCookieAccessAllowed(url, site_for_cookies, top_frame_origin); diff --git a/chromium_src/components/content_settings/core/common/cookie_settings_base.h b/chromium_src/components/content_settings/core/common/cookie_settings_base.h index 65aa549e33ea..b019df3486a0 100644 --- a/chromium_src/components/content_settings/core/common/cookie_settings_base.h +++ b/chromium_src/components/content_settings/core/common/cookie_settings_base.h @@ -6,10 +6,30 @@ #ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ #define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ +#include "base/auto_reset.h" + +namespace content_settings { + +// Helper to allow patchless ephemeral storage access in Chromium code. +class ScopedEphemeralStorageAwareness { + public: + explicit ScopedEphemeralStorageAwareness(bool* ephemeral_storage_aware); + ScopedEphemeralStorageAwareness(ScopedEphemeralStorageAwareness&&); + ScopedEphemeralStorageAwareness& operator=(ScopedEphemeralStorageAwareness&&); + ~ScopedEphemeralStorageAwareness(); + + private: + base::AutoReset ephemeral_storage_aware_auto_reset_; +}; + +} // namespace content_settings + #define BRAVE_COOKIE_SETTINGS_BASE_H \ bool ShouldUseEphemeralStorage( \ const GURL& url, const GURL& site_for_cookies, \ const base::Optional& top_frame_origin) const; \ + ScopedEphemeralStorageAwareness CreateScopedEphemeralStorageAwareness() \ + const; \ bool IsEphemeralCookieAccessAllowed(const GURL& url, \ const GURL& first_party_url) const; \ bool IsEphemeralCookieAccessAllowed( \ @@ -19,7 +39,14 @@ const GURL& first_party_url) const; \ bool IsChromiumCookieAccessAllowed( \ const GURL& url, const GURL& site_for_cookies, \ - const base::Optional& top_frame_origin) const; + const base::Optional& top_frame_origin) const; \ + \ + private: \ + bool IsCookieAccessAllowedImpl( \ + const GURL& url, const GURL& site_for_cookies, \ + const base::Optional& top_frame_origin) const; \ + \ + mutable bool ephemeral_storage_aware_ = false; #include "../../../../../../components/content_settings/core/common/cookie_settings_base.h" diff --git a/chromium_src/net/cookies/cookie_access_delegate.cc b/chromium_src/net/cookies/cookie_access_delegate.cc new file mode 100644 index 000000000000..003f675d5ae8 --- /dev/null +++ b/chromium_src/net/cookies/cookie_access_delegate.cc @@ -0,0 +1,26 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ + +#include "net/cookies/cookie_access_delegate.h" + +#include "base/notreached.h" + +#include "../../../../net/cookies/cookie_access_delegate.cc" + +namespace net { + +bool CookieAccessDelegate::NotUsed() const { + return false; +} + +bool CookieAccessDelegate::ShouldUseEphemeralStorage( + const GURL& url, + const net::SiteForCookies& site_for_cookies, + const base::Optional& top_frame_origin) const { + NOTREACHED() << "Should be overridden"; + return false; +} + +} // namespace net diff --git a/chromium_src/net/cookies/cookie_access_delegate.h b/chromium_src/net/cookies/cookie_access_delegate.h new file mode 100644 index 000000000000..a862fa7f433a --- /dev/null +++ b/chromium_src/net/cookies/cookie_access_delegate.h @@ -0,0 +1,25 @@ +/* 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ +#define BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ + +#include "base/optional.h" +#include "net/cookies/site_for_cookies.h" +#include "url/gurl.h" +#include "url/origin.h" + +#define ShouldTreatUrlAsTrustworthy \ + NotUsed() const; \ + virtual bool ShouldUseEphemeralStorage( \ + const GURL& url, const net::SiteForCookies& site_for_cookies, \ + const base::Optional& top_frame_origin) const; \ + virtual bool ShouldTreatUrlAsTrustworthy + +#include "../../../../net/cookies/cookie_access_delegate.h" + +#undef ShouldTreatUrlAsTrustworthy + +#endif // BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_ACCESS_DELEGATE_H_ diff --git a/chromium_src/net/cookies/cookie_monster.cc b/chromium_src/net/cookies/cookie_monster.cc index e0f488585dd2..f65a9c911b63 100644 --- a/chromium_src/net/cookies/cookie_monster.cc +++ b/chromium_src/net/cookies/cookie_monster.cc @@ -94,27 +94,55 @@ void CookieMonster::SetCookieableSchemes( ChromiumCookieMonster::SetCookieableSchemes(schemes, std::move(callback)); } -void CookieMonster::GetEphemeralCookieListWithOptionsAsync( - const GURL& url, - const GURL& top_frame_url, - const CookieOptions& options, - GetCookieListCallback callback) { - ChromiumCookieMonster* ephemeral_monster = - GetOrCreateEphemeralCookieStoreForTopFrameURL(top_frame_url); - ephemeral_monster->GetCookieListWithOptionsAsync(url, options, - std::move(callback)); -} - -void CookieMonster::SetEphemeralCanonicalCookieAsync( +void CookieMonster::SetCanonicalCookieAsync( std::unique_ptr cookie, const GURL& source_url, - const GURL& top_frame_url, const CookieOptions& options, SetCookiesCallback callback) { - ChromiumCookieMonster* ephemeral_monster = - GetOrCreateEphemeralCookieStoreForTopFrameURL(top_frame_url); - ephemeral_monster->SetCanonicalCookieAsync(std::move(cookie), source_url, - options, std::move(callback)); + if (options.should_use_ephemeral_storage()) { + if (!options.top_frame_origin()) { + // Shouldn't happen, but don't do anything in this case. + NOTREACHED(); + MaybeRunCookieCallback( + std::move(callback), + CookieAccessResult(CookieInclusionStatus( + CookieInclusionStatus::EXCLUDE_UNKNOWN_ERROR))); + return; + } + ChromiumCookieMonster* ephemeral_monster = + GetOrCreateEphemeralCookieStoreForTopFrameURL( + options.top_frame_origin()->GetURL()); + ephemeral_monster->SetCanonicalCookieAsync(std::move(cookie), source_url, + options, std::move(callback)); + return; + } + + ChromiumCookieMonster::SetCanonicalCookieAsync(std::move(cookie), source_url, + options, std::move(callback)); +} + +void CookieMonster::GetCookieListWithOptionsAsync( + const GURL& url, + const CookieOptions& options, + GetCookieListCallback callback) { + if (options.should_use_ephemeral_storage()) { + if (!options.top_frame_origin()) { + // Shouldn't happen, but don't do anything in this case. + NOTREACHED(); + MaybeRunCookieCallback(std::move(callback), CookieAccessResultList(), + CookieAccessResultList()); + return; + } + ChromiumCookieMonster* ephemeral_monster = + GetOrCreateEphemeralCookieStoreForTopFrameURL( + options.top_frame_origin()->GetURL()); + ephemeral_monster->GetCookieListWithOptionsAsync(url, options, + std::move(callback)); + return; + } + + ChromiumCookieMonster::GetCookieListWithOptionsAsync(url, options, + std::move(callback)); } } // namespace net diff --git a/chromium_src/net/cookies/cookie_monster.h b/chromium_src/net/cookies/cookie_monster.h index 5cd16ae44b79..cfcf70807178 100644 --- a/chromium_src/net/cookies/cookie_monster.h +++ b/chromium_src/net/cookies/cookie_monster.h @@ -37,15 +37,13 @@ class NET_EXPORT CookieMonster : public ChromiumCookieMonster { void SetCookieableSchemes(const std::vector& schemes, SetCookieableSchemesCallback callback) override; - void GetEphemeralCookieListWithOptionsAsync(const GURL& url, - const GURL& top_frame_url, - const CookieOptions& options, - GetCookieListCallback callback); - void SetEphemeralCanonicalCookieAsync(std::unique_ptr cookie, - const GURL& source_url, - const GURL& top_frame_url, - const CookieOptions& options, - SetCookiesCallback callback); + void SetCanonicalCookieAsync(std::unique_ptr cookie, + const GURL& source_url, + const CookieOptions& options, + SetCookiesCallback callback) override; + void GetCookieListWithOptionsAsync(const GURL& url, + const CookieOptions& options, + GetCookieListCallback callback) override; private: NetLogWithSource net_log_; diff --git a/chromium_src/net/cookies/cookie_options.cc b/chromium_src/net/cookies/cookie_options.cc new file mode 100644 index 000000000000..de682998737a --- /dev/null +++ b/chromium_src/net/cookies/cookie_options.cc @@ -0,0 +1,47 @@ +/* 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 https://mozilla.org/MPL/2.0/. */ + +#include "net/cookies/cookie_options.h" + +#include "net/cookies/cookie_access_delegate.h" + +#define CookieOptions CookieOptions_ChromiumImpl +#include "../../../../net/cookies/cookie_options.cc" +#undef CookieOptions + +namespace net { + +CookieOptions::CookieOptions() = default; +CookieOptions::CookieOptions(const CookieOptions&) = default; +CookieOptions::CookieOptions(CookieOptions&&) = default; +CookieOptions::~CookieOptions() = default; +CookieOptions& CookieOptions::operator=(const CookieOptions&) = default; +CookieOptions& CookieOptions::operator=(CookieOptions&&) = default; + +CookieOptions::CookieOptions(const CookieOptions_ChromiumImpl& rhs) + : CookieOptions_ChromiumImpl(rhs) {} +CookieOptions::CookieOptions(CookieOptions_ChromiumImpl&& rhs) + : CookieOptions_ChromiumImpl(std::move(rhs)) {} + +void FillEphemeralStorageParams( + const GURL& url, + const SiteForCookies& site_for_cookies, + const base::Optional& top_frame_origin, + const CookieAccessDelegate* cookie_access_delegate, + CookieOptions* cookie_options) { + DCHECK(cookie_options); + if (!cookie_access_delegate) { + return; + } + cookie_options->set_should_use_ephemeral_storage( + cookie_access_delegate->ShouldUseEphemeralStorage(url, site_for_cookies, + top_frame_origin)); + if (cookie_options->should_use_ephemeral_storage()) { + cookie_options->set_site_for_cookies(site_for_cookies); + cookie_options->set_top_frame_origin(top_frame_origin); + } +} + +} // namespace net diff --git a/chromium_src/net/cookies/cookie_options.h b/chromium_src/net/cookies/cookie_options.h new file mode 100644 index 000000000000..6021e6144c72 --- /dev/null +++ b/chromium_src/net/cookies/cookie_options.h @@ -0,0 +1,73 @@ +/* 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_OPTIONS_H_ +#define BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_OPTIONS_H_ + +#include "base/optional.h" +#include "net/cookies/site_for_cookies.h" +#include "url/gurl.h" +#include "url/origin.h" + +#define CookieOptions CookieOptions_ChromiumImpl +#include "../../../../net/cookies/cookie_options.h" +#undef CookieOptions + +namespace net { + +class CookieAccessDelegate; + +class NET_EXPORT CookieOptions : public CookieOptions_ChromiumImpl { + public: + CookieOptions(); + CookieOptions(const CookieOptions&); + CookieOptions(CookieOptions&&); + ~CookieOptions(); + + CookieOptions& operator=(const CookieOptions&); + CookieOptions& operator=(CookieOptions&&); + + CookieOptions(const CookieOptions_ChromiumImpl&); // NOLINT + CookieOptions(CookieOptions_ChromiumImpl&&); // NOLINT + + const net::SiteForCookies& site_for_cookies() const { + return site_for_cookies_; + } + void set_site_for_cookies(const net::SiteForCookies& site_for_cookies) { + site_for_cookies_ = site_for_cookies; + } + + const base::Optional& top_frame_origin() const { + return top_frame_origin_; + } + void set_top_frame_origin( + const base::Optional& top_frame_origin) { + top_frame_origin_ = top_frame_origin; + } + + bool should_use_ephemeral_storage() const { + return should_use_ephemeral_storage_; + } + void set_should_use_ephemeral_storage(bool should_use_ephemeral_storage) { + should_use_ephemeral_storage_ = should_use_ephemeral_storage; + } + + private: + net::SiteForCookies site_for_cookies_; + base::Optional top_frame_origin_; + bool should_use_ephemeral_storage_ = false; +}; + +// Fills ephemeral storage-specific parameters. +void NET_EXPORT +FillEphemeralStorageParams(const GURL& url, + const SiteForCookies& site_for_cookies, + const base::Optional& top_frame_origin, + const CookieAccessDelegate* cookie_access_delegate, + CookieOptions* cookie_options); + +} // namespace net + +#endif // BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_OPTIONS_H_ diff --git a/chromium_src/net/url_request/url_request_http_job.cc b/chromium_src/net/url_request/url_request_http_job.cc new file mode 100644 index 000000000000..453f87bab509 --- /dev/null +++ b/chromium_src/net/url_request/url_request_http_job.cc @@ -0,0 +1,28 @@ +/* Copyright 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 "net/url_request/url_request_http_job.h" + +#include "../../../../net/url_request/url_request_http_job.cc" + +namespace net { + +CookieOptions URLRequestHttpJob::CreateCookieOptions( + CookieOptions::SameSiteCookieContext same_site_context, + CookieOptions::SamePartyCookieContextType same_party_context, + const IsolationInfo& isolation_info, + bool is_in_nontrivial_first_party_set) const { + CookieOptions cookie_options = + ::CreateCookieOptions(same_site_context, same_party_context, + isolation_info, is_in_nontrivial_first_party_set); + FillEphemeralStorageParams( + request_->url(), request_->site_for_cookies(), + isolation_info.top_frame_origin(), + request_->context()->cookie_store()->cookie_access_delegate(), + &cookie_options); + return cookie_options; +} + +} // namespace net diff --git a/chromium_src/net/url_request/url_request_http_job.h b/chromium_src/net/url_request/url_request_http_job.h new file mode 100644 index 000000000000..1d9d6ab85106 --- /dev/null +++ b/chromium_src/net/url_request/url_request_http_job.h @@ -0,0 +1,26 @@ +/* Copyright 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ +#define BRAVE_CHROMIUM_SRC_NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ + +#include "net/base/isolation_info.h" +#include "net/base/request_priority.h" +#include "net/cookies/cookie_options.h" + +#define NotifyBeforeStartTransactionCallback \ + NotUsed() const {} \ + CookieOptions CreateCookieOptions( \ + CookieOptions::SameSiteCookieContext same_site_context, \ + CookieOptions::SamePartyCookieContextType same_party_context, \ + const IsolationInfo& isolation_info, \ + bool is_in_nontrivial_first_party_set) const; \ + void NotifyBeforeStartTransactionCallback + +#include "../../../../net/url_request/url_request_http_job.h" + +#undef NotifyBeforeStartTransactionCallback + +#endif // BRAVE_CHROMIUM_SRC_NET_URL_REQUEST_URL_REQUEST_HTTP_JOB_H_ diff --git a/chromium_src/services/network/cookie_access_delegate_impl.cc b/chromium_src/services/network/cookie_access_delegate_impl.cc new file mode 100644 index 000000000000..3653e58e4a3f --- /dev/null +++ b/chromium_src/services/network/cookie_access_delegate_impl.cc @@ -0,0 +1,26 @@ +/* Copyright 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 "services/network/cookie_access_delegate_impl.h" + +#include "../../../../services/network/cookie_access_delegate_impl.cc" + +namespace network { + +bool CookieAccessDelegateImpl::NotUsed() const { + return false; +} + +bool CookieAccessDelegateImpl::ShouldUseEphemeralStorage( + const GURL& url, + const net::SiteForCookies& site_for_cookies, + const base::Optional& top_frame_origin) const { + if (!cookie_settings_) + return false; + return cookie_settings_->ShouldUseEphemeralStorage( + url, site_for_cookies.RepresentativeUrl(), top_frame_origin); +} + +} // namespace network diff --git a/chromium_src/services/network/cookie_access_delegate_impl.h b/chromium_src/services/network/cookie_access_delegate_impl.h new file mode 100644 index 000000000000..d453551efdfb --- /dev/null +++ b/chromium_src/services/network/cookie_access_delegate_impl.h @@ -0,0 +1,22 @@ +/* Copyright 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_COOKIE_ACCESS_DELEGATE_IMPL_H_ +#define BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_COOKIE_ACCESS_DELEGATE_IMPL_H_ + +#include "net/cookies/cookie_access_delegate.h" + +#define ShouldTreatUrlAsTrustworthy \ + NotUsed() const override; \ + bool ShouldUseEphemeralStorage( \ + const GURL& url, const net::SiteForCookies& site_for_cookies, \ + const base::Optional& top_frame_origin) const override; \ + bool ShouldTreatUrlAsTrustworthy + +#include "../../../../services/network/cookie_access_delegate_impl.h" + +#undef ShouldTreatUrlAsTrustworthy + +#endif // BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_COOKIE_ACCESS_DELEGATE_IMPL_H_ diff --git a/chromium_src/services/network/network_service_network_delegate.cc b/chromium_src/services/network/network_service_network_delegate.cc new file mode 100644 index 000000000000..4cdfe2318ab0 --- /dev/null +++ b/chromium_src/services/network/network_service_network_delegate.cc @@ -0,0 +1,43 @@ +/* Copyright 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 "services/network/network_service_network_delegate.h" + +#define OnCanGetCookies OnCanGetCookies_ChromiumImpl +#define OnCanSetCookie OnCanSetCookie_ChromiumImpl + +#include "../../../../services/network/network_service_network_delegate.cc" + +#undef OnCanSetCookie +#undef OnCanGetCookies + +namespace network { + +bool NetworkServiceNetworkDelegate::OnCanGetCookies( + const net::URLRequest& request, + bool allowed_from_caller) { + // Enable ephemeral storage support for the call. + auto scoped_ephemeral_storage_awareness = + network_context_->cookie_manager() + ->cookie_settings() + .CreateScopedEphemeralStorageAwareness(); + return OnCanGetCookies_ChromiumImpl(request, allowed_from_caller); +} + +bool NetworkServiceNetworkDelegate::OnCanSetCookie( + const net::URLRequest& request, + const net::CanonicalCookie& cookie, + net::CookieOptions* options, + bool allowed_from_caller) { + // Enable ephemeral storage support for the call. + auto scoped_ephemeral_storage_awareness = + network_context_->cookie_manager() + ->cookie_settings() + .CreateScopedEphemeralStorageAwareness(); + return OnCanSetCookie_ChromiumImpl(request, cookie, options, + allowed_from_caller); +} + +} // namespace network diff --git a/chromium_src/services/network/network_service_network_delegate.h b/chromium_src/services/network/network_service_network_delegate.h new file mode 100644 index 000000000000..200f71ea081d --- /dev/null +++ b/chromium_src/services/network/network_service_network_delegate.h @@ -0,0 +1,22 @@ +/* Copyright 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_NETWORK_SERVICE_NETWORK_DELEGATE_H_ +#define BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_NETWORK_SERVICE_NETWORK_DELEGATE_H_ + +#define FinishedCanSendReportingReports \ + NotUsed() {} \ + bool OnCanGetCookies_ChromiumImpl(const net::URLRequest& request, \ + bool allowed_from_caller); \ + bool OnCanSetCookie_ChromiumImpl( \ + const net::URLRequest& request, const net::CanonicalCookie& cookie, \ + net::CookieOptions* options, bool allowed_from_caller); \ + void FinishedCanSendReportingReports + +#include "../../../../services/network/network_service_network_delegate.h" + +#undef FinishedCanSendReportingReports + +#endif // BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_NETWORK_SERVICE_NETWORK_DELEGATE_H_ diff --git a/chromium_src/services/network/public/cpp/DEPS b/chromium_src/services/network/public/cpp/DEPS new file mode 100644 index 000000000000..99f7ad41a90f --- /dev/null +++ b/chromium_src/services/network/public/cpp/DEPS @@ -0,0 +1,6 @@ +include_rules = [ + "+../../../../../../services/network", + "+../../../../../components/content_settings/browser", + "+components/content_settings/browser", + "+services/network", +] diff --git a/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.cc b/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.cc new file mode 100644 index 000000000000..2db85e7116d0 --- /dev/null +++ b/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.cc @@ -0,0 +1,40 @@ +/* Copyright (c) 2020 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 "services/network/public/cpp/cookie_manager_mojom_traits.h" + +#include "services/network/public/mojom/cookie_manager.mojom.h" + +#define CookieOptions CookieOptions_ChromiumImpl + +#include "../../../../../../services/network/public/cpp/cookie_manager_mojom_traits.cc" + +#undef CookieOptions + +namespace mojo { + +bool StructTraits:: + Read(network::mojom::CookieOptionsDataView data, net::CookieOptions* out) { + if (!StructTraits::Read(data, out)) { + return false; + } + + net::SiteForCookies site_for_cookies; + if (!data.ReadSiteForCookies(&site_for_cookies)) + return false; + out->set_site_for_cookies(site_for_cookies); + + base::Optional top_frame_origin; + if (!data.ReadTopFrameOrigin(&top_frame_origin)) + return false; + out->set_top_frame_origin(top_frame_origin); + + out->set_should_use_ephemeral_storage(data.should_use_ephemeral_storage()); + + return true; +} + +} // namespace mojo diff --git a/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.h b/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.h new file mode 100644 index 000000000000..d8d06ca0590d --- /dev/null +++ b/chromium_src/services/network/public/cpp/cookie_manager_mojom_traits.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2020 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_PUBLIC_CPP_COOKIE_MANAGER_MOJOM_TRAITS_H_ +#define BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_PUBLIC_CPP_COOKIE_MANAGER_MOJOM_TRAITS_H_ + +#include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_access_result.h" +#include "net/cookies/cookie_change_dispatcher.h" +#include "net/cookies/cookie_options.h" +#include "services/network/public/mojom/cookie_manager.mojom.h" + +#define CookieOptions CookieOptions_ChromiumImpl + +#include "../../../../../../services/network/public/cpp/cookie_manager_mojom_traits.h" + +#undef CookieOptions + +namespace mojo { + +template <> +struct StructTraits + : public StructTraits { + static const net::SiteForCookies& site_for_cookies( + const net::CookieOptions& o) { + return o.site_for_cookies(); + } + static const base::Optional& top_frame_origin( + const net::CookieOptions& o) { + return o.top_frame_origin(); + } + static bool should_use_ephemeral_storage(const net::CookieOptions& o) { + return o.should_use_ephemeral_storage(); + } + + static bool Read(network::mojom::CookieOptionsDataView mojo_options, + net::CookieOptions* cookie_options); +}; + +} // namespace mojo + +#endif // BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_PUBLIC_CPP_COOKIE_MANAGER_MOJOM_TRAITS_H_ diff --git a/chromium_src/services/network/public/mojom/cookie_manager.mojom b/chromium_src/services/network/public/mojom/cookie_manager.mojom index a38c177fc884..1e65657d3edb 100644 --- a/chromium_src/services/network/public/mojom/cookie_manager.mojom +++ b/chromium_src/services/network/public/mojom/cookie_manager.mojom @@ -5,7 +5,17 @@ module network.mojom; +import "services/network/public/mojom/site_for_cookies.mojom"; +import "url/mojom/origin.mojom"; + [BraveExtend] struct CookieDeletionFilter { string? ephemeral_storage_domain; }; + +[BraveExtend] +struct CookieOptions { + SiteForCookies site_for_cookies; + url.mojom.Origin? top_frame_origin; + bool should_use_ephemeral_storage = false; +}; diff --git a/chromium_src/services/network/restricted_cookie_manager.cc b/chromium_src/services/network/restricted_cookie_manager.cc index 3442732c3fe4..ee8f6f90ccee 100644 --- a/chromium_src/services/network/restricted_cookie_manager.cc +++ b/chromium_src/services/network/restricted_cookie_manager.cc @@ -14,47 +14,40 @@ #include "url/gurl.h" #include "url/origin.h" -namespace { +#define IsCookieAccessAllowed IsEphemeralCookieAccessAllowed +#include "../../../../services/network/restricted_cookie_manager.cc" +#undef IsCookieAccessAllowed -bool ShouldUseEphemeralStorage( +namespace network { + +net::CookieOptions RestrictedCookieManager::MakeOptionsForSet( + mojom::RestrictedCookieManagerRole role, const GURL& url, - const url::Origin& top_frame_origin, const net::SiteForCookies& site_for_cookies, - const network::CookieSettings* const cookie_settings) { - return cookie_settings->ShouldUseEphemeralStorage( - url, site_for_cookies.RepresentativeUrl(), top_frame_origin); + const net::IsolationInfo& isolation_info, + const CookieSettings* cookie_settings, + const net::CookieAccessDelegate* cookie_access_delegate) const { + net::CookieOptions cookie_options = + ::network::MakeOptionsForSet(role, url, site_for_cookies, isolation_info, + cookie_settings, cookie_access_delegate); + net::FillEphemeralStorageParams(url, site_for_cookies, BoundTopFrameOrigin(), + cookie_access_delegate, &cookie_options); + return cookie_options; } -} // namespace - -#define BRAVE_GETALLFORURL \ - if (ShouldUseEphemeralStorage(url, top_frame_origin, site_for_cookies, \ - cookie_settings_)) { \ - static_cast(cookie_store_) \ - ->GetEphemeralCookieListWithOptionsAsync( \ - url, top_frame_origin.GetURL(), net_options, \ - base::BindOnce( \ - &RestrictedCookieManager::CookieListToGetAllForUrlCallback, \ - weak_ptr_factory_.GetWeakPtr(), url, site_for_cookies, \ - top_frame_origin, net_options, std::move(options), \ - std::move(callback))); \ - return; \ - } - -#define BRAVE_SETCANONICALCOOKIE \ - if (ShouldUseEphemeralStorage(url, top_frame_origin, site_for_cookies, \ - cookie_settings_)) { \ - static_cast(cookie_store_) \ - ->SetEphemeralCanonicalCookieAsync( \ - std::move(sanitized_cookie), origin_.GetURL(), \ - top_frame_origin.GetURL(), options, \ - base::BindOnce(&RestrictedCookieManager::SetCanonicalCookieResult, \ - weak_ptr_factory_.GetWeakPtr(), url, \ - site_for_cookies, cookie_copy, options, \ - std::move(callback))); \ - return; \ - } +net::CookieOptions RestrictedCookieManager::MakeOptionsForGet( + mojom::RestrictedCookieManagerRole role, + const GURL& url, + const net::SiteForCookies& site_for_cookies, + const net::IsolationInfo& isolation_info, + const CookieSettings* cookie_settings, + const net::CookieAccessDelegate* cookie_access_delegate) const { + net::CookieOptions cookie_options = + ::network::MakeOptionsForGet(role, url, site_for_cookies, isolation_info, + cookie_settings, cookie_access_delegate); + net::FillEphemeralStorageParams(url, site_for_cookies, BoundTopFrameOrigin(), + cookie_access_delegate, &cookie_options); + return cookie_options; +} -#define IsCookieAccessAllowed IsEphemeralCookieAccessAllowed -#include "../../../../services/network/restricted_cookie_manager.cc" -#undef IsCookieAccessAllowed +} // namespace network diff --git a/chromium_src/services/network/restricted_cookie_manager.h b/chromium_src/services/network/restricted_cookie_manager.h new file mode 100644 index 000000000000..1b1e5b44f8de --- /dev/null +++ b/chromium_src/services/network/restricted_cookie_manager.h @@ -0,0 +1,35 @@ +/* Copyright 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/. */ + +#ifndef BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_RESTRICTED_COOKIE_MANAGER_H_ +#define BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_RESTRICTED_COOKIE_MANAGER_H_ + +#include "net/base/isolation_info.h" +#include "net/cookies/cookie_access_delegate.h" +#include "net/cookies/cookie_options.h" +#include "net/cookies/site_for_cookies.h" +#include "services/network/public/mojom/restricted_cookie_manager.mojom.h" + +#define RemoveChangeListener \ + NotUsed() const {} \ + net::CookieOptions MakeOptionsForSet( \ + mojom::RestrictedCookieManagerRole role, const GURL& url, \ + const net::SiteForCookies& site_for_cookies, \ + const net::IsolationInfo& isolation_info, \ + const CookieSettings* cookie_settings, \ + const net::CookieAccessDelegate* cookie_access_delegate) const; \ + net::CookieOptions MakeOptionsForGet( \ + mojom::RestrictedCookieManagerRole role, const GURL& url, \ + const net::SiteForCookies& site_for_cookies, \ + const net::IsolationInfo& isolation_info, \ + const CookieSettings* cookie_settings, \ + const net::CookieAccessDelegate* cookie_access_delegate) const; \ + void RemoveChangeListener + +#include "../../../../services/network/restricted_cookie_manager.h" + +#undef RemoveChangeListener + +#endif // BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_RESTRICTED_COOKIE_MANAGER_H_ diff --git a/components/content_settings/renderer/brave_content_settings_agent_impl.cc b/components/content_settings/renderer/brave_content_settings_agent_impl.cc index 4941703da83a..cf9d2975e2dc 100644 --- a/components/content_settings/renderer/brave_content_settings_agent_impl.cc +++ b/components/content_settings/renderer/brave_content_settings_agent_impl.cc @@ -147,16 +147,25 @@ bool BraveContentSettingsAgentImpl::UseEphemeralStorageSync( if (!frame || IsFrameWithOpaqueOrigin(frame)) return false; + auto frame_origin = url::Origin(frame->GetSecurityOrigin()); + StoragePermissionsKey key(frame_origin, storage_type); + const auto permissions = cached_storage_permissions_.find(key); + if (permissions != cached_storage_permissions_.end()) + return permissions->second; + auto top_origin = url::Origin(frame->Top()->GetSecurityOrigin()); if (net::registry_controlled_domains::SameDomainOrHost( - top_origin, url::Origin(frame->GetSecurityOrigin()), + top_origin, frame_origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) return false; - return // block 3p - !ContentSettingsAgentImpl::AllowStorageAccessSync(storage_type) && - // allow 1p - AllowStorageAccessForMainFrameSync(storage_type); + bool result = false; + GetContentSettingsManager().AllowEphemeralStorageAccess( + routing_id(), ConvertToMojoStorageType(storage_type), frame_origin, + frame->GetDocument().SiteForCookies().RepresentativeUrl(), top_origin, + &result); + cached_storage_permissions_[key] = result; + return result; } bool BraveContentSettingsAgentImpl::AllowStorageAccessSync( @@ -169,32 +178,6 @@ bool BraveContentSettingsAgentImpl::AllowStorageAccessSync( return false; } -bool BraveContentSettingsAgentImpl::AllowStorageAccessForMainFrameSync( - StorageType storage_type) { - blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); - - if (IsFrameWithOpaqueOrigin(frame)) - return false; - - bool result = false; - - StoragePermissionsKey key(url::Origin(frame->GetSecurityOrigin()), - storage_type); - const auto permissions = cached_storage_permissions_.find(key); - if (permissions != cached_storage_permissions_.end()) - return permissions->second; - - // check for block all by looking at top domain only - GetContentSettingsManager().AllowStorageAccess( - routing_id(), ConvertToMojoStorageType(storage_type), - frame->GetDocument().TopFrameOrigin(), - url::Origin(frame->GetDocument().TopFrameOrigin()).GetURL(), - frame->GetDocument().TopFrameOrigin(), &result); - cached_storage_permissions_[key] = result; - - return result; -} - bool BraveContentSettingsAgentImpl::AllowScriptFromSource( bool enabled_per_settings, const blink::WebURL& script_url) { diff --git a/components/content_settings/renderer/brave_content_settings_agent_impl.h b/components/content_settings/renderer/brave_content_settings_agent_impl.h index a5a1c42f91bc..ccdc7620c1d7 100644 --- a/components/content_settings/renderer/brave_content_settings_agent_impl.h +++ b/components/content_settings/renderer/brave_content_settings_agent_impl.h @@ -71,7 +71,6 @@ class BraveContentSettingsAgentImpl void DidCommitProvisionalLoad(ui::PageTransition transition) override; bool IsScriptTemporilyAllowed(const GURL& script_url); - bool AllowStorageAccessForMainFrameSync(StorageType storage_type); // brave_shields::mojom::BraveShields. void SetAllowScriptsFromOriginsOnce( diff --git a/components/content_settings/renderer/brave_content_settings_agent_impl_autoplay_browsertest.cc b/components/content_settings/renderer/brave_content_settings_agent_impl_autoplay_browsertest.cc index cffc6af71198..710379840d18 100644 --- a/components/content_settings/renderer/brave_content_settings_agent_impl_autoplay_browsertest.cc +++ b/components/content_settings/renderer/brave_content_settings_agent_impl_autoplay_browsertest.cc @@ -40,6 +40,14 @@ class MockContentSettingsManagerImpl : public mojom::ContentSettingsManager { const url::Origin& top_frame_origin, base::OnceCallback callback) override {} + void AllowEphemeralStorageAccess( + int32_t render_frame_id, + ContentSettingsManager::StorageType storage_type, + const ::url::Origin& origin, + const ::GURL& site_for_cookies, + const ::url::Origin& top_frame_origin, + AllowEphemeralStorageAccessCallback callback) override {} + void OnContentBlocked(int32_t render_frame_id, ContentSettingsType type) override { ++log_->on_content_blocked_count; diff --git a/patches/services-network-restricted_cookie_manager.cc.patch b/patches/services-network-restricted_cookie_manager.cc.patch deleted file mode 100644 index 9a23e79f9757..000000000000 --- a/patches/services-network-restricted_cookie_manager.cc.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/services/network/restricted_cookie_manager.cc b/services/network/restricted_cookie_manager.cc -index eb72668601ad388d98dfc21020557af6a18051f4..18f068cfd1c55a9c4e3f5f07282e0fde1316c79d 100644 ---- a/services/network/restricted_cookie_manager.cc -+++ b/services/network/restricted_cookie_manager.cc -@@ -286,6 +286,7 @@ void RestrictedCookieManager::GetAllForUrl( - // removing deprecation warnings. - net_options.set_return_excluded_cookies(); - -+ BRAVE_GETALLFORURL - cookie_store_->GetCookieListWithOptionsAsync( - url, net_options, - base::BindOnce(&RestrictedCookieManager::CookieListToGetAllForUrlCallback, -@@ -437,6 +438,7 @@ void RestrictedCookieManager::SetCanonicalCookie( - role_, url, site_for_cookies, isolation_info_, cookie_settings(), - cookie_store_->cookie_access_delegate()); - -+ BRAVE_SETCANONICALCOOKIE - cookie_store_->SetCanonicalCookieAsync( - std::move(sanitized_cookie), origin_url, options, - base::BindOnce(&RestrictedCookieManager::SetCanonicalCookieResult,