| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/safe_builtins.h" | 5 #include "extensions/renderer/safe_builtins.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
| 11 #include "extensions/renderer/v8_helpers.h" | 11 #include "extensions/renderer/v8_helpers.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 using namespace v8_helpers; | 15 using namespace v8_helpers; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kClassName[] = "extensions::SafeBuiltins"; | 19 const char kClassName[] = "extensions::SafeBuiltins"; |
| 20 | 20 |
| 21 // Documentation for makeCallback in the JavaScript, out here to reduce the | 21 // Documentation for makeCallback in the JavaScript, out here to reduce the |
| 22 // (very small) amount of effort that the v8 parser needs to do: | 22 // (very small) amount of effort that the v8 parser needs to do: |
| 23 // | 23 // |
| 24 // Returns a new object with every function on |obj| configured to call()\n" | 24 // Returns a new object with every function on |obj| configured to call() |
| 25 // itself with the given arguments.\n" | 25 // itself with the given arguments. |
| 26 // E.g. given\n" | 26 // E.g. given |
| 27 // var result = makeCallable(Function.prototype)\n" | 27 // var result = makeCallable(Function.prototype) |
| 28 // |result| will be a object including 'bind' such that\n" | 28 // |result| will be a object including 'bind' such that |
| 29 // result.bind(foo, 1, 2, 3);\n" | 29 // result.bind(foo, 1, 2, 3); |
| 30 // is equivalent to Function.prototype.bind.call(foo, 1, 2, 3), and so on.\n" | 30 // is equivalent to Function.prototype.bind.call(foo, 1, 2, 3), and so on. |
| 31 // This is a convenient way to save functions that user scripts may clobber.\n" | 31 // This is a convenient way to save functions that user scripts may clobber. |
| 32 const char kScript[] = | 32 const char kScript[] = |
| 33 "(function() {\n" | 33 "(function() {\n" |
| 34 "'use strict';\n" | 34 "'use strict';\n" |
| 35 "native function Apply();\n" | 35 "native function Apply();\n" |
| 36 "native function Save();\n" | 36 "native function Save();\n" |
| 37 "\n" | 37 "\n" |
| 38 "// Used in the callback implementation, could potentially be clobbered.\n" | 38 "// Used in the callback implementation, could potentially be clobbered.\n" |
| 39 "function makeCallable(obj, target, isStatic, propertyNames) {\n" | 39 "function makeCallable(obj, target, isStatic, propertyNames) {\n" |
| 40 " propertyNames.forEach(function(propertyName) {\n" | 40 " propertyNames.forEach(function(propertyName) {\n" |
| 41 " var property = obj[propertyName];\n" | 41 " var property = obj[propertyName];\n" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 248 |
| 249 v8::Local<v8::Object> SafeBuiltins::GetString() const { | 249 v8::Local<v8::Object> SafeBuiltins::GetString() const { |
| 250 return Load("String", context_->v8_context()); | 250 return Load("String", context_->v8_context()); |
| 251 } | 251 } |
| 252 | 252 |
| 253 v8::Local<v8::Object> SafeBuiltins::GetError() const { | 253 v8::Local<v8::Object> SafeBuiltins::GetError() const { |
| 254 return Load("Error", context_->v8_context()); | 254 return Load("Error", context_->v8_context()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 } // namespace extensions | 257 } // namespace extensions |
| OLD | NEW |