OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "headless/lib/browser/headless_browser_impl.h" | 5 #include "headless/lib/browser/headless_browser_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 HeadlessBrowserContextImpl::Create(builder); | 154 HeadlessBrowserContextImpl::Create(builder); |
155 | 155 |
156 if (!browser_context) { | 156 if (!browser_context) { |
157 return nullptr; | 157 return nullptr; |
158 } | 158 } |
159 | 159 |
160 HeadlessBrowserContext* result = browser_context.get(); | 160 HeadlessBrowserContext* result = browser_context.get(); |
161 | 161 |
162 browser_contexts_[browser_context->Id()] = std::move(browser_context); | 162 browser_contexts_[browser_context->Id()] = std::move(browser_context); |
163 | 163 |
| 164 HeadlessDownloadManagerDelegate* download_delegate = |
| 165 static_cast<HeadlessDownloadManagerDelegate*>( |
| 166 browser_context->GetDownloadManagerDelegate()); |
| 167 |
| 168 if (download_behavior_.has_value()) |
| 169 download_delegate->SetDownloadBehavior(download_behavior_.value()); |
| 170 |
| 171 if (download_path_.has_value()) |
| 172 download_delegate->SetDownloadDirectory(download_path_.value()); |
| 173 |
164 return result; | 174 return result; |
165 } | 175 } |
166 | 176 |
167 void HeadlessBrowserImpl::DestroyBrowserContext( | 177 void HeadlessBrowserImpl::DestroyBrowserContext( |
168 HeadlessBrowserContextImpl* browser_context) { | 178 HeadlessBrowserContextImpl* browser_context) { |
169 auto it = browser_contexts_.find(browser_context->Id()); | 179 auto it = browser_contexts_.find(browser_context->Id()); |
170 DCHECK(it != browser_contexts_.end()); | 180 DCHECK(it != browser_contexts_.end()); |
171 browser_contexts_.erase(it); | 181 browser_contexts_.erase(it); |
172 if (default_browser_context_ == browser_context) | 182 if (default_browser_context_ == browser_context) |
173 SetDefaultBrowserContext(nullptr); | 183 SetDefaultBrowserContext(nullptr); |
174 } | 184 } |
175 | 185 |
176 void HeadlessBrowserImpl::SetDefaultBrowserContext( | 186 void HeadlessBrowserImpl::SetDefaultBrowserContext( |
177 HeadlessBrowserContext* browser_context) { | 187 HeadlessBrowserContext* browser_context) { |
178 DCHECK(!browser_context || | 188 DCHECK(!browser_context || |
179 this == HeadlessBrowserContextImpl::From(browser_context)->browser()); | 189 this == HeadlessBrowserContextImpl::From(browser_context)->browser()); |
180 default_browser_context_ = browser_context; | 190 default_browser_context_ = browser_context; |
181 } | 191 } |
182 | 192 |
183 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { | 193 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { |
184 return default_browser_context_; | 194 return default_browser_context_; |
185 } | 195 } |
186 | 196 |
187 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { | 197 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { |
188 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
189 return weak_ptr_factory_.GetWeakPtr(); | 199 return weak_ptr_factory_.GetWeakPtr(); |
190 } | 200 } |
191 | 201 |
| 202 void HeadlessBrowserImpl::SetDownloadBehavior( |
| 203 HeadlessDownloadManagerDelegate::DownloadBehavior behavior) { |
| 204 download_behavior_ = behavior; |
| 205 |
| 206 for (HeadlessBrowserContext* hbc : GetAllBrowserContexts()) { |
| 207 HeadlessBrowserContextImpl* hbci = |
| 208 static_cast<HeadlessBrowserContextImpl*>(hbc); |
| 209 |
| 210 HeadlessDownloadManagerDelegate* download_delegate = |
| 211 static_cast<HeadlessDownloadManagerDelegate*>( |
| 212 hbci->GetDownloadManagerDelegate()); |
| 213 |
| 214 download_delegate->SetDownloadBehavior(behavior); |
| 215 } |
| 216 } |
| 217 |
| 218 void HeadlessBrowserImpl::SetDownloadDirectory(const base::FilePath& path) { |
| 219 download_path_ = path; |
| 220 |
| 221 for (HeadlessBrowserContext* hbc : GetAllBrowserContexts()) { |
| 222 HeadlessBrowserContextImpl* hbci = |
| 223 static_cast<HeadlessBrowserContextImpl*>(hbc); |
| 224 |
| 225 HeadlessDownloadManagerDelegate* download_delegate = |
| 226 static_cast<HeadlessDownloadManagerDelegate*>( |
| 227 hbci->GetDownloadManagerDelegate()); |
| 228 |
| 229 download_delegate->SetDownloadDirectory(path); |
| 230 } |
| 231 } |
| 232 |
192 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( | 233 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( |
193 const std::string& devtools_agent_host_id) { | 234 const std::string& devtools_agent_host_id) { |
194 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { | 235 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { |
195 HeadlessWebContents* web_contents = | 236 HeadlessWebContents* web_contents = |
196 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); | 237 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); |
197 if (web_contents) | 238 if (web_contents) |
198 return web_contents; | 239 return web_contents; |
199 } | 240 } |
200 return nullptr; | 241 return nullptr; |
201 } | 242 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 328 |
288 // Child processes should not end up here. | 329 // Child processes should not end up here. |
289 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 330 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
290 ::switches::kProcessType)); | 331 ::switches::kProcessType)); |
291 #endif | 332 #endif |
292 return RunContentMain(std::move(options), | 333 return RunContentMain(std::move(options), |
293 std::move(on_browser_start_callback)); | 334 std::move(on_browser_start_callback)); |
294 } | 335 } |
295 | 336 |
296 } // namespace headless | 337 } // namespace headless |
OLD | NEW |