Skip to content

Commit

Permalink
Add devtools cookies display support.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodov committed May 26, 2021
1 parent 7a40da2 commit a29c0bf
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chromium_src/content/browser/devtools/protocol/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include_rules = [
"+../../../../../../content/browser/devtools/protocol",
"+content/browser/devtools/protocol",
]
28 changes: 28 additions & 0 deletions chromium_src/content/browser/devtools/protocol/network_handler.cc
Original file line number Diff line number Diff line change
@@ -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<url::Origin>(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
8 changes: 8 additions & 0 deletions chromium_src/net/cookies/cookie_monster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
48 changes: 48 additions & 0 deletions chromium_src/services/network/cookie_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<net::CanonicalCookie>(cookie), source_url,
ephemeral_cookie_options, std::move(callback));
return;
}

SetCanonicalCookie_ChromiumImpl(cookie, source_url, cookie_options,
std::move(callback));
}

} // namespace network
29 changes: 29 additions & 0 deletions chromium_src/services/network/cookie_manager.h
Original file line number Diff line number Diff line change
@@ -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_
41 changes: 41 additions & 0 deletions patches/content-browser-devtools-protocol-network_handler.cc.patch
Original file line number Diff line number Diff line change
@@ -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<GURL> urls,
+ BRAVE_COOKIE_RETRIEVER_NETWORK_SERVICE_RETRIEVE_ARGS
std::unique_ptr<GetCookiesCallback> callback) {
scoped_refptr<CookieRetrieverNetworkService> 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<ClearBrowserCookiesCallback> callback,
@@ -1327,6 +1328,7 @@ void NetworkHandler::GetCookies(Maybe<Array<String>> 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,

0 comments on commit a29c0bf

Please sign in to comment.