| 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/object_backed_native_handler.h" | 12 #include "chrome/renderer/extensions/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 // | |
| 31 // This is a base class for chrome extension bindings. Common features that | 29 // This is a base class for chrome extension bindings. Common features that |
| 32 // are shared by different modules go here. | 30 // are shared by different modules go here. |
| 33 // | 31 // TODO(koz): Rename this to ExtensionNativeModule. |
| 34 // TODO(kalman): Delete this class entirely, it has no value anymore. | 32 class ChromeV8Extension : public NativeHandler { |
| 35 // Custom bindings should extend ObjectBackedNativeHandler. | |
| 36 class ChromeV8Extension : public ObjectBackedNativeHandler { | |
| 37 public: | 33 public: |
| 38 // EXTRA DEPRECATED. DO NOT USE THIS CONSTRUCTOR. It doesn't work in subtle | 34 typedef std::set<ChromeV8Extension*> InstanceSet; |
| 39 // cases. | 35 static const InstanceSet& GetAll(); |
| 36 |
| 40 explicit ChromeV8Extension(Dispatcher* dispatcher); | 37 explicit ChromeV8Extension(Dispatcher* dispatcher); |
| 41 | |
| 42 ChromeV8Extension(Dispatcher* dispatcher, v8::Handle<v8::Context> context); | |
| 43 virtual ~ChromeV8Extension(); | 38 virtual ~ChromeV8Extension(); |
| 44 | 39 |
| 45 Dispatcher* dispatcher() { return dispatcher_; } | 40 Dispatcher* dispatcher() { return dispatcher_; } |
| 46 | 41 |
| 47 ChromeV8Context* GetContext(); | |
| 48 | |
| 49 // Shortcuts through to the context's render view and extension. | |
| 50 content::RenderView* GetRenderView(); | |
| 51 const Extension* GetExtensionForRenderView(); | |
| 52 | |
| 53 protected: | 42 protected: |
| 54 template<class T> | 43 template<class T> |
| 55 static T* GetFromArguments(const v8::Arguments& args) { | 44 static T* GetFromArguments(const v8::Arguments& args) { |
| 56 CHECK(!args.Data().IsEmpty()); | 45 CHECK(!args.Data().IsEmpty()); |
| 57 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value()); | 46 T* result = static_cast<T*>(args.Data().As<v8::External>()->Value()); |
| 58 return result; | 47 return result; |
| 59 } | 48 } |
| 60 | 49 |
| 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_; | 61 Dispatcher* dispatcher_; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); | 64 DISALLOW_COPY_AND_ASSIGN(ChromeV8Extension); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace extensions | 67 } // namespace extensions |
| 68 | 68 |
| 69 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ | 69 #endif // CHROME_RENDERER_EXTENSIONS_CHROME_V8_EXTENSION_H_ |
| OLD | NEW |