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

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: Making the return statement in FrameMatchingPredicate safe against null dereferencing. 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
« no previous file with comments | « content/browser/webui/web_ui_impl.h ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..74a4876ae7a1626344bc817283eb49845663f82c 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,12 @@ 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);
+ FrameTreeNode* frame_tree_node = static_cast<WebContentsImpl*>(web_contents_)
+ ->GetFrameTree()
+ ->FindByName(frame_name_);
+ if (frame_tree_node)
+ return frame_tree_node->current_frame_host();
+ return nullptr;
}
void WebUIImpl::DisallowJavascriptOnAllHandlers() {
« no previous file with comments | « content/browser/webui/web_ui_impl.h ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698