| 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/renderer_host/dip_util.h" | 14 #include "content/browser/renderer_host/dip_util.h" |
| 15 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/browser/web_contents/web_contents_view.h" | 17 #include "content/browser/web_contents/web_contents_view.h" |
| 18 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 18 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 19 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
| 20 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 23 #include "content/public/browser/web_ui_controller.h" | 24 #include "content/public/browser/web_ui_controller.h" |
| 24 #include "content/public/browser/web_ui_message_handler.h" | 25 #include "content/public/browser/web_ui_message_handler.h" |
| 25 #include "content/public/common/bindings_policy.h" | 26 #include "content/public/common/bindings_policy.h" |
| 26 #include "content/public/common/content_client.h" | 27 #include "content/public/common/content_client.h" |
| 28 #include "content/public/common/url_constants.h" |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 | 31 |
| 30 const WebUI::TypeID WebUI::kNoWebUI = NULL; | 32 const WebUI::TypeID WebUI::kNoWebUI = NULL; |
| 31 | 33 |
| 32 // static | 34 // static |
| 33 base::string16 WebUI::GetJavascriptCall( | 35 base::string16 WebUI::GetJavascriptCall( |
| 34 const std::string& function_name, | 36 const std::string& function_name, |
| 35 const std::vector<const base::Value*>& arg_list) { | 37 const std::vector<const base::Value*>& arg_list) { |
| 36 base::string16 parameters; | 38 base::string16 parameters; |
| 37 std::string json; | 39 std::string json; |
| 38 for (size_t i = 0; i < arg_list.size(); ++i) { | 40 for (size_t i = 0; i < arg_list.size(); ++i) { |
| 39 if (i > 0) | 41 if (i > 0) |
| 40 parameters += base::char16(','); | 42 parameters += base::char16(','); |
| 41 | 43 |
| 42 base::JSONWriter::Write(*arg_list[i], &json); | 44 base::JSONWriter::Write(*arg_list[i], &json); |
| 43 parameters += base::UTF8ToUTF16(json); | 45 parameters += base::UTF8ToUTF16(json); |
| 44 } | 46 } |
| 45 return base::ASCIIToUTF16(function_name) + | 47 return base::ASCIIToUTF16(function_name) + |
| 46 base::char16('(') + parameters + base::char16(')') + base::char16(';'); | 48 base::char16('(') + parameters + base::char16(')') + base::char16(';'); |
| 47 } | 49 } |
| 48 | 50 |
| 51 // static |
| 52 bool WebUIImpl::RenderProcessAllowedForURL(RenderProcessHost* process, |
| 53 const GURL& url) { |
| 54 bool is_web_ui_scheme = |
| 55 url.SchemeIs(kChromeDevToolsScheme) || url.SchemeIs(kChromeUIScheme); |
| 56 std::vector<std::string> additional_schemes; |
| 57 GetContentClient()->browser()->GetAdditionalWebUISchemes(&additional_schemes); |
| 58 if (std::find(additional_schemes.begin(), additional_schemes.end(), |
| 59 url.scheme()) != additional_schemes.end()) { |
| 60 is_web_ui_scheme = true; |
| 61 } |
| 62 |
| 63 if (!is_web_ui_scheme) |
| 64 return true; |
| 65 |
| 66 if (!process) |
| 67 return false; |
| 68 |
| 69 StoragePartition* partition = BrowserContext::GetStoragePartitionForSite( |
| 70 process->GetBrowserContext(), url); |
| 71 return partition == process->GetStoragePartition(); |
| 72 } |
| 73 |
| 49 WebUIImpl::WebUIImpl(WebContents* contents, const std::string& frame_name) | 74 WebUIImpl::WebUIImpl(WebContents* contents, const std::string& frame_name) |
| 50 : link_transition_type_(ui::PAGE_TRANSITION_LINK), | 75 : link_transition_type_(ui::PAGE_TRANSITION_LINK), |
| 51 bindings_(BINDINGS_POLICY_WEB_UI), | 76 bindings_(BINDINGS_POLICY_WEB_UI), |
| 52 web_contents_(contents), | 77 web_contents_(contents), |
| 53 frame_name_(frame_name) { | 78 frame_name_(frame_name) { |
| 54 DCHECK(contents); | 79 DCHECK(contents); |
| 55 } | 80 } |
| 56 | 81 |
| 57 WebUIImpl::~WebUIImpl() { | 82 WebUIImpl::~WebUIImpl() { |
| 58 // Delete the controller first, since it may also be keeping a pointer to some | 83 // Delete the controller first, since it may also be keeping a pointer to some |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 294 } |
| 270 | 295 |
| 271 void WebUIImpl::AddToSetIfFrameNameMatches( | 296 void WebUIImpl::AddToSetIfFrameNameMatches( |
| 272 std::set<RenderFrameHost*>* frame_set, | 297 std::set<RenderFrameHost*>* frame_set, |
| 273 RenderFrameHost* host) { | 298 RenderFrameHost* host) { |
| 274 if (host->GetFrameName() == frame_name_) | 299 if (host->GetFrameName() == frame_name_) |
| 275 frame_set->insert(host); | 300 frame_set->insert(host); |
| 276 } | 301 } |
| 277 | 302 |
| 278 } // namespace content | 303 } // namespace content |
| OLD | NEW |