OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/extensions/bindings_utils.h" | 5 #include "chrome/renderer/extensions/bindings_utils.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/stringprintf.h" |
8 #include "base/string_split.h" | 9 #include "base/string_split.h" |
9 #include "base/string_util.h" | |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_set.h" | 11 #include "chrome/common/extensions/extension_set.h" |
12 #include "chrome/renderer/extensions/extension_dispatcher.h" | 12 #include "chrome/renderer/extensions/extension_dispatcher.h" |
13 #include "content/renderer/render_view.h" | 13 #include "content/renderer/render_view.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
17 | 17 |
18 using WebKit::WebFrame; | 18 using WebKit::WebFrame; |
19 using WebKit::WebView; | 19 using WebKit::WebView; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 const std::string& function_name) const { | 64 const std::string& function_name) const { |
65 const ::Extension* extension = GetExtensionForCurrentContext(); | 65 const ::Extension* extension = GetExtensionForCurrentContext(); |
66 if (extension && | 66 if (extension && |
67 extension_dispatcher_->IsExtensionActive(extension->id()) && | 67 extension_dispatcher_->IsExtensionActive(extension->id()) && |
68 extension->HasApiPermission(function_name)) | 68 extension->HasApiPermission(function_name)) |
69 return true; | 69 return true; |
70 | 70 |
71 static const char kMessage[] = | 71 static const char kMessage[] = |
72 "You do not have permission to use '%s'. Be sure to declare" | 72 "You do not have permission to use '%s'. Be sure to declare" |
73 " in your manifest what permissions you need."; | 73 " in your manifest what permissions you need."; |
74 std::string error_msg = StringPrintf(kMessage, function_name.c_str()); | 74 std::string error_msg = base::StringPrintf(kMessage, function_name.c_str()); |
75 | 75 |
76 v8::ThrowException(v8::Exception::Error(v8::String::New(error_msg.c_str()))); | 76 v8::ThrowException(v8::Exception::Error(v8::String::New(error_msg.c_str()))); |
77 return false; | 77 return false; |
78 } | 78 } |
79 | 79 |
80 v8::Handle<v8::FunctionTemplate> | 80 v8::Handle<v8::FunctionTemplate> |
81 ExtensionBase::GetNativeFunction(v8::Handle<v8::String> name) { | 81 ExtensionBase::GetNativeFunction(v8::Handle<v8::String> name) { |
82 if (name->Equals(v8::String::New("GetChromeHidden"))) { | 82 if (name->Equals(v8::String::New("GetChromeHidden"))) { |
83 return v8::FunctionTemplate::New(GetChromeHidden); | 83 return v8::FunctionTemplate::New(GetChromeHidden); |
84 } | 84 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 212 } |
213 | 213 |
214 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 214 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
215 if (!function.IsEmpty()) | 215 if (!function.IsEmpty()) |
216 return function->Call(v8::Object::New(), argc, argv); | 216 return function->Call(v8::Object::New(), argc, argv); |
217 | 217 |
218 return v8::Undefined(); | 218 return v8::Undefined(); |
219 } | 219 } |
220 | 220 |
221 } // namespace bindings_utils | 221 } // namespace bindings_utils |
OLD | NEW |