FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ActiveXBrowserHost.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Oct 30, 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_ACTIVEXBROWSERHOST
17 #define H_ACTIVEXBROWSERHOST
18 
19 #include "win_common.h"
20 //#include "global/COM_config.h"
21 #include <atlctl.h>
22 #include <map>
23 #include "BrowserHost.h"
24 #include "APITypes.h"
25 #include "FBPointers.h"
26 #include "SafeQueue.h"
27 #include "ShareableReference.h"
28 #include "ActiveXFactoryDefinitions.h"
29 
30 namespace FB {
31  class WinMessageWindow;
32  class BrowserStreamRequest;
33  namespace ActiveX {
34  FB_FORWARD_PTR(ActiveXBrowserHost);
35  FB_FORWARD_PTR(IDispatchAPI);
36 
37  typedef boost::weak_ptr<FB::ShareableReference<IDispatch> > IDispatchWRef;
38  typedef boost::shared_ptr<FB::ShareableReference<IDispatch> > IDispatchSRef;
45  public FB::BrowserHost
46  {
47  public:
48  ActiveXBrowserHost(IWebBrowser2 *doc, IOleClientSite* clientSite);
49  virtual ~ActiveXBrowserHost(void);
50  virtual bool _scheduleAsyncCall(void (*func)(void *), void *userData) const;
51 
52  virtual void *getContextID() const;
53 
54  virtual FB::BrowserStreamPtr _createStream( const BrowserStreamRequest& req ) const;
55  virtual FB::BrowserStreamPtr _createUnsolicitedStream(const BrowserStreamRequest& req) const { return FB::BrowserStreamPtr(); }
56 
57  IDispatchEx* getJSAPIWrapper(const FB::JSAPIWeakPtr& api, bool autoRelease = false);
58  IDispatchWRef getIDispatchRef(IDispatch* obj);
59 
60  public:
64  void Navigate(const std::string& url, const std::string& target);
65 
66  bool hasHTMLWindow() { return m_htmlWin != NULL; }
67 
68  void suspend();
69  void resume(IWebBrowser2 *doc, IOleClientSite* clientSite);
70 
71  void evaluateJavaScript(const std::string &script);
72  void shutdown();
73 
74  public:
75  FB::DOM::WindowPtr _createWindow(const FB::JSObjectPtr& obj) const;
76  FB::DOM::DocumentPtr _createDocument(const FB::JSObjectPtr& obj) const;
77  FB::DOM::ElementPtr _createElement(const FB::JSObjectPtr& obj) const;
78  FB::DOM::NodePtr _createNode(const FB::JSObjectPtr& obj) const;
79 
80  protected:
81  void initDOMObjects(); // This is const so that getDOMDocument/Window can be
82  CComQIPtr<IOleClientSite> m_spClientSite;
83  CComQIPtr<IDispatch> m_htmlDocDisp;
84  CComPtr<IHTMLWindow2> m_htmlWin;
85  CComPtr<IWebBrowser2> m_webBrowser;
86  mutable FB::DOM::WindowPtr m_window;
87  mutable FB::DOM::DocumentPtr m_document;
88  boost::scoped_ptr<FB::WinMessageWindow> m_messageWin;
89 
90  private:
91  mutable boost::shared_mutex m_xtmutex;
92  mutable FB::SafeQueue<IDispatchWRef> m_deferredObjects;
93  typedef std::map<void*, FB::WeakIDispatchExRef> IDispatchExRefMap;
94  typedef std::list<IDispatchSRef> IDispatchRefList;
95  mutable IDispatchExRefMap m_cachedIDispatch;
96  mutable IDispatchRefList m_heldIDispatch;
97 
98  public:
99  FB::variant getVariant(const VARIANT *cVar);
100  void getComVariant(VARIANT *dest, const FB::variant &var);
101  void deferred_release( const IDispatchWRef& obj ) const;
102  void DoDeferredRelease() const;
103  void ReleaseAllHeldObjects();
104  };
105  }
106 }
107 
108 #endif // H_ACTIVEXBROWSERHOST
109 
boost::shared_ptr< FB::JSObject > JSObjectPtr
Defines an alias representing a JSObject shared_ptr (you should never use a JSObject* directly) ...
Definition: APITypes.h:109
boost::shared_ptr< Node > NodePtr
shared_ptr for a FB::DOM::Node
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
void evaluateJavaScript(const std::string &script)
Evaluates arbitrary javascript; note that it does not return the result due to cross- browser compati...
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
FB::DOM::ElementPtr getDOMElement()
Gets a DOM::Element wrapper for the DOM/JS object tag 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...
void shutdown()
Notifies the browserhost object that the associated plugin object is shutting down.
Information about an HTTP request to be made.
void DoDeferredRelease() const
Releases any browser-specific objects that were destroyed on a thread other than the main thread...
boost::shared_ptr< Element > ElementPtr
shared_ptr for a FB::DOM::Element
Provides a BrowserHost implementation for ActiveX.
FB::DOM::WindowPtr getDOMWindow()
Gets a DOM::Window wrapper for the DOM/JS window object that the plugin resides in.
void Navigate(const std::string &url, const std::string &target)
Instructs the browser to navigate to the specified url in the target window.
FB::DOM::DocumentPtr getDOMDocument()
Gets a DOM::Document wrapper for the document object that the plugin resides in.