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

Side by Side 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, 7 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 | « content/browser/webui/web_ui_impl.h ('k') | content/public/test/browser_test_utils.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 (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/webui/web_ui_impl.h" 5 #include "content/browser/webui/web_ui_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/debug/dump_without_crashing.h" 9 #include "base/debug/dump_without_crashing.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/browser/child_process_security_policy_impl.h" 13 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/frame_host/frame_tree.h"
15 #include "content/browser/frame_host/frame_tree_node.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h"
14 #include "content/browser/renderer_host/dip_util.h" 17 #include "content/browser/renderer_host/dip_util.h"
15 #include "content/browser/renderer_host/render_process_host_impl.h" 18 #include "content/browser/renderer_host/render_process_host_impl.h"
16 #include "content/browser/web_contents/web_contents_impl.h" 19 #include "content/browser/web_contents/web_contents_impl.h"
17 #include "content/browser/web_contents/web_contents_view.h" 20 #include "content/browser/web_contents/web_contents_view.h"
18 #include "content/browser/webui/web_ui_controller_factory_registry.h" 21 #include "content/browser/webui/web_ui_controller_factory_registry.h"
19 #include "content/common/view_messages.h" 22 #include "content/common/view_messages.h"
20 #include "content/public/browser/content_browser_client.h" 23 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/navigation_handle.h" 24 #include "content/public/browser/navigation_handle.h"
22 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (!CanCallJavascript()) 276 if (!CanCallJavascript())
274 return; 277 return;
275 278
276 TargetFrame()->ExecuteJavaScript(javascript); 279 TargetFrame()->ExecuteJavaScript(javascript);
277 } 280 }
278 281
279 RenderFrameHost* WebUIImpl::TargetFrame() { 282 RenderFrameHost* WebUIImpl::TargetFrame() {
280 if (frame_name_.empty()) 283 if (frame_name_.empty())
281 return web_contents_->GetMainFrame(); 284 return web_contents_->GetMainFrame();
282 285
283 std::set<RenderFrameHost*> frame_set; 286 FrameTreeNode* frame_tree_node = static_cast<WebContentsImpl*>(web_contents_)
284 web_contents_->ForEachFrame(base::Bind(&WebUIImpl::AddToSetIfFrameNameMatches, 287 ->GetFrameTree()
285 base::Unretained(this), 288 ->FindByName(frame_name_);
286 &frame_set)); 289 if (frame_tree_node)
287 290 return frame_tree_node->current_frame_host();
288 // It happens that some sub-pages attempt to send JavaScript messages before 291 return nullptr;
289 // their frames are loaded.
290 DCHECK_GE(1U, frame_set.size());
291 if (frame_set.empty())
292 return NULL;
293 return *frame_set.begin();
294 }
295
296 void WebUIImpl::AddToSetIfFrameNameMatches(
297 std::set<RenderFrameHost*>* frame_set,
298 RenderFrameHost* host) {
299 if (host->GetFrameName() == frame_name_)
300 frame_set->insert(host);
301 } 292 }
302 293
303 void WebUIImpl::DisallowJavascriptOnAllHandlers() { 294 void WebUIImpl::DisallowJavascriptOnAllHandlers() {
304 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_) 295 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_)
305 handler->DisallowJavascript(); 296 handler->DisallowJavascript();
306 } 297 }
307 298
308 } // namespace content 299 } // namespace content
OLDNEW
« 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