summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions/chrome_v8_extension.h
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer/extensions/chrome_v8_extension.h')
-rw-r--r--chrome/renderer/extensions/chrome_v8_extension.h41
1 files changed, 37 insertions, 4 deletions
diff --git a/chrome/renderer/extensions/chrome_v8_extension.h b/chrome/renderer/extensions/chrome_v8_extension.h
index 7e4b8e8..511273f 100644
--- a/chrome/renderer/extensions/chrome_v8_extension.h
+++ b/chrome/renderer/extensions/chrome_v8_extension.h
@@ -10,7 +10,6 @@
#include "base/memory/linked_ptr.h"
#include "base/string_piece.h"
#include "chrome/renderer/extensions/chrome_v8_extension_handler.h"
-#include "chrome/renderer/native_handler.h"
#include "v8/include/v8.h"
#include <map>
@@ -27,17 +26,31 @@ class RenderView;
// This is a base class for chrome extension bindings. Common features that
// are shared by different modules go here.
-// TODO(koz): Rename this to ExtensionNativeModule.
-class ChromeV8Extension : public NativeHandler {
+class ChromeV8Extension : public v8::Extension {
public:
typedef std::set<ChromeV8Extension*> InstanceSet;
static const InstanceSet& GetAll();
- explicit ChromeV8Extension(ExtensionDispatcher* extension_dispatcher);
+ ChromeV8Extension(const char* name,
+ int resource_id,
+ ExtensionDispatcher* extension_dispatcher);
+ ChromeV8Extension(const char* name,
+ int resource_id,
+ int dependency_count,
+ const char** dependencies,
+ ExtensionDispatcher* extension_dispatcher);
virtual ~ChromeV8Extension();
ExtensionDispatcher* extension_dispatcher() { return extension_dispatcher_; }
+ void ContextWillBeReleased(ChromeV8Context* context);
+
+ // Derived classes should call this at the end of their implementation in
+ // order to expose common native functions, like GetChromeHidden, to the
+ // v8 extension.
+ virtual v8::Handle<v8::FunctionTemplate>
+ GetNativeFunction(v8::Handle<v8::String> name) OVERRIDE;
+
protected:
template<class T>
static T* GetFromArguments(const v8::Arguments& args) {
@@ -60,12 +73,32 @@ class ChromeV8Extension : public NativeHandler {
bool CheckCurrentContextAccessToExtensionAPI(
const std::string& function_name) const;
+ // Create a handler for |context|. If a subclass of ChromeV8Extension wishes
+ // to support handlers, it should override this.
+ virtual ChromeV8ExtensionHandler* CreateHandler(ChromeV8Context* context);
+
// Returns the chromeHidden object for the current context.
static v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args);
ExtensionDispatcher* extension_dispatcher_;
private:
+ static base::StringPiece GetStringResource(int resource_id);
+
+ // Helper to print from bindings javascript.
+ static v8::Handle<v8::Value> Print(const v8::Arguments& args);
+
+ // Handle a native function call from JavaScript.
+ static v8::Handle<v8::Value> HandleNativeFunction(const v8::Arguments& args);
+
+ // Get the handler instance for |context|, or NULL if no such context exists.
+ ChromeV8ExtensionHandler* GetHandler(ChromeV8Context* context) const;
+
+ // Map of all current handlers.
+ typedef std::map<ChromeV8Context*,
+ linked_ptr<ChromeV8ExtensionHandler> > HandlerMap;
+ HandlerMap handlers_;
+
DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension);
};