Revert of Enable find-in-page across GuestViews. (patchset #6 id:270001 of https://codereview.chromium.org/2700613003/ )
Reason for revert:
Suspected cause of crashes: https://bugs.chromium.org/p/chromium/issues/detail?id=709478
Original issue's description:
> Enable find-in-page across GuestViews.
>
> This patch enables find-in-page to work across GuestViews, including
> WebViews and PDFs, as explained in this design doc:
> https://drive.google.com/open?id=1tl1L99oTgqQxolV7jRvDLzFQ9K251rQ_E16mOwB-BuU.
> Specifically, this will allow find-in-page to work with embedded PDFs,
> which has been a (very) longstanding bug in Chrome.
>
> This patch also cleans up code that was previously used to route find
> requests to the guest WebContents in the case of full-page GuestViews.
> This shortcut is no longer needed, as this patch implements a more general
> solution to traversing frames across all WebContentses during a find
> session.
>
> BUG=55421
>
> Review-Url: https://codereview.chromium.org/2700613003
> Cr-Commit-Position: refs/heads/master@{#462327}
> Committed: https://chromium.googlesource.com/chromium/src/+/9dedb9f32fca0666761f83c405c5959c148ea751
[email protected],[email protected],[email protected]
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=55421
Review-Url: https://codereview.chromium.org/2808923003
Cr-Commit-Position: refs/heads/master@{#463379}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 7f45ab8..f406d84 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -257,14 +257,6 @@
AXTreeSnapshotCallback callback_;
};
-// Helper for GetInnerWebContents().
-bool GetInnerWebContentsHelper(
- std::vector<WebContentsImpl*>* all_guest_contents,
- WebContents* guest_contents) {
- all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents));
- return false;
-}
-
} // namespace
WebContents* WebContents::Create(const WebContents::CreateParams& params) {
@@ -389,9 +381,6 @@
WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
if (OuterContentsFrameTreeNode())
OuterContentsFrameTreeNode()->RemoveObserver(this);
-
- if (outer_web_contents_)
- outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_);
}
void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
@@ -402,25 +391,9 @@
outer_contents_frame_tree_node_id_ =
outer_contents_frame->frame_tree_node()->frame_tree_node_id();
- outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_);
outer_contents_frame->frame_tree_node()->AddObserver(this);
}
-void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents(
- WebContentsImpl* inner_web_contents) {
- inner_web_contents_.push_back(inner_web_contents);
-}
-
-void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents(
- WebContentsImpl* inner_web_contents) {
- DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(),
- inner_web_contents) != inner_web_contents_.end());
- inner_web_contents_.erase(
- std::remove(inner_web_contents_.begin(), inner_web_contents_.end(),
- inner_web_contents),
- inner_web_contents_.end());
-}
-
FrameTreeNode*
WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const {
return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_);
@@ -441,23 +414,6 @@
focused_web_contents_ = web_contents;
}
-WebContentsImpl*
-WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame(
- const FrameTreeNode* frame) {
- auto ftn_id = frame->frame_tree_node_id();
- for (WebContentsImpl* contents : inner_web_contents_) {
- if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) {
- return contents;
- }
- }
- return nullptr;
-}
-
-const std::vector<WebContentsImpl*>&
-WebContentsImpl::WebContentsTreeNode::inner_web_contents() const {
- return inner_web_contents_;
-}
-
// WebContentsImpl -------------------------------------------------------------
WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
@@ -708,7 +664,7 @@
// static
WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
- const FrameTreeNode* frame_tree_node) {
+ FrameTreeNode* frame_tree_node) {
return static_cast<WebContentsImpl*>(
WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
}
@@ -725,13 +681,6 @@
return WebContents::FromRenderFrameHost(render_frame_host);
}
-// static
-WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode(
- const FrameTreeNode* frame_tree_node) {
- return WebContentsImpl::FromFrameTreeNode(frame_tree_node)
- ->node_.GetInnerWebContentsInFrame(frame_tree_node);
-}
-
RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
return GetRenderManager();
}
@@ -1089,29 +1038,6 @@
return it->second;
}
-std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() {
- if (browser_plugin_embedder_) {
- std::vector<WebContentsImpl*> inner_contents;
- GetBrowserContext()->GetGuestManager()->ForEachGuest(
- this, base::Bind(&GetInnerWebContentsHelper, &inner_contents));
- return inner_contents;
- }
-
- return node_.inner_web_contents();
-}
-
-std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() {
- std::vector<WebContentsImpl*> all_contents(1, this);
-
- for (size_t i = 0; i != all_contents.size(); ++i) {
- for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) {
- all_contents.push_back(inner_contents);
- }
- }
-
- return all_contents;
-}
-
void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) {
SendPageMessage(
new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor));
@@ -1925,16 +1851,8 @@
if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
return receiving_widget;
- // If the focused WebContents is a guest WebContents, then get the focused
- // frame in the embedder WebContents instead.
- FrameTreeNode* focused_frame = nullptr;
- WebContentsImpl* focused_contents = GetFocusedWebContents();
- if (focused_contents->browser_plugin_guest_ &&
- !GuestMode::IsCrossProcessFrameGuest(focused_contents)) {
- focused_frame = frame_tree_.GetFocusedFrame();
- } else {
- focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
- }
+ FrameTreeNode* focused_frame =
+ GetFocusedWebContents()->frame_tree_.GetFocusedFrame();
if (!focused_frame)
return receiving_widget;
@@ -3360,12 +3278,25 @@
return;
}
+ // See if a top level browser plugin handles the find request first.
+ // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
+ if (browser_plugin_embedder_ &&
+ browser_plugin_embedder_->Find(request_id, search_text, options)) {
+ return;
+ }
+
GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
}
void WebContentsImpl::StopFinding(StopFindAction action) {
- if (FindRequestManager* manager = GetFindRequestManager())
- manager->StopFinding(action);
+ // See if a top level browser plugin handles the stop finding request first.
+ // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
+ if (browser_plugin_embedder_ &&
+ browser_plugin_embedder_->StopFinding(action)) {
+ return;
+ }
+
+ GetOrCreateFindRequestManager()->StopFinding(action);
}
bool WebContentsImpl::WasRecentlyAudible() {
@@ -4845,8 +4776,6 @@
// input redirection mechanism. It must not become focused direcly.
if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) {
frame_tree_.SetFocusedFrame(node, source);
- if (GetFocusedWebContents() != this)
- GetOutermostWebContents()->node_.SetFocusedWebContents(this);
return;
}
@@ -5294,34 +5223,12 @@
return nullptr;
}
-FindRequestManager* WebContentsImpl::GetFindRequestManager() {
- for (WebContentsImpl* contents = this; contents;
- contents = contents->GetOuterWebContents()) {
- if (contents->find_request_manager_)
- return contents->find_request_manager_.get();
- }
-
- return nullptr;
-}
-
FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
- if (FindRequestManager* manager = GetFindRequestManager())
- return manager;
-
- // No existing FindRequestManager found, so one must be created.
- find_request_manager_.reset(new FindRequestManager(this));
-
- // Concurrent find sessions must not overlap, so destroy any existing
- // FindRequestManagers in any inner WebContentses.
- for (WebContentsImpl* contents : GetWebContentsAndAllInner()) {
- if (contents == this)
- continue;
- if (contents->find_request_manager_) {
- contents->find_request_manager_->StopFinding(
- content::STOP_FIND_ACTION_CLEAR_SELECTION);
- contents->find_request_manager_.release();
- }
- }
+ // TODO(paulmeyer): This method will need to access (or potentially create)
+ // the FindRequestManager in the outermost WebContents once find-in-page
+ // across GuestViews is implemented.
+ if (!find_request_manager_)
+ find_request_manager_.reset(new FindRequestManager(this));
return find_request_manager_.get();
}
@@ -5373,12 +5280,6 @@
media_web_contents_observer()->RequestPersistentVideo(has_persistent_video);
}
-void WebContentsImpl::BrowserPluginGuestWillDestroy() {
- WebContentsImpl* outermost = GetOutermostWebContents();
- if (this != outermost && ContainsOrIsFocusedWebContents())
- outermost->SetAsFocusedWebContentsIfNecessary();
-}
-
#if defined(OS_ANDROID)
void WebContentsImpl::NotifyFindMatchRectsReply(
int version,