forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atom_browser_context.h
196 lines (165 loc) · 6.72 KB
/
atom_browser_context.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright (c) 2013 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_ATOM_BROWSER_CONTEXT_H_
#define SHELL_BROWSER_ATOM_BROWSER_CONTEXT_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/net/proxy_config_monitor.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/resource_context.h"
#include "electron/buildflags/buildflags.h"
#include "shell/browser/media/media_device_id_salt.h"
#include "shell/browser/net/url_request_context_getter.h"
class PrefRegistrySimple;
class PrefService;
class ValueMapPrefStore;
namespace storage {
class SpecialStoragePolicy;
}
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
namespace extensions {
class AtomExtensionSystem;
}
#endif
namespace electron {
class AtomBlobReader;
class AtomBrowserContext;
class AtomDownloadManagerDelegate;
class AtomPermissionManager;
class CookieChangeNotifier;
class ResolveProxyHelper;
class SpecialStoragePolicy;
class WebViewManager;
class AtomBrowserContext
: public base::RefCountedDeleteOnSequence<AtomBrowserContext>,
public content::BrowserContext {
public:
// partition_id => browser_context
struct PartitionKey {
std::string partition;
bool in_memory;
PartitionKey(const std::string& partition, bool in_memory)
: partition(partition), in_memory(in_memory) {}
bool operator<(const PartitionKey& other) const {
if (partition == other.partition)
return in_memory < other.in_memory;
return partition < other.partition;
}
bool operator==(const PartitionKey& other) const {
return (partition == other.partition) && (in_memory == other.in_memory);
}
};
using BrowserContextMap =
std::map<PartitionKey, base::WeakPtr<AtomBrowserContext>>;
// Get or create the BrowserContext according to its |partition| and
// |in_memory|. The |options| will be passed to constructor when there is no
// existing BrowserContext.
static scoped_refptr<AtomBrowserContext> From(
const std::string& partition,
bool in_memory,
const base::DictionaryValue& options = base::DictionaryValue());
static BrowserContextMap browser_context_map() {
return browser_context_map_;
}
void SetUserAgent(const std::string& user_agent);
std::string GetUserAgent() const;
bool CanUseHttpCache() const;
int GetMaxCacheSize() const;
AtomBlobReader* GetBlobReader();
network::mojom::NetworkContextPtr GetNetworkContext();
// Get the request context, if there is none, create it.
net::URLRequestContextGetter* GetRequestContext();
ResolveProxyHelper* GetResolveProxyHelper();
// content::BrowserContext:
base::FilePath GetPath() override;
bool IsOffTheRecord() override;
content::ResourceContext* GetResourceContext() override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
content::PushMessagingService* GetPushMessagingService() override;
content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override;
std::string GetMediaDeviceIDSalt() override;
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
content::PermissionControllerDelegate* GetPermissionControllerDelegate()
override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
net::URLRequestContextGetter* CreateRequestContext(
content::ProtocolHandlerMap* protocol_handlers,
content::URLRequestInterceptorScopedVector request_interceptors) override;
net::URLRequestContextGetter* CreateMediaRequestContext() override;
content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate()
override;
// extensions deps
void SetCorsOriginAccessListForOrigin(
const url::Origin& source_origin,
std::vector<network::mojom::CorsOriginPatternPtr> allow_patterns,
std::vector<network::mojom::CorsOriginPatternPtr> block_patterns,
base::OnceClosure closure) override;
CookieChangeNotifier* cookie_change_notifier() const {
return cookie_change_notifier_.get();
}
ProxyConfigMonitor* proxy_config_monitor() {
return proxy_config_monitor_.get();
}
PrefService* prefs() const { return prefs_.get(); }
void set_in_memory_pref_store(ValueMapPrefStore* pref_store) {
in_memory_pref_store_ = pref_store;
}
ValueMapPrefStore* in_memory_pref_store() const {
return in_memory_pref_store_;
}
base::WeakPtr<AtomBrowserContext> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
protected:
AtomBrowserContext(const std::string& partition,
bool in_memory,
const base::DictionaryValue& options);
~AtomBrowserContext() override;
private:
friend class base::RefCountedDeleteOnSequence<AtomBrowserContext>;
friend class base::DeleteHelper<AtomBrowserContext>;
// Initialize pref registry.
void InitPrefs();
static BrowserContextMap browser_context_map_;
// Self-destructing class responsible for creating URLRequestContextGetter
// on the UI thread and deletes itself on the IO thread.
URLRequestContextGetter::Handle* io_handle_;
ValueMapPrefStore* in_memory_pref_store_;
std::unique_ptr<content::ResourceContext> resource_context_;
std::unique_ptr<CookieChangeNotifier> cookie_change_notifier_;
std::unique_ptr<PrefService> prefs_;
std::unique_ptr<AtomDownloadManagerDelegate> download_manager_delegate_;
std::unique_ptr<WebViewManager> guest_manager_;
std::unique_ptr<AtomPermissionManager> permission_manager_;
std::unique_ptr<AtomBlobReader> blob_reader_;
std::unique_ptr<MediaDeviceIDSalt> media_device_id_salt_;
scoped_refptr<ResolveProxyHelper> resolve_proxy_helper_;
scoped_refptr<storage::SpecialStoragePolicy> storage_policy_;
// Tracks the ProxyConfig to use, and passes any updates to a NetworkContext
// ProxyConfigClient.
std::unique_ptr<ProxyConfigMonitor> proxy_config_monitor_;
std::string user_agent_;
base::FilePath path_;
bool in_memory_ = false;
bool use_cache_ = true;
int max_cache_size_ = 0;
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// Owned by the KeyedService system.
extensions::AtomExtensionSystem* extension_system_;
#endif
base::WeakPtrFactory<AtomBrowserContext> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
};
} // namespace electron
#endif // SHELL_BROWSER_ATOM_BROWSER_CONTEXT_H_