FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ActiveXCore/AXDOM/Window.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Sep 21, 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 PacketPass, Inc and the Firebreath development team
13 \**********************************************************/
14 
15 #include "Document.h"
16 #include "IDispatchAPI.h"
17 
18 #include "precompiled_headers.h" // On windows, everything above this line in PCH
19 #include "Window.h"
20 
21 using namespace FB::ActiveX::AXDOM;
22 
23 Window::Window(FB::JSObjectPtr obj, IWebBrowser2 *web)
24  : FB::ActiveX::AXDOM::Node(obj, web), FB::DOM::Window(obj), FB::DOM::Node(obj),
25  m_webBrowser(web), m_htmlWin(FB::ptr_cast<IDispatchAPI>(obj)->getIDispatch())
26 {
27  if (!m_htmlWin) {
28  throw new std::bad_cast();
29  }
30 }
31 
33 {
34 }
35 
37 {
38  CComPtr<IHTMLDocument2> htmlDoc;
39  m_htmlWin->get_document(&htmlDoc);
40  CComQIPtr<IDispatch> htmlDocDisp(htmlDoc);
41  FB::JSObjectPtr docAPI(IDispatchAPI::create(htmlDocDisp, FB::ptr_cast<ActiveXBrowserHost>(this->m_element->getHost())));
42  return FB::DOM::Document::create(docAPI);
43 }
44 
45 void Window::alert(const std::string& str) const
46 {
47  m_htmlWin->alert(CComBSTR(FB::utf8_to_wstring(str).c_str()));
48 }
49 
50 std::string Window::getLocation() const
51 {
52  CComBSTR bstr;
53  m_webBrowser->get_LocationURL(&bstr);
54  return FB::wstring_to_utf8(std::wstring(bstr.m_str));
55 }
56 
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
ActiveX specific implementation of DOM::Window.
boost::shared_ptr< T > ptr_cast(boost::shared_ptr< U > const &r)
Convenience function for doing a dynamic cast of one boost::shared_ptr to another.
Definition: APITypes.h:339
boost::shared_ptr< Document > DocumentPtr
shared_ptr for a FB::DOM::Document
virtual DocumentPtr getDocument() const
Gets the DOM Document contained in this window.
static DocumentPtr create(const FB::JSObjectPtr &api)
Creates a FB::DOM::Document object from a JSObjectPtr representing a DOM object. This will probably t...
std::string wstring_to_utf8(const std::wstring &src)
Accepts a std::wstring and returns a UTF8-encoded std::string.
Definition: utf8_tools.cpp:37
Provides an ActiveX specific implementation of DOM::Node.
virtual std::string getLocation() const
Returns window.location for the containing page.
virtual void alert(const std::string &str) const
Pop up a JS alert box.
virtual ~Window()
Finaliser.
std::wstring utf8_to_wstring(const std::string &src)
Accepts a UTF8-encoded std::string and returns a std::wstring.
Definition: utf8_tools.cpp:50