Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 return 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 ->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
| |
| 287 | |
| 288 // It happens that some sub-pages attempt to send JavaScript messages before | |
| 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 } | 290 } |
| 302 | 291 |
| 303 void WebUIImpl::DisallowJavascriptOnAllHandlers() { | 292 void WebUIImpl::DisallowJavascriptOnAllHandlers() { |
| 304 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_) | 293 for (const std::unique_ptr<WebUIMessageHandler>& handler : handlers_) |
| 305 handler->DisallowJavascript(); | 294 handler->DisallowJavascript(); |
| 306 } | 295 } |
| 307 | 296 |
| 308 } // namespace content | 297 } // namespace content |
| OLD | NEW |