Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: headless/lib/browser/headless_browser_context.cc

Issue 1674263002: headless: Initial headless embedder API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fine, no console logging Mr. Presubmit. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "headless/lib/browser/headless_browser_context.h"
6
7 #include "base/path_service.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/resource_context.h"
10 #include "content/public/browser/storage_partition.h"
11 #include "headless/lib/browser/headless_url_request_context_getter.h"
12 #include "net/url_request/url_request_context.h"
13
14 namespace headless {
15
16 // Contains net::URLRequestContextGetter required for resource loading.
17 // Must be destructed on the IO thread as per content::ResourceContext
18 // requirements.
19 class HeadlessResourceContext : public content::ResourceContext {
20 public:
21 HeadlessResourceContext();
22 ~HeadlessResourceContext() override;
23
24 // ResourceContext implementation:
25 net::HostResolver* GetHostResolver() override;
26 net::URLRequestContext* GetRequestContext() override;
27
28 // Configure the URL request context getter to be used for resource fetching.
29 // Must be called before any of the other methods of this class are used. Must
30 // be called on the browser UI thread.
31 void set_url_request_context_getter(
32 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
33 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
34 url_request_context_getter_ = std::move(url_request_context_getter);
35 }
36
37 private:
38 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
39
40 DISALLOW_COPY_AND_ASSIGN(HeadlessResourceContext);
41 };
42
43 HeadlessResourceContext::HeadlessResourceContext() {
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
45 }
46
47 HeadlessResourceContext::~HeadlessResourceContext() {
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
49 }
50
51 net::HostResolver* HeadlessResourceContext::GetHostResolver() {
52 CHECK(url_request_context_getter_);
53 return url_request_context_getter_->GetURLRequestContext()->host_resolver();
54 }
55
56 net::URLRequestContext* HeadlessResourceContext::GetRequestContext() {
57 CHECK(url_request_context_getter_);
58 return url_request_context_getter_->GetURLRequestContext();
59 }
60
61 HeadlessBrowserContext::HeadlessBrowserContext(
62 const HeadlessBrowser::Options& options)
63 : resource_context_(new HeadlessResourceContext), options_(options) {
64 InitWhileIOAllowed();
65 }
66
67 HeadlessBrowserContext::~HeadlessBrowserContext() {
68 if (resource_context_) {
69 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
70 resource_context_.release());
71 }
72 }
73
74 void HeadlessBrowserContext::InitWhileIOAllowed() {
75 // TODO(skyostil): Allow the embedder to override this.
76 PathService::Get(base::DIR_EXE, &path_);
77 }
78
79 scoped_ptr<content::ZoomLevelDelegate>
80 HeadlessBrowserContext::CreateZoomLevelDelegate(
81 const base::FilePath& partition_path) {
82 return scoped_ptr<content::ZoomLevelDelegate>();
83 }
84
85 base::FilePath HeadlessBrowserContext::GetPath() const {
86 return path_;
87 }
88
89 bool HeadlessBrowserContext::IsOffTheRecord() const {
90 return false;
91 }
92
93 net::URLRequestContextGetter* HeadlessBrowserContext::GetRequestContext() {
94 return GetDefaultStoragePartition(this)->GetURLRequestContext();
95 }
96
97 net::URLRequestContextGetter*
98 HeadlessBrowserContext::GetRequestContextForRenderProcess(
99 int renderer_child_id) {
100 return GetRequestContext();
101 }
102
103 net::URLRequestContextGetter* HeadlessBrowserContext::GetMediaRequestContext() {
104 return GetRequestContext();
105 }
106
107 net::URLRequestContextGetter*
108 HeadlessBrowserContext::GetMediaRequestContextForRenderProcess(
109 int renderer_child_id) {
110 return GetRequestContext();
111 }
112
113 net::URLRequestContextGetter*
114 HeadlessBrowserContext::GetMediaRequestContextForStoragePartition(
115 const base::FilePath& partition_path,
116 bool in_memory) {
117 return GetRequestContext();
118 }
119
120 content::ResourceContext* HeadlessBrowserContext::GetResourceContext() {
121 return resource_context_.get();
122 }
123
124 content::DownloadManagerDelegate*
125 HeadlessBrowserContext::GetDownloadManagerDelegate() {
126 return nullptr;
127 }
128
129 content::BrowserPluginGuestManager* HeadlessBrowserContext::GetGuestManager() {
130 // TODO(altimin): Should be non-null? (is null in content/shell).
131 return nullptr;
132 }
133
134 storage::SpecialStoragePolicy*
135 HeadlessBrowserContext::GetSpecialStoragePolicy() {
136 return nullptr;
137 }
138
139 content::PushMessagingService*
140 HeadlessBrowserContext::GetPushMessagingService() {
141 return nullptr;
142 }
143
144 content::SSLHostStateDelegate*
145 HeadlessBrowserContext::GetSSLHostStateDelegate() {
146 return nullptr;
147 }
148
149 content::PermissionManager* HeadlessBrowserContext::GetPermissionManager() {
150 return nullptr;
151 }
152
153 content::BackgroundSyncController*
154 HeadlessBrowserContext::GetBackgroundSyncController() {
155 return nullptr;
156 }
157
158 void HeadlessBrowserContext::SetURLRequestContextGetter(
159 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) {
160 resource_context_->set_url_request_context_getter(url_request_context_getter);
161 }
162
163 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/browser/headless_browser_context.h ('k') | headless/lib/browser/headless_browser_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698