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