| 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 #ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ | 5 #ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ |
| 6 #define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ | 6 #define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" |
| 8 #include "v8/include/v8.h" | 9 #include "v8/include/v8.h" |
| 9 | 10 |
| 10 namespace extensions { | 11 namespace extensions { |
| 11 class ScriptContext; | 12 class ScriptContext; |
| 12 | 13 |
| 13 // A collection of safe builtin objects, in that they won't be tained by | 14 // A collection of safe builtin objects, in that they won't be tainted by |
| 14 // extensions overriding methods on them. | 15 // extensions overriding methods on them. |
| 15 class SafeBuiltins { | 16 class SafeBuiltins { |
| 16 public: | 17 public: |
| 17 // Creates the v8::Extension which manages SafeBuiltins instances. | 18 // Creates the v8::Extension which manages SafeBuiltins instances. |
| 18 static v8::Extension* CreateV8Extension(); | 19 static v8::Extension* CreateV8Extension(); |
| 19 | 20 |
| 20 explicit SafeBuiltins(ScriptContext* context); | 21 explicit SafeBuiltins(ScriptContext* context); |
| 21 | 22 ~SafeBuiltins(); |
| 22 virtual ~SafeBuiltins(); | |
| 23 | 23 |
| 24 // Each method returns an object with methods taken from their respective | 24 // Each method returns an object with methods taken from their respective |
| 25 // builtin object's prototype, adapted to automatically call() themselves. | 25 // builtin object's prototype, adapted to automatically call() themselves. |
| 26 // | 26 // |
| 27 // Examples: | 27 // Examples: |
| 28 // Array.prototype.forEach.call(...) becomes Array.forEach(...) | 28 // Array.prototype.forEach.call(...) becomes Array.forEach(...) |
| 29 // Object.prototype.toString.call(...) becomes Object.toString(...) | 29 // Object.prototype.toString.call(...) becomes Object.toString(...) |
| 30 // Object.keys.call(...) becomes Object.keys(...) | 30 // Object.keys.call(...) becomes Object.keys(...) |
| 31 v8::Local<v8::Object> GetArray() const; | 31 v8::Local<v8::Object> GetArray() const; |
| 32 v8::Local<v8::Object> GetFunction() const; | 32 v8::Local<v8::Object> GetFunction() const; |
| 33 v8::Local<v8::Object> GetJSON() const; | 33 v8::Local<v8::Object> GetJSON() const; |
| 34 // NOTE(kalman): VS2010 won't compile "GetObject", it mysteriously renames it | 34 // NOTE(kalman): VS2010 won't compile "GetObject", it mysteriously renames it |
| 35 // to "GetObjectW" - hence GetObjekt. Sorry. | 35 // to "GetObjectW" - hence GetObjekt. Sorry. |
| 36 v8::Local<v8::Object> GetObjekt() const; | 36 v8::Local<v8::Object> GetObjekt() const; |
| 37 v8::Local<v8::Object> GetRegExp() const; | 37 v8::Local<v8::Object> GetRegExp() const; |
| 38 v8::Local<v8::Object> GetString() const; | 38 v8::Local<v8::Object> GetString() const; |
| 39 v8::Local<v8::Object> GetError() const; | 39 v8::Local<v8::Object> GetError() const; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 ScriptContext* context_; | 42 ScriptContext* context_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(SafeBuiltins); |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 } // namespace extensions | 47 } // namespace extensions |
| 46 | 48 |
| 47 #endif // EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ | 49 #endif // EXTENSIONS_RENDERER_SAFE_BUILTINS_H_ |
| OLD | NEW |