[email protected] | 5c969b8 | 2014-03-12 04:59:05 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef GIN_INTERCEPTOR_H_ |
| 6 | #define GIN_INTERCEPTOR_H_ |
| 7 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | 5c969b8 | 2014-03-12 04:59:05 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
avi | 90e658dd | 2015-12-21 07:16:19 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 5c969b8 | 2014-03-12 04:59:05 | [diff] [blame] | 14 | #include "gin/gin_export.h" |
| 15 | #include "v8/include/v8.h" |
| 16 | |
| 17 | namespace gin { |
| 18 | |
| 19 | class WrappableBase; |
| 20 | |
| 21 | // Base class for gin::Wrappable-derived classes that want to implement a |
| 22 | // property interceptor. |
| 23 | class GIN_EXPORT NamedPropertyInterceptor { |
| 24 | public: |
| 25 | NamedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base); |
| 26 | virtual ~NamedPropertyInterceptor(); |
| 27 | |
| 28 | virtual v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate, |
| 29 | const std::string& property); |
[email protected] | d656f87 | 2014-08-13 17:12:55 | [diff] [blame] | 30 | // Return true if the set was interecepted. |
| 31 | virtual bool SetNamedProperty(v8::Isolate* isolate, |
[email protected] | 5c969b8 | 2014-03-12 04:59:05 | [diff] [blame] | 32 | const std::string& property, |
| 33 | v8::Local<v8::Value> value); |
| 34 | virtual std::vector<std::string> EnumerateNamedProperties( |
| 35 | v8::Isolate* isolate); |
| 36 | |
| 37 | private: |
| 38 | v8::Isolate* isolate_; |
| 39 | WrappableBase* base_; |
| 40 | |
| 41 | DISALLOW_COPY_AND_ASSIGN(NamedPropertyInterceptor); |
| 42 | }; |
| 43 | |
| 44 | class GIN_EXPORT IndexedPropertyInterceptor { |
| 45 | public: |
| 46 | IndexedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base); |
| 47 | virtual ~IndexedPropertyInterceptor(); |
| 48 | |
| 49 | virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate, |
| 50 | uint32_t index); |
[email protected] | d656f87 | 2014-08-13 17:12:55 | [diff] [blame] | 51 | // Return true if the set was interecepted. |
| 52 | virtual bool SetIndexedProperty(v8::Isolate* isolate, |
[email protected] | 5c969b8 | 2014-03-12 04:59:05 | [diff] [blame] | 53 | uint32_t index, |
| 54 | v8::Local<v8::Value> value); |
| 55 | virtual std::vector<uint32_t> EnumerateIndexedProperties( |
| 56 | v8::Isolate* isolate); |
| 57 | |
| 58 | private: |
| 59 | v8::Isolate* isolate_; |
| 60 | WrappableBase* base_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(IndexedPropertyInterceptor); |
| 63 | }; |
| 64 | |
| 65 | } // namespace gin |
| 66 | |
| 67 | #endif // GIN_INTERCEPTOR_H_ |