[email protected] | b8ce52f | 2014-04-04 22:45:15 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | b8ce52f | 2014-04-04 22:45:15 | [diff] [blame] | 5 | #ifndef EXTENSIONS_RENDERER_NATIVE_HANDLER_H_ |
6 | #define EXTENSIONS_RENDERER_NATIVE_HANDLER_H_ | ||||
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 7 | |
avi | 2d124c0 | 2015-12-23 06:36:42 | [diff] [blame] | 8 | #include "base/macros.h" |
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 9 | #include "v8/include/v8.h" |
10 | |||||
[email protected] | 3c6babd | 2012-08-28 03:17:29 | [diff] [blame] | 11 | namespace extensions { |
12 | |||||
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 13 | // NativeHandlers are intended to be used with a ModuleSystem. The ModuleSystem |
14 | // will assume ownership of the NativeHandler, and as a ModuleSystem is tied to | ||||
15 | // a single v8::Context, this implies that NativeHandlers will also be tied to | ||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 16 | // a single v8::Context. |
[email protected] | ecde191 | 2012-03-16 06:25:31 | [diff] [blame] | 17 | // TODO(koz): Rename this to NativeJavaScriptModule. |
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 18 | class NativeHandler { |
19 | public: | ||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 20 | NativeHandler(); |
[email protected] | e3e77872 | 2013-03-03 23:28:03 | [diff] [blame] | 21 | virtual ~NativeHandler(); |
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 22 | |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 23 | // Initializes the native handler. |
24 | virtual void Initialize() = 0; | ||||
25 | |||||
Devlin Cronin | 6fed7f0 | 2018-01-31 22:38:20 | [diff] [blame] | 26 | // Returns true if the handler has been initialized. |
27 | virtual bool IsInitialized() = 0; | ||||
28 | |||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 29 | // Create a new instance of the object this handler specifies. |
tfarina | f85316f | 2015-04-29 17:03:40 | [diff] [blame] | 30 | virtual v8::Local<v8::Object> NewInstance() = 0; |
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 31 | |
32 | // Invalidate this object so it cannot be used any more. This is needed | ||||
33 | // because it's possible for this to outlive its owner context. Invalidate | ||||
34 | // must be called before this happens. | ||||
35 | // | ||||
36 | // Subclasses should override to invalidate their own V8 state. If they do | ||||
37 | // they must call their superclass' Invalidate(). | ||||
kalman | b0c1c50 | 2015-04-15 00:25:06 | [diff] [blame] | 38 | // |
39 | // Invalidate() will be called on destruction, if it hasn't already been. | ||||
40 | // Subclasses don't need to do it themselves. | ||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 41 | virtual void Invalidate(); |
[email protected] | e3e77872 | 2013-03-03 23:28:03 | [diff] [blame] | 42 | |
43 | protected: | ||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 44 | // Allow subclasses to query valid state. |
45 | bool is_valid() { return is_valid_; } | ||||
[email protected] | e3e77872 | 2013-03-03 23:28:03 | [diff] [blame] | 46 | |
47 | private: | ||||
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 48 | bool is_valid_; |
[email protected] | 630b9deb | 2013-03-07 18:38:34 | [diff] [blame] | 49 | |
50 | DISALLOW_COPY_AND_ASSIGN(NativeHandler); | ||||
[email protected] | 58e1045 | 2012-02-22 03:34:45 | [diff] [blame] | 51 | }; |
52 | |||||
[email protected] | b8ce52f | 2014-04-04 22:45:15 | [diff] [blame] | 53 | } // namespace extensions |
[email protected] | 3c6babd | 2012-08-28 03:17:29 | [diff] [blame] | 54 | |
[email protected] | b8ce52f | 2014-04-04 22:45:15 | [diff] [blame] | 55 | #endif // EXTENSIONS_RENDERER_NATIVE_HANDLER_H_ |