Chromium Code Reviews| 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 #include "headless/lib/browser/headless_browser_impl.h" | |
| 6 | |
| 7 #include "base/thread_task_runner_handle.h" | |
| 8 #include "content/public/app/content_main.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 #include "headless/lib/browser/headless_browser_context.h" | |
| 12 #include "headless/lib/browser/headless_browser_main_parts.h" | |
| 13 #include "headless/lib/browser/headless_web_contents_impl.h" | |
| 14 #include "headless/lib/headless_content_main_delegate.h" | |
| 15 #include "ui/aura/env.h" | |
| 16 #include "ui/aura/window_tree_host.h" | |
| 17 #include "ui/gfx/geometry/size.h" | |
| 18 | |
| 19 namespace headless { | |
| 20 | |
| 21 HeadlessBrowserImpl::HeadlessBrowserImpl( | |
| 22 const StartCallback& on_start_callback, | |
| 23 const HeadlessBrowser::Options& options) | |
|
Ryan Sleevi
2016/02/22 22:01:21
STYLE: Your .cc order should match your .h order -
Sami
2016/02/23 20:19:07
Done.
| |
| 24 : on_start_callback_(on_start_callback), | |
| 25 options_(options), | |
| 26 browser_main_parts_(nullptr) {} | |
| 27 | |
| 28 HeadlessBrowserImpl::~HeadlessBrowserImpl() {} | |
| 29 | |
| 30 scoped_ptr<HeadlessWebContents> HeadlessBrowserImpl::CreateWebContents( | |
| 31 const gfx::Size& size) { | |
| 32 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | |
| 33 return make_scoped_ptr(new HeadlessWebContentsImpl( | |
| 34 browser_context(), window_tree_host_->window(), size)); | |
| 35 } | |
| 36 | |
| 37 scoped_refptr<base::SingleThreadTaskRunner> | |
| 38 HeadlessBrowserImpl::BrowserMainThread() const { | |
| 39 return content::BrowserThread::GetMessageLoopProxyForThread( | |
| 40 content::BrowserThread::UI); | |
| 41 } | |
| 42 | |
| 43 void HeadlessBrowserImpl::Stop() { | |
| 44 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | |
| 45 BrowserMainThread()->PostTask(FROM_HERE, | |
| 46 base::MessageLoop::QuitWhenIdleClosure()); | |
|
Ryan Sleevi
2016/02/22 22:01:21
Are you sure this is the right place to put this?
Sami
2016/02/23 20:19:08
The RunLoop is actually still owned by content::Br
| |
| 47 } | |
| 48 | |
| 49 HeadlessBrowserContext* HeadlessBrowserImpl::browser_context() const { | |
| 50 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | |
| 51 DCHECK(browser_main_parts()); | |
| 52 return browser_main_parts()->browser_context(); | |
| 53 } | |
| 54 | |
| 55 HeadlessBrowserMainParts* HeadlessBrowserImpl::browser_main_parts() const { | |
| 56 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | |
| 57 return browser_main_parts_; | |
| 58 } | |
| 59 | |
| 60 void HeadlessBrowserImpl::set_browser_main_parts( | |
| 61 HeadlessBrowserMainParts* browser_main_parts) { | |
| 62 DCHECK(!browser_main_parts_); | |
| 63 browser_main_parts_ = browser_main_parts; | |
| 64 } | |
| 65 | |
| 66 void HeadlessBrowserImpl::RunOnStartCallback() { | |
| 67 DCHECK(aura::Env::GetInstance()); | |
| 68 window_tree_host_.reset(aura::WindowTreeHost::Create(gfx::Rect())); | |
| 69 window_tree_host_->InitHost(); | |
| 70 | |
| 71 if (!on_start_callback_.is_null()) { | |
| 72 on_start_callback_.Run(this); | |
| 73 on_start_callback_ = StartCallback(); | |
| 74 } | |
|
Ryan Sleevi
2016/02/22 22:01:21
DESIGN: This is a confusing API contract that you
Sami
2016/02/23 20:19:07
Good point. This was here only for testing -- I've
| |
| 75 } | |
| 76 | |
| 77 int HeadlessBrowser::Run(const Options& options, | |
| 78 const StartCallback& on_browser_start_callback) { | |
| 79 scoped_ptr<HeadlessBrowserImpl> browser( | |
| 80 new HeadlessBrowserImpl(on_browser_start_callback, options)); | |
| 81 | |
| 82 // TODO(skyostil): Implement custom message pumps. | |
| 83 DCHECK(!options.message_pump); | |
| 84 | |
| 85 headless::HeadlessContentMainDelegate delegate(std::move(browser)); | |
| 86 content::ContentMainParams params(&delegate); | |
| 87 params.argc = options.argc; | |
| 88 params.argv = options.argv; | |
| 89 return content::ContentMain(params); | |
| 90 } | |
| 91 | |
| 92 } // namespace headless | |
| OLD | NEW |