Skip to content

Commit

Permalink
Fix build for Windows
Browse files Browse the repository at this point in the history
No longer use CookieOptions to pass ephemeral top-frame information.
Instead add a new CookieStore API.
  • Loading branch information
mrobinson committed Dec 8, 2020
1 parent 41b6bff commit 7121219
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 155 deletions.
2 changes: 1 addition & 1 deletion chromium_src/net/cookies/cookie_deletion_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define BRAVE_COOKIE_DELETION_INFO_H \
base::Optional<std::string> ephemeral_storage_domain;

#include "../../../../../net/cookies/cookie_deletion_info.h"
#include "../../../../../../net/cookies/cookie_deletion_info.h"

#undef BRAVE_COOKIE_DELETION_INFO_H

Expand Down
68 changes: 26 additions & 42 deletions chromium_src/net/cookies/cookie_monster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@

namespace net {

namespace {

CookieOptions OptionsWithoutEphemeralStorageURL(const CookieOptions& options) {
CookieOptions new_options(options);
new_options.top_frame_url_ = GURL();
return new_options;
}

} // namespace

CookieMonster::CookieMonster(scoped_refptr<PersistentCookieStore> store,
NetLog* net_log)
: ChromiumCookieMonster(store, net_log),
Expand Down Expand Up @@ -53,40 +43,11 @@ CookieMonster::GetOrCreateEphemeralCookieStoreForTopFrameURL(
.first->second.get();
}

void CookieMonster::SetCanonicalCookieAsync(
std::unique_ptr<CanonicalCookie> cookie,
const GURL& source_url,
const CookieOptions& options,
SetCookiesCallback callback) {
if (!options.top_frame_url_.is_empty()) {
ChromiumCookieMonster* ephemeral_monster =
GetOrCreateEphemeralCookieStoreForTopFrameURL(options.top_frame_url_);
ephemeral_monster->SetCanonicalCookieAsync(
std::move(cookie), source_url,
OptionsWithoutEphemeralStorageURL(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.top_frame_url_.is_empty()) {
ChromiumCookieMonster* ephemeral_monster =
GetOrCreateEphemeralCookieStoreForTopFrameURL(options.top_frame_url_);
ephemeral_monster->GetCookieListWithOptionsAsync(
url, OptionsWithoutEphemeralStorageURL(options), std::move(callback));
return;
}
ChromiumCookieMonster::GetCookieListWithOptionsAsync(url, options,
std::move(callback));
}

void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
DeleteCallback callback) {
for (auto& it : ephemeral_cookie_stores_) {
it.second->DeleteCanonicalCookieAsync(cookie, DeleteCallback());
}
ChromiumCookieMonster::DeleteCanonicalCookieAsync(cookie,
std::move(callback));
}
Expand Down Expand Up @@ -133,4 +94,27 @@ 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(
std::unique_ptr<CanonicalCookie> 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));
}

} // namespace net
19 changes: 11 additions & 8 deletions chromium_src/net/cookies/cookie_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_MONSTER_H_

#define CookieMonster ChromiumCookieMonster
#include "../../../../../net/cookies/cookie_monster.h"
#include "../../../../../../net/cookies/cookie_monster.h"
#undef CookieMonster

namespace net {
Expand All @@ -26,13 +26,6 @@ class NET_EXPORT CookieMonster : public ChromiumCookieMonster {
//
// This only includes methods that needs special behavior to deal with
// our collection of ephemeral monsters.
void SetCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
const GURL& source_url,
const CookieOptions& options,
SetCookiesCallback callback) override;
void GetCookieListWithOptionsAsync(const GURL& url,
const CookieOptions& options,
GetCookieListCallback callback) override;
void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
DeleteCallback callback) override;
void DeleteAllCreatedInTimeRangeAsync(
Expand All @@ -44,6 +37,16 @@ class NET_EXPORT CookieMonster : public ChromiumCookieMonster {
void SetCookieableSchemes(const std::vector<std::string>& schemes,
SetCookieableSchemesCallback callback) override;

void GetEphemeralCookieListWithOptionsAsync(const GURL& url,
const GURL& top_frame_url,
const CookieOptions& options,
GetCookieListCallback callback);
void SetEphemeralCanonicalCookieAsync(std::unique_ptr<CanonicalCookie> cookie,
const GURL& source_url,
const GURL& top_frame_url,
const CookieOptions& options,
SetCookiesCallback callback);

private:
NetLogWithSource net_log_;
std::map<std::string, std::unique_ptr<ChromiumCookieMonster>>
Expand Down
17 changes: 0 additions & 17 deletions chromium_src/net/cookies/cookie_options.h

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 29 additions & 11 deletions chromium_src/services/network/restricted_cookie_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@
#include "services/network/restricted_cookie_manager.h"

#include "net/base/features.h"
#include "net/cookies/cookie_monster.h"

namespace {

void AddEphemeralStorageDomainIfNecessary(const GURL& url,
const url::Origin& top_frame_origin,
net::CookieOptions* options) {
bool ShouldUseEphemeralStorage(const GURL& url,
const url::Origin& top_frame_origin) {
if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage))
return;
return false;
if (url::Origin::Create(url) == top_frame_origin)
return;
options->top_frame_url_ = top_frame_origin.GetURL();
return false;
return true;
}

} // namespace

#define BRAVE_GETALLFORURL \
AddEphemeralStorageDomainIfNecessary(url, top_frame_origin, &net_options);

#define BRAVE_SETCANONICALCOOKIE \
AddEphemeralStorageDomainIfNecessary(url, top_frame_origin, &options);
#define BRAVE_GETALLFORURL \
if (ShouldUseEphemeralStorage(url, top_frame_origin)) { \
static_cast<net::CookieMonster*>(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))); \
} else // NOLINT

#define BRAVE_SETCANONICALCOOKIE \
if (ShouldUseEphemeralStorage(url, top_frame_origin)) { \
static_cast<net::CookieMonster*>(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))); \
} else // NOLINT

#include "../../../../../services/network/restricted_cookie_manager.cc"
12 changes: 0 additions & 12 deletions patches/net-cookies-cookie_options.h.patch

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 2 additions & 10 deletions patches/services-network-public-mojom-cookie_manager.mojom.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
diff --git a/services/network/public/mojom/cookie_manager.mojom b/services/network/public/mojom/cookie_manager.mojom
index efb5fa353efa87c39de48c477c0bddd8dc4d4b19..b9353e785a9e980acb0a5768567c4c81a324864b 100644
index efb5fa353efa87c39de48c477c0bddd8dc4d4b19..f6a9a246963cbad38b66ae21ca06341f8675b277 100644
--- a/services/network/public/mojom/cookie_manager.mojom
+++ b/services/network/public/mojom/cookie_manager.mojom
@@ -114,6 +114,7 @@ struct CookieOptions {
CookieSameSiteContext same_site_cookie_context;
bool update_access_time = true;
bool return_excluded_cookies = false;
+ url.mojom.Url top_frame_url;
};

// See net/cookies/canonical_cookie.{h,cc} for documentation.
@@ -250,6 +251,7 @@ struct CookieDeletionFilter {
@@ -250,6 +250,7 @@ struct CookieDeletionFilter {

// Delete session/persistent cookies.
CookieDeletionSessionControl session_control = IGNORE_CONTROL;
Expand Down

0 comments on commit 7121219

Please sign in to comment.