| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "content/public/app/content_main.h" | 14 #include "content/public/app/content_main.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 18 #include "headless/lib/browser/headless_browser_context_impl.h" | 18 #include "headless/lib/browser/headless_browser_context_impl.h" |
| 19 #include "headless/lib/browser/headless_browser_main_parts.h" | 19 #include "headless/lib/browser/headless_browser_main_parts.h" |
| 20 #include "headless/lib/browser/headless_web_contents_impl.h" | 20 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 21 #include "headless/lib/browser/headless_window_parenting_client.h" | |
| 22 #include "headless/lib/browser/headless_window_tree_host.h" | 21 #include "headless/lib/browser/headless_window_tree_host.h" |
| 23 #include "headless/lib/headless_content_main_delegate.h" | 22 #include "headless/lib/headless_content_main_delegate.h" |
| 24 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 25 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
| 26 #include "ui/events/devices/device_data_manager.h" | 25 #include "ui/events/devices/device_data_manager.h" |
| 27 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 28 | 27 |
| 29 namespace headless { | 28 namespace headless { |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return browser_main_parts_; | 113 return browser_main_parts_; |
| 115 } | 114 } |
| 116 | 115 |
| 117 void HeadlessBrowserImpl::set_browser_main_parts( | 116 void HeadlessBrowserImpl::set_browser_main_parts( |
| 118 HeadlessBrowserMainParts* browser_main_parts) { | 117 HeadlessBrowserMainParts* browser_main_parts) { |
| 119 DCHECK(!browser_main_parts_); | 118 DCHECK(!browser_main_parts_); |
| 120 browser_main_parts_ = browser_main_parts; | 119 browser_main_parts_ = browser_main_parts; |
| 121 } | 120 } |
| 122 | 121 |
| 123 void HeadlessBrowserImpl::RunOnStartCallback() { | 122 void HeadlessBrowserImpl::RunOnStartCallback() { |
| 124 DCHECK(aura::Env::GetInstance()); | 123 PlatformCreateWindow(); |
| 125 ui::DeviceDataManager::CreateInstance(); | |
| 126 | |
| 127 window_tree_host_.reset( | |
| 128 new HeadlessWindowTreeHost(gfx::Rect(options()->window_size))); | |
| 129 window_tree_host_->InitHost(); | |
| 130 window_tree_host_->window()->Show(); | |
| 131 | |
| 132 window_parenting_client_.reset( | |
| 133 new HeadlessWindowParentingClient(window_tree_host_->window())); | |
| 134 | |
| 135 on_start_callback_.Run(this); | 124 on_start_callback_.Run(this); |
| 136 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); | 125 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); |
| 137 } | 126 } |
| 138 | 127 |
| 139 HeadlessBrowserContext* HeadlessBrowserImpl::CreateBrowserContext( | 128 HeadlessBrowserContext* HeadlessBrowserImpl::CreateBrowserContext( |
| 140 HeadlessBrowserContext::Builder* builder) { | 129 HeadlessBrowserContext::Builder* builder) { |
| 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 130 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 142 | 131 |
| 143 std::unique_ptr<HeadlessBrowserContextImpl> browser_context = | 132 std::unique_ptr<HeadlessBrowserContextImpl> browser_context = |
| 144 HeadlessBrowserContextImpl::Create(builder); | 133 HeadlessBrowserContextImpl::Create(builder); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 | 161 |
| 173 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { | 162 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { |
| 174 return default_browser_context_; | 163 return default_browser_context_; |
| 175 } | 164 } |
| 176 | 165 |
| 177 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { | 166 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { |
| 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 167 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 179 return weak_ptr_factory_.GetWeakPtr(); | 168 return weak_ptr_factory_.GetWeakPtr(); |
| 180 } | 169 } |
| 181 | 170 |
| 182 aura::WindowTreeHost* HeadlessBrowserImpl::window_tree_host() const { | 171 HeadlessWindowTreeHost* HeadlessBrowserImpl::window_tree_host() const { |
| 183 return window_tree_host_.get(); | 172 return window_tree_host_.get(); |
| 184 } | 173 } |
| 185 | 174 |
| 186 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( | 175 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( |
| 187 const std::string& devtools_agent_host_id) { | 176 const std::string& devtools_agent_host_id) { |
| 188 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { | 177 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { |
| 189 HeadlessWebContents* web_contents = | 178 HeadlessWebContents* web_contents = |
| 190 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); | 179 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); |
| 191 if (web_contents) | 180 if (web_contents) |
| 192 return web_contents; | 181 return web_contents; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 213 |
| 225 // Child processes should not end up here. | 214 // Child processes should not end up here. |
| 226 base::CommandLine command_line(options.argc, options.argv); | 215 base::CommandLine command_line(options.argc, options.argv); |
| 227 DCHECK(!command_line.HasSwitch(switches::kProcessType)); | 216 DCHECK(!command_line.HasSwitch(switches::kProcessType)); |
| 228 #endif | 217 #endif |
| 229 return RunContentMain(std::move(options), | 218 return RunContentMain(std::move(options), |
| 230 std::move(on_browser_start_callback)); | 219 std::move(on_browser_start_callback)); |
| 231 } | 220 } |
| 232 | 221 |
| 233 } // namespace headless | 222 } // namespace headless |
| OLD | NEW |