Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: headless/lib/browser/headless_web_contents_impl.cc

Issue 2709433002: Add HeadlessFocusClient to fix document.hasFocus() issues. (Closed)
Patch Set: Add test and use Delegate to focus RenderWidgetHost Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | headless/lib/headless_web_contents_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h"
25 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/common/bindings_policy.h" 28 #include "content/public/common/bindings_policy.h"
27 #include "content/public/common/origin_util.h" 29 #include "content/public/common/origin_util.h"
28 #include "headless/lib/browser/headless_browser_context_impl.h" 30 #include "headless/lib/browser/headless_browser_context_impl.h"
29 #include "headless/lib/browser/headless_browser_impl.h" 31 #include "headless/lib/browser/headless_browser_impl.h"
30 #include "headless/lib/browser/headless_browser_main_parts.h" 32 #include "headless/lib/browser/headless_browser_main_parts.h"
31 #include "headless/lib/browser/headless_devtools_client_impl.h" 33 #include "headless/lib/browser/headless_devtools_client_impl.h"
32 #include "services/service_manager/public/cpp/interface_registry.h" 34 #include "services/service_manager/public/cpp/interface_registry.h"
33 35
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 override { 92 override {
91 security_state::SecurityInfo security_info; 93 security_state::SecurityInfo security_info;
92 security_state::GetSecurityInfo( 94 security_state::GetSecurityInfo(
93 security_state::GetVisibleSecurityState(web_contents), 95 security_state::GetVisibleSecurityState(web_contents),
94 false /* used_policy_installed_certificate */, 96 false /* used_policy_installed_certificate */,
95 base::Bind(&content::IsOriginSecure), &security_info); 97 base::Bind(&content::IsOriginSecure), &security_info);
96 return security_state::GetSecurityStyle(security_info, 98 return security_state::GetSecurityStyle(security_info,
97 security_style_explanations); 99 security_style_explanations);
98 } 100 }
99 101
102 void ActivateContents(content::WebContents* contents) override {
103 contents->GetTopLevelRenderWidgetHostView()->GetRenderWidgetHost()->Focus();
Eric Seckler 2017/02/21 09:28:02 Hm, the content shell does: contents->GetRenderV
irisu 2017/02/22 05:34:35 No, I don't. Done.
104 }
105
100 private: 106 private:
101 HeadlessBrowserContextImpl* browser_context_; // Not owned. 107 HeadlessBrowserContextImpl* browser_context_; // Not owned.
102 DISALLOW_COPY_AND_ASSIGN(Delegate); 108 DISALLOW_COPY_AND_ASSIGN(Delegate);
103 }; 109 };
104 110
105 // static 111 // static
106 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create( 112 std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create(
107 HeadlessWebContents::Builder* builder) { 113 HeadlessWebContents::Builder* builder) {
108 content::WebContents::CreateParams create_params(builder->browser_context_, 114 content::WebContents::CreateParams create_params(builder->browser_context_,
109 nullptr); 115 nullptr);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 180 }
175 181
176 bool HeadlessWebContentsImpl::OpenURL(const GURL& url) { 182 bool HeadlessWebContentsImpl::OpenURL(const GURL& url) {
177 if (!url.is_valid()) 183 if (!url.is_valid())
178 return false; 184 return false;
179 content::NavigationController::LoadURLParams params(url); 185 content::NavigationController::LoadURLParams params(url);
180 params.transition_type = ui::PageTransitionFromInt( 186 params.transition_type = ui::PageTransitionFromInt(
181 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); 187 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
182 web_contents_->GetController().LoadURLWithParams(params); 188 web_contents_->GetController().LoadURLWithParams(params);
183 web_contents_->Focus(); 189 web_contents_->Focus();
190 web_contents_delegate_->ActivateContents(web_contents_.get());
Eric Seckler 2017/02/21 09:28:02 Ah, okay. I thought ActivateContents would be call
irisu 2017/02/22 05:34:35 Done. I'm getting a presubmit warning for using Te
Eric Seckler 2017/02/22 09:00:03 Yeah, it's a reasonable warning, but given that th
Eric Seckler 2017/02/22 10:28:59 Seems like we'll also have to add a build dependen
184 return true; 191 return true;
185 } 192 }
186 193
187 void HeadlessWebContentsImpl::Close() { 194 void HeadlessWebContentsImpl::Close() {
188 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 195 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
189 browser_context()->DestroyWebContents(this); 196 browser_context()->DestroyWebContents(this);
190 } 197 }
191 198
192 std::string HeadlessWebContentsImpl::GetDevToolsAgentHostId() { 199 std::string HeadlessWebContentsImpl::GetDevToolsAgentHostId() {
193 return agent_host_->GetId(); 200 return agent_host_->GetId();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 HeadlessWebContents::Builder::MojoService::MojoService() {} 301 HeadlessWebContents::Builder::MojoService::MojoService() {}
295 302
296 HeadlessWebContents::Builder::MojoService::MojoService( 303 HeadlessWebContents::Builder::MojoService::MojoService(
297 const std::string& service_name, 304 const std::string& service_name,
298 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory) 305 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& service_factory)
299 : service_name(service_name), service_factory(service_factory) {} 306 : service_name(service_name), service_factory(service_factory) {}
300 307
301 HeadlessWebContents::Builder::MojoService::~MojoService() {} 308 HeadlessWebContents::Builder::MojoService::~MojoService() {}
302 309
303 } // namespace headless 310 } // namespace headless
OLDNEW
« no previous file with comments | « no previous file | headless/lib/headless_web_contents_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698