FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
IDispatchAPI.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Nov 4, 2009
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_IDISPATCHAPI
17 #define H_IDISPATCHAPI
18 
19 #include "win_common.h"
20 #include "JSAPI.h"
21 #include "JSObject.h"
22 #include "ActiveXBrowserHost.h"
23 #include <atlctl.h>
24 #include <vector>
25 #include <string>
26 
27 namespace FB { namespace ActiveX {
33  class IDispatchAPI :
34  public FB::JSObject
35  {
36  public:
37  static boost::shared_ptr<IDispatchAPI> create(IDispatch *, const ActiveXBrowserHostPtr&);
38  virtual ~IDispatchAPI(void);
39 
40  void *getEventId() const
41  {
42  IDispatchSRef sref(m_obj.lock());
43  if (sref) return (void*)sref->getPtr();
44  else return NULL;
45  }
46  void *getEventContext() const {
47  if (m_browser.expired()) return NULL;
48  else return getHost()->getContextID();
49  };
50  IDispatch* getIDispatch() const {
51  IDispatchSRef sref(m_obj);
52  return sref->getPtr();
53  }
54  bool isValid() { return !m_obj.expired() && !m_browser.expired(); }
55  virtual bool supportsOptimizedCalls() const { return true; }
56  virtual void callMultipleFunctions(const std::string& name, const FB::VariantList& args,
57  const std::vector<JSObjectPtr>& direct,
58  const std::vector<JSObjectPtr>& ifaces);
59  void invalidate() { m_obj.reset(); }
60 
61  // Enumerate members
62  void getMemberNames(std::vector<std::string> &nameVector) const;
63  size_t getMemberCount() const;
64 
65  protected:
66  ActiveXBrowserHostPtr getHost() const {
67  ActiveXBrowserHostPtr ptr(m_browser.lock());
68  if (!ptr) {
69  throw std::bad_cast();
70  }
71  return ptr;
72  }
73  ActiveXBrowserHostWeakPtr m_browser;
74  IDispatchWRef m_obj;
75  bool is_JSAPI;
76  FB::JSAPIWeakPtr inner;
77 
78  protected:
79  DISPID getIDForName(const std::wstring& name) const;
80 
81  public:
82  bool HasMethod(const std::string& methodName) const;
83  bool HasMethod(const std::wstring& methodName) const;
84  bool HasProperty(const std::string& propertyName) const;
85  bool HasProperty(const std::wstring& propertyName) const;
86  bool HasProperty(int idx) const;
87 
88  FB::variant GetProperty(const std::string& propertyName);
89  void SetProperty(const std::string& propertyName, const FB::variant& value);
90  void RemoveProperty(const std::string& propertyName);
91  FB::variant GetProperty(int idx);
92  void SetProperty(int idx, const FB::variant& value);
93  void RemoveProperty(int idx);
94 
95  FB::variant Invoke(const std::string& methodName, const FB::VariantList& args);
96  FB::variant Construct(const FB::VariantList& args);
97 
98  public:
99  virtual FB::JSAPIPtr getJSAPI() const;
100 
101  private:
102  IDispatchAPI(IDispatch *, const ActiveXBrowserHostPtr&);
103  };
104 } }
105 #endif
106 
void SetProperty(const std::string &propertyName, const FB::variant &value)
Sets the value of a property.
Provide a JSObject implementation to wrap a IDispatch ActiveX object.
Definition: IDispatchAPI.h:33
bool HasProperty(const std::string &propertyName) const
Query if 'propertyName' is a valid property.
Wraps a Javascript Object.
Definition: JSObject.h:46
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
virtual FB::JSAPIPtr getJSAPI() const
Get associated FB::JSAPI.
void invalidate()
Invalidates this object.
Definition: IDispatchAPI.h:59
std::vector< variant > VariantList
Defines an alias representing list of variants.
Definition: APITypes.h:64
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
void getMemberNames(std::vector< std::string > &nameVector) const
Called by the browser to enumerate the members of this JSAPI object.
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
size_t getMemberCount() const
Gets the member count.
FB::variant GetProperty(const std::string &propertyName)
Gets a property value.
void RemoveProperty(const std::string &propertyName)
Removes a property.
bool HasMethod(const std::string &methodName) const
Query if the JSAPI object has the 'methodName' method.