| 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_web_contents_impl.h" | 5 #include "headless/lib/browser/headless_web_contents_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "components/security_state/content/content_utils.h" | 16 #include "components/security_state/content/content_utils.h" |
| 17 #include "components/security_state/core/security_state.h" | 17 #include "components/security_state/core/security_state.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/devtools_agent_host.h" | 19 #include "content/public/browser/devtools_agent_host.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 24 #include "content/public/browser/render_widget_host_view.h" | |
| 25 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_contents_delegate.h" | 25 #include "content/public/browser/web_contents_delegate.h" |
| 27 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
| 28 #include "content/public/common/origin_util.h" | 27 #include "content/public/common/origin_util.h" |
| 29 #include "headless/lib/browser/headless_browser_context_impl.h" | 28 #include "headless/lib/browser/headless_browser_context_impl.h" |
| 30 #include "headless/lib/browser/headless_browser_impl.h" | 29 #include "headless/lib/browser/headless_browser_impl.h" |
| 31 #include "headless/lib/browser/headless_browser_main_parts.h" | 30 #include "headless/lib/browser/headless_browser_main_parts.h" |
| 32 #include "headless/lib/browser/headless_devtools_client_impl.h" | 31 #include "headless/lib/browser/headless_devtools_client_impl.h" |
| 33 #include "services/service_manager/public/cpp/interface_registry.h" | 32 #include "services/service_manager/public/cpp/interface_registry.h" |
| 34 #include "ui/aura/window.h" | |
| 35 | 33 |
| 36 namespace headless { | 34 namespace headless { |
| 37 | 35 |
| 38 // static | 36 // static |
| 39 HeadlessWebContentsImpl* HeadlessWebContentsImpl::From( | 37 HeadlessWebContentsImpl* HeadlessWebContentsImpl::From( |
| 40 HeadlessWebContents* web_contents) { | 38 HeadlessWebContents* web_contents) { |
| 41 // This downcast is safe because there is only one implementation of | 39 // This downcast is safe because there is only one implementation of |
| 42 // HeadlessWebContents. | 40 // HeadlessWebContents. |
| 43 return static_cast<HeadlessWebContentsImpl*>(web_contents); | 41 return static_cast<HeadlessWebContentsImpl*>(web_contents); |
| 44 } | 42 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 security_style_explanations); | 97 security_style_explanations); |
| 100 } | 98 } |
| 101 | 99 |
| 102 private: | 100 private: |
| 103 HeadlessBrowserContextImpl* browser_context_; // Not owned. | 101 HeadlessBrowserContextImpl* browser_context_; // Not owned. |
| 104 DISALLOW_COPY_AND_ASSIGN(Delegate); | 102 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 // static | 105 // static |
| 108 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create( | 106 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create( |
| 109 HeadlessWebContents::Builder* builder, | 107 HeadlessWebContents::Builder* builder) { |
| 110 aura::Window* parent_window) { | |
| 111 content::WebContents::CreateParams create_params(builder->browser_context_, | 108 content::WebContents::CreateParams create_params(builder->browser_context_, |
| 112 nullptr); | 109 nullptr); |
| 113 create_params.initial_size = builder->window_size_; | 110 create_params.initial_size = builder->window_size_; |
| 114 | 111 |
| 115 std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents = | 112 std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents = |
| 116 base::WrapUnique(new HeadlessWebContentsImpl( | 113 base::WrapUnique(new HeadlessWebContentsImpl( |
| 117 content::WebContents::Create(create_params), | 114 content::WebContents::Create(create_params), |
| 118 builder->browser_context_)); | 115 builder->browser_context_)); |
| 119 | 116 |
| 120 headless_web_contents->mojo_services_ = std::move(builder->mojo_services_); | 117 headless_web_contents->mojo_services_ = std::move(builder->mojo_services_); |
| 121 headless_web_contents->InitializeScreen(parent_window, builder->window_size_); | 118 headless_web_contents->InitializeScreen(builder->window_size_); |
| 122 if (!headless_web_contents->OpenURL(builder->initial_url_)) | 119 if (!headless_web_contents->OpenURL(builder->initial_url_)) |
| 123 return nullptr; | 120 return nullptr; |
| 124 return headless_web_contents; | 121 return headless_web_contents; |
| 125 } | 122 } |
| 126 | 123 |
| 127 // static | 124 // static |
| 128 std::unique_ptr<HeadlessWebContentsImpl> | 125 std::unique_ptr<HeadlessWebContentsImpl> |
| 129 HeadlessWebContentsImpl::CreateFromWebContents( | 126 HeadlessWebContentsImpl::CreateFromWebContents( |
| 130 content::WebContents* web_contents, | 127 content::WebContents* web_contents, |
| 131 HeadlessBrowserContextImpl* browser_context) { | 128 HeadlessBrowserContextImpl* browser_context) { |
| 132 std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents = | 129 std::unique_ptr<HeadlessWebContentsImpl> headless_web_contents = |
| 133 base::WrapUnique( | 130 base::WrapUnique( |
| 134 new HeadlessWebContentsImpl(web_contents, browser_context)); | 131 new HeadlessWebContentsImpl(web_contents, browser_context)); |
| 135 | 132 |
| 136 return headless_web_contents; | 133 return headless_web_contents; |
| 137 } | 134 } |
| 138 | 135 |
| 139 void HeadlessWebContentsImpl::InitializeScreen(aura::Window* parent_window, | 136 void HeadlessWebContentsImpl::InitializeScreen(const gfx::Size& initial_size) { |
| 140 const gfx::Size& initial_size) { | 137 browser()->PlatformSetWebContents(initial_size, web_contents_.get()); |
| 141 aura::Window* contents = web_contents_->GetNativeView(); | |
| 142 DCHECK(!parent_window->Contains(contents)); | |
| 143 parent_window->AddChild(contents); | |
| 144 contents->Show(); | |
| 145 | |
| 146 contents->SetBounds(gfx::Rect(initial_size)); | |
| 147 content::RenderWidgetHostView* host_view = | |
| 148 web_contents_->GetRenderWidgetHostView(); | |
| 149 if (host_view) | |
| 150 host_view->SetSize(initial_size); | |
| 151 } | 138 } |
| 152 | 139 |
| 153 HeadlessWebContentsImpl::HeadlessWebContentsImpl( | 140 HeadlessWebContentsImpl::HeadlessWebContentsImpl( |
| 154 content::WebContents* web_contents, | 141 content::WebContents* web_contents, |
| 155 HeadlessBrowserContextImpl* browser_context) | 142 HeadlessBrowserContextImpl* browser_context) |
| 156 : content::WebContentsObserver(web_contents), | 143 : content::WebContentsObserver(web_contents), |
| 157 web_contents_delegate_( | 144 web_contents_delegate_( |
| 158 new HeadlessWebContentsImpl::Delegate(browser_context)), | 145 new HeadlessWebContentsImpl::Delegate(browser_context)), |
| 159 web_contents_(web_contents), | 146 web_contents_(web_contents), |
| 160 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), | 147 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 HeadlessWebContents::Builder::MojoService::MojoService() {} | 294 HeadlessWebContents::Builder::MojoService::MojoService() {} |
| 308 | 295 |
| 309 HeadlessWebContents::Builder::MojoService::MojoService( | 296 HeadlessWebContents::Builder::MojoService::MojoService( |
| 310 const std::string& service_name, | 297 const std::string& service_name, |
| 311 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) | 298 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) |
| 312 : service_name(service_name), service_factory(service_factory) {} | 299 : service_name(service_name), service_factory(service_factory) {} |
| 313 | 300 |
| 314 HeadlessWebContents::Builder::MojoService::~MojoService() {} | 301 HeadlessWebContents::Builder::MojoService::~MojoService() {} |
| 315 | 302 |
| 316 } // namespace headless | 303 } // namespace headless |
| OLD | NEW |