diff --git a/chromium_src/content/browser/devtools/protocol/DEPS b/chromium_src/content/browser/devtools/protocol/DEPS new file mode 100644 index 000000000000..0789dae23999 --- /dev/null +++ b/chromium_src/content/browser/devtools/protocol/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+../../../../../../content/browser/devtools/protocol", + "+content/browser/devtools/protocol", +] diff --git a/chromium_src/content/browser/devtools/protocol/network_handler.cc b/chromium_src/content/browser/devtools/protocol/network_handler.cc new file mode 100644 index 000000000000..c720aaa714d9 --- /dev/null +++ b/chromium_src/content/browser/devtools/protocol/network_handler.cc @@ -0,0 +1,28 @@ +/* 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 "content/browser/devtools/protocol/network_handler.h" + +#define BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_ARGS \ + const url::Origin &top_frame_origin, + +#define BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_BODY \ + cookie_options.set_top_frame_origin(top_frame_origin); + +#define BRAVE_NETWORK_HANDLER_GET_COOKIES_RETREIVE_CALL_ARGS \ + host_->ComputeTopFrameOrigin(host_->GetLastCommittedOrigin()), + +#define BRAVE_NETWORK_HANDLER_SET_COOKIES_SET_COOKIE_OPTIONS \ + options.set_top_frame_origin( \ + host_ ? base::make_optional(host_->ComputeTopFrameOrigin( \ + host_->GetLastCommittedOrigin())) \ + : base::nullopt); + +#include "../../../../../../content/browser/devtools/protocol/network_handler.cc" + +#undef BRAVE_NETWORK_HANDLER_SET_COOKIES_SET_COOKIE_OPTIONS +#undef BRAVE_NETWORK_HANDLER_GET_COOKIES_RETREIVE_CALL_ARGS +#undef BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_BODY +#undef BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_ARGS diff --git a/chromium_src/net/cookies/cookie_monster.cc b/chromium_src/net/cookies/cookie_monster.cc index 45727a5c6080..b6ef02cdfbc2 100644 --- a/chromium_src/net/cookies/cookie_monster.cc +++ b/chromium_src/net/cookies/cookie_monster.cc @@ -101,7 +101,12 @@ void CookieMonster::SetCanonicalCookieAsync( SetCookiesCallback 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 = @@ -121,7 +126,10 @@ void CookieMonster::GetCookieListWithOptionsAsync( 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 = diff --git a/chromium_src/services/network/cookie_manager.cc b/chromium_src/services/network/cookie_manager.cc index b445b9f1b7e9..700d3ddc9eb0 100644 --- a/chromium_src/services/network/cookie_manager.cc +++ b/chromium_src/services/network/cookie_manager.cc @@ -3,10 +3,58 @@ * 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_manager.h" #include "services/network/restricted_cookie_manager.h" #define BRAVE_DELETIONFILTERTOINFO \ delete_info.ephemeral_storage_domain = \ std::move(filter->ephemeral_storage_domain); +#define GetCookieList GetCookieList_ChromiumImpl +#define SetCanonicalCookie SetCanonicalCookie_ChromiumImpl + #include "../../../../services/network/cookie_manager.cc" + +#undef GetCookieList +#undef SetCanonicalCookie + +namespace network { + +void CookieManager::GetCookieList(const GURL& url, + const net::CookieOptions& cookie_options, + GetCookieListCallback callback) { + if (!cookie_options.should_use_ephemeral_storage() && + cookie_settings_.ShouldUseEphemeralStorage( + url, cookie_options.site_for_cookies().RepresentativeUrl(), + cookie_options.top_frame_origin())) { + auto ephemeral_cookie_options = cookie_options; + ephemeral_cookie_options.set_should_use_ephemeral_storage(true); + cookie_store_->GetCookieListWithOptionsAsync(url, ephemeral_cookie_options, + std::move(callback)); + return; + } + + GetCookieList_ChromiumImpl(url, cookie_options, std::move(callback)); +} + +void CookieManager::SetCanonicalCookie(const net::CanonicalCookie& cookie, + const GURL& source_url, + const net::CookieOptions& cookie_options, + SetCanonicalCookieCallback callback) { + if (!cookie_options.should_use_ephemeral_storage() && + cookie_settings_.ShouldUseEphemeralStorage( + source_url, cookie_options.site_for_cookies().RepresentativeUrl(), + cookie_options.top_frame_origin())) { + auto ephemeral_cookie_options = cookie_options; + ephemeral_cookie_options.set_should_use_ephemeral_storage(true); + cookie_store_->SetCanonicalCookieAsync( + std::make_unique(cookie), source_url, + ephemeral_cookie_options, std::move(callback)); + return; + } + + SetCanonicalCookie_ChromiumImpl(cookie, source_url, cookie_options, + std::move(callback)); +} + +} // namespace network diff --git a/chromium_src/services/network/cookie_manager.h b/chromium_src/services/network/cookie_manager.h new file mode 100644 index 000000000000..aca48d61d99b --- /dev/null +++ b/chromium_src/services/network/cookie_manager.h @@ -0,0 +1,29 @@ +/* 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_MANAGER_H_ +#define BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_COOKIE_MANAGER_H_ + +#include "services/network/public/mojom/cookie_manager.mojom.h" + +#define GetCookieList \ + GetCookieList_ChromiumImpl(const GURL& url, \ + const net::CookieOptions& cookie_options, \ + GetCookieListCallback callback); \ + void GetCookieList + +#define SetCanonicalCookie \ + SetCanonicalCookie_ChromiumImpl(const net::CanonicalCookie& cookie, \ + const GURL& source_url, \ + const net::CookieOptions& cookie_options, \ + SetCanonicalCookieCallback callback); \ + void SetCanonicalCookie + +#include "../../../../services/network/cookie_manager.h" + +#undef SetCanonicalCookie +#undef GetCookieList + +#endif // BRAVE_CHROMIUM_SRC_SERVICES_NETWORK_COOKIE_MANAGER_H_ diff --git a/patches/content-browser-devtools-protocol-network_handler.cc.patch b/patches/content-browser-devtools-protocol-network_handler.cc.patch new file mode 100644 index 000000000000..18a23f97ed54 --- /dev/null +++ b/patches/content-browser-devtools-protocol-network_handler.cc.patch @@ -0,0 +1,41 @@ +diff --git a/content/browser/devtools/protocol/network_handler.cc b/content/browser/devtools/protocol/network_handler.cc +index 33907f5922a626913dc11d0372fba32d10cb10a1..707df85a130f13ca1ebff745125809308fb28d35 100644 +--- a/content/browser/devtools/protocol/network_handler.cc ++++ b/content/browser/devtools/protocol/network_handler.cc +@@ -199,10 +199,12 @@ class CookieRetrieverNetworkService + public: + static void Retrieve(network::mojom::CookieManager* cookie_manager, + const std::vector urls, ++ BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_ARGS + std::unique_ptr callback) { + scoped_refptr self = + new CookieRetrieverNetworkService(std::move(callback)); + net::CookieOptions cookie_options = net::CookieOptions::MakeAllInclusive(); ++ BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_BODY + for (const auto& url : urls) { + cookie_manager->GetCookieList( + url, cookie_options, +@@ -1309,7 +1311,6 @@ void NetworkHandler::ClearBrowserCookies( + callback->sendFailure(Response::InternalError()); + return; + } +- + storage_partition_->GetCookieManagerForBrowserProcess()->DeleteCookies( + network::mojom::CookieDeletionFilter::New(), + base::BindOnce([](std::unique_ptr callback, +@@ -1327,6 +1328,7 @@ void NetworkHandler::GetCookies(Maybe> protocol_urls, + + CookieRetrieverNetworkService::Retrieve( + storage_partition_->GetCookieManagerForBrowserProcess(), urls, ++ BRAVE_NETWORK_HANDLER_GET_COOKIES_RETREIVE_CALL_ARGS + std::move(callback)); + } + +@@ -1383,6 +1385,7 @@ void NetworkHandler::SetCookie(const std::string& name, + options.set_same_site_cookie_context( + net::CookieOptions::SameSiteCookieContext::MakeInclusive()); + options.set_include_httponly(); ++ BRAVE_NETWORK_HANDLER_SET_COOKIES_SET_COOKIE_OPTIONS + storage_partition_->GetCookieManagerForBrowserProcess()->SetCanonicalCookie( + *cookie, net::cookie_util::SimulatedCookieSource(*cookie, "https"), + options,