OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ | |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "content/public/browser/browser_context.h" | |
10 #include "content/public/browser/content_browser_client.h" | |
11 #include "content/public/browser/resource_context.h" | |
12 #include "headless/lib/browser/headless_url_request_context_getter.h" | |
13 #include "headless/public/headless_browser.h" | |
14 | |
15 namespace headless { | |
16 | |
17 class HeadlessBrowserContext : public content::BrowserContext { | |
18 public: | |
19 explicit HeadlessBrowserContext(const HeadlessBrowser::Options& options); | |
20 ~HeadlessBrowserContext() override; | |
21 | |
22 // BrowserContext implementation: | |
23 scoped_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( | |
24 const base::FilePath& partition_path) override; | |
25 base::FilePath GetPath() const override; | |
26 bool IsOffTheRecord() const override; | |
27 net::URLRequestContextGetter* GetRequestContext() override; | |
28 net::URLRequestContextGetter* GetRequestContextForRenderProcess( | |
29 int renderer_child_id) override; | |
30 net::URLRequestContextGetter* GetMediaRequestContext() override; | |
31 net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( | |
32 int renderer_child_id) override; | |
33 net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( | |
34 const base::FilePath& partition_path, | |
35 bool in_memory) override; | |
36 content::ResourceContext* GetResourceContext() override; | |
37 content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; | |
38 content::BrowserPluginGuestManager* GetGuestManager() override; | |
39 storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; | |
40 content::PushMessagingService* GetPushMessagingService() override; | |
41 content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; | |
42 content::PermissionManager* GetPermissionManager() override; | |
43 content::BackgroundSyncController* GetBackgroundSyncController() override; | |
44 | |
45 // Clears |protocol_handlers| but does not take ownership of it. | |
46 scoped_refptr<net::URLRequestContextGetter> CreateRequestContext( | |
47 content::ProtocolHandlerMap* protocol_handlers, | |
48 content::URLRequestInterceptorScopedVector request_interceptors); | |
Ryan Sleevi
2016/02/22 22:01:21
STYLE: The documentation for this (which appears t
Sami
2016/02/23 20:19:07
Agreed -- refactored this into HeadlessContentBrow
| |
49 | |
50 const HeadlessBrowser::Options& options() const { return options_; } | |
51 | |
52 private: | |
53 // Contains net::URLRequestContextGetter required for resource loading. | |
54 class HeadlessResourceContext : public content::ResourceContext { | |
Ryan Sleevi
2016/02/22 21:11:13
Why don't you simply forward declare this class, a
Sami
2016/02/23 20:19:07
Done.
| |
55 public: | |
56 HeadlessResourceContext(); | |
57 ~HeadlessResourceContext() override; | |
58 | |
59 // ResourceContext implementation: | |
60 net::HostResolver* GetHostResolver() override; | |
61 net::URLRequestContext* GetRequestContext() override; | |
62 | |
63 void set_url_request_context_getter( | |
64 scoped_refptr<net::URLRequestContextGetter> getter) { | |
65 getter_ = getter; | |
66 } | |
67 | |
68 private: | |
69 scoped_refptr<net::URLRequestContextGetter> getter_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(HeadlessResourceContext); | |
72 }; | |
73 | |
74 // Used by HeadlessBrowserContext to initiate and set different types of | |
75 // URLRequestContextGetter. | |
Ryan Sleevi
2016/02/22 22:01:21
Document that it does, not how it's used. https://
Sami
2016/02/23 20:19:07
Removed.
| |
76 HeadlessURLRequestContextGetter* CreateURLRequestContextGetter( | |
77 content::ProtocolHandlerMap* protocol_handlers, | |
78 content::URLRequestInterceptorScopedVector request_interceptors); | |
79 | |
80 void set_url_request_context_getter( | |
81 scoped_refptr<HeadlessURLRequestContextGetter> getter) { | |
82 url_request_getter_ = getter; | |
Ryan Sleevi
2016/02/22 21:11:13
This is a weird API that you have two different cl
Sami
2016/02/23 20:19:07
Agreed, I've now only made one of them hang on to
| |
83 } | |
84 | |
85 // Performs initialization of the HeadlessBrowserContext while IO is still | |
86 // allowed on the current thread. | |
87 void InitWhileIOAllowed(); | |
88 | |
89 base::FilePath path_; | |
90 scoped_ptr<HeadlessResourceContext> resource_context_; | |
91 scoped_refptr<net::URLRequestContextGetter> url_request_getter_; | |
92 HeadlessBrowser::Options options_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(HeadlessBrowserContext); | |
95 }; | |
96 | |
97 } // namespace headless | |
98 | |
99 #endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_CONTEXT_H_ | |
OLD | NEW |