| 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" | |
| 23 #include "headless/lib/headless_content_main_delegate.h" | 21 #include "headless/lib/headless_content_main_delegate.h" |
| 24 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
| 25 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 26 #include "ui/events/devices/device_data_manager.h" | 24 #include "ui/events/devices/device_data_manager.h" |
| 27 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 28 | 26 |
| 29 namespace headless { | 27 namespace headless { |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 int RunContentMain( | 30 int RunContentMain( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 return browser_main_parts_; | 112 return browser_main_parts_; |
| 115 } | 113 } |
| 116 | 114 |
| 117 void HeadlessBrowserImpl::set_browser_main_parts( | 115 void HeadlessBrowserImpl::set_browser_main_parts( |
| 118 HeadlessBrowserMainParts* browser_main_parts) { | 116 HeadlessBrowserMainParts* browser_main_parts) { |
| 119 DCHECK(!browser_main_parts_); | 117 DCHECK(!browser_main_parts_); |
| 120 browser_main_parts_ = browser_main_parts; | 118 browser_main_parts_ = browser_main_parts; |
| 121 } | 119 } |
| 122 | 120 |
| 123 void HeadlessBrowserImpl::RunOnStartCallback() { | 121 void HeadlessBrowserImpl::RunOnStartCallback() { |
| 124 DCHECK(aura::Env::GetInstance()); | 122 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); | 123 on_start_callback_.Run(this); |
| 136 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); | 124 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); |
| 137 } | 125 } |
| 138 | 126 |
| 139 HeadlessBrowserContext* HeadlessBrowserImpl::CreateBrowserContext( | 127 HeadlessBrowserContext* HeadlessBrowserImpl::CreateBrowserContext( |
| 140 HeadlessBrowserContext::Builder* builder) { | 128 HeadlessBrowserContext::Builder* builder) { |
| 141 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 142 | 130 |
| 143 std::unique_ptr<HeadlessBrowserContextImpl> browser_context = | 131 std::unique_ptr<HeadlessBrowserContextImpl> browser_context = |
| 144 HeadlessBrowserContextImpl::Create(builder); | 132 HeadlessBrowserContextImpl::Create(builder); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 | 160 |
| 173 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { | 161 HeadlessBrowserContext* HeadlessBrowserImpl::GetDefaultBrowserContext() { |
| 174 return default_browser_context_; | 162 return default_browser_context_; |
| 175 } | 163 } |
| 176 | 164 |
| 177 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { | 165 base::WeakPtr<HeadlessBrowserImpl> HeadlessBrowserImpl::GetWeakPtr() { |
| 178 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 179 return weak_ptr_factory_.GetWeakPtr(); | 167 return weak_ptr_factory_.GetWeakPtr(); |
| 180 } | 168 } |
| 181 | 169 |
| 182 aura::WindowTreeHost* HeadlessBrowserImpl::window_tree_host() const { | |
| 183 return window_tree_host_.get(); | |
| 184 } | |
| 185 | |
| 186 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( | 170 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevToolsAgentHostId( |
| 187 const std::string& devtools_agent_host_id) { | 171 const std::string& devtools_agent_host_id) { |
| 188 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { | 172 for (HeadlessBrowserContext* context : GetAllBrowserContexts()) { |
| 189 HeadlessWebContents* web_contents = | 173 HeadlessWebContents* web_contents = |
| 190 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); | 174 context->GetWebContentsForDevToolsAgentHostId(devtools_agent_host_id); |
| 191 if (web_contents) | 175 if (web_contents) |
| 192 return web_contents; | 176 return web_contents; |
| 193 } | 177 } |
| 194 return nullptr; | 178 return nullptr; |
| 195 } | 179 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 224 | 208 |
| 225 // Child processes should not end up here. | 209 // Child processes should not end up here. |
| 226 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( | 210 DCHECK(!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 227 switches::kProcessType)); | 211 switches::kProcessType)); |
| 228 #endif | 212 #endif |
| 229 return RunContentMain(std::move(options), | 213 return RunContentMain(std::move(options), |
| 230 std::move(on_browser_start_callback)); | 214 std::move(on_browser_start_callback)); |
| 231 } | 215 } |
| 232 | 216 |
| 233 } // namespace headless | 217 } // namespace headless |
| OLD | NEW |