forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcookie_manager.h
147 lines (120 loc) · 5.68 KB
/
cookie_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SERVICES_NETWORK_COOKIE_MANAGER_H_
#define SERVICES_NETWORK_COOKIE_MANAGER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/component_export.h"
#include "base/macros.h"
#include "components/content_settings/core/common/content_settings.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/cookies/cookie_change_dispatcher.h"
#include "net/cookies/cookie_deletion_info.h"
#include "services/network/cookie_settings.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
namespace net {
class CookieStore;
class URLRequestContext;
} // namespace net
class GURL;
namespace network {
class FirstPartySets;
class SessionCleanupCookieStore;
// Wrap a cookie store in an implementation of the mojo cookie interface.
class COMPONENT_EXPORT(NETWORK_SERVICE) CookieManager
: public mojom::CookieManager {
public:
// Construct a CookieService that can serve mojo requests for the underlying
// cookie store. |url_request_context->cookie_store()| must outlive this
// object. `*first_party_sets` must outlive
// `url_request_context->cookie_store()`.
CookieManager(
net::URLRequestContext* url_request_context,
const FirstPartySets* first_party_sets,
scoped_refptr<SessionCleanupCookieStore> session_cleanup_cookie_store,
mojom::CookieManagerParamsPtr params);
~CookieManager() override;
const CookieSettings& cookie_settings() const { return cookie_settings_; }
// Bind a cookie receiver to this object. Mojo messages
// coming through the associated pipe will be served by this object.
void AddReceiver(mojo::PendingReceiver<mojom::CookieManager> receiver);
// TODO(rdsmith): Add a verion of AddRequest that does renderer-appropriate
// security checks on bindings coming through that interface.
// mojom::CookieManager
void GetAllCookies(GetAllCookiesCallback callback) override;
void GetAllCookiesWithAccessSemantics(
GetAllCookiesWithAccessSemanticsCallback callback) override;
void GetCookieList(const GURL& url,
const net::CookieOptions& cookie_options,
GetCookieListCallback callback) override;
void SetCanonicalCookie(const net::CanonicalCookie& cookie,
const GURL& source_url,
const net::CookieOptions& cookie_options,
SetCanonicalCookieCallback callback) override;
void DeleteCanonicalCookie(const net::CanonicalCookie& cookie,
DeleteCanonicalCookieCallback callback) override;
void SetContentSettings(const ContentSettingsForOneType& settings) override;
void DeleteCookies(mojom::CookieDeletionFilterPtr filter,
DeleteCookiesCallback callback) override;
void AddCookieChangeListener(
const GURL& url,
const base::Optional<std::string>& name,
mojo::PendingRemote<mojom::CookieChangeListener> listener) override;
void AddGlobalChangeListener(
mojo::PendingRemote<mojom::CookieChangeListener> listener) override;
void CloneInterface(
mojo::PendingReceiver<mojom::CookieManager> new_interface) override;
size_t GetClientsBoundForTesting() const { return receivers_.size(); }
size_t GetListenersRegisteredForTesting() const {
return listener_registrations_.size();
}
void FlushCookieStore(FlushCookieStoreCallback callback) override;
void AllowFileSchemeCookies(bool allow,
AllowFileSchemeCookiesCallback callback) override;
void SetForceKeepSessionState() override;
void BlockThirdPartyCookies(bool block) override;
void SetContentSettingsForLegacyCookieAccess(
const ContentSettingsForOneType& settings) override;
void SetStorageAccessGrantSettings(
const ContentSettingsForOneType& settings,
SetStorageAccessGrantSettingsCallback callback) override;
// Configures |out| based on |params|. (This doesn't honor
// allow_file_scheme_cookies, which affects the cookie store rather than the
// settings).
static void ConfigureCookieSettings(
const network::mojom::CookieManagerParams& params,
CookieSettings* out);
// Causes the next call to GetCookieList to crash the process.
static void CrashOnGetCookieList();
private:
// State associated with a CookieChangeListener.
struct ListenerRegistration {
ListenerRegistration();
~ListenerRegistration();
// Translates a CookieStore change callback to a CookieChangeListener call.
void DispatchCookieStoreChange(const net::CookieChangeInfo& change);
// Owns the callback registration in the store.
std::unique_ptr<net::CookieChangeSubscription> subscription;
// The observer receiving change notifications.
mojo::Remote<mojom::CookieChangeListener> listener;
DISALLOW_COPY_AND_ASSIGN(ListenerRegistration);
};
// Handles connection errors on change listener pipes.
void RemoveChangeListener(ListenerRegistration* registration);
net::CookieStore* const cookie_store_;
scoped_refptr<SessionCleanupCookieStore> session_cleanup_cookie_store_;
mojo::ReceiverSet<mojom::CookieManager> receivers_;
std::vector<std::unique_ptr<ListenerRegistration>> listener_registrations_;
// Note: RestrictedCookieManager and CookieAccessDelegate store pointers to
// |cookie_settings_|.
CookieSettings cookie_settings_;
DISALLOW_COPY_AND_ASSIGN(CookieManager);
};
COMPONENT_EXPORT(NETWORK_SERVICE)
net::CookieDeletionInfo DeletionFilterToInfo(
mojom::CookieDeletionFilterPtr filter);
} // namespace network
#endif // SERVICES_NETWORK_COOKIE_MANAGER_H_