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

Unified Diff: content/browser/webui/web_ui_impl.cc

Issue 2849603005: Do not reinvent the wheel / use content APIs to find a frame by name. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/webui/web_ui_impl.cc
diff --git a/content/browser/webui/web_ui_impl.cc b/content/browser/webui/web_ui_impl.cc
index c024bc82b8b20a0ef06f6a5aa0061f25bdf23437..c5e8a7a215e77094699ee597d1986d846e705437 100644
--- a/content/browser/webui/web_ui_impl.cc
+++ b/content/browser/webui/web_ui_impl.cc
@@ -11,6 +11,9 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "content/browser/child_process_security_policy_impl.h"
+#include "content/browser/frame_host/frame_tree.h"
+#include "content/browser/frame_host/frame_tree_node.h"
+#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
@@ -280,24 +283,10 @@ RenderFrameHost* WebUIImpl::TargetFrame() {
if (frame_name_.empty())
return web_contents_->GetMainFrame();
- std::set<RenderFrameHost*> frame_set;
- web_contents_->ForEachFrame(base::Bind(&WebUIImpl::AddToSetIfFrameNameMatches,
- base::Unretained(this),
- &frame_set));
-
- // It happens that some sub-pages attempt to send JavaScript messages before
- // their frames are loaded.
- DCHECK_GE(1U, frame_set.size());
- if (frame_set.empty())
- return NULL;
- return *frame_set.begin();
-}
-
-void WebUIImpl::AddToSetIfFrameNameMatches(
- std::set<RenderFrameHost*>* frame_set,
- RenderFrameHost* host) {
- if (host->GetFrameName() == frame_name_)
- frame_set->insert(host);
+ return static_cast<WebContentsImpl*>(web_contents_)
+ ->GetFrameTree()
+ ->FindByName(frame_name_)
+ ->current_frame_host();
ncarter (slow) 2017/04/27 22:03:42 We need to handle a null return value of FindByNam
Łukasz Anforowicz 2017/04/27 22:59:28 Ooops. Done. (I first wrote returning of FindByN
}
void WebUIImpl::DisallowJavascriptOnAllHandlers() {

Powered by Google App Engine
This is Rietveld 408576698