FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
NpapiBrowserHost.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Oct 15, 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_NPAPIBROWSERHOST
17 #define H_NPAPIBROWSERHOST
18 
19 #include "NpapiTypes.h"
20 #include "BrowserHost.h"
21 #include "SafeQueue.h"
22 #include "ShareableReference.h"
23 #include <boost/thread.hpp>
24 
25 namespace FB {
26  class BrowserStreamRequest;
27  namespace Npapi {
28 
29  FB_FORWARD_PTR(NpapiPluginModule);
30  FB_FORWARD_PTR(NPObjectAPI);
31  FB_FORWARD_PTR(NpapiBrowserHost);
32  FB_FORWARD_PTR(NPJavascriptObject);
33  typedef boost::shared_ptr<NPObjectAPI> NPObjectAPIPtr;
34  typedef boost::weak_ptr<FB::ShareableReference<NPJavascriptObject> > NPObjectWeakRef;
35 
42  public FB::BrowserHost
43  {
44  public:
45  NpapiBrowserHost(NpapiPluginModule *module, NPP npp);
46  virtual ~NpapiBrowserHost(void);
47 
48  void setBrowserFuncs(NPNetscapeFuncs *pFuncs);
49 
50  public:
51  virtual BrowserStreamPtr _createStream( const BrowserStreamRequest& req ) const;
52 
53  virtual BrowserStreamPtr _createUnsolicitedStream(const BrowserStreamRequest& req) const;
54 
55  public:
56  virtual bool _scheduleAsyncCall(void (*func)(void *), void *userData) const;
57  virtual void *getContextID() const { return (void *)m_npp; }
58  virtual void deferred_release(NPObject* obj);
59  virtual void DoDeferredRelease() const;
60  NPJavascriptObject* getJSAPIWrapper( const FB::JSAPIWeakPtr& api, bool autoRelease = false );
61 
62  public:
66  void Navigate(const std::string& url, const std::string& target);
67  void evaluateJavaScript(const std::string &script);
68  bool isSafari() const;
69  bool isFirefox() const;
70  bool isChrome() const;
71 
72  virtual bool DetectProxySettings(std::map<std::string, std::string>& settingsMap, const std::string& url = "");
73 
74  public:
75  void shutdown();
76 
77  public:
78  FB::variant getVariant(const NPVariant *npVar);
79  void getNPVariant(NPVariant *dst, const FB::variant &var);
80 
81  // NPN_ functions -- for scope reasons, we no longer access these using the global functions
82  protected:
83  NPNetscapeFuncs NPNFuncs; // Function pointers
84  NpapiPluginModule *module;
85  NPP m_npp;
86  NPObjectAPIPtr m_htmlDoc;
87  NPObjectAPIPtr m_htmlWin;
88  NPObjectAPIPtr m_htmlElement;
89  mutable FB::SafeQueue<NPObject*> m_deferredObjects;
90  typedef std::map<void*, NPObjectWeakRef> NPObjectRefMap;
91  mutable NPObjectRefMap m_cachedNPObject;
92 
93  public:
94  void* MemAlloc(uint32_t size) const;
95  void MemFree(void* ptr) const;
96  uint32_t MemFlush(uint32_t size) const;
97 
98  NPObject *RetainObject(NPObject *npobj) const;
99  void ReleaseObject(NPObject *npobj) const;
100  void ReleaseVariantValue(NPVariant *variant) const;
101 
102  NPIdentifier GetStringIdentifier(const NPUTF8 *name) const;
103  void GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers) const;
104  NPIdentifier GetIntIdentifier(int32_t intid) const;
105  bool IdentifierIsString(NPIdentifier identifier) const;
106  NPUTF8 *UTF8FromIdentifier(NPIdentifier identifier) const;
107  std::string StringFromIdentifier(NPIdentifier identifier) const;
108  int32_t IntFromIdentifier(NPIdentifier identifier) const;
109 
110  /* npapi.h definitions */
111  NPError GetURLNotify(const char* url, const char* target, void* notifyData) const;
112  NPError GetURL(const char* url, const char* target) const;
113  NPError PostURLNotify(const char* url, const char* target, uint32_t len, const char* buf, NPBool file, void* notifyData) const;
114  NPError PostURL(const char* url, const char* target, uint32_t len, const char* buf, NPBool file) const;
115  NPError RequestRead(NPStream* stream, NPByteRange* rangeList) const;
116  NPError NewStream(NPMIMEType type, const char* target, NPStream** stream) const;
117  int32_t Write(NPStream* stream, int32_t len, void* buffer) const;
118  NPError DestroyStream(NPStream* stream, NPReason reason) const;
119  void SetStatus(const char* message) const;
120  const char* UserAgent() const;
121  NPError GetValue(NPNVariable variable, void *value) const;
122  NPError SetValue(NPPVariable variable, void *value) const;
123  void InvalidateRect(NPRect *invalidRect) const;
124  void InvalidateRect2(const NPRect& invalidRect) const;
125  void InvalidateRegion(NPRegion invalidRegion) const;
126  void ForceRedraw() const;
127  void PushPopupsEnabledState(NPBool enabled) const;
128  void PopPopupsEnabledState() const;
129  void PluginThreadAsyncCall(void (*func) (void *), void *userData) const;
130 
131  NPError GetValueForURL(NPNURLVariable variable,
132  const char *url,
133  char **value,
134  uint32_t *len);
135  NPError SetValueForURL(NPNURLVariable variable,
136  const char *url, const char *value,
137  uint32_t len);
138  NPError GetAuthenticationInfo(const char *protocol,
139  const char *host, int32_t port,
140  const char *scheme,
141  const char *realm,
142  char **username, uint32_t *ulen,
143  char **password,
144  uint32_t *plen);
145 
146  /* npruntime.h definitions */
147  NPObject *CreateObject(NPClass *aClass) const;
148  bool Invoke(NPObject *npobj, NPIdentifier methodName, const NPVariant *args,
149  uint32_t argCount, NPVariant *result) const;
150  bool InvokeDefault(NPObject *npobj, const NPVariant *args,
151  uint32_t argCount, NPVariant *result) const;
152  bool Evaluate(NPObject *npobj, NPString *script,
153  NPVariant *result) const;
154  bool GetProperty(NPObject *npobj, NPIdentifier propertyName,
155  NPVariant *result) const;
156  bool SetProperty(NPObject *npobj, NPIdentifier propertyName,
157  const NPVariant *value) const;
158  bool RemoveProperty(NPObject *npobj, NPIdentifier propertyName) const;
159  bool HasProperty(NPObject *npobj, NPIdentifier propertyName) const;
160  bool HasMethod(NPObject *npobj, NPIdentifier methodName) const;
161  bool Enumerate(NPObject *npobj, NPIdentifier **identifier,
162  uint32_t *count) const;
163  bool Construct(NPObject *npobj, const NPVariant *args,
164  uint32_t argCount, NPVariant *result) const;
165  void SetException(NPObject *npobj, const NPUTF8 *message) const;
166 
167  int ScheduleTimer(int interval, bool repeat, void(*func)(NPP npp, uint32_t timerID)) const;
168  void UnscheduleTimer(int timerId) const;
169 
170  NPError InitAsyncSurface(NPSize* size, NPImageFormat format, void* initData, NPAsyncSurface* surface) const;
171  NPError FinalizeAsyncSurface(NPAsyncSurface* surface) const;
172  void SetCurrentAsyncSurface(NPAsyncSurface* surface, NPRect* changed) const;
173  };
174 
175  typedef boost::shared_ptr<NpapiBrowserHost> NpapiBrowserHostPtr;
176  typedef boost::shared_ptr<const NpapiBrowserHost> NpapiBrowserHostConstPtr;
177  typedef boost::weak_ptr<NpapiBrowserHost> NpapiBrowserHostWeakPtr;
178  typedef boost::weak_ptr<const NpapiBrowserHost> NpapiBrowserHostWeakConstPtr;
179 }; };
180 
181 #endif
182 
void Navigate(const std::string &url, const std::string &target)
Instructs the browser to navigate to the specified url in the target window.
Accepts any datatype, used in all interactions with javascript. Provides tools for getting back out t...
Definition: variant.h:198
Browser host base class.
Definition: BrowserHost.h:69
boost::shared_ptr< Window > WindowPtr
shared_ptr for a FB::DOM::Window
boost::shared_ptr< Document > DocumentPtr
shared_ptr for a FB::DOM::Document
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
Information about an HTTP request to be made.
FB::DOM::ElementPtr getDOMElement()
Gets a DOM::Element wrapper for the DOM/JS object tag that the plugin resides in. ...
FB::DOM::WindowPtr getDOMWindow()
Gets a DOM::Window wrapper for the DOM/JS window object that the plugin resides in.
virtual void DoDeferredRelease() const
Releases any browser-specific objects that were destroyed on a thread other than the main thread...
void evaluateJavaScript(const std::string &script)
Evaluates arbitrary javascript; note that it does not return the result due to cross- browser compati...
void shutdown()
Notifies the browserhost object that the associated plugin object is shutting down.
FB::DOM::DocumentPtr getDOMDocument()
Gets a DOM::Document wrapper for the document object that the plugin resides in.
virtual void * getContextID() const
Gets a unique identifier for this BrowserHost. There are cases where you may need multiple BrowserHos...
boost::shared_ptr< Element > ElementPtr
shared_ptr for a FB::DOM::Element
virtual bool DetectProxySettings(std::map< std::string, std::string > &settingsMap, const std::string &url="")
Detects the proxy settings from the browser.
Provides a FB::BrowserHost implementation for Npapi.