2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "WebDocument.h"
34 #include "AXObjectCache.h"
35 #include "CSSStyleSheet.h"
37 #include "DocumentLoader.h"
38 #include "DocumentType.h"
40 #include "HTMLAllCollection.h"
41 #include "HTMLBodyElement.h"
42 #include "HTMLCollection.h"
43 #include "HTMLElement.h"
44 #include "HTMLFormElement.h"
45 #include "HTMLHeadElement.h"
47 #include "SecurityOrigin.h"
48 #include "WebAccessibilityObject.h"
49 #include "WebDocumentType.h"
50 #include "WebElement.h"
51 #include "WebFormElement.h"
52 #include "WebFrameImpl.h"
53 #include "WebNodeCollection.h"
54 #include "WebNodeList.h"
57 #include <wtf/PassRefPtr.h>
59 using namespace WebCore;
63 WebURL WebDocument::url() const
65 return constUnwrap<Document>()->url();
68 WebSecurityOrigin WebDocument::securityOrigin() const
70 if (!constUnwrap<Document>())
71 return WebSecurityOrigin();
72 return WebSecurityOrigin(constUnwrap<Document>()->securityOrigin());
75 WebString WebDocument::encoding() const
77 return constUnwrap<Document>()->encoding();
80 WebURL WebDocument::openSearchDescriptionURL() const
82 return const_cast<Document*>(constUnwrap<Document>())->openSearchDescriptionURL();
85 WebFrame* WebDocument::frame() const
87 return WebFrameImpl::fromFrame(constUnwrap<Document>()->frame());
90 bool WebDocument::isHTMLDocument() const
92 return constUnwrap<Document>()->isHTMLDocument();
95 bool WebDocument::isXHTMLDocument() const
97 return constUnwrap<Document>()->isXHTMLDocument();
100 bool WebDocument::isPluginDocument() const
102 return constUnwrap<Document>()->isPluginDocument();
105 WebURL WebDocument::baseURL() const
107 return constUnwrap<Document>()->baseURL();
110 WebURL WebDocument::firstPartyForCookies() const
112 return constUnwrap<Document>()->firstPartyForCookies();
115 WebElement WebDocument::documentElement() const
117 return WebElement(constUnwrap<Document>()->documentElement());
120 WebElement WebDocument::body() const
122 return WebElement(constUnwrap<Document>()->body());
125 WebElement WebDocument::head()
127 return WebElement(unwrap<Document>()->head());
130 WebString WebDocument::title() const
132 return WebString(constUnwrap<Document>()->title());
135 WebNodeCollection WebDocument::all()
137 return WebNodeCollection(unwrap<Document>()->all());
140 void WebDocument::forms(WebVector<WebFormElement>& results) const
142 RefPtr<HTMLCollection> forms = const_cast<Document*>(constUnwrap<Document>())->forms();
143 size_t sourceLength = forms->length();
144 Vector<WebFormElement> temp;
145 temp.reserveCapacity(sourceLength);
146 for (size_t i = 0; i < sourceLength; ++i) {
147 Node* node = forms->item(i);
148 // Strange but true, sometimes node can be 0.
149 if (node && node->isHTMLElement())
150 temp.append(WebFormElement(static_cast<HTMLFormElement*>(node)));
152 results.assign(temp);
155 WebURL WebDocument::completeURL(const WebString& partialURL) const
157 return constUnwrap<Document>()->completeURL(partialURL);
160 WebElement WebDocument::getElementById(const WebString& id) const
162 return WebElement(constUnwrap<Document>()->getElementById(id));
165 WebNode WebDocument::focusedNode() const
167 return WebNode(constUnwrap<Document>()->focusedNode());
170 WebDocumentType WebDocument::doctype() const
172 return WebDocumentType(constUnwrap<Document>()->doctype());
175 WebAccessibilityObject WebDocument::accessibilityObject() const
177 const Document* document = constUnwrap<Document>();
178 return WebAccessibilityObject(
179 document->axObjectCache()->getOrCreate(document->renderer()));
182 void WebDocument::insertUserStyleSheet(const WebString& sourceCode, UserStyleLevel level)
184 RefPtr<Document> document = unwrap<Document>();
186 RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::create(document.get());
187 parsedSheet->setIsUserStyleSheet(level == UserStyleUserLevel);
188 parsedSheet->parseString(sourceCode, !document->inQuirksMode());
189 document->addUserSheet(parsedSheet.release());
192 void WebDocument::cancelFullScreen()
194 #if ENABLE(FULLSCREEN_API)
195 unwrap<Document>()->webkitCancelFullScreen();
199 WebDocument::WebDocument(const PassRefPtr<Document>& elem)
204 WebDocument& WebDocument::operator=(const PassRefPtr<Document>& elem)
210 WebDocument::operator PassRefPtr<Document>() const
212 return static_cast<Document*>(m_private.get());
215 } // namespace WebKit