| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "chrome/renderer/extensions/chrome_v8_extension_handler.h" | 11 #include "chrome/renderer/extensions/chrome_v8_extension_handler.h" |
| 12 #include "chrome/renderer/extensions/native_handler.h" | 12 #include "chrome/renderer/extensions/object_backed_native_handler.h" |
| 13 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 14 | 14 |
| 15 #include <map> | 15 #include <map> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class RenderView; | 21 class RenderView; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 class ChromeV8Context; | 25 class ChromeV8Context; |
| 26 class Dispatcher; | 26 class Dispatcher; |
| 27 class Extension; | 27 class Extension; |
| 28 | 28 |
| 29 // DEPRECATED. |
| 30 // |
| 29 // This is a base class for chrome extension bindings. Common features that | 31 // This is a base class for chrome extension bindings. Common features that |
| 30 // are shared by different modules go here. | 32 // are shared by different modules go here. |
| 31 // TODO(koz): Rename this to ExtensionNativeModule. | 33 // |
| 32 class ChromeV8Extension : public NativeHandler { | 34 // TODO(kalman): Delete this class entirely, it has no value anymore. |
| 35 // Custom bindings should extend ObjectBackedNativeHandler. |
| 36 class ChromeV8Extension : public ObjectBackedNativeHandler { |
| 33 public: | 37 public: |
| 34 typedef std::set<ChromeV8Extension*> InstanceSet; | 38 ChromeV8Extension(Dispatcher* dispatcher, v8::Handle<v8::Context> context); |
| 35 static const InstanceSet& GetAll(); | |
| 36 | |
| 37 explicit ChromeV8Extension(Dispatcher* dispatcher); | |
| 38 virtual ~ChromeV8Extension(); | 39 virtual ~ChromeV8Extension(); |
| 39 | 40 |
| 40 Dispatcher* dispatcher() { return dispatcher_; } | 41 Dispatcher* dispatcher() { return dispatcher_; } |
| 41 | 42 |
| 43 ChromeV8Context* GetContext(); |
| 44 |
| 45 // Shortcuts through to the context's render view and extension. |
| 46 content::RenderView* GetRenderView(); |
| 47 const Extension* GetExtensionForRenderView(); |
| 48 |
| 42 protected: | 49 protected: |
| 43 template<class T> | 50 template<class T> |
| 44 static T* GetFromArguments(const v8::Arguments& args) { | 51 static T* GetFromArguments(const v8::Arguments& args) { |
| 45 CHECK(!args.Data().IsEmpty()); | 52 CHECK(!args.Data().IsEmpty()); |
| 46 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value()); | 53 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value()); |
| 47 return result; | 54 return result; |
| 48 } | 55 } |
| 49 | 56 |
| 50 // Gets the render view for the current v8 context. | |
| 51 static content::RenderView* GetCurrentRenderView(); | |
| 52 | |
| 53 // Note: do not call this function before or during the chromeHidden.onLoad | |
| 54 // event dispatch. The URL might not have been committed yet and might not | |
| 55 // be an extension URL. | |
| 56 const Extension* GetExtensionForCurrentRenderView() const; | |
| 57 | |
| 58 // Returns the chromeHidden object for the current context. | |
| 59 static v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args); | |
| 60 | |
| 61 Dispatcher* dispatcher_; | 57 Dispatcher* dispatcher_; |
| 62 | 58 |
| 63 private: | 59 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); | 60 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); |
| 65 }; | 61 }; |
| 66 | 62 |
| 67 } // namespace extensions | 63 } // namespace extensions |
| 68 | 64 |
| 69 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ | 65 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ |
| OLD | NEW |