1// Copyright (c) 2010 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 PPAPI_CPP_SCRIPTABLE_OBJECT_DEPRECATED_H_
6#define PPAPI_CPP_SCRIPTABLE_OBJECT_DEPRECATED_H_
7
8#include <vector>
9
10struct PPP_Class_Deprecated;
11
12namespace pp {
13class Var;
14class VarPrivate;
15}
16
17namespace pp {
18
19namespace deprecated {
20
21// This class allows you to implement objects accessible by JavaScript. Derive
22// from this class and override the virtual functions you support. pp::Var has
23// a constructor that takes a pointer to a ScriptableObject for when you want
24// to convert your custom object to a var.
25//
26// Please see the PPB_Core C interface for more information on how to implement
27// these functions. These functions are the backend implementation for the
28// functions in PPB_Var, which contains further information.
29//
30// Please see:
31//   http://code.google.com/p/ppapi/wiki/InterfacingWithJavaScript
32// for a general overview of interfacing with JavaScript.
33class ScriptableObject {
34 public:
35  ScriptableObject() {}
36  virtual ~ScriptableObject() {}
37
38  // The default implementation returns false.
39  virtual bool HasProperty(const Var& name, Var* exception);
40
41  // The default implementation returns false.
42  virtual bool HasMethod(const Var& name, Var* exception);
43
44  // The default implementation sets an exception that the property doesn't
45  // exist.
46  virtual Var GetProperty(const Var& name, Var* exception);
47
48  // The default implementation returns no properties.
49  virtual void GetAllPropertyNames(std::vector<Var>* properties,
50                                   Var* exception);
51
52  // The default implementation sets an exception that the property can not be
53  // set.
54  virtual void SetProperty(const Var& name,
55                           const Var& value,
56                           Var* exception);
57
58  // The default implementation sets an exception that the method does not
59  // exist.
60  virtual void RemoveProperty(const Var& name,
61                              Var* exception);
62
63  // TODO(brettw) need native array access here.
64
65  // method_name is guaranteed to be either a string or an integer.
66  //
67  // The default implementation sets an exception that the method does not
68  // exist.
69  virtual Var Call(const Var& method_name,
70                   const std::vector<Var>& args,
71                   Var* exception);
72
73  // The default implementation sets an exception that the method does not
74  // exist.
75  virtual Var Construct(const std::vector<Var>& args,
76                        Var* exception);
77
78 private:
79  friend class ::pp::Var;
80  friend class ::pp::VarPrivate;
81  static const PPP_Class_Deprecated* GetClass();
82
83  // Unimplemented, copy and assignment is not allowed.
84  ScriptableObject(const ScriptableObject& other);
85  ScriptableObject& operator=(const ScriptableObject& other);
86};
87
88}  // namespace deprecated
89
90}  // namespace pp
91
92#endif  // PPAPI_CPP_SCRIPTABLE_OBJECT_DEPRECATED_H_
93
94