FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
JSAPIProxy.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Nov 23, 2010
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2009 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 
15 #pragma once
16 #ifndef H_FB_JSAPIProxy
17 #define H_FB_JSAPIProxy
18 
19 #include "APITypes.h"
20 #include "JSAPIImpl.h"
21 
22 namespace FB
23 {
24  FB_FORWARD_PTR(JSAPIProxy);
45  class JSAPIProxy : public JSAPIImpl
46  {
47  protected:
48  JSAPIProxy(const FB::JSAPIPtr &inner);
49  JSAPIProxy(const FB::JSAPIWeakPtr &inner);
50 
51  JSAPIProxy(const SecurityZone& securityLevel, const FB::JSAPIPtr &inner);
52  JSAPIProxy(const SecurityZone& securityLevel, const FB::JSAPIWeakPtr &inner);
53 
54  public:
55  virtual ~JSAPIProxy(void);
56 
67  static JSAPIProxyPtr create(const FB::JSAPIPtr &inner);
69  static JSAPIProxyPtr create(const SecurityZone& securityLevel, const FB::JSAPIPtr &inner);
70 
83  static JSAPIProxyPtr create(const FB::JSAPIWeakPtr &inner);
85  static JSAPIProxyPtr create(const SecurityZone& securityLevel, const FB::JSAPIWeakPtr &inner);
86 
97  inline bool isExpired() const {
98  return m_apiWeak.expired();
99  }
100 
109  void changeObject(const FB::JSAPIPtr &inner);
118  void changeObject(const FB::JSAPIWeakPtr &inner);
119  void reset();
120 
121  inline FB::JSAPIPtr getAPI() const {
122  FB::JSAPIPtr tmp = m_apiWeak.lock();
123  if (tmp)
124  return tmp;
125  throw FB::object_invalidated();
126  }
127 
128  protected:
129  mutable FB::JSAPIPtr m_api;
130  mutable FB::JSAPIWeakPtr m_apiWeak;
131 
132  public:
133 
134  void invalidate();
135  virtual void getMemberNames(std::vector<std::string> &nameVector) const;
136  virtual size_t getMemberCount() const;
137 
138  virtual bool HasMethod(const std::wstring& methodName) const;
139  virtual bool HasMethod(const std::string& methodName) const;
140  virtual bool HasProperty(const std::wstring& propertyName) const;
141  virtual bool HasProperty(const std::string& propertyName) const;
142  virtual bool HasProperty(int idx) const;
143 
144  virtual variant GetProperty(const std::wstring& propertyName);
145  virtual variant GetProperty(const std::string& propertyName);
146 
147  virtual void SetProperty(const std::wstring& propertyName, const variant& value);
148  virtual void SetProperty(const std::string& propertyName, const variant& value);
149 
150  virtual void RemoveProperty(const std::wstring& propertyName);
151  virtual void RemoveProperty(const std::string& propertyName);
152 
153  virtual variant GetProperty(int idx);
154  virtual void SetProperty(int idx, const variant& value);
155  virtual void RemoveProperty(int idx);
156 
157  virtual variant Invoke(const std::wstring& methodName, const std::vector<variant>& args);
158  virtual variant Invoke(const std::string& methodName, const std::vector<variant>& args);
159 
160  virtual variant Construct(const std::vector<variant>& args);
161  };
162 
163 };
164 #endif
165 
JavaScript API base class implementation – provides basic functionality for C++ JSAPI objects...
Definition: JSAPIImpl.h:49
static JSAPIProxyPtr create(const FB::JSAPIPtr &inner)
Creates a JSAPIProxy that holds a shared_ptr reference to the JSAPI object provided.
Definition: JSAPIProxy.cpp:20
virtual variant Invoke(const std::wstring &methodName, const std::vector< variant > &args)
Definition: JSAPIProxy.cpp:241
Thrown by a JSAPI object when a call is made on it after the object has been invalidated.
Definition: JSExceptions.h:69
JavaScript API Wrapper – this can wrap any type of JSAPI object and be passed back to any browser tha...
Definition: JSAPIProxy.h:45
boost::weak_ptr< FB::JSAPI > JSAPIWeakPtr
Defines an alias for a JSAPI weak_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:88
virtual void RemoveProperty(const std::wstring &propertyName)
Definition: JSAPIProxy.cpp:223
virtual size_t getMemberCount() const
Gets the member count.
Definition: JSAPIProxy.cpp:143
int SecurityZone
Used to set a SecurityZone for a method or property – used by JSAPIAuto.
Definition: APITypes.h:275
virtual bool HasProperty(const std::wstring &propertyName) const
Definition: JSAPIProxy.cpp:161
virtual void SetProperty(const std::wstring &propertyName, const variant &value)
Definition: JSAPIProxy.cpp:205
boost::shared_ptr< FB::JSAPI > JSAPIPtr
Defines an alias for a JSAPI shared_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:94
bool isExpired() const
Returns true if the weak_ptr this contains doesn't point to anything.
Definition: JSAPIProxy.h:97
virtual bool HasMethod(const std::wstring &methodName) const
Definition: JSAPIProxy.cpp:149
virtual variant Construct(const std::vector< variant > &args)
Called by the browser to construct the JSAPI object.
Definition: JSAPIProxy.cpp:253
virtual variant GetProperty(const std::wstring &propertyName)
Definition: JSAPIProxy.cpp:183
void changeObject(const FB::JSAPIPtr &inner)
Changes the wrapped JSAPIPtr to the given one.
Definition: JSAPIProxy.cpp:108
void invalidate()
Invalidates this object.
Definition: JSAPIProxy.cpp:128
virtual void getMemberNames(std::vector< std::string > &nameVector) const
Called by the browser to enumerate the members of this JSAPI object.
Definition: JSAPIProxy.cpp:137