OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "v8/include/v8.h" |
| 11 |
| 12 #include <string> |
| 13 |
| 14 class Extension; |
| 15 class ExtensionDispatcher; |
| 16 class RenderView; |
| 17 |
| 18 namespace WebKit { |
| 19 class WebFrame; |
| 20 } |
| 21 |
| 22 // This is a base class for chrome extension bindings. Common features that |
| 23 // are shared by different modules go here. |
| 24 class ExtensionBase : public v8::Extension { |
| 25 public: |
| 26 static const char* GetStringResource(int resource_id); |
| 27 |
| 28 ExtensionBase(const char* name, |
| 29 const char* source, |
| 30 int dep_count, |
| 31 const char** deps, |
| 32 ExtensionDispatcher* extension_dispatcher) |
| 33 : v8::Extension(name, source, dep_count, deps), |
| 34 extension_dispatcher_(extension_dispatcher) { |
| 35 } |
| 36 |
| 37 // Derived classes should call this at the end of their implementation in |
| 38 // order to expose common native functions, like GetChromeHidden, to the |
| 39 // v8 extension. |
| 40 virtual v8::Handle<v8::FunctionTemplate> |
| 41 GetNativeFunction(v8::Handle<v8::String> name); |
| 42 |
| 43 // TODO(jstritar): Used for testing http://crbug.com/91582. Remove when done. |
| 44 ExtensionDispatcher* extension_dispatcher() { return extension_dispatcher_; } |
| 45 |
| 46 protected: |
| 47 template<class T> |
| 48 static T* GetFromArguments(const v8::Arguments& args) { |
| 49 CHECK(!args.Data().IsEmpty()); |
| 50 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value()); |
| 51 return result; |
| 52 } |
| 53 |
| 54 // Note: do not call this function before or during the chromeHidden.onLoad |
| 55 // event dispatch. The URL might not have been committed yet and might not |
| 56 // be an extension URL. |
| 57 const ::Extension* GetExtensionForCurrentContext() const; |
| 58 |
| 59 // Checks that the current context contains an extension that has permission |
| 60 // to execute the specified function. If it does not, a v8 exception is thrown |
| 61 // and the method returns false. Otherwise returns true. |
| 62 bool CheckPermissionForCurrentContext(const std::string& function_name) const; |
| 63 |
| 64 // Returns a hidden variable for use by the bindings that is unreachable |
| 65 // by the page. |
| 66 static v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args); |
| 67 |
| 68 ExtensionDispatcher* extension_dispatcher_; |
| 69 |
| 70 private: |
| 71 // Helper to print from bindings javascript. |
| 72 static v8::Handle<v8::Value> Print(const v8::Arguments& args); |
| 73 }; |
| 74 |
| 75 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_BASE_H_ |
OLD | NEW |