OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
11 #include "chrome/renderer/extensions/chrome_v8_extension_handler.h" | 11 #include "chrome/renderer/extensions/chrome_v8_extension_handler.h" |
12 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <set> | 15 #include <set> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 class ChromeV8Context; | 18 class ChromeV8Context; |
19 class Extension; | 19 class Extension; |
20 class ExtensionDispatcher; | 20 class ExtensionDispatcher; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 class RenderView; | 23 class RenderView; |
24 } | 24 } |
25 | 25 |
26 // This is a base class for chrome extension bindings. Common features that | 26 // This is a base class for chrome extension bindings. Common features that |
27 // are shared by different modules go here. | 27 // are shared by different modules go here. |
28 // | |
29 // TODO(aa): Remove the extension-system specific bits of this and move to | |
30 // renderer/, or even to renderer/bindings and use DEPS to enforce separation | |
31 // from extension system. | |
32 // | |
33 // TODO(aa): Add unit testing for this class. | |
34 class ChromeV8Extension : public v8::Extension { | 28 class ChromeV8Extension : public v8::Extension { |
35 public: | 29 public: |
36 typedef std::set<ChromeV8Extension*> InstanceSet; | 30 typedef std::set<ChromeV8Extension*> InstanceSet; |
37 static const InstanceSet& GetAll(); | 31 static const InstanceSet& GetAll(); |
38 | 32 |
39 ChromeV8Extension(const char* name, | 33 ChromeV8Extension(const char* name, |
40 int resource_id, | 34 int resource_id, |
41 ExtensionDispatcher* extension_dispatcher); | 35 ExtensionDispatcher* extension_dispatcher); |
42 ChromeV8Extension(const char* name, | 36 ChromeV8Extension(const char* name, |
43 int resource_id, | 37 int resource_id, |
44 int dependency_count, | 38 int dependency_count, |
45 const char** dependencies, | 39 const char** dependencies, |
46 ExtensionDispatcher* extension_dispatcher); | 40 ExtensionDispatcher* extension_dispatcher); |
47 virtual ~ChromeV8Extension(); | 41 virtual ~ChromeV8Extension(); |
48 | 42 |
49 ExtensionDispatcher* extension_dispatcher() { return extension_dispatcher_; } | 43 ExtensionDispatcher* extension_dispatcher() { return extension_dispatcher_; } |
50 | 44 |
51 // Returns a hidden variable for use by the bindings in the specified context | |
52 // that is unreachable by the page for the current context. | |
53 static v8::Handle<v8::Value> GetChromeHidden( | |
54 const v8::Handle<v8::Context>& context); | |
55 | |
56 void ContextWillBeReleased(ChromeV8Context* context); | 45 void ContextWillBeReleased(ChromeV8Context* context); |
57 | 46 |
58 // Derived classes should call this at the end of their implementation in | 47 // Derived classes should call this at the end of their implementation in |
59 // order to expose common native functions, like GetChromeHidden, to the | 48 // order to expose common native functions, like GetChromeHidden, to the |
60 // v8 extension. | 49 // v8 extension. |
61 virtual v8::Handle<v8::FunctionTemplate> | 50 virtual v8::Handle<v8::FunctionTemplate> |
62 GetNativeFunction(v8::Handle<v8::String> name) OVERRIDE; | 51 GetNativeFunction(v8::Handle<v8::String> name) OVERRIDE; |
63 | 52 |
64 protected: | 53 protected: |
65 template<class T> | 54 template<class T> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 95 |
107 // Map of all current handlers. | 96 // Map of all current handlers. |
108 typedef std::map<ChromeV8Context*, | 97 typedef std::map<ChromeV8Context*, |
109 linked_ptr<ChromeV8ExtensionHandler> > HandlerMap; | 98 linked_ptr<ChromeV8ExtensionHandler> > HandlerMap; |
110 HandlerMap handlers_; | 99 HandlerMap handlers_; |
111 | 100 |
112 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); | 101 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); |
113 }; | 102 }; |
114 | 103 |
115 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ | 104 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ |
OLD | NEW |