Fix invalid cast in AppCacheGroup::AddUpdateObserver.
[chromium-blink-merge.git] / extensions / renderer / safe_builtins.h
blob0da56bb3385714c9a8c31904101165232e0c586d
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
6 #define EXTENSIONS_RENDERER_SAFE_BUILTINS_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "v8/include/v8.h"
12 namespace extensions {
13 class ScriptContext;
15 // Saves a subset of the JavaScript builtin types, so that they can be used
16 // later without extensions tampering with them.
17 class SafeBuiltins {
18 public:
19 ~SafeBuiltins();
21 // Creates and immediately installs a SafeBuiltins instance in |context|.
22 static scoped_ptr<SafeBuiltins> Install(ScriptContext* context);
24 // Each method returns an object with methods taken from their respective
25 // builtin object's prototype, adapted to automatically call() themselves.
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;
33 v8::Local<v8::Object> GetJSON() const;
34 // NOTE(kalman): VS2010 won't compile "GetObject", it mysteriously renames it
35 // to "GetObjectW" - hence GetObjekt. Sorry.
36 v8::Local<v8::Object> GetObjekt() const;
37 v8::Local<v8::Object> GetRegExp() const;
38 v8::Local<v8::Object> GetString() const;
39 v8::Local<v8::Object> GetError() const;
41 private:
42 explicit SafeBuiltins(ScriptContext* context);
44 v8::Local<v8::Object> Load(const char* name) const;
46 ScriptContext* context_;
48 DISALLOW_COPY_AND_ASSIGN(SafeBuiltins);
51 } // namespace extensions
53 #endif // EXTENSIONS_RENDERER_SAFE_BUILTINS_H_