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

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 2836973002: Enable find-in-page across GuestViews. (Closed)
Patch Set: Small fix. Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 // when there are no more references to this object. 250 // when there are no more references to this object.
251 ~AXTreeSnapshotCombiner() { 251 ~AXTreeSnapshotCombiner() {
252 combiner_.Combine(); 252 combiner_.Combine();
253 callback_.Run(combiner_.combined()); 253 callback_.Run(combiner_.combined());
254 } 254 }
255 255
256 ui::AXTreeCombiner combiner_; 256 ui::AXTreeCombiner combiner_;
257 AXTreeSnapshotCallback callback_; 257 AXTreeSnapshotCallback callback_;
258 }; 258 };
259 259
260 // Helper for GetInnerWebContents().
261 bool GetInnerWebContentsHelper(
262 std::vector<WebContentsImpl*>* all_guest_contents,
263 WebContents* guest_contents) {
264 all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
265 return false;
266 }
267
260 } // namespace 268 } // namespace
261 269
262 WebContents* WebContents::Create(const WebContents::CreateParams& params) { 270 WebContents* WebContents::Create(const WebContents::CreateParams& params) {
263 FrameTreeNode* opener_node = nullptr; 271 FrameTreeNode* opener_node = nullptr;
264 if (params.opener_render_frame_id != MSG_ROUTING_NONE) { 272 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
265 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( 273 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
266 params.opener_render_process_id, params.opener_render_frame_id); 274 params.opener_render_process_id, params.opener_render_frame_id);
267 if (opener_rfh) 275 if (opener_rfh)
268 opener_node = opener_rfh->frame_tree_node(); 276 opener_node = opener_rfh->frame_tree_node();
269 } 277 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 WebContentsImpl* current_web_contents) 382 WebContentsImpl* current_web_contents)
375 : current_web_contents_(current_web_contents), 383 : current_web_contents_(current_web_contents),
376 outer_web_contents_(nullptr), 384 outer_web_contents_(nullptr),
377 outer_contents_frame_tree_node_id_( 385 outer_contents_frame_tree_node_id_(
378 FrameTreeNode::kFrameTreeNodeInvalidId), 386 FrameTreeNode::kFrameTreeNodeInvalidId),
379 focused_web_contents_(current_web_contents) {} 387 focused_web_contents_(current_web_contents) {}
380 388
381 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { 389 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
382 if (OuterContentsFrameTreeNode()) 390 if (OuterContentsFrameTreeNode())
383 OuterContentsFrameTreeNode()->RemoveObserver(this); 391 OuterContentsFrameTreeNode()->RemoveObserver(this);
392
393 if (outer_web_contents_)
394 outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
384 } 395 }
385 396
386 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( 397 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
387 WebContentsImpl* outer_web_contents, 398 WebContentsImpl* outer_web_contents,
388 RenderFrameHostImpl* outer_contents_frame) { 399 RenderFrameHostImpl* outer_contents_frame) {
389 focused_web_contents_ = nullptr; 400 focused_web_contents_ = nullptr;
390 outer_web_contents_ = outer_web_contents; 401 outer_web_contents_ = outer_web_contents;
391 outer_contents_frame_tree_node_id_ = 402 outer_contents_frame_tree_node_id_ =
392 outer_contents_frame->frame_tree_node()->frame_tree_node_id(); 403 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
393 404
405 outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
394 outer_contents_frame->frame_tree_node()->AddObserver(this); 406 outer_contents_frame->frame_tree_node()->AddObserver(this);
395 } 407 }
396 408
409 void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
410 WebContentsImpl* inner_web_contents) {
411 inner_web_contents_.push_back(inner_web_contents);
412 }
413
414 void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
415 WebContentsImpl* inner_web_contents) {
416 DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
417 inner_web_contents) != inner_web_contents_.end());
418 inner_web_contents_.erase(
419 std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
420 inner_web_contents),
421 inner_web_contents_.end());
422 }
423
397 FrameTreeNode* 424 FrameTreeNode*
398 WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const { 425 WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
399 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_); 426 return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
400 } 427 }
401 428
402 void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed( 429 void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed(
403 FrameTreeNode* node) { 430 FrameTreeNode* node) {
404 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id()) 431 DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id())
405 << "WebContentsTreeNode should only receive notifications for the " 432 << "WebContentsTreeNode should only receive notifications for the "
406 "FrameTreeNode in its outer WebContents that hosts it."; 433 "FrameTreeNode in its outer WebContents that hosts it.";
407 delete current_web_contents_; // deletes |this| too. 434 delete current_web_contents_; // deletes |this| too.
408 } 435 }
409 436
410 void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( 437 void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents(
411 WebContentsImpl* web_contents) { 438 WebContentsImpl* web_contents) {
412 DCHECK(!outer_web_contents()) 439 DCHECK(!outer_web_contents())
413 << "Only the outermost WebContents tracks focus."; 440 << "Only the outermost WebContents tracks focus.";
414 focused_web_contents_ = web_contents; 441 focused_web_contents_ = web_contents;
415 } 442 }
416 443
444 WebContentsImpl*
445 WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
446 const FrameTreeNode* frame) {
447 auto ftn_id = frame->frame_tree_node_id();
448 for (WebContentsImpl* contents : inner_web_contents_) {
449 if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
450 return contents;
451 }
452 }
453 return nullptr;
454 }
455
456 const std::vector<WebContentsImpl*>&
457 WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
458 return inner_web_contents_;
459 }
460
417 // WebContentsImpl ------------------------------------------------------------- 461 // WebContentsImpl -------------------------------------------------------------
418 462
419 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) 463 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
420 : delegate_(NULL), 464 : delegate_(NULL),
421 controller_(this, browser_context), 465 controller_(this, browser_context),
422 render_view_host_delegate_view_(NULL), 466 render_view_host_delegate_view_(NULL),
423 created_with_opener_(false), 467 created_with_opener_(false),
424 frame_tree_(new NavigatorImpl(&controller_, this), 468 frame_tree_(new NavigatorImpl(&controller_, this),
425 this, 469 this,
426 this, 470 this,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 continue; 701 continue;
658 // Because a WebContents can only have one current RVH at a time, there will 702 // Because a WebContents can only have one current RVH at a time, there will
659 // be no duplicate WebContents here. 703 // be no duplicate WebContents here.
660 result.push_back(static_cast<WebContentsImpl*>(web_contents)); 704 result.push_back(static_cast<WebContentsImpl*>(web_contents));
661 } 705 }
662 return result; 706 return result;
663 } 707 }
664 708
665 // static 709 // static
666 WebContentsImpl* WebContentsImpl::FromFrameTreeNode( 710 WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
667 FrameTreeNode* frame_tree_node) { 711 const FrameTreeNode* frame_tree_node) {
668 return static_cast<WebContentsImpl*>( 712 return static_cast<WebContentsImpl*>(
669 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); 713 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
670 } 714 }
671 715
672 // static 716 // static
673 WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, 717 WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
674 int render_frame_host_id) { 718 int render_frame_host_id) {
675 DCHECK_CURRENTLY_ON(BrowserThread::UI); 719 DCHECK_CURRENTLY_ON(BrowserThread::UI);
676 RenderFrameHost* render_frame_host = 720 RenderFrameHost* render_frame_host =
677 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); 721 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
678 if (!render_frame_host) 722 if (!render_frame_host)
679 return nullptr; 723 return nullptr;
680 724
681 return WebContents::FromRenderFrameHost(render_frame_host); 725 return WebContents::FromRenderFrameHost(render_frame_host);
682 } 726 }
683 727
728 // static
729 WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
730 const FrameTreeNode* frame_tree_node) {
731 return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
732 ->node_.GetInnerWebContentsInFrame(frame_tree_node);
733 }
734
684 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { 735 RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
685 return GetRenderManager(); 736 return GetRenderManager();
686 } 737 }
687 738
688 bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host, 739 bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host,
689 const IPC::Message& message) { 740 const IPC::Message& message) {
690 RenderFrameHost* main_frame = render_view_host->GetMainFrame(); 741 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
691 if (main_frame) { 742 if (main_frame) {
692 WebUIImpl* web_ui = static_cast<RenderFrameHostImpl*>(main_frame)->web_ui(); 743 WebUIImpl* web_ui = static_cast<RenderFrameHostImpl*>(main_frame)->web_ui();
693 if (web_ui && web_ui->OnMessageReceived(message)) 744 if (web_ui && web_ui->OnMessageReceived(message))
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 } 1082 }
1032 1083
1033 WebContentsBindingSet* WebContentsImpl::GetBindingSet( 1084 WebContentsBindingSet* WebContentsImpl::GetBindingSet(
1034 const std::string& interface_name) { 1085 const std::string& interface_name) {
1035 auto it = binding_sets_.find(interface_name); 1086 auto it = binding_sets_.find(interface_name);
1036 if (it == binding_sets_.end()) 1087 if (it == binding_sets_.end())
1037 return nullptr; 1088 return nullptr;
1038 return it->second; 1089 return it->second;
1039 } 1090 }
1040 1091
1092 std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
1093 if (browser_plugin_embedder_) {
1094 std::vector<WebContentsImpl*> inner_contents;
1095 GetBrowserContext()->GetGuestManager()->ForEachGuest(
1096 this, base::Bind(&GetInnerWebContentsHelper, &inner_contents));
1097 return inner_contents;
1098 }
1099
1100 return node_.inner_web_contents();
1101 }
1102
1103 std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
1104 std::vector<WebContentsImpl*> all_contents(1, this);
1105
1106 for (size_t i = 0; i != all_contents.size(); ++i) {
1107 for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
1108 all_contents.push_back(inner_contents);
1109 }
1110 }
1111
1112 return all_contents;
1113 }
1114
1041 void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) { 1115 void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
1042 SendPageMessage( 1116 SendPageMessage(
1043 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor)); 1117 new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
1044 } 1118 }
1045 1119
1046 void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) { 1120 void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) {
1047 if (GetView()) 1121 if (GetView())
1048 GetView()->GetScreenInfo(screen_info); 1122 GetView()->GetScreenInfo(screen_info);
1049 } 1123 }
1050 1124
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 // If the focused WebContents is showing an interstitial, return the 1926 // If the focused WebContents is showing an interstitial, return the
1853 // interstitial's widget. 1927 // interstitial's widget.
1854 if (focused_contents->ShowingInterstitialPage()) { 1928 if (focused_contents->ShowingInterstitialPage()) {
1855 return static_cast<RenderFrameHostImpl*>( 1929 return static_cast<RenderFrameHostImpl*>(
1856 focused_contents->GetRenderManager() 1930 focused_contents->GetRenderManager()
1857 ->interstitial_page() 1931 ->interstitial_page()
1858 ->GetMainFrame()) 1932 ->GetMainFrame())
1859 ->GetRenderWidgetHost(); 1933 ->GetRenderWidgetHost();
1860 } 1934 }
1861 1935
1862 FrameTreeNode* focused_frame = 1936 // If the focused WebContents is a guest WebContents, then get the focused
1863 focused_contents->frame_tree_.GetFocusedFrame(); 1937 // frame in the embedder WebContents instead.
1938 FrameTreeNode* focused_frame = nullptr;
1939 if (focused_contents->browser_plugin_guest_ &&
1940 !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
1941 focused_frame = frame_tree_.GetFocusedFrame();
1942 } else {
1943 focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
1944 }
1864 1945
1865 if (!focused_frame) 1946 if (!focused_frame)
1866 return receiving_widget; 1947 return receiving_widget;
1867 1948
1868 // The view may be null if a subframe's renderer process has crashed while 1949 // The view may be null if a subframe's renderer process has crashed while
1869 // the subframe has focus. Drop the event in that case. Do not give 1950 // the subframe has focus. Drop the event in that case. Do not give
1870 // it to the main frame, so that the user doesn't unexpectedly type into the 1951 // it to the main frame, so that the user doesn't unexpectedly type into the
1871 // wrong frame if a focused subframe renderer crashes while they type. 1952 // wrong frame if a focused subframe renderer crashes while they type.
1872 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); 1953 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1873 if (!view) 1954 if (!view)
(...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after
3316 3397
3317 void WebContentsImpl::Find(int request_id, 3398 void WebContentsImpl::Find(int request_id,
3318 const base::string16& search_text, 3399 const base::string16& search_text,
3319 const blink::WebFindOptions& options) { 3400 const blink::WebFindOptions& options) {
3320 // Cowardly refuse to search for no text. 3401 // Cowardly refuse to search for no text.
3321 if (search_text.empty()) { 3402 if (search_text.empty()) {
3322 NOTREACHED(); 3403 NOTREACHED();
3323 return; 3404 return;
3324 } 3405 }
3325 3406
3326 // See if a top level browser plugin handles the find request first.
3327 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
3328 if (browser_plugin_embedder_ &&
3329 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3330 return;
3331 }
3332
3333 GetOrCreateFindRequestManager()->Find(request_id, search_text, options); 3407 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
3334 } 3408 }
3335 3409
3336 void WebContentsImpl::StopFinding(StopFindAction action) { 3410 void WebContentsImpl::StopFinding(StopFindAction action) {
3337 // See if a top level browser plugin handles the stop finding request first. 3411 if (FindRequestManager* manager = GetFindRequestManager())
3338 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews. 3412 manager->StopFinding(action);
3339 if (browser_plugin_embedder_ &&
3340 browser_plugin_embedder_->StopFinding(action)) {
3341 return;
3342 }
3343
3344 GetOrCreateFindRequestManager()->StopFinding(action);
3345 } 3413 }
3346 3414
3347 bool WebContentsImpl::WasRecentlyAudible() { 3415 bool WebContentsImpl::WasRecentlyAudible() {
3348 return audio_stream_monitor_.WasRecentlyAudible() || 3416 return audio_stream_monitor_.WasRecentlyAudible() ||
3349 (browser_plugin_embedder_ && 3417 (browser_plugin_embedder_ &&
3350 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible()); 3418 browser_plugin_embedder_->WereAnyGuestsRecentlyAudible());
3351 } 3419 }
3352 3420
3353 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { 3421 void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3354 manifest_manager_host_->GetManifest(GetMainFrame(), callback); 3422 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 // written to this one field. 3857 // written to this one field.
3790 page_importance_signals_ = signals; 3858 page_importance_signals_ = signals;
3791 } 3859 }
3792 3860
3793 void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source, 3861 void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source,
3794 int request_id, 3862 int request_id,
3795 int number_of_matches, 3863 int number_of_matches,
3796 const gfx::Rect& selection_rect, 3864 const gfx::Rect& selection_rect,
3797 int active_match_ordinal, 3865 int active_match_ordinal,
3798 bool final_update) { 3866 bool final_update) {
3867 if (active_match_ordinal > 0)
3868 SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance());
3869
3799 // Forward the find reply to the FindRequestManager, along with the 3870 // Forward the find reply to the FindRequestManager, along with the
3800 // RenderFrameHost associated with the frame that the reply came from. 3871 // RenderFrameHost associated with the frame that the reply came from.
3801 GetOrCreateFindRequestManager()->OnFindReply( 3872 GetOrCreateFindRequestManager()->OnFindReply(
3802 source, request_id, number_of_matches, selection_rect, 3873 source, request_id, number_of_matches, selection_rect,
3803 active_match_ordinal, final_update); 3874 active_match_ordinal, final_update);
3804 } 3875 }
3805 3876
3806 #if defined(OS_ANDROID) 3877 #if defined(OS_ANDROID)
3807 void WebContentsImpl::OnFindMatchRectsReply( 3878 void WebContentsImpl::OnFindMatchRectsReply(
3808 RenderFrameHostImpl* source, 3879 RenderFrameHostImpl* source,
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 } 4864 }
4794 } 4865 }
4795 } 4866 }
4796 4867
4797 void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { 4868 void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() {
4798 // Only change focus if we are not currently focused. 4869 // Only change focus if we are not currently focused.
4799 WebContentsImpl* old_contents = GetFocusedWebContents(); 4870 WebContentsImpl* old_contents = GetFocusedWebContents();
4800 if (old_contents == this) 4871 if (old_contents == this)
4801 return; 4872 return;
4802 4873
4874 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
4875
4876 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_)
4877 return;
4878
4803 // Send a page level blur to the old contents so that it displays inactive UI 4879 // Send a page level blur to the old contents so that it displays inactive UI
4804 // and focus this contents to activate it. 4880 // and focus this contents to activate it.
4805 if (old_contents) 4881 if (old_contents)
4806 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); 4882 old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false);
4807 4883
4808 // Make sure the outer web contents knows our frame is focused. Otherwise, the 4884 // Make sure the outer web contents knows our frame is focused. Otherwise, the
4809 // outer renderer could have the element before or after the frame element 4885 // outer renderer could have the element before or after the frame element
4810 // focused which would return early without actually advancing focus. 4886 // focused which would return early without actually advancing focus.
4811 if (GetRenderManager()->GetProxyToOuterDelegate()) 4887 if (GetRenderManager()->GetProxyToOuterDelegate())
4812 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); 4888 GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame();
4813 4889
4814 if (ShowingInterstitialPage()) { 4890 if (ShowingInterstitialPage()) {
4815 static_cast<RenderFrameHostImpl*>( 4891 static_cast<RenderFrameHostImpl*>(
4816 GetRenderManager()->interstitial_page()->GetMainFrame()) 4892 GetRenderManager()->interstitial_page()->GetMainFrame())
4817 ->GetRenderWidgetHost() 4893 ->GetRenderWidgetHost()
4818 ->SetPageFocus(true); 4894 ->SetPageFocus(true);
4819 } else { 4895 } else {
4820 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); 4896 GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true);
4821 } 4897 }
4822 GetOutermostWebContents()->node_.SetFocusedWebContents(this);
4823 } 4898 }
4824 4899
4825 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, 4900 void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node,
4826 SiteInstance* source) { 4901 SiteInstance* source) {
4827 // The PDF plugin still runs as a BrowserPlugin and must go through the
4828 // input redirection mechanism. It must not become focused direcly.
4829 if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
4830 frame_tree_.SetFocusedFrame(node, source);
4831 return;
4832 }
4833
4834 SetAsFocusedWebContentsIfNecessary(); 4902 SetAsFocusedWebContentsIfNecessary();
4835
4836 frame_tree_.SetFocusedFrame(node, source); 4903 frame_tree_.SetFocusedFrame(node, source);
4837 } 4904 }
4838 4905
4839 void WebContentsImpl::OnFocusedElementChangedInFrame( 4906 void WebContentsImpl::OnFocusedElementChangedInFrame(
4840 RenderFrameHostImpl* frame, 4907 RenderFrameHostImpl* frame,
4841 const gfx::Rect& bounds_in_root_view) { 4908 const gfx::Rect& bounds_in_root_view) {
4842 RenderWidgetHostViewBase* root_view = 4909 RenderWidgetHostViewBase* root_view =
4843 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); 4910 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
4844 if (!root_view || !frame->GetView()) 4911 if (!root_view || !frame->GetView())
4845 return; 4912 return;
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
5268 ->CreateWebUIControllerForURL(web_ui.get(), url); 5335 ->CreateWebUIControllerForURL(web_ui.get(), url);
5269 if (controller) { 5336 if (controller) {
5270 web_ui->AddMessageHandler(base::MakeUnique<GenericHandler>()); 5337 web_ui->AddMessageHandler(base::MakeUnique<GenericHandler>());
5271 web_ui->SetController(controller); 5338 web_ui->SetController(controller);
5272 return web_ui; 5339 return web_ui;
5273 } 5340 }
5274 5341
5275 return nullptr; 5342 return nullptr;
5276 } 5343 }
5277 5344
5345 FindRequestManager* WebContentsImpl::GetFindRequestManager() {
5346 for (WebContentsImpl* contents = this; contents;
5347 contents = contents->GetOuterWebContents()) {
5348 if (contents->find_request_manager_)
5349 return contents->find_request_manager_.get();
5350 }
5351
5352 return nullptr;
5353 }
5354
5278 FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { 5355 FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
5279 // TODO(paulmeyer): This method will need to access (or potentially create) 5356 if (FindRequestManager* manager = GetFindRequestManager())
5280 // the FindRequestManager in the outermost WebContents once find-in-page 5357 return manager;
5281 // across GuestViews is implemented. 5358
5282 if (!find_request_manager_) 5359 // No existing FindRequestManager found, so one must be created.
5283 find_request_manager_.reset(new FindRequestManager(this)); 5360 find_request_manager_.reset(new FindRequestManager(this));
5361
5362 // Concurrent find sessions must not overlap, so destroy any existing
5363 // FindRequestManagers in any inner WebContentses.
5364 for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
5365 if (contents == this)
5366 continue;
5367 if (contents->find_request_manager_) {
5368 contents->find_request_manager_->StopFinding(
5369 content::STOP_FIND_ACTION_CLEAR_SELECTION);
5370 contents->find_request_manager_.release();
5371 }
5372 }
5284 5373
5285 return find_request_manager_.get(); 5374 return find_request_manager_.get();
5286 } 5375 }
5287 5376
5288 void WebContentsImpl::NotifyFindReply(int request_id, 5377 void WebContentsImpl::NotifyFindReply(int request_id,
5289 int number_of_matches, 5378 int number_of_matches,
5290 const gfx::Rect& selection_rect, 5379 const gfx::Rect& selection_rect,
5291 int active_match_ordinal, 5380 int active_match_ordinal,
5292 bool final_update) { 5381 bool final_update) {
5293 if (delegate_ && !is_being_destroyed_) { 5382 if (delegate_ && !is_being_destroyed_) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
5325 5414
5326 void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) { 5415 void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) {
5327 if (has_persistent_video_ == has_persistent_video) 5416 if (has_persistent_video_ == has_persistent_video)
5328 return; 5417 return;
5329 5418
5330 has_persistent_video_ = has_persistent_video; 5419 has_persistent_video_ = has_persistent_video;
5331 NotifyPreferencesChanged(); 5420 NotifyPreferencesChanged();
5332 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video); 5421 media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
5333 } 5422 }
5334 5423
5424 void WebContentsImpl::BrowserPluginGuestWillDetach() {
5425 WebContentsImpl* outermost = GetOutermostWebContents();
5426 if (this != outermost && ContainsOrIsFocusedWebContents())
5427 outermost->SetAsFocusedWebContentsIfNecessary();
5428 }
5429
5335 #if defined(OS_ANDROID) 5430 #if defined(OS_ANDROID)
5336 void WebContentsImpl::NotifyFindMatchRectsReply( 5431 void WebContentsImpl::NotifyFindMatchRectsReply(
5337 int version, 5432 int version,
5338 const std::vector<gfx::RectF>& rects, 5433 const std::vector<gfx::RectF>& rects,
5339 const gfx::RectF& active_rect) { 5434 const gfx::RectF& active_rect) {
5340 if (delegate_) 5435 if (delegate_)
5341 delegate_->FindMatchRectsReply(this, version, rects, active_rect); 5436 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
5342 } 5437 }
5343 #endif 5438 #endif
5344 5439
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
5472 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); 5567 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
5473 if (!render_view_host) 5568 if (!render_view_host)
5474 continue; 5569 continue;
5475 render_view_host_set.insert(render_view_host); 5570 render_view_host_set.insert(render_view_host);
5476 } 5571 }
5477 for (RenderViewHost* render_view_host : render_view_host_set) 5572 for (RenderViewHost* render_view_host : render_view_host_set)
5478 render_view_host->OnWebkitPreferencesChanged(); 5573 render_view_host->OnWebkitPreferencesChanged();
5479 } 5574 }
5480 5575
5481 } // namespace content 5576 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/browser_plugin_guest_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698