blob: 3c8db44037271e413b0f4e42a0b625cca1e5c2d5 [file] [log] [blame]
[email protected]f55c90ee62014-04-12 00:50:031// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]295890bd2013-06-15 10:52:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f55c90ee62014-04-12 00:50:035#ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
6#define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
[email protected]295890bd2013-06-15 10:52:457
8#include "v8/include/v8.h"
9
10namespace extensions {
[email protected]f55c90ee62014-04-12 00:50:0311class ScriptContext;
[email protected]295890bd2013-06-15 10:52:4512
13// A collection of safe builtin objects, in that they won't be tained by
14// extensions overriding methods on them.
15class SafeBuiltins {
16 public:
17 // Creates the v8::Extension which manages SafeBuiltins instances.
18 static v8::Extension* CreateV8Extension();
19
[email protected]f55c90ee62014-04-12 00:50:0320 explicit SafeBuiltins(ScriptContext* context);
[email protected]295890bd2013-06-15 10:52:4521
22 virtual ~SafeBuiltins();
23
24 // Each method returns an object with methods taken from their respective
25 // builtin object's prototype, adapted to automatically call() themselves.
26 //
27 // Examples:
28 // Array.prototype.forEach.call(...) becomes Array.forEach(...)
29 // Object.prototype.toString.call(...) becomes Object.toString(...)
30 // Object.keys.call(...) becomes Object.keys(...)
31 v8::Local<v8::Object> GetArray() const;
32 v8::Local<v8::Object> GetFunction() const;
[email protected]53229732013-06-21 02:56:0233 v8::Local<v8::Object> GetJSON() const;
[email protected]295890bd2013-06-15 10:52:4534 // NOTE(kalman): VS2010 won't compile "GetObject", it mysteriously renames it
35 // to "GetObjectW" - hence GetObjekt. Sorry.
36 v8::Local<v8::Object> GetObjekt() const;
[email protected]31bbfd72013-06-22 02:35:5437 v8::Local<v8::Object> GetRegExp() const;
38 v8::Local<v8::Object> GetString() const;
[email protected]295890bd2013-06-15 10:52:4539
40 private:
[email protected]f55c90ee62014-04-12 00:50:0341 ScriptContext* context_;
[email protected]295890bd2013-06-15 10:52:4542};
43
[email protected]f55c90ee62014-04-12 00:50:0344} // namespace extensions
[email protected]295890bd2013-06-15 10:52:4545
[email protected]f55c90ee62014-04-12 00:50:0346#endif // EXTENSIONS_RENDERER_SAFE_BUILTINS_H_