FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
ScriptingCore/DOM/Window.cpp
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Dec 9, 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 PacketPass, Inc and the Firebreath development team
13 \**********************************************************/
14 
15 #include "variant_list.h"
16 #include "../precompiled_headers.h" // On windows, everything above this line in PCH
17 #include "Node.h"
18 #include "Element.h"
19 #include "Document.h"
20 
21 #include "Window.h"
22 
23 using namespace FB::DOM;
24 
25 Window::Window(const FB::JSObjectPtr& element) : Node(element)
26 {
27 }
28 
30 {
31 }
32 
34 {
35  JSObjectPtr api = getProperty<JSObjectPtr>("document");
36  return Document::create(api);
37 }
38 
39 void Window::alert(const std::wstring& str) const
40 {
42 }
43 
44 void Window::alert(const std::string& str) const
45 {
46  callMethod<void>("alert", variant_list_of(str));
47 }
48 
50 {
51  JSObjectPtr arr = this->callMethod<JSObjectPtr>("Array", FB::VariantList());
52  return arr;
53 }
54 
56 {
57  JSObjectPtr arr = this->callMethod<JSObjectPtr>("Object", FB::VariantList());
58  return arr;
59 }
60 
61 std::string Window::getLocation() const
62 {
63  return getNode("location")->getProperty<std::string>("href");
64 }
65 
66 //FB::JSObjectPtr FB::DOM::Window::createDate( const std::string& datestring ) const
67 //{
68 // // This is not working; I'm leaving it here in hopes that we can find a way to make it work.
69 // // My best idea so far is to inject a help function into javascript :-/
70 // try {
71 // JSObjectPtr obj;
72 // if (datestring.empty())
73 // obj = getJSObject()->Construct("Date", FB::VariantList());
74 // else
75 // obj = getJSObject()->Construct("Date", FB::variant_list_of(datestring));
76 // return obj;
77 // } catch (...) {
78 // return FB::JSObjectPtr();
79 // }
80 //}
81 
DOM Node wrapper.
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
virtual NodePtr getNode(const std::wstring &name) const
Window(const JSObjectPtr &element)
Constructor. DO NOT USE.
FB::detail::VariantListInserter variant_list_of(FB::variant v)
Allows convenient creation of an FB::VariantList.
Definition: variant_list.h:122
virtual FB::JSObjectPtr createMap() const
Creates a javascript object and returns it.
std::vector< variant > VariantList
Defines an alias representing list of variants.
Definition: APITypes.h:64
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
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 FB::JSObjectPtr createArray() const
Creates a javascript array object and returns it.
virtual ~Window()
Finaliser.