| 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" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 bool WebUIImpl::CanCallJavascript() { | 147 bool WebUIImpl::CanCallJavascript() { |
| 148 RenderFrameHost* target_frame = TargetFrame(); | 148 RenderFrameHost* target_frame = TargetFrame(); |
| 149 return target_frame && | 149 return target_frame && |
| 150 (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 150 (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 151 target_frame->GetProcess()->GetID()) || | 151 target_frame->GetProcess()->GetID()) || |
| 152 // It's possible to load about:blank in a Web UI renderer. | 152 // It's possible to load about:blank in a Web UI renderer. |
| 153 // See http://crbug.com/42547 | 153 // See http://crbug.com/42547 |
| 154 target_frame->GetLastCommittedURL().spec() == url::kAboutBlankURL); | 154 target_frame->GetLastCommittedURL().spec() == url::kAboutBlankURL); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void WebUIImpl::CallJavascriptFunction(const std::string& function_name) { | 157 void WebUIImpl::CallJavascriptFunctionUnsafe(const std::string& function_name) { |
| 158 DCHECK(base::IsStringASCII(function_name)); | 158 DCHECK(base::IsStringASCII(function_name)); |
| 159 base::string16 javascript = base::ASCIIToUTF16(function_name + "();"); | 159 base::string16 javascript = base::ASCIIToUTF16(function_name + "();"); |
| 160 ExecuteJavascript(javascript); | 160 ExecuteJavascript(javascript); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void WebUIImpl::CallJavascriptFunction(const std::string& function_name, | 163 void WebUIImpl::CallJavascriptFunctionUnsafe(const std::string& function_name, |
| 164 const base::Value& arg) { | 164 const base::Value& arg) { |
| 165 DCHECK(base::IsStringASCII(function_name)); | 165 DCHECK(base::IsStringASCII(function_name)); |
| 166 std::vector<const base::Value*> args; | 166 std::vector<const base::Value*> args; |
| 167 args.push_back(&arg); | 167 args.push_back(&arg); |
| 168 ExecuteJavascript(GetJavascriptCall(function_name, args)); | 168 ExecuteJavascript(GetJavascriptCall(function_name, args)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void WebUIImpl::CallJavascriptFunction( | 171 void WebUIImpl::CallJavascriptFunctionUnsafe(const std::string& function_name, |
| 172 const std::string& function_name, | 172 const base::Value& arg1, |
| 173 const base::Value& arg1, const base::Value& arg2) { | 173 const base::Value& arg2) { |
| 174 DCHECK(base::IsStringASCII(function_name)); | 174 DCHECK(base::IsStringASCII(function_name)); |
| 175 std::vector<const base::Value*> args; | 175 std::vector<const base::Value*> args; |
| 176 args.push_back(&arg1); | 176 args.push_back(&arg1); |
| 177 args.push_back(&arg2); | 177 args.push_back(&arg2); |
| 178 ExecuteJavascript(GetJavascriptCall(function_name, args)); | 178 ExecuteJavascript(GetJavascriptCall(function_name, args)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void WebUIImpl::CallJavascriptFunction( | 181 void WebUIImpl::CallJavascriptFunctionUnsafe(const std::string& function_name, |
| 182 const std::string& function_name, | 182 const base::Value& arg1, |
| 183 const base::Value& arg1, const base::Value& arg2, const base::Value& arg3) { | 183 const base::Value& arg2, |
| 184 const base::Value& arg3) { |
| 184 DCHECK(base::IsStringASCII(function_name)); | 185 DCHECK(base::IsStringASCII(function_name)); |
| 185 std::vector<const base::Value*> args; | 186 std::vector<const base::Value*> args; |
| 186 args.push_back(&arg1); | 187 args.push_back(&arg1); |
| 187 args.push_back(&arg2); | 188 args.push_back(&arg2); |
| 188 args.push_back(&arg3); | 189 args.push_back(&arg3); |
| 189 ExecuteJavascript(GetJavascriptCall(function_name, args)); | 190 ExecuteJavascript(GetJavascriptCall(function_name, args)); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void WebUIImpl::CallJavascriptFunction( | 193 void WebUIImpl::CallJavascriptFunctionUnsafe(const std::string& function_name, |
| 193 const std::string& function_name, | 194 const base::Value& arg1, |
| 194 const base::Value& arg1, | 195 const base::Value& arg2, |
| 195 const base::Value& arg2, | 196 const base::Value& arg3, |
| 196 const base::Value& arg3, | 197 const base::Value& arg4) { |
| 197 const base::Value& arg4) { | |
| 198 DCHECK(base::IsStringASCII(function_name)); | 198 DCHECK(base::IsStringASCII(function_name)); |
| 199 std::vector<const base::Value*> args; | 199 std::vector<const base::Value*> args; |
| 200 args.push_back(&arg1); | 200 args.push_back(&arg1); |
| 201 args.push_back(&arg2); | 201 args.push_back(&arg2); |
| 202 args.push_back(&arg3); | 202 args.push_back(&arg3); |
| 203 args.push_back(&arg4); | 203 args.push_back(&arg4); |
| 204 ExecuteJavascript(GetJavascriptCall(function_name, args)); | 204 ExecuteJavascript(GetJavascriptCall(function_name, args)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void WebUIImpl::CallJavascriptFunction( | 207 void WebUIImpl::CallJavascriptFunctionUnsafe( |
| 208 const std::string& function_name, | 208 const std::string& function_name, |
| 209 const std::vector<const base::Value*>& args) { | 209 const std::vector<const base::Value*>& args) { |
| 210 DCHECK(base::IsStringASCII(function_name)); | 210 DCHECK(base::IsStringASCII(function_name)); |
| 211 ExecuteJavascript(GetJavascriptCall(function_name, args)); | 211 ExecuteJavascript(GetJavascriptCall(function_name, args)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void WebUIImpl::RegisterMessageCallback(const std::string &message, | 214 void WebUIImpl::RegisterMessageCallback(const std::string &message, |
| 215 const MessageCallback& callback) { | 215 const MessageCallback& callback) { |
| 216 message_callbacks_.insert(std::make_pair(message, callback)); | 216 message_callbacks_.insert(std::make_pair(message, callback)); |
| 217 } | 217 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 void WebUIImpl::AddToSetIfFrameNameMatches( | 271 void WebUIImpl::AddToSetIfFrameNameMatches( |
| 272 std::set<RenderFrameHost*>* frame_set, | 272 std::set<RenderFrameHost*>* frame_set, |
| 273 RenderFrameHost* host) { | 273 RenderFrameHost* host) { |
| 274 if (host->GetFrameName() == frame_name_) | 274 if (host->GetFrameName() == frame_name_) |
| 275 frame_set->insert(host); | 275 frame_set->insert(host); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace content | 278 } // namespace content |
| OLD | NEW |