| 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 "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "content/public/app/content_main.h" | 9 #include "content/public/app/content_main.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "headless/lib/browser/headless_browser_context.h" | 12 #include "headless/lib/browser/headless_browser_context.h" |
| 13 #include "headless/lib/browser/headless_browser_main_parts.h" | 13 #include "headless/lib/browser/headless_browser_main_parts.h" |
| 14 #include "headless/lib/browser/headless_web_contents_impl.h" | 14 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 15 #include "headless/lib/browser/headless_window_tree_client.h" | 15 #include "headless/lib/browser/headless_window_tree_client.h" |
| 16 #include "headless/lib/headless_content_main_delegate.h" | 16 #include "headless/lib/headless_content_main_delegate.h" |
| 17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
| 18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 20 | 20 |
| 21 namespace headless { | 21 namespace headless { |
| 22 | 22 |
| 23 HeadlessBrowserImpl::HeadlessBrowserImpl( | 23 HeadlessBrowserImpl::HeadlessBrowserImpl( |
| 24 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, | 24 const base::Callback<void(HeadlessBrowser*)>& on_start_callback, |
| 25 const HeadlessBrowser::Options& options) | 25 HeadlessBrowser::Options options) |
| 26 : on_start_callback_(on_start_callback), | 26 : on_start_callback_(on_start_callback), |
| 27 options_(options), | 27 options_(std::move(options)), |
| 28 browser_main_parts_(nullptr) { | 28 browser_main_parts_(nullptr) { |
| 29 DCHECK(!on_start_callback_.is_null()); | 29 DCHECK(!on_start_callback_.is_null()); |
| 30 } | 30 } |
| 31 | 31 |
| 32 HeadlessBrowserImpl::~HeadlessBrowserImpl() {} | 32 HeadlessBrowserImpl::~HeadlessBrowserImpl() {} |
| 33 | 33 |
| 34 HeadlessWebContents* HeadlessBrowserImpl::CreateWebContents( | 34 HeadlessWebContents* HeadlessBrowserImpl::CreateWebContents( |
| 35 const GURL& initial_url, | 35 const GURL& initial_url, |
| 36 const gfx::Size& size) { | 36 const gfx::Size& size) { |
| 37 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | 37 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 void HeadlessBrowserImpl::DestroyWebContents( | 107 void HeadlessBrowserImpl::DestroyWebContents( |
| 108 HeadlessWebContentsImpl* web_contents) { | 108 HeadlessWebContentsImpl* web_contents) { |
| 109 auto it = web_contents_.find(web_contents); | 109 auto it = web_contents_.find(web_contents); |
| 110 DCHECK(it != web_contents_.end()); | 110 DCHECK(it != web_contents_.end()); |
| 111 web_contents_.erase(it); | 111 web_contents_.erase(it); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void HeadlessBrowserImpl::SetOptionsForTesting( | 114 void HeadlessBrowserImpl::SetOptionsForTesting( |
| 115 const HeadlessBrowser::Options& options) { | 115 HeadlessBrowser::Options options) { |
| 116 options_ = options; | 116 options_ = std::move(options); |
| 117 browser_context()->SetOptionsForTesting(options); | 117 browser_context()->SetOptionsForTesting(&options_); |
| 118 } | 118 } |
| 119 | 119 |
| 120 int HeadlessBrowserMain( | 120 int HeadlessBrowserMain( |
| 121 const HeadlessBrowser::Options& options, | 121 HeadlessBrowser::Options options, |
| 122 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { | 122 const base::Callback<void(HeadlessBrowser*)>& on_browser_start_callback) { |
| 123 std::unique_ptr<HeadlessBrowserImpl> browser( | 123 content::ContentMainParams params(nullptr); |
| 124 new HeadlessBrowserImpl(on_browser_start_callback, options)); | 124 params.argc = options.argc; |
| 125 params.argv = options.argv; |
| 125 | 126 |
| 126 // TODO(skyostil): Implement custom message pumps. | 127 // TODO(skyostil): Implement custom message pumps. |
| 127 DCHECK(!options.message_pump); | 128 DCHECK(!options.message_pump); |
| 128 | 129 |
| 130 std::unique_ptr<HeadlessBrowserImpl> browser( |
| 131 new HeadlessBrowserImpl(on_browser_start_callback, std::move(options))); |
| 129 headless::HeadlessContentMainDelegate delegate(std::move(browser)); | 132 headless::HeadlessContentMainDelegate delegate(std::move(browser)); |
| 130 content::ContentMainParams params(&delegate); | 133 params.delegate = &delegate; |
| 131 params.argc = options.argc; | |
| 132 params.argv = options.argv; | |
| 133 return content::ContentMain(params); | 134 return content::ContentMain(params); |
| 134 } | 135 } |
| 135 | 136 |
| 136 } // namespace headless | 137 } // namespace headless |
| OLD | NEW |