FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
NPObjectAPI.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Oct 16, 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_NPOBJECTAPI
17 #define H_NPOBJECTAPI
18 
19 #include "NpapiTypes.h"
20 #include "npruntime.h"
21 #include "JSAPI.h"
22 #include "JSObject.h"
23 #include "NpapiBrowserHost.h"
24 
25 namespace FB { namespace Npapi {
26 
32  class NPObjectAPI :
33  public FB::JSObject
34  {
35  public:
36  NPObjectAPI(NPObject *, const NpapiBrowserHostPtr&);
37  virtual ~NPObjectAPI(void);
38 
39  void *getEventId() const { return (void*)obj; }
40  void *getEventContext() const {
41  if (!m_browser.expired())
42  return getHost()->getContextID();
43  else
44  return NULL;
45  };
46  NPObject *getNPObject() const { return obj; }
47 
48  void getMemberNames(std::vector<std::string> &nameVector) const;
49  size_t getMemberCount() const;
50  public:
51  virtual JSAPIPtr getJSAPI() const;
52  void invalidate() { inner.reset(); }
53  bool isValid() { return !m_browser.expired(); }
54  virtual bool supportsOptimizedCalls() const { return true; }
55  virtual void callMultipleFunctions(const std::string& name, const FB::VariantList& args,
56  const std::vector<JSObjectPtr>& direct,
57  const std::vector<JSObjectPtr>& ifaces);
58 
59  protected:
60  NpapiBrowserHostPtr getHost() const {
61  NpapiBrowserHostPtr ptr(m_browser.lock());
62  if (!ptr) {
63  throw std::bad_cast();
64  }
65  return ptr;
66  }
67  NpapiBrowserHostWeakPtr m_browser;
68  NPObject *obj;
69  bool is_JSAPI;
70  FB::JSAPIWeakPtr inner;
71 
72  public:
73  bool HasMethod(const std::string& methodName) const;
74  bool HasProperty(const std::string& propertyName) const;
75  bool HasProperty(int idx) const;
76 
77  variant GetProperty(const std::string& propertyName);
78  void SetProperty(const std::string& propertyName, const variant& value);
79  void RemoveProperty(const std::string& propertyName);
80  variant GetProperty(int idx);
81  void SetProperty(int idx, const variant& value);
82  void RemoveProperty(int idx);
83 
84  variant Invoke(const std::string& methodName, const std::vector<variant>& args);
85 
86  variant Construct(const std::vector<variant>& args);
87  };
88 
89 }; };
90 
91 #endif
92 
variant GetProperty(const std::string &propertyName)
Gets a property value.
void SetProperty(const std::string &propertyName, const variant &value)
Sets the value of a property.
variant Invoke(const std::string &methodName, const std::vector< variant > &args)
Called by the browser to invoke a method on the JSAPI object.
void RemoveProperty(const std::string &propertyName)
Removes a property.
Wraps a Javascript Object.
Definition: JSObject.h:46
virtual JSAPIPtr getJSAPI() const
Get associated FB::JSAPI.
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
bool HasMethod(const std::string &methodName) const
Query if the JSAPI object has the 'methodName' method.
variant Construct(const std::vector< variant > &args)
Called by the browser to construct the JSAPI object.
size_t getMemberCount() const
Gets the member count.
Definition: NPObjectAPI.cpp:79
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
void invalidate()
Invalidates this object.
Definition: NPObjectAPI.h:52
Provides a FB::JSObject implementation that wraps a NPObject*.
Definition: NPObjectAPI.h:32
void getMemberNames(std::vector< std::string > &nameVector) const
Called by the browser to enumerate the members of this JSAPI object.
Definition: NPObjectAPI.cpp:52
bool HasProperty(const std::string &propertyName) const
Query if 'propertyName' is a valid property.