| 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_NATIVE_HANDLER_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| 6 #define CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| 7 | 7 |
| 8 #include "v8/include/v8.h" | 8 #include "v8/include/v8.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 | 11 |
| 12 // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem | 12 // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem |
| 13 // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to | 13 // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to |
| 14 // a single v8::Context, this implies that NativeHandlers will also be tied to | 14 // a single v8::Context, this implies that NativeHandlers will also be tied to |
| 15 // a single v8::Context. | 15 // a single v8::Context. |
| 16 // TODO(koz): Rename this to NativeJavaScriptModule. | 16 // TODO(koz): Rename this to NativeJavaScriptModule. |
| 17 class NativeHandler { | 17 class NativeHandler { |
| 18 public: | 18 public: |
| 19 virtual ~NativeHandler() {} | 19 NativeHandler(); |
| 20 virtual ~NativeHandler(); |
| 20 | 21 |
| 21 // Create a new instance of the object this handler specifies. | 22 // Create a new instance of the object this handler specifies. |
| 22 virtual v8::Handle<v8::Object> NewInstance() = 0; | 23 virtual v8::Handle<v8::Object> NewInstance() = 0; |
| 24 |
| 25 // Invalidate this object so it cannot be used any more. This is needed |
| 26 // because it's possible for this to outlive its owner context. Invalidate |
| 27 // must be called before this happens. |
| 28 // |
| 29 // Subclasses should override to invalidate their own V8 state. If they do |
| 30 // they must call their superclass' Invalidate(). |
| 31 virtual void Invalidate(); |
| 32 |
| 33 protected: |
| 34 // Allow subclasses to query valid state. |
| 35 bool is_valid() { return is_valid_; } |
| 36 |
| 37 private: |
| 38 bool is_valid_; |
| 23 }; | 39 }; |
| 24 | 40 |
| 25 } // extensions | 41 } // extensions |
| 26 | 42 |
| 27 #endif // CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ | 43 #endif // CHROME_RENDERER_EXTENSIONS_NATIVE_HANDLER_H_ |
| OLD | NEW |