blob: bd265fb094de888b2b6bf1d1a92a84d28281e0f6 [file] [log] [blame]
[email protected]5c969b82014-03-12 04:59:051// 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
avi90e658dd2015-12-21 07:16:198#include <stdint.h>
9
[email protected]5c969b82014-03-12 04:59:0510#include <string>
11#include <vector>
12
avi90e658dd2015-12-21 07:16:1913#include "base/macros.h"
[email protected]5c969b82014-03-12 04:59:0514#include "gin/gin_export.h"
15#include "v8/include/v8.h"
16
17namespace gin {
18
19class WrappableBase;
20
21// Base class for gin::Wrappable-derived classes that want to implement a
22// property interceptor.
23class 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]d656f872014-08-13 17:12:5530 // Return true if the set was interecepted.
31 virtual bool SetNamedProperty(v8::Isolate* isolate,
[email protected]5c969b82014-03-12 04:59:0532 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
44class 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]d656f872014-08-13 17:12:5551 // Return true if the set was interecepted.
52 virtual bool SetIndexedProperty(v8::Isolate* isolate,
[email protected]5c969b82014-03-12 04:59:0553 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_