Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / gin / interceptor.h
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
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "gin/gin_export.h"
13 #include "v8/include/v8.h"
14
15 namespace gin {
16
17 class WrappableBase;
18
19 // Base class for gin::Wrappable-derived classes that want to implement a
20 // property interceptor.
21 class GIN_EXPORT NamedPropertyInterceptor {
22  public:
23   NamedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
24   virtual ~NamedPropertyInterceptor();
25
26   virtual v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate,
27                                                 const std::string& property);
28   // Return true if the set was interecepted.
29   virtual bool SetNamedProperty(v8::Isolate* isolate,
30                                 const std::string& property,
31                                 v8::Local<v8::Value> value);
32   virtual std::vector<std::string> EnumerateNamedProperties(
33       v8::Isolate* isolate);
34
35  private:
36   v8::Isolate* isolate_;
37   WrappableBase* base_;
38
39   DISALLOW_COPY_AND_ASSIGN(NamedPropertyInterceptor);
40 };
41
42 class GIN_EXPORT IndexedPropertyInterceptor {
43  public:
44   IndexedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
45   virtual ~IndexedPropertyInterceptor();
46
47   virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
48                                                   uint32_t index);
49   // Return true if the set was interecepted.
50   virtual bool SetIndexedProperty(v8::Isolate* isolate,
51                                   uint32_t index,
52                                   v8::Local<v8::Value> value);
53   virtual std::vector<uint32_t> EnumerateIndexedProperties(
54       v8::Isolate* isolate);
55
56  private:
57   v8::Isolate* isolate_;
58   WrappableBase* base_;
59
60   DISALLOW_COPY_AND_ASSIGN(IndexedPropertyInterceptor);
61 };
62
63 }  // namespace gin
64
65 #endif  // GIN_INTERCEPTOR_H_