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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 false /* used_policy_installed_certificate */, | 95 false /* used_policy_installed_certificate */, |
96 base::Bind(&content::IsOriginSecure), &security_info); | 96 base::Bind(&content::IsOriginSecure), &security_info); |
97 return security_state::GetSecurityStyle(security_info, | 97 return security_state::GetSecurityStyle(security_info, |
98 security_style_explanations); | 98 security_style_explanations); |
99 } | 99 } |
100 | 100 |
101 void ActivateContents(content::WebContents* contents) override { | 101 void ActivateContents(content::WebContents* contents) override { |
102 contents->GetRenderViewHost()->GetWidget()->Focus(); | 102 contents->GetRenderViewHost()->GetWidget()->Focus(); |
103 } | 103 } |
104 | 104 |
| 105 void CloseContents(content::WebContents* source) override { |
| 106 if (!browser_context_) { |
| 107 return; |
| 108 } |
| 109 |
| 110 std::vector<HeadlessWebContents*> all_contents = |
| 111 browser_context_->GetAllWebContents(); |
| 112 |
| 113 for (HeadlessWebContents* wc : all_contents) { |
| 114 if (!wc) { |
| 115 continue; |
| 116 } |
| 117 HeadlessWebContentsImpl* hwc = HeadlessWebContentsImpl::From(wc); |
| 118 if (hwc->web_contents() == source) { |
| 119 wc->Close(); |
| 120 return; |
| 121 } |
| 122 } |
| 123 } |
| 124 |
105 private: | 125 private: |
106 HeadlessBrowserContextImpl* browser_context_; // Not owned. | 126 HeadlessBrowserContextImpl* browser_context_; // Not owned. |
107 DISALLOW_COPY_AND_ASSIGN(Delegate); | 127 DISALLOW_COPY_AND_ASSIGN(Delegate); |
108 }; | 128 }; |
109 | 129 |
110 // static | 130 // static |
111 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create( | 131 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create( |
112 HeadlessWebContents::Builder* builder) { | 132 HeadlessWebContents::Builder* builder) { |
113 content::WebContents::CreateParams create_params(builder->browser_context_, | 133 content::WebContents::CreateParams create_params(builder->browser_context_, |
114 nullptr); | 134 nullptr); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 new HeadlessWebContentsImpl::Delegate(browser_context)), | 170 new HeadlessWebContentsImpl::Delegate(browser_context)), |
151 web_contents_(web_contents), | 171 web_contents_(web_contents), |
152 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), | 172 agent_host_(content::DevToolsAgentHost::GetOrCreateFor(web_contents)), |
153 browser_context_(browser_context), | 173 browser_context_(browser_context), |
154 render_process_host_(web_contents->GetRenderProcessHost()) { | 174 render_process_host_(web_contents->GetRenderProcessHost()) { |
155 web_contents_->SetDelegate(web_contents_delegate_.get()); | 175 web_contents_->SetDelegate(web_contents_delegate_.get()); |
156 render_process_host_->AddObserver(this); | 176 render_process_host_->AddObserver(this); |
157 } | 177 } |
158 | 178 |
159 HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { | 179 HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { |
160 web_contents_->Close(); | |
161 if (render_process_host_) | 180 if (render_process_host_) |
162 render_process_host_->RemoveObserver(this); | 181 render_process_host_->RemoveObserver(this); |
163 } | 182 } |
164 | 183 |
165 void HeadlessWebContentsImpl::RenderFrameCreated( | 184 void HeadlessWebContentsImpl::RenderFrameCreated( |
166 content::RenderFrameHost* render_frame_host) { | 185 content::RenderFrameHost* render_frame_host) { |
167 if (!mojo_services_.empty()) { | 186 if (!mojo_services_.empty()) { |
168 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS); | 187 render_frame_host->AllowBindings(content::BINDINGS_POLICY_HEADLESS); |
169 } | 188 } |
170 | 189 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 HeadlessWebContents::Builder::MojoService::MojoService() {} | 318 HeadlessWebContents::Builder::MojoService::MojoService() {} |
300 | 319 |
301 HeadlessWebContents::Builder::MojoService::MojoService( | 320 HeadlessWebContents::Builder::MojoService::MojoService( |
302 const std::string& service_name, | 321 const std::string& service_name, |
303 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) | 322 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) |
304 : service_name(service_name), service_factory(service_factory) {} | 323 : service_name(service_name), service_factory(service_factory) {} |
305 | 324 |
306 HeadlessWebContents::Builder::MojoService::~MojoService() {} | 325 HeadlessWebContents::Builder::MojoService::~MojoService() {} |
307 | 326 |
308 } // namespace headless | 327 } // namespace headless |
OLD | NEW |