[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.17-1283-gcf603cf
yaar at google.com
yaar at google.com
Tue Jan 5 23:52:29 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit ad0fb55d8135c46806eb8f446b7f51a467aff943
Author: yaar at google.com <yaar at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Dec 17 19:18:40 2009 +0000
2009-12-17 Yaar Schnitman <yaar at chromium.org>
Reviewed by Darin Fisher.
Added WebPageSerializer to WebKit API and enriched the WebNode hierarchy to support
downstream unit-testing of serialization.
WebPageSerializer was adapted from Chromium's dom_serializer, originally authored by Johnny Ding.
https://bugs.webkit.org/show_bug.cgi?id=31737
* WebKit.gyp:
* public/WebDocument.h: Added.
(WebKit::WebDocument::WebDocument):
(WebKit::WebDocument::operator=):
(WebKit::WebDocument::assign):
* public/WebElement.h:
* public/WebFormElement.h:
(WebKit::WebFormElement::operator=):
* public/WebFrame.h:
* public/WebNode.h:
(WebKit::WebNode::):
(WebKit::WebNode::toConstElement):
* public/WebNodeCollection.h: Added.
(WebKit::WebNodeCollection::~WebNodeCollection):
(WebKit::WebNodeCollection::WebNodeCollection):
(WebKit::WebNodeCollection::operator=):
* public/WebNodeList.h: Added.
(WebKit::WebNodeList::~WebNodeList):
(WebKit::WebNodeList::WebNodeList):
(WebKit::WebNodeList::operator=):
* public/WebPageSerializer.h: Added.
* public/WebPageSerializerClient.h: Added.
(WebKit::WebPageSerializerClient::):
(WebKit::WebPageSerializerClient::WebPageSerializerClient):
(WebKit::WebPageSerializerClient::~WebPageSerializerClient):
* public/WebString.h:
* public/WebView.h:
* src/AssertMatchingEnums.cpp:
* src/DOMUtilitiesPrivate.cpp:
(WebKit::elementHasLegalLinkAttribute):
* src/DOMUtilitiesPrivate.h:
* src/WebDocument.cpp: Added.
(WebKit::WebDocument::WebDocument):
(WebKit::WebDocument::operator=):
(WebKit::WebDocument::operator WTF::PassRefPtr<Document>):
(WebKit::WebDocument::frame):
(WebKit::WebDocument::isHTMLDocument):
(WebKit::WebDocument::baseURL):
(WebKit::WebDocument::body):
(WebKit::WebDocument::head):
(WebKit::WebDocument::all):
(WebKit::WebDocument::completeURL):
* src/WebElement.cpp:
(WebKit::WebElement::hasTagName):
(WebKit::WebElement::hasAttribute):
(WebKit::WebElement::getAttribute):
* src/WebEntities.cpp: Added.
(WebKit::populateMap):
(WebKit::):
(WebKit::WebEntities::WebEntities):
(WebKit::WebEntities::entityNameByCode):
(WebKit::WebEntities::convertEntitiesInString):
* src/WebEntities.h: Added.
* src/WebFrameImpl.cpp:
(WebKit::WebFrame::fromFrameOwnerElement):
(WebKit::WebFrameImpl::encoding):
(WebKit::WebFrameImpl::document):
(WebKit::WebFrameImpl::fromFrameOwnerElement):
* src/WebFrameImpl.h:
* src/WebNode.cpp:
(WebKit::WebNode::nodeType):
(WebKit::WebNode::nodeValue):
(WebKit::WebNode::document):
(WebKit::WebNode::firstChild):
(WebKit::WebNode::lastChild):
(WebKit::WebNode::previousSibling):
(WebKit::WebNode::nextSibling):
(WebKit::WebNode::hasChildNodes):
(WebKit::WebNode::childNodes):
(WebKit::WebNode::createMarkup):
(WebKit::WebNode::isTextNode):
(WebKit::WebNode::isElementNode):
* src/WebNodeCollection.cpp: Added.
(WebKit::WebNodeCollection::reset):
(WebKit::WebNodeCollection::assign):
(WebKit::WebNodeCollection::WebNodeCollection):
(WebKit::WebNodeCollection::length):
(WebKit::WebNodeCollection::nextItem):
(WebKit::WebNodeCollection::firstItem):
* src/WebNodeList.cpp: Added.
(WebKit::WebNodeList::reset):
(WebKit::WebNodeList::assign):
(WebKit::WebNodeList::WebNodeList):
(WebKit::WebNodeList::length):
(WebKit::WebNodeList::item):
* src/WebPageSerializer.cpp: Added.
(WebKit::WebPageSerializer::serialize):
(WebKit::WebPageSerializer::generateMetaCharsetDeclaration):
(WebKit::WebPageSerializer::generateMarkOfTheWebDeclaration):
(WebKit::WebPageSerializer::generateBaseTagDeclaration):
* src/WebPageSerializerImpl.cpp: Added.
(WebKit::WebPageSerializerImpl::SerializeDomParam::SerializeDomParam):
(WebKit::WebPageSerializerImpl::preActionBeforeSerializeOpenTag):
(WebKit::WebPageSerializerImpl::postActionAfterSerializeOpenTag):
(WebKit::WebPageSerializerImpl::preActionBeforeSerializeEndTag):
(WebKit::WebPageSerializerImpl::postActionAfterSerializeEndTag):
(WebKit::WebPageSerializerImpl::saveHTMLContentToBuffer):
(WebKit::WebPageSerializerImpl::openTagToString):
(WebKit::WebPageSerializerImpl::endTagToString):
(WebKit::WebPageSerializerImpl::buildContentForNode):
(WebKit::WebPageSerializerImpl::WebPageSerializerImpl):
(WebKit::WebPageSerializerImpl::collectTargetFrames):
(WebKit::WebPageSerializerImpl::serialize):
* src/WebPageSerializerImpl.h: Added.
* src/WebString.cpp:
(WebKit::WebString::WebString):
(WebKit::WebString::operator=):
* src/WebViewImpl.cpp:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52268 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 1f049bc..df4d374 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,16 @@
+2009-12-17 Yaar Schnitman <yaar at chromium.org>
+
+ Reviewed by Darin Fisher.
+
+ Added WebPageSerializer to WebKit API.
+
+ https://bugs.webkit.org/show_bug.cgi?id=31737
+
+ * platform/text/StringBuilder.cpp: Added methods to make StringBuilder even more useful for large scale string concatenation.
+ (WebCore::StringBuilder::clear):
+ (WebCore::StringBuilder::length):
+ * platform/text/StringBuilder.h:
+
2009-12-10 Philippe Normand <pnormand at igalia.com>
Reviewed by Xan Lopez.
diff --git a/WebCore/platform/text/StringBuilder.cpp b/WebCore/platform/text/StringBuilder.cpp
index c21e366..3e34981 100644
--- a/WebCore/platform/text/StringBuilder.cpp
+++ b/WebCore/platform/text/StringBuilder.cpp
@@ -95,4 +95,17 @@ String StringBuilder::toString() const
return result;
}
+void StringBuilder::clear()
+{
+ m_totalLength = UINT_MAX;
+ m_strings.clear();
+}
+
+unsigned StringBuilder::length() const
+{
+ if (m_totalLength == UINT_MAX)
+ return 0;
+ return m_totalLength;
+}
+
}
diff --git a/WebCore/platform/text/StringBuilder.h b/WebCore/platform/text/StringBuilder.h
index 8d76b9c..7f72fbf 100644
--- a/WebCore/platform/text/StringBuilder.h
+++ b/WebCore/platform/text/StringBuilder.h
@@ -42,6 +42,9 @@ namespace WebCore {
void append(const String&);
void append(UChar);
void append(char);
+
+ void clear();
+ unsigned length() const;
String toString() const;
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index c4ff1bc..8609df6 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,123 @@
+2009-12-17 Yaar Schnitman <yaar at chromium.org>
+
+ Reviewed by Darin Fisher.
+
+ Added WebPageSerializer to WebKit API and enriched the WebNode hierarchy to support
+ downstream unit-testing of serialization.
+
+ WebPageSerializer was adapted from Chromium's dom_serializer, originally authored by Johnny Ding.
+
+ https://bugs.webkit.org/show_bug.cgi?id=31737
+
+ * WebKit.gyp:
+ * public/WebDocument.h: Added.
+ (WebKit::WebDocument::WebDocument):
+ (WebKit::WebDocument::operator=):
+ (WebKit::WebDocument::assign):
+ * public/WebElement.h:
+ * public/WebFormElement.h:
+ (WebKit::WebFormElement::operator=):
+ * public/WebFrame.h:
+ * public/WebNode.h:
+ (WebKit::WebNode::):
+ (WebKit::WebNode::toConstElement):
+ * public/WebNodeCollection.h: Added.
+ (WebKit::WebNodeCollection::~WebNodeCollection):
+ (WebKit::WebNodeCollection::WebNodeCollection):
+ (WebKit::WebNodeCollection::operator=):
+ * public/WebNodeList.h: Added.
+ (WebKit::WebNodeList::~WebNodeList):
+ (WebKit::WebNodeList::WebNodeList):
+ (WebKit::WebNodeList::operator=):
+ * public/WebPageSerializer.h: Added.
+ * public/WebPageSerializerClient.h: Added.
+ (WebKit::WebPageSerializerClient::):
+ (WebKit::WebPageSerializerClient::WebPageSerializerClient):
+ (WebKit::WebPageSerializerClient::~WebPageSerializerClient):
+ * public/WebString.h:
+ * public/WebView.h:
+ * src/AssertMatchingEnums.cpp:
+ * src/DOMUtilitiesPrivate.cpp:
+ (WebKit::elementHasLegalLinkAttribute):
+ * src/DOMUtilitiesPrivate.h:
+ * src/WebDocument.cpp: Added.
+ (WebKit::WebDocument::WebDocument):
+ (WebKit::WebDocument::operator=):
+ (WebKit::WebDocument::operator WTF::PassRefPtr<Document>):
+ (WebKit::WebDocument::frame):
+ (WebKit::WebDocument::isHTMLDocument):
+ (WebKit::WebDocument::baseURL):
+ (WebKit::WebDocument::body):
+ (WebKit::WebDocument::head):
+ (WebKit::WebDocument::all):
+ (WebKit::WebDocument::completeURL):
+ * src/WebElement.cpp:
+ (WebKit::WebElement::hasTagName):
+ (WebKit::WebElement::hasAttribute):
+ (WebKit::WebElement::getAttribute):
+ * src/WebEntities.cpp: Added.
+ (WebKit::populateMap):
+ (WebKit::):
+ (WebKit::WebEntities::WebEntities):
+ (WebKit::WebEntities::entityNameByCode):
+ (WebKit::WebEntities::convertEntitiesInString):
+ * src/WebEntities.h: Added.
+ * src/WebFrameImpl.cpp:
+ (WebKit::WebFrame::fromFrameOwnerElement):
+ (WebKit::WebFrameImpl::encoding):
+ (WebKit::WebFrameImpl::document):
+ (WebKit::WebFrameImpl::fromFrameOwnerElement):
+ * src/WebFrameImpl.h:
+ * src/WebNode.cpp:
+ (WebKit::WebNode::nodeType):
+ (WebKit::WebNode::nodeValue):
+ (WebKit::WebNode::document):
+ (WebKit::WebNode::firstChild):
+ (WebKit::WebNode::lastChild):
+ (WebKit::WebNode::previousSibling):
+ (WebKit::WebNode::nextSibling):
+ (WebKit::WebNode::hasChildNodes):
+ (WebKit::WebNode::childNodes):
+ (WebKit::WebNode::createMarkup):
+ (WebKit::WebNode::isTextNode):
+ (WebKit::WebNode::isElementNode):
+ * src/WebNodeCollection.cpp: Added.
+ (WebKit::WebNodeCollection::reset):
+ (WebKit::WebNodeCollection::assign):
+ (WebKit::WebNodeCollection::WebNodeCollection):
+ (WebKit::WebNodeCollection::length):
+ (WebKit::WebNodeCollection::nextItem):
+ (WebKit::WebNodeCollection::firstItem):
+ * src/WebNodeList.cpp: Added.
+ (WebKit::WebNodeList::reset):
+ (WebKit::WebNodeList::assign):
+ (WebKit::WebNodeList::WebNodeList):
+ (WebKit::WebNodeList::length):
+ (WebKit::WebNodeList::item):
+ * src/WebPageSerializer.cpp: Added.
+ (WebKit::WebPageSerializer::serialize):
+ (WebKit::WebPageSerializer::generateMetaCharsetDeclaration):
+ (WebKit::WebPageSerializer::generateMarkOfTheWebDeclaration):
+ (WebKit::WebPageSerializer::generateBaseTagDeclaration):
+ * src/WebPageSerializerImpl.cpp: Added.
+ (WebKit::WebPageSerializerImpl::SerializeDomParam::SerializeDomParam):
+ (WebKit::WebPageSerializerImpl::preActionBeforeSerializeOpenTag):
+ (WebKit::WebPageSerializerImpl::postActionAfterSerializeOpenTag):
+ (WebKit::WebPageSerializerImpl::preActionBeforeSerializeEndTag):
+ (WebKit::WebPageSerializerImpl::postActionAfterSerializeEndTag):
+ (WebKit::WebPageSerializerImpl::saveHTMLContentToBuffer):
+ (WebKit::WebPageSerializerImpl::openTagToString):
+ (WebKit::WebPageSerializerImpl::endTagToString):
+ (WebKit::WebPageSerializerImpl::buildContentForNode):
+ (WebKit::WebPageSerializerImpl::WebPageSerializerImpl):
+ (WebKit::WebPageSerializerImpl::collectTargetFrames):
+ (WebKit::WebPageSerializerImpl::serialize):
+ * src/WebPageSerializerImpl.h: Added.
+ * src/WebString.cpp:
+ (WebKit::WebString::WebString):
+ (WebKit::WebString::operator=):
+ * src/WebViewImpl.cpp:
+
2009-12-17 Yury Semikhatsky <yurys at chromium.org>
Reviewed by David Levin.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index c41bf5b..44c40b9 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -112,6 +112,7 @@
'public/WebDevToolsFrontend.h',
'public/WebDevToolsFrontendClient.h',
'public/WebDevToolsMessageData.h',
+ 'public/WebDocument.h',
'public/WebDragData.h',
'public/WebEditingAction.h',
'public/WebElement.h',
@@ -138,10 +139,14 @@
'public/WebMimeRegistry.h',
'public/WebNavigationType.h',
'public/WebNode.h',
+ 'public/WebNodeCollection.h',
+ 'public/WebNodeList.h',
'public/WebNonCopyable.h',
'public/WebNotification.h',
'public/WebNotificationPresenter.h',
'public/WebNotificationPermissionCallback.h',
+ 'public/WebPageSerializer.h',
+ 'public/WebPageSerializerClient.h',
'public/WebPasswordAutocompleteListener.h',
'public/WebPasswordFormData.h',
'public/WebPlugin.h',
@@ -253,8 +258,11 @@
'src/WebDatabase.cpp',
'src/WebDataSourceImpl.cpp',
'src/WebDataSourceImpl.h',
+ 'src/WebDocument.cpp',
'src/WebDragData.cpp',
'src/WebElement.cpp',
+ 'src/WebEntities.cpp',
+ 'src/WebEntities.h',
'src/WebFileChooserCompletionImpl.cpp',
'src/WebFileChooserCompletionImpl.h',
'src/WebFontCache.cpp',
@@ -273,7 +281,12 @@
'src/WebMediaPlayerClientImpl.cpp',
'src/WebMediaPlayerClientImpl.h',
'src/WebNode.cpp',
+ 'src/WebNodeCollection.cpp',
+ 'src/WebNodeList.cpp',
'src/WebNotification.cpp',
+ 'src/WebPageSerializer.cpp',
+ 'src/WebPageSerializerImpl.cpp',
+ 'src/WebPageSerializerImpl.h',
'src/WebPasswordFormData.cpp',
'src/WebPasswordFormUtils.cpp',
'src/WebPasswordFormUtils.h',
diff --git a/WebKit/chromium/public/WebDocument.h b/WebKit/chromium/public/WebDocument.h
new file mode 100644
index 0000000..58bf1ea
--- /dev/null
+++ b/WebKit/chromium/public/WebDocument.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebDocument_h
+#define WebDocument_h
+
+#include "WebNode.h"
+
+#if WEBKIT_IMPLEMENTATION
+namespace WebCore { class Document; }
+namespace WTF { template <typename T> class PassRefPtr; }
+#endif
+
+namespace WebKit {
+class WebElement;
+class WebFrame;
+class WebNodeCollection;
+class WebString;
+class WebURL;
+
+// Provides readonly access to some properties of a DOM document.
+class WebDocument : public WebNode {
+public:
+ WebDocument() { }
+ WebDocument(const WebDocument& e) : WebNode(e) { }
+
+ WebDocument& operator=(const WebDocument& e)
+ {
+ WebNode::assign(e);
+ return *this;
+ }
+ void assign(const WebDocument& e) { WebNode::assign(e); }
+
+ // Returns the frame the document belongs to or 0 if the document is frameless.
+ WEBKIT_API WebFrame* frame() const;
+ WEBKIT_API bool isHTMLDocument() const;
+ WEBKIT_API WebURL baseURL() const;
+ WEBKIT_API WebElement body() const;
+ WEBKIT_API WebElement head();
+ WEBKIT_API WebNodeCollection all();
+ WEBKIT_API WebURL completeURL(const WebString&) const;
+
+#if WEBKIT_IMPLEMENTATION
+ WebDocument(const WTF::PassRefPtr<WebCore::Document>&);
+ WebDocument& operator=(const WTF::PassRefPtr<WebCore::Document>&);
+ operator WTF::PassRefPtr<WebCore::Document>() const;
+#endif
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebElement.h b/WebKit/chromium/public/WebElement.h
index d7a2cbf..ac55593 100644
--- a/WebKit/chromium/public/WebElement.h
+++ b/WebKit/chromium/public/WebElement.h
@@ -39,7 +39,6 @@ namespace WTF { template <typename T> class PassRefPtr; }
#endif
namespace WebKit {
-
// Provides readonly access to some properties of a DOM element node.
class WebElement : public WebNode {
public:
@@ -47,7 +46,11 @@ namespace WebKit {
WebElement(const WebElement& e) : WebNode(e) { }
WebElement& operator=(const WebElement& e) { WebNode::assign(e); return *this; }
- WEBKIT_API void assign(const WebElement& e) { WebNode::assign(e); }
+ void assign(const WebElement& e) { WebNode::assign(e); }
+
+ WEBKIT_API bool hasTagName(const WebString&) const;
+ WEBKIT_API bool hasAttribute(const WebString&) const;
+ WEBKIT_API WebString getAttribute(const WebString&) const;
#if WEBKIT_IMPLEMENTATION
WebElement(const WTF::PassRefPtr<WebCore::Element>&);
diff --git a/WebKit/chromium/public/WebFormElement.h b/WebKit/chromium/public/WebFormElement.h
index 27a1edb..b07bff9 100644
--- a/WebKit/chromium/public/WebFormElement.h
+++ b/WebKit/chromium/public/WebFormElement.h
@@ -50,7 +50,11 @@ namespace WebKit {
WebFormElement() : WebElement() { }
WebFormElement(const WebFormElement& e) : WebElement(e) { }
- WebElement& operator=(const WebFormElement& e) { WebElement::assign(e); return *this; }
+ WebFormElement& operator=(const WebFormElement& e)
+ {
+ WebElement::assign(e);
+ return *this;
+ }
WEBKIT_API void assign(const WebFormElement& e) { WebElement::assign(e); }
#if WEBKIT_IMPLEMENTATION
diff --git a/WebKit/chromium/public/WebFrame.h b/WebKit/chromium/public/WebFrame.h
index 44b57aa..db6cfaf 100644
--- a/WebKit/chromium/public/WebFrame.h
+++ b/WebKit/chromium/public/WebFrame.h
@@ -47,6 +47,8 @@ namespace WebKit {
class WebData;
class WebDataSource;
+class WebDocument;
+class WebElement;
class WebFormElement;
class WebHistoryItem;
class WebInputElement;
@@ -85,6 +87,10 @@ public:
WEBKIT_API static WebFrame* frameForEnteredContext();
WEBKIT_API static WebFrame* frameForCurrentContext();
+ // Returns the frame inside a given frame or iframe element. Returns 0 if
+ // the given element is not a frame, iframe or if the frame is empty.
+ WEBKIT_API static WebFrame* fromFrameOwnerElement(const WebElement&);
+
// Basic properties ---------------------------------------------------
@@ -103,6 +109,8 @@ public:
// the document loaded in this frame.
virtual WebURL openSearchDescriptionURL() const = 0;
+ // Return the frame's encoding.
+ virtual WebString encoding() const = 0;
// Geometry -----------------------------------------------------------
@@ -164,8 +172,9 @@ public:
// Content ------------------------------------------------------------
- virtual void forms(WebVector<WebFormElement>&) const = 0;
+ virtual WebDocument document() const = 0;
+ virtual void forms(WebVector<WebFormElement>&) const = 0;
// Scripting ----------------------------------------------------------
@@ -444,6 +453,7 @@ public:
// relative to the base URL of the frame's document. This uses the
// same algorithm that WebKit uses to resolve hyperlinks found in a
// HTML document.
+ // Deprecated. Use document().completeURL() instead.
virtual WebURL completeURL(const WebString&) const = 0;
// Returns the contents of this frame as a string. If the text is
diff --git a/WebKit/chromium/public/WebNode.h b/WebKit/chromium/public/WebNode.h
index 03afa90..dfbb0aa 100644
--- a/WebKit/chromium/public/WebNode.h
+++ b/WebKit/chromium/public/WebNode.h
@@ -40,7 +40,9 @@ namespace WTF { template <typename T> class PassRefPtr; }
#endif
namespace WebKit {
+class WebDocument;
class WebFrame;
+class WebNodeList;
// Provides readonly access to some properties of a DOM node.
class WebNode {
@@ -66,9 +68,37 @@ public:
operator WTF::PassRefPtr<WebCore::Node>() const;
#endif
+ enum NodeType {
+ ElementNode = 1,
+ AttributeNode,
+ TextNode,
+ CDataSectionNode,
+ EntityReferenceNode,
+ EntityNode,
+ ProcessingInstructionsNode,
+ CommentNode,
+ DocumentNode,
+ DocumentTypeNode,
+ DocumentFragmentNode,
+ NotationNode,
+ XPathNamespaceNode
+ };
+ WEBKIT_API NodeType nodeType() const;
WEBKIT_API WebNode parentNode() const;
WEBKIT_API WebString nodeName() const;
+ WEBKIT_API WebString nodeValue() const;
+ // Deprecated. Use document().frame() instead.
WEBKIT_API WebFrame* frame() const;
+ WEBKIT_API WebDocument document() const;
+ WEBKIT_API WebNode firstChild() const;
+ WEBKIT_API WebNode lastChild() const;
+ WEBKIT_API WebNode previousSibling() const;
+ WEBKIT_API WebNode nextSibling() const;
+ WEBKIT_API bool hasChildNodes() const;
+ WEBKIT_API WebNodeList childNodes();
+ WEBKIT_API WebString createMarkup() const;
+ WEBKIT_API bool isTextNode() const;
+ WEBKIT_API bool isElementNode() const;
template<typename T> T toElement()
{
@@ -77,6 +107,13 @@ public:
return res;
}
+ template<typename T> const T toConstElement() const
+ {
+ T res;
+ res.m_private = m_private;
+ return res;
+ }
+
protected:
typedef WebCore::Node WebNodePrivate;
void assign(WebNodePrivate*);
diff --git a/WebKit/chromium/public/WebNodeCollection.h b/WebKit/chromium/public/WebNodeCollection.h
new file mode 100644
index 0000000..fee4f44
--- /dev/null
+++ b/WebKit/chromium/public/WebNodeCollection.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebNodeCollection_h
+#define WebNodeCollection_h
+
+#include "WebCommon.h"
+
+namespace WebCore { class HTMLCollection; }
+#if WEBKIT_IMPLEMENTATION
+namespace WTF { template <typename T> class PassRefPtr; }
+#endif
+
+namespace WebKit {
+class WebNode;
+
+// Provides readonly access to some properties of a DOM node.
+class WebNodeCollection {
+public:
+ ~WebNodeCollection() { reset(); }
+
+ WebNodeCollection() : m_private(0) { }
+ WebNodeCollection(const WebNodeCollection& n) : m_private(0) { assign(n); }
+ WebNodeCollection& operator=(const WebNodeCollection& n)
+ {
+ assign(n);
+ return *this;
+ }
+
+ WEBKIT_API void reset();
+ WEBKIT_API void assign(const WebNodeCollection&);
+
+ WEBKIT_API unsigned length() const;
+ WEBKIT_API WebNode nextItem() const;
+ WEBKIT_API WebNode firstItem() const;
+
+#if WEBKIT_IMPLEMENTATION
+ WebNodeCollection(const WTF::PassRefPtr<WebCore::HTMLCollection>&);
+#endif
+
+private:
+ void assign(WebCore::HTMLCollection*);
+ WebCore::HTMLCollection* m_private;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebNodeList.h b/WebKit/chromium/public/WebNodeList.h
new file mode 100644
index 0000000..23efab0
--- /dev/null
+++ b/WebKit/chromium/public/WebNodeList.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebNodeList_h
+#define WebNodeList_h
+
+#include "WebCommon.h"
+
+namespace WebCore { class NodeList; }
+#if WEBKIT_IMPLEMENTATION
+namespace WTF { template <typename T> class PassRefPtr; }
+#endif
+
+namespace WebKit {
+class WebNode;
+
+// Provides readonly access to some properties of a DOM node.
+class WebNodeList {
+public:
+ ~WebNodeList() { reset(); }
+
+ WebNodeList() : m_private(0) { }
+ WebNodeList(const WebNodeList& n) : m_private(0) { assign(n); }
+ WebNodeList& operator=(const WebNodeList& n)
+ {
+ assign(n);
+ return *this;
+ }
+
+ WEBKIT_API void reset();
+ WEBKIT_API void assign(const WebNodeList&);
+
+ WEBKIT_API unsigned length() const;
+ WEBKIT_API WebNode item(size_t) const;
+
+#if WEBKIT_IMPLEMENTATION
+ WebNodeList(const WTF::PassRefPtr<WebCore::NodeList>&);
+#endif
+
+private:
+ void assign(WebCore::NodeList*);
+ WebCore::NodeList* m_private;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebPageSerializer.h b/WebKit/chromium/public/WebPageSerializer.h
new file mode 100644
index 0000000..94f7994
--- /dev/null
+++ b/WebKit/chromium/public/WebPageSerializer.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPageSerializer_h
+#define WebPageSerializer_h
+
+#include "WebCommon.h"
+
+namespace WebKit {
+class WebFrame;
+class WebPageSerializerClient;
+class WebString;
+class WebURL;
+template <typename T> class WebVector;
+
+// Get html data by serializing all frames of current page with lists
+// which contain all resource links that have local copy.
+class WebPageSerializer {
+public:
+ // This function will find out all frames and serialize them to HTML data.
+ // We have a data buffer to temporary saving generated html data. We will
+ // sequentially call WebPageSeriazlierClient once the data buffer is full.
+ //
+ // Return false means no available frame has been serialized, otherwise
+ // return true.
+ //
+ // The parameter frame specifies which frame need to be serialized.
+ // The parameter recursive specifies whether we need to
+ // serialize all sub frames of the specified frame or not.
+ // The parameter client specifies the pointer of interface
+ // WebPageSerializerClient providing a sink interface to receive the
+ // individual chunks of data to be saved.
+ // The parameter links contain original URLs of all saved links.
+ // The parameter localPaths contain corresponding local file paths of all
+ // saved links, which matched with vector:links one by one.
+ // The parameter localDirectoryName is relative path of directory which
+ // contain all saved auxiliary files included all sub frames and resources.
+ WEBKIT_API static bool serialize(WebFrame* frame,
+ bool recursive,
+ WebPageSerializerClient* client,
+ const WebVector<WebURL>& links,
+ const WebVector<WebString>& localPaths,
+ const WebString& localDirectoryName);
+
+ // FIXME: The following are here for unit testing purposes. Consider
+ // changing the unit tests instead.
+
+ // Generate the META for charset declaration.
+ WEBKIT_API static WebString generateMetaCharsetDeclaration(const WebString& charset);
+ // Generate the MOTW declaration.
+ WEBKIT_API static WebString generateMarkOfTheWebDeclaration(const WebURL& url);
+ // Generate the default base tag declaration.
+ WEBKIT_API static WebString generateBaseTagDeclaration(const WebString& baseTarget);
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebPageSerializerClient.h b/WebKit/chromium/public/WebPageSerializerClient.h
new file mode 100644
index 0000000..c30ddbc
--- /dev/null
+++ b/WebKit/chromium/public/WebPageSerializerClient.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPageSerializerClient_h
+#define WebPageSerializerClient_h
+
+namespace WebKit {
+class WebCString;
+class WebURL;
+
+// This class is used for providing sink interface that can be used to receive
+// the individual chunks of data to be saved.
+class WebPageSerializerClient {
+public:
+ // This enum indicates This sink interface can receive the individual chunks
+ // of serialized data to be saved, so we use values of following enum
+ // definition to indicate the serialization status of serializing all html
+ // content. If current frame is not complete serialized, call
+ // didSerializeDataForFrame with URL of current frame, data, data length and
+ // flag CurrentFrameIsNotFinished.
+ // If current frame is complete serialized, call didSerializeDataForFrame
+ // with URL of current frame, data, data length and flag
+ // CurrentFrameIsFinished.
+ // If all frames of page are complete serialized, call
+ // didSerializeDataForFrame with empty URL, empty data, 0 and flag
+ // AllFramesAreFinished.
+ enum PageSerializationStatus {
+ CurrentFrameIsNotFinished,
+ CurrentFrameIsFinished,
+ AllFramesAreFinished,
+ };
+
+ // Receive the individual chunks of serialized and encoded data to be saved.
+ // The parameter frameURL specifies what frame the data belongs. The
+ // parameter data contains the available data for saving. The parameter
+ // status indicates the status of data serialization.
+ virtual void didSerializeDataForFrame(const WebURL& frameURL,
+ const WebCString& data,
+ PageSerializationStatus status) = 0;
+ WebPageSerializerClient() { }
+
+protected:
+ virtual ~WebPageSerializerClient() { }
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebString.h b/WebKit/chromium/public/WebString.h
index d9b66b2..95e9305 100644
--- a/WebKit/chromium/public/WebString.h
+++ b/WebKit/chromium/public/WebString.h
@@ -87,6 +87,18 @@ public:
WEBKIT_API static WebString fromUTF8(const char* data, size_t length);
WEBKIT_API static WebString fromUTF8(const char* data);
+ template <int N> WebString(const char (&data)[N])
+ : m_private(0)
+ {
+ assign(fromUTF8(data, N - 1));
+ }
+
+ template <int N> WebString& operator=(const char (&data)[N])
+ {
+ assign(fromUTF8(data, N - 1));
+ return *this;
+ }
+
#if WEBKIT_IMPLEMENTATION
WebString(const WebCore::String&);
WebString& operator=(const WebCore::String&);
@@ -96,6 +108,7 @@ public:
WebString& operator=(const WebCore::AtomicString&);
operator WebCore::AtomicString() const;
#else
+
WebString(const string16& s) : m_private(0)
{
assign(s.data(), s.length());
diff --git a/WebKit/chromium/src/AssertMatchingEnums.cpp b/WebKit/chromium/src/AssertMatchingEnums.cpp
index 9e39ec6..95b2bd9 100644
--- a/WebKit/chromium/src/AssertMatchingEnums.cpp
+++ b/WebKit/chromium/src/AssertMatchingEnums.cpp
@@ -247,6 +247,20 @@ COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Month, HTMLInputElement::MONTH);
COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Time, HTMLInputElement::TIME);
COMPILE_ASSERT_MATCHING_ENUM(WebInputElement::Week, HTMLInputElement::WEEK);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::ElementNode, Node::ELEMENT_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::AttributeNode, Node::ATTRIBUTE_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::TextNode, Node::TEXT_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::CDataSectionNode, Node::CDATA_SECTION_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::EntityReferenceNode, Node::ENTITY_REFERENCE_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::EntityNode, Node::ENTITY_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::ProcessingInstructionsNode, Node::PROCESSING_INSTRUCTION_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::CommentNode, Node::COMMENT_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentNode, Node::DOCUMENT_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentTypeNode, Node::DOCUMENT_TYPE_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::DocumentFragmentNode, Node::DOCUMENT_FRAGMENT_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::NotationNode, Node::NOTATION_NODE);
+COMPILE_ASSERT_MATCHING_ENUM(WebNode::XPathNamespaceNode, Node::XPATH_NAMESPACE_NODE);
+
#if ENABLE(VIDEO)
COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::Empty, MediaPlayer::Empty);
COMPILE_ASSERT_MATCHING_ENUM(WebMediaPlayer::Idle, MediaPlayer::Idle);
diff --git a/WebKit/chromium/src/DOMUtilitiesPrivate.cpp b/WebKit/chromium/src/DOMUtilitiesPrivate.cpp
index ffdd85d..4081db6 100644
--- a/WebKit/chromium/src/DOMUtilitiesPrivate.cpp
+++ b/WebKit/chromium/src/DOMUtilitiesPrivate.cpp
@@ -84,4 +84,53 @@ String nameOfInputElement(HTMLInputElement* element)
return WebInputElement(element).nameForAutofill();
}
+bool elementHasLegalLinkAttribute(const Element* element,
+ const QualifiedName& attrName)
+{
+ if (attrName == HTMLNames::srcAttr) {
+ // Check src attribute.
+ if (element->hasTagName(HTMLNames::imgTag)
+ || element->hasTagName(HTMLNames::scriptTag)
+ || element->hasTagName(HTMLNames::iframeTag)
+ || element->hasTagName(HTMLNames::frameTag))
+ return true;
+ if (element->hasTagName(HTMLNames::inputTag)) {
+ const HTMLInputElement* input =
+ static_cast<const HTMLInputElement*>(element);
+ if (input->inputType() == HTMLInputElement::IMAGE)
+ return true;
+ }
+ } else if (attrName == HTMLNames::hrefAttr) {
+ // Check href attribute.
+ if (element->hasTagName(HTMLNames::linkTag)
+ || element->hasTagName(HTMLNames::aTag)
+ || element->hasTagName(HTMLNames::areaTag))
+ return true;
+ } else if (attrName == HTMLNames::actionAttr) {
+ if (element->hasTagName(HTMLNames::formTag))
+ return true;
+ } else if (attrName == HTMLNames::backgroundAttr) {
+ if (element->hasTagName(HTMLNames::bodyTag)
+ || element->hasTagName(HTMLNames::tableTag)
+ || element->hasTagName(HTMLNames::trTag)
+ || element->hasTagName(HTMLNames::tdTag))
+ return true;
+ } else if (attrName == HTMLNames::citeAttr) {
+ if (element->hasTagName(HTMLNames::blockquoteTag)
+ || element->hasTagName(HTMLNames::qTag)
+ || element->hasTagName(HTMLNames::delTag)
+ || element->hasTagName(HTMLNames::insTag))
+ return true;
+ } else if (attrName == HTMLNames::classidAttr
+ || attrName == HTMLNames::dataAttr) {
+ if (element->hasTagName(HTMLNames::objectTag))
+ return true;
+ } else if (attrName == HTMLNames::codebaseAttr) {
+ if (element->hasTagName(HTMLNames::objectTag)
+ || element->hasTagName(HTMLNames::appletTag))
+ return true;
+ }
+ return false;
+}
+
} // namespace WebKit
diff --git a/WebKit/chromium/src/DOMUtilitiesPrivate.h b/WebKit/chromium/src/DOMUtilitiesPrivate.h
index c02bf84..253ab3f 100644
--- a/WebKit/chromium/src/DOMUtilitiesPrivate.h
+++ b/WebKit/chromium/src/DOMUtilitiesPrivate.h
@@ -32,11 +32,13 @@
#define DOMUtilitiesPrivate_h
namespace WebCore {
+class Element;
class HTMLInputElement;
class HTMLLinkElement;
class HTMLMetaElement;
class HTMLOptionElement;
class Node;
+class QualifiedName;
class String;
}
@@ -53,6 +55,16 @@ WebCore::HTMLOptionElement* toHTMLOptionElement(WebCore::Node*);
// FIXME: Deprecate. Use WebInputElement::nameForAutofill instead.
WebCore::String nameOfInputElement(WebCore::HTMLInputElement*);
+// For img, script, iframe, frame element, when attribute name is src,
+// for link, a, area element, when attribute name is href,
+// for form element, when attribute name is action,
+// for input, type=image, when attribute name is src,
+// for body, table, tr, td, when attribute name is background,
+// for blockquote, q, del, ins, when attribute name is cite,
+// we can consider the attribute value has legal link.
+bool elementHasLegalLinkAttribute(const WebCore::Element* element,
+ const WebCore::QualifiedName& attrName);
+
} // namespace WebKit
#endif
diff --git a/WebKit/chromium/src/WebDocument.cpp b/WebKit/chromium/src/WebDocument.cpp
new file mode 100644
index 0000000..2467a69
--- /dev/null
+++ b/WebKit/chromium/src/WebDocument.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebDocument.h"
+
+#include "Document.h"
+#include "Element.h"
+#include "HTMLAllCollection.h"
+#include "HTMLBodyElement.h"
+#include "HTMLCollection.h"
+#include "HTMLElement.h"
+#include "HTMLHeadElement.h"
+
+#include "WebElement.h"
+#include "WebFrameImpl.h"
+#include "WebNodeCollection.h"
+#include "WebURL.h"
+
+#include <wtf/PassRefPtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebDocument::WebDocument(const PassRefPtr<Document>& elem)
+ : WebNode(elem.releaseRef())
+{
+}
+
+WebDocument& WebDocument::operator=(const PassRefPtr<Document>& elem)
+{
+ WebNode::assign(elem.releaseRef());
+ return *this;
+}
+
+WebDocument::operator PassRefPtr<Document>() const
+{
+ return PassRefPtr<Document>(static_cast<Document*>(m_private));
+}
+
+WebFrame* WebDocument::frame() const
+{
+ return WebFrameImpl::fromFrame(constUnwrap<Document>()->frame());
+}
+
+bool WebDocument::isHTMLDocument() const
+{
+ return constUnwrap<Document>()->isHTMLDocument();
+}
+
+WebURL WebDocument::baseURL() const
+{
+ return constUnwrap<Document>()->baseURL();
+}
+
+WebElement WebDocument::body() const
+{
+ return WebElement(constUnwrap<Document>()->body());
+}
+
+WebElement WebDocument::head()
+{
+ return WebElement(unwrap<Document>()->head());
+}
+
+WebNodeCollection WebDocument::all()
+{
+ return WebNodeCollection(unwrap<Document>()->all());
+}
+
+WebURL WebDocument::completeURL(const WebString& partialURL) const
+{
+ return constUnwrap<Document>()->completeURL(partialURL);
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebElement.cpp b/WebKit/chromium/src/WebElement.cpp
index 3f13ee1..56980fe 100644
--- a/WebKit/chromium/src/WebElement.cpp
+++ b/WebKit/chromium/src/WebElement.cpp
@@ -54,5 +54,21 @@ WebElement::operator WTF::PassRefPtr<Element>() const
return PassRefPtr<Element>(static_cast<Element*>(m_private));
}
+bool WebElement::hasTagName(const WebString& tagName) const
+{
+ return equalIgnoringCase(constUnwrap<Element>()->tagName(),
+ tagName.operator WebCore::String());
+}
+
+bool WebElement::hasAttribute(const WebString& attrName) const
+{
+ return constUnwrap<Element>()->hasAttribute(attrName);
+}
+
+WebString WebElement::getAttribute(const WebString& attrName) const
+{
+ return constUnwrap<Element>()->getAttribute(attrName);
+}
+
} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEntities.cpp b/WebKit/chromium/src/WebEntities.cpp
new file mode 100644
index 0000000..b9143d9
--- /dev/null
+++ b/WebKit/chromium/src/WebEntities.cpp
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEntities.h"
+
+#include <string.h>
+
+#include "PlatformString.h"
+#include "StringBuilder.h"
+#include <wtf/HashMap.h>
+
+#include "WebString.h"
+
+using namespace WebCore;
+
+namespace {
+// Note that this file is also included by HTMLTokenizer.cpp so we are getting
+// two copies of the data in memory. We can fix this by changing the script
+// that generated the array to create a static const that is its length, but
+// this is low priority since the data is less than 4K. We use anonymous
+// namespace to prevent name collisions.
+#include "HTMLEntityNames.c" // NOLINT
+}
+
+namespace WebKit {
+
+void populateMap(WTF::HashMap<int, WebCore::String>& map,
+ const Entity* entities,
+ size_t entitiesCount,
+ bool standardHTML)
+{
+ ASSERT(map.isEmpty());
+ const Entity* entity = &entities[0];
+ for (size_t i = 0; i < entitiesCount; i++, entity++) {
+ int code = entity->code;
+ String name = entity->name;
+ // For consistency, use the lowe case for entities that have both.
+ if (map.contains(code) && map.get(code) == name.lower())
+ continue;
+ // Don't register %, ⊅ and &supl;.
+ if (standardHTML && (code == '%' || code == 0x2285 || code == 0x00b9))
+ continue;
+ map.set(code, name);
+ }
+ if (standardHTML)
+ map.set(static_cast<int>(0x0027), String("#39"));
+}
+
+static const Entity xmlBuiltInEntityCodes[] = {
+ { "lt", 0x003c },
+ { "gt", 0x003e },
+ { "amp", 0x0026 },
+ { "apos", 0x0027 },
+ { "quot", 0x0022 }
+};
+
+WebEntities::WebEntities(bool xmlEntities)
+{
+ if (xmlEntities)
+ populateMap(m_entitiesMap,
+ xmlBuiltInEntityCodes,
+ sizeof(xmlBuiltInEntityCodes) / sizeof(Entity),
+ false);
+ else
+ populateMap(m_entitiesMap,
+ wordlist,
+ sizeof(wordlist) / sizeof(Entity),
+ true);
+}
+
+String WebEntities::entityNameByCode(int code) const
+{
+ if (m_entitiesMap.contains(code))
+ return m_entitiesMap.get(code);
+ return "";
+}
+
+String WebEntities::convertEntitiesInString(const String& value) const
+{
+ unsigned len = value.length();
+ const UChar* startPos = value.characters();
+ const UChar* curPos = startPos;
+
+ // FIXME: Optimize - create StringBuilder only if value has any entities.
+ StringBuilder result;
+ while (len--) {
+ if (m_entitiesMap.contains(*curPos)) {
+ // Append content before entity code.
+ if (curPos > startPos)
+ result.append(String(startPos, curPos - startPos));
+ result.append("&");
+ result.append(m_entitiesMap.get(*curPos));
+ result.append(";");
+ startPos = ++curPos;
+ } else
+ curPos++;
+ }
+ // Append the remaining content.
+ if (curPos > startPos)
+ result.append(String(startPos, curPos - startPos));
+
+ return result.toString();
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEntities.h b/WebKit/chromium/src/WebEntities.h
new file mode 100644
index 0000000..ad3c310
--- /dev/null
+++ b/WebKit/chromium/src/WebEntities.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebEntities_h
+#define WebEntities_h
+
+#include "PlatformString.h"
+#include <wtf/HashMap.h>
+
+namespace WebKit {
+
+class WebEntities {
+public:
+ // ', %, ⊅, &supl; are not defined by the HTML standards.
+ // - IE does not support ' as an HTML entity (but support it as an XML
+ // entity.)
+ // - Firefox supports ' as an HTML entity.
+ // - Both of IE and Firefox don't support %, ⊅ and &supl;.
+ //
+ // A web page saved by Chromium should be able to be read by other browsers
+ // such as IE and Firefox. Chromium should produce only the standard entity
+ // references which other browsers can recognize.
+ // So if standard_html_entities_ is true, we will use a numeric character
+ // reference for ', and don't use entity references for %, ⊅
+ // and &supl; for serialization.
+ //
+ // If xmlEntities is true, WebEntities will only contain standard XML
+ // entities.
+ explicit WebEntities(bool xmlEntities);
+
+ // Check whether specified unicode has corresponding html or xml built-in
+ // entity name. If yes, return the entity notation. If not, returns an
+ // empty string. Parameter isHTML indicates check the code in html entity
+ // map or in xml entity map.
+ WebCore::String entityNameByCode(int code) const;
+
+ // Returns a new string with corresponding entity names replaced.
+ WebCore::String convertEntitiesInString(const WebCore::String&) const;
+private:
+ typedef HashMap<int, WebCore::String> EntitiesMapType;
+ // An internal object that maps the Unicode character to corresponding
+ // entity notation.
+ EntitiesMapType m_entitiesMap;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/WebFrameImpl.cpp b/WebKit/chromium/src/WebFrameImpl.cpp
index f709d9f..f6ccc24 100644
--- a/WebKit/chromium/src/WebFrameImpl.cpp
+++ b/WebKit/chromium/src/WebFrameImpl.cpp
@@ -122,6 +122,7 @@
#include "TextIterator.h"
#include "WebConsoleMessage.h"
#include "WebDataSourceImpl.h"
+#include "WebDocument.h"
#include "WebFindOptions.h"
#include "WebFormElement.h"
#include "WebFrameClient.h"
@@ -343,6 +344,12 @@ WebFrame* WebFrame::frameForCurrentContext()
return WebFrameImpl::fromFrame(frame);
}
+WebFrame* WebFrame::fromFrameOwnerElement(const WebElement& element)
+{
+ return WebFrameImpl::fromFrameOwnerElement(
+ PassRefPtr<Element>(element).get());
+}
+
WebString WebFrameImpl::name() const
{
return m_frame->tree()->name();
@@ -391,6 +398,11 @@ WebURL WebFrameImpl::openSearchDescriptionURL() const
return WebURL();
}
+WebString WebFrameImpl::encoding() const
+{
+ return frame()->loader()->encoding();
+}
+
WebSize WebFrameImpl::scrollOffset() const
{
FrameView* view = frameView();
@@ -515,6 +527,13 @@ WebFrame* WebFrameImpl::findChildByExpression(const WebString& xpath) const
return fromFrame(frameElement->contentFrame());
}
+WebDocument WebFrameImpl::document() const
+{
+ if (!m_frame || !m_frame->document())
+ return WebDocument();
+ return WebDocument(m_frame->document());
+}
+
void WebFrameImpl::forms(WebVector<WebFormElement>& results) const
{
if (!m_frame)
@@ -1630,6 +1649,19 @@ WebFrameImpl* WebFrameImpl::fromFrame(Frame* frame)
return static_cast<FrameLoaderClientImpl*>(frame->loader()->client())->webFrame();
}
+WebFrameImpl* WebFrameImpl::fromFrameOwnerElement(Element* element)
+{
+ if (!element
+ || !element->isFrameOwnerElement()
+ || (!element->hasTagName(HTMLNames::iframeTag)
+ && !element->hasTagName(HTMLNames::frameTag)))
+ return 0;
+
+ HTMLFrameOwnerElement* frameElement =
+ static_cast<HTMLFrameOwnerElement*>(element);
+ return fromFrame(frameElement->contentFrame());
+}
+
WebViewImpl* WebFrameImpl::viewImpl() const
{
if (!m_frame)
diff --git a/WebKit/chromium/src/WebFrameImpl.h b/WebKit/chromium/src/WebFrameImpl.h
index 2cd332a..6123fa5 100644
--- a/WebKit/chromium/src/WebFrameImpl.h
+++ b/WebKit/chromium/src/WebFrameImpl.h
@@ -65,6 +65,7 @@ public:
virtual WebURL url() const;
virtual WebURL favIconURL() const;
virtual WebURL openSearchDescriptionURL() const;
+ virtual WebString encoding() const;
virtual WebSize scrollOffset() const;
virtual WebSize contentsSize() const;
virtual int contentsPreferredWidth() const;
@@ -82,6 +83,7 @@ public:
virtual WebFrame* traversePrevious(bool wrap) const;
virtual WebFrame* findChildByName(const WebString&) const;
virtual WebFrame* findChildByExpression(const WebString&) const;
+ virtual WebDocument document() const;
virtual void forms(WebVector<WebFormElement>&) const;
virtual WebSecurityOrigin securityOrigin() const;
virtual void grantUniversalAccess();
@@ -157,7 +159,6 @@ public:
virtual WebURL completeURL(const WebString& url) const;
virtual WebString contentAsText(size_t maxChars) const;
virtual WebString contentAsMarkup() const;
-
static PassRefPtr<WebFrameImpl> create(WebFrameClient* client);
~WebFrameImpl();
@@ -174,6 +175,7 @@ public:
void createFrameView();
static WebFrameImpl* fromFrame(WebCore::Frame* frame);
+ static WebFrameImpl* fromFrameOwnerElement(WebCore::Element* element);
WebViewImpl* viewImpl() const;
diff --git a/WebKit/chromium/src/WebNode.cpp b/WebKit/chromium/src/WebNode.cpp
index 965c412..5dcd0c9 100644
--- a/WebKit/chromium/src/WebNode.cpp
+++ b/WebKit/chromium/src/WebNode.cpp
@@ -35,9 +35,15 @@
#include "Frame.h"
#include "FrameLoaderClientImpl.h"
#include "Node.h"
+#include "NodeList.h"
+#include "WebDocument.h"
#include "WebFrameImpl.h"
+#include "WebNodeList.h"
#include "WebString.h"
+#include "WebVector.h"
+
+#include "markup.h"
#include <wtf/PassRefPtr.h>
@@ -61,6 +67,11 @@ void WebNode::assign(const WebNode& other)
assign(p);
}
+WebNode::NodeType WebNode::nodeType() const
+{
+ return static_cast<NodeType>(m_private->nodeType());
+}
+
WebNode WebNode::parentNode() const
{
return PassRefPtr<Node>(const_cast<Node*>(m_private->parentNode()));
@@ -71,18 +82,23 @@ WebString WebNode::nodeName() const
return m_private->nodeName();
}
-WebNode::WebNode(const WTF::PassRefPtr<WebCore::Node>& node)
+WebString WebNode::nodeValue() const
+{
+ return m_private->nodeValue();
+}
+
+WebNode::WebNode(const PassRefPtr<Node>& node)
: m_private(static_cast<WebNodePrivate*>(node.releaseRef()))
{
}
-WebNode& WebNode::operator=(const WTF::PassRefPtr<WebCore::Node>& node)
+WebNode& WebNode::operator=(const PassRefPtr<Node>& node)
{
assign(static_cast<WebNodePrivate*>(node.releaseRef()));
return *this;
}
-WebNode::operator WTF::PassRefPtr<WebCore::Node>() const
+WebNode::operator PassRefPtr<Node>() const
{
return PassRefPtr<Node>(const_cast<WebNodePrivate*>(m_private));
}
@@ -100,4 +116,54 @@ WebFrame* WebNode::frame() const
return WebFrameImpl::fromFrame(m_private->document()->frame());
}
+WebDocument WebNode::document() const
+{
+ return WebDocument(m_private->document());
+}
+
+WebNode WebNode::firstChild() const
+{
+ return WebNode(m_private->firstChild());
+}
+
+WebNode WebNode::lastChild() const
+{
+ return WebNode(m_private->lastChild());
+}
+
+WebNode WebNode::previousSibling() const
+{
+ return WebNode(m_private->previousSibling());
+}
+
+WebNode WebNode::nextSibling() const
+{
+ return WebNode(m_private->nextSibling());
+}
+
+bool WebNode::hasChildNodes() const
+{
+ return m_private->hasChildNodes();
+}
+
+WebNodeList WebNode::childNodes()
+{
+ return WebNodeList(m_private->childNodes());
+}
+
+WebString WebNode::createMarkup() const
+{
+ return WebCore::createMarkup(m_private);
+}
+
+bool WebNode::isTextNode() const
+{
+ return m_private->isTextNode();
+}
+
+bool WebNode::isElementNode() const
+{
+ return m_private->isElementNode();
+}
+
} // namespace WebKit
diff --git a/WebKit/chromium/src/WebNodeCollection.cpp b/WebKit/chromium/src/WebNodeCollection.cpp
new file mode 100644
index 0000000..a9e532f
--- /dev/null
+++ b/WebKit/chromium/src/WebNodeCollection.cpp
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebNodeCollection.h"
+
+#include "HTMLCollection.h"
+#include "Node.h"
+#include <wtf/PassRefPtr.h>
+
+#include "WebNode.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebNodeCollection::reset()
+{
+ assign(0);
+}
+
+void WebNodeCollection::assign(const WebNodeCollection& other)
+{
+ HTMLCollection* p = const_cast<HTMLCollection*>(other.m_private);
+ if (p)
+ p->ref();
+ assign(p);
+}
+
+WebNodeCollection::WebNodeCollection(const PassRefPtr<HTMLCollection>& col)
+ : m_private(static_cast<HTMLCollection*>(col.releaseRef()))
+{
+}
+
+void WebNodeCollection::assign(HTMLCollection* p)
+{
+ // p is already ref'd for us by the caller
+ if (m_private)
+ m_private->deref();
+ m_private = p;
+}
+
+unsigned WebNodeCollection::length() const
+{
+ return m_private->length();
+}
+
+WebNode WebNodeCollection::nextItem() const
+{
+ return WebNode(m_private->nextItem());
+}
+
+WebNode WebNodeCollection::firstItem() const
+{
+ return WebNode(m_private->firstItem());
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebNodeList.cpp b/WebKit/chromium/src/WebNodeList.cpp
new file mode 100644
index 0000000..f68f961
--- /dev/null
+++ b/WebKit/chromium/src/WebNodeList.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebNodeList.h"
+
+#include "Node.h"
+#include "NodeList.h"
+#include <wtf/PassRefPtr.h>
+
+#include "WebNode.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebNodeList::reset()
+{
+ assign(0);
+}
+
+void WebNodeList::assign(const WebNodeList& other)
+{
+ NodeList* p = const_cast<NodeList*>(other.m_private);
+ if (p)
+ p->ref();
+ assign(p);
+}
+
+WebNodeList::WebNodeList(const PassRefPtr<NodeList>& col)
+ : m_private(static_cast<NodeList*>(col.releaseRef()))
+{
+}
+
+void WebNodeList::assign(NodeList* p)
+{
+ // p is already ref'd for us by the caller
+ if (m_private)
+ m_private->deref();
+ m_private = p;
+}
+
+unsigned WebNodeList::length() const
+{
+ return m_private->length();
+}
+
+WebNode WebNodeList::item(size_t index) const
+{
+ return WebNode(m_private->item(index));
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebPageSerializer.cpp b/WebKit/chromium/src/WebPageSerializer.cpp
new file mode 100644
index 0000000..1010285
--- /dev/null
+++ b/WebKit/chromium/src/WebPageSerializer.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebPageSerializer.h"
+
+#include "KURL.h"
+#include "PlatformString.h"
+
+#include "WebFrame.h"
+#include "WebPageSerializerClient.h"
+#include "WebPageSerializerImpl.h"
+#include "WebString.h"
+#include "WebURL.h"
+#include "WebVector.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+bool WebPageSerializer::serialize(WebFrame* frame,
+ bool recursive,
+ WebPageSerializerClient* client,
+ const WebVector<WebURL>& links,
+ const WebVector<WebString>& localPaths,
+ const WebString& localDirectoryName)
+{
+ WebPageSerializerImpl serializerImpl(
+ frame, recursive, client, links, localPaths, localDirectoryName);
+ return serializerImpl.serialize();
+}
+
+WebString WebPageSerializer::generateMetaCharsetDeclaration(const WebString& charset)
+{
+ return String::format("<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">",
+ charset.utf8().data());
+}
+
+WebString WebPageSerializer::generateMarkOfTheWebDeclaration(const WebURL& url)
+{
+ return String::format("\n<!-- saved from url=(%04d)%s -->\n",
+ static_cast<int>(url.spec().length()),
+ url.spec().data());
+}
+
+WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTarget)
+{
+ String targetDeclaration;
+ if (!baseTarget.isEmpty())
+ targetDeclaration = String::format(" target=\"%s\"", baseTarget.utf8().data());
+ return String::format("<BASE href=\".\"%s>", targetDeclaration.utf8().data());
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebPageSerializerImpl.cpp b/WebKit/chromium/src/WebPageSerializerImpl.cpp
new file mode 100644
index 0000000..d5b2b7f
--- /dev/null
+++ b/WebKit/chromium/src/WebPageSerializerImpl.cpp
@@ -0,0 +1,547 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// How we handle the base tag better.
+// Current status:
+// At now the normal way we use to handling base tag is
+// a) For those links which have corresponding local saved files, such as
+// savable CSS, JavaScript files, they will be written to relative URLs which
+// point to local saved file. Why those links can not be resolved as absolute
+// file URLs, because if they are resolved as absolute URLs, after moving the
+// file location from one directory to another directory, the file URLs will
+// be dead links.
+// b) For those links which have not corresponding local saved files, such as
+// links in A, AREA tags, they will be resolved as absolute URLs.
+// c) We comment all base tags when serialzing DOM for the page.
+// FireFox also uses above way to handle base tag.
+//
+// Problem:
+// This way can not handle the following situation:
+// the base tag is written by JavaScript.
+// For example. The page "www.yahoo.com" use
+// "document.write('<base href="http://www.yahoo.com/"...');" to setup base URL
+// of page when loading page. So when saving page as completed-HTML, we assume
+// that we save "www.yahoo.com" to "c:\yahoo.htm". After then we load the saved
+// completed-HTML page, then the JavaScript will insert a base tag
+// <base href="http://www.yahoo.com/"...> to DOM, so all URLs which point to
+// local saved resource files will be resolved as
+// "http://www.yahoo.com/yahoo_files/...", which will cause all saved resource
+// files can not be loaded correctly. Also the page will be rendered ugly since
+// all saved sub-resource files (such as CSS, JavaScript files) and sub-frame
+// files can not be fetched.
+// Now FireFox, IE and WebKit based Browser all have this problem.
+//
+// Solution:
+// My solution is that we comment old base tag and write new base tag:
+// <base href="." ...> after the previous commented base tag. In WebKit, it
+// always uses the latest "href" attribute of base tag to set document's base
+// URL. Based on this behavior, when we encounter a base tag, we comment it and
+// write a new base tag <base href="."> after the previous commented base tag.
+// The new added base tag can help engine to locate correct base URL for
+// correctly loading local saved resource files. Also I think we need to inherit
+// the base target value from document object when appending new base tag.
+// If there are multiple base tags in original document, we will comment all old
+// base tags and append new base tag after each old base tag because we do not
+// know those old base tags are original content or added by JavaScript. If
+// they are added by JavaScript, it means when loading saved page, the script(s)
+// will still insert base tag(s) to DOM, so the new added base tag(s) can
+// override the incorrect base URL and make sure we alway load correct local
+// saved resource files.
+
+#include "config.h"
+#include "WebPageSerializerImpl.h"
+
+#include "Document.h"
+#include "DocumentType.h"
+#include "Element.h"
+#include "FrameLoader.h"
+#include "HTMLAllCollection.h"
+#include "HTMLElement.h"
+#include "HTMLFormElement.h"
+#include "HTMLMetaElement.h"
+#include "HTMLNames.h"
+#include "KURL.h"
+#include "PlatformString.h"
+#include "StringBuilder.h"
+#include "TextEncoding.h"
+#include "markup.h"
+
+#include "DOMUtilitiesPrivate.h"
+#include "WebFrameImpl.h"
+#include "WebURL.h"
+#include "WebVector.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+// Maximum length of data buffer which is used to temporary save generated
+// html content data. This is a soft limit which might be passed if a very large
+// contegious string is found in the page.
+static const unsigned dataBufferCapacity = 65536;
+
+WebPageSerializerImpl::SerializeDomParam::SerializeDomParam(const KURL& currentFrameURL,
+ const TextEncoding& textEncoding,
+ Document* doc,
+ const String& directoryName)
+ : currentFrameURL(currentFrameURL)
+ , textEncoding(textEncoding)
+ , doc(doc)
+ , directoryName(directoryName)
+ , hasDoctype(false)
+ , hasCheckedMeta(false)
+ , skipMetaElement(0)
+ , isInScriptOrStyleTag(false)
+ , hasDocDeclaration(false)
+{
+ // Cache the value since we check it lots of times.
+ isHTMLDocument = doc->isHTMLDocument();
+}
+
+String WebPageSerializerImpl::preActionBeforeSerializeOpenTag(
+ const Element* element, SerializeDomParam* param, bool* needSkip)
+{
+ StringBuilder result;
+
+ *needSkip = false;
+ if (param->isHTMLDocument) {
+ // Skip the open tag of original META tag which declare charset since we
+ // have overrided the META which have correct charset declaration after
+ // serializing open tag of HEAD element.
+ if (element->hasTagName(HTMLNames::metaTag)) {
+ const HTMLMetaElement* meta = static_cast<const HTMLMetaElement*>(element);
+ // Check whether the META tag has declared charset or not.
+ String equiv = meta->httpEquiv();
+ if (equalIgnoringCase(equiv, "content-type")) {
+ String content = meta->content();
+ if (content.length() && content.contains("charset", false)) {
+ // Find META tag declared charset, we need to skip it when
+ // serializing DOM.
+ param->skipMetaElement = element;
+ *needSkip = true;
+ }
+ }
+ } else if (element->hasTagName(HTMLNames::htmlTag)) {
+ // Check something before processing the open tag of HEAD element.
+ // First we add doc type declaration if original doc has it.
+ if (!param->hasDoctype) {
+ param->hasDoctype = true;
+ result.append(createMarkup(param->doc->doctype()));
+ }
+
+ // Add MOTW declaration before html tag.
+ // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx.
+ result.append(WebPageSerializer::generateMarkOfTheWebDeclaration(param->currentFrameURL));
+ } else if (element->hasTagName(HTMLNames::baseTag)) {
+ // Comment the BASE tag when serializing dom.
+ result.append("<!--");
+ }
+ } else {
+ // Write XML declaration.
+ if (!param->hasDocDeclaration) {
+ param->hasDocDeclaration = true;
+ // Get encoding info.
+ String xmlEncoding = param->doc->xmlEncoding();
+ if (xmlEncoding.isEmpty())
+ xmlEncoding = param->doc->frame()->loader()->encoding();
+ if (xmlEncoding.isEmpty())
+ xmlEncoding = UTF8Encoding().name();
+ result.append("<?xml version=\"");
+ result.append(param->doc->xmlVersion());
+ result.append("\" encoding=\"");
+ result.append(xmlEncoding);
+ if (param->doc->xmlStandalone())
+ result.append("\" standalone=\"yes");
+ result.append("\"?>\n");
+ }
+ // Add doc type declaration if original doc has it.
+ if (!param->hasDoctype) {
+ param->hasDoctype = true;
+ result.append(createMarkup(param->doc->doctype()));
+ }
+ }
+ return result.toString();
+}
+
+String WebPageSerializerImpl::postActionAfterSerializeOpenTag(
+ const Element* element, SerializeDomParam* param)
+{
+ StringBuilder result;
+
+ param->hasAddedContentsBeforeEnd = false;
+ if (!param->isHTMLDocument)
+ return result.toString();
+ // Check after processing the open tag of HEAD element
+ if (!param->hasCheckedMeta
+ && element->hasTagName(HTMLNames::headTag)) {
+ param->hasCheckedMeta = true;
+ // Check meta element. WebKit only pre-parse the first 512 bytes
+ // of the document. If the whole <HEAD> is larger and meta is the
+ // end of head part, then this kind of pages aren't decoded correctly
+ // because of this issue. So when we serialize the DOM, we need to
+ // make sure the meta will in first child of head tag.
+ // See http://bugs.webkit.org/show_bug.cgi?id=16621.
+ // First we generate new content for writing correct META element.
+ result.append(WebPageSerializer::generateMetaCharsetDeclaration(
+ String(param->textEncoding.name())));
+
+ param->hasAddedContentsBeforeEnd = true;
+ // Will search each META which has charset declaration, and skip them all
+ // in PreActionBeforeSerializeOpenTag.
+ } else if (element->hasTagName(HTMLNames::scriptTag)
+ || element->hasTagName(HTMLNames::styleTag)) {
+ param->isInScriptOrStyleTag = true;
+ }
+
+ return result.toString();
+}
+
+String WebPageSerializerImpl::preActionBeforeSerializeEndTag(
+ const Element* element, SerializeDomParam* param, bool* needSkip)
+{
+ String result;
+
+ *needSkip = false;
+ if (!param->isHTMLDocument)
+ return result;
+ // Skip the end tag of original META tag which declare charset.
+ // Need not to check whether it's META tag since we guarantee
+ // skipMetaElement is definitely META tag if it's not 0.
+ if (param->skipMetaElement == element)
+ *needSkip = true;
+ else if (element->hasTagName(HTMLNames::scriptTag)
+ || element->hasTagName(HTMLNames::styleTag)) {
+ ASSERT(param->isInScriptOrStyleTag);
+ param->isInScriptOrStyleTag = false;
+ }
+
+ return result;
+}
+
+// After we finish serializing end tag of a element, we give the target
+// element a chance to do some post work to add some additional data.
+String WebPageSerializerImpl::postActionAfterSerializeEndTag(
+ const Element* element, SerializeDomParam* param)
+{
+ StringBuilder result;
+
+ if (!param->isHTMLDocument)
+ return result.toString();
+ // Comment the BASE tag when serializing DOM.
+ if (element->hasTagName(HTMLNames::baseTag)) {
+ result.append("-->");
+ // Append a new base tag declaration.
+ result.append(WebPageSerializer::generateBaseTagDeclaration(
+ param->doc->baseTarget()));
+ }
+
+ return result.toString();
+}
+
+void WebPageSerializerImpl::saveHTMLContentToBuffer(
+ const String& result, SerializeDomParam* param)
+{
+ m_dataBuffer.append(result);
+ encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsNotFinished,
+ param,
+ 0);
+}
+
+void WebPageSerializerImpl::encodeAndFlushBuffer(
+ WebPageSerializerClient::PageSerializationStatus status,
+ SerializeDomParam* param,
+ bool force)
+{
+ // Data buffer is not full nor do we want to force flush.
+ if (!force && m_dataBuffer.length() <= dataBufferCapacity)
+ return;
+
+ String content = m_dataBuffer.toString();
+ m_dataBuffer.clear();
+
+ // Convert the unicode content to target encoding
+ CString encodedContent = param->textEncoding.encode(
+ content.characters(), content.length(), EntitiesForUnencodables);
+
+ // Send result to the client.
+ m_client->didSerializeDataForFrame(param->currentFrameURL,
+ WebCString(encodedContent.data(), encodedContent.length()),
+ status);
+}
+
+void WebPageSerializerImpl::openTagToString(const Element* element,
+ SerializeDomParam* param)
+{
+ // FIXME: use StringBuilder instead of String.
+ bool needSkip;
+ // Do pre action for open tag.
+ String result = preActionBeforeSerializeOpenTag(element, param, &needSkip);
+ if (needSkip)
+ return;
+ // Add open tag
+ result += "<" + element->nodeName();
+ // Go through all attributes and serialize them.
+ const NamedNodeMap *attrMap = element->attributes(true);
+ if (attrMap) {
+ unsigned numAttrs = attrMap->length();
+ for (unsigned i = 0; i < numAttrs; i++) {
+ result += " ";
+ // Add attribute pair
+ const Attribute *attribute = attrMap->attributeItem(i);
+ result += attribute->name().toString();
+ result += "=\"";
+ if (!attribute->value().isEmpty()) {
+ const String& attrValue = attribute->value();
+
+ // Check whether we need to replace some resource links
+ // with local resource paths.
+ const QualifiedName& attrName = attribute->name();
+ if (elementHasLegalLinkAttribute(element, attrName)) {
+ // For links start with "javascript:", we do not change it.
+ if (attrValue.startsWith("javascript:", false))
+ result += attrValue;
+ else {
+ // Get the absolute link
+ String completeURL = param->doc->completeURL(attrValue);
+ // Check whether we have local files for those link.
+ if (m_localLinks.contains(completeURL)) {
+ if (!m_localDirectoryName.isEmpty())
+ result += "./" + m_localDirectoryName + "/";
+ result += m_localLinks.get(completeURL);
+ } else
+ result += completeURL;
+ }
+ } else {
+ if (param->isHTMLDocument)
+ result += m_htmlEntities.convertEntitiesInString(attrValue);
+ else
+ result += m_xmlEntities.convertEntitiesInString(attrValue);
+ }
+ }
+ result += "\"";
+ }
+ }
+
+ // Do post action for open tag.
+ String addedContents = postActionAfterSerializeOpenTag(element, param);
+ // Complete the open tag for element when it has child/children.
+ if (element->hasChildNodes() || param->hasAddedContentsBeforeEnd)
+ result += ">";
+ // Append the added contents generate in post action of open tag.
+ result += addedContents;
+ // Save the result to data buffer.
+ saveHTMLContentToBuffer(result, param);
+}
+
+// Serialize end tag of an specified element.
+void WebPageSerializerImpl::endTagToString(const Element* element,
+ SerializeDomParam* param)
+{
+ bool needSkip;
+ // Do pre action for end tag.
+ String result = preActionBeforeSerializeEndTag(element,
+ param,
+ &needSkip);
+ if (needSkip)
+ return;
+ // Write end tag when element has child/children.
+ if (element->hasChildNodes() || param->hasAddedContentsBeforeEnd) {
+ result += "</";
+ result += element->nodeName();
+ result += ">";
+ } else {
+ // Check whether we have to write end tag for empty element.
+ if (param->isHTMLDocument) {
+ result += ">";
+ const HTMLElement* htmlElement =
+ static_cast<const HTMLElement*>(element);
+ if (htmlElement->endTagRequirement() == TagStatusRequired) {
+ // We need to write end tag when it is required.
+ result += "</";
+ result += element->nodeName();
+ result += ">";
+ }
+ } else {
+ // For xml base document.
+ result += " />";
+ }
+ }
+ // Do post action for end tag.
+ result += postActionAfterSerializeEndTag(element, param);
+ // Save the result to data buffer.
+ saveHTMLContentToBuffer(result, param);
+}
+
+void WebPageSerializerImpl::buildContentForNode(const Node* node,
+ SerializeDomParam* param)
+{
+ switch (node->nodeType()) {
+ case Node::ELEMENT_NODE:
+ // Process open tag of element.
+ openTagToString(static_cast<const Element*>(node), param);
+ // Walk through the children nodes and process it.
+ for (const Node *child = node->firstChild(); child; child = child->nextSibling())
+ buildContentForNode(child, param);
+ // Process end tag of element.
+ endTagToString(static_cast<const Element*>(node), param);
+ break;
+ case Node::TEXT_NODE:
+ saveHTMLContentToBuffer(createMarkup(node), param);
+ break;
+ case Node::ATTRIBUTE_NODE:
+ case Node::DOCUMENT_NODE:
+ case Node::DOCUMENT_FRAGMENT_NODE:
+ // Should not exist.
+ ASSERT_NOT_REACHED();
+ break;
+ // Document type node can be in DOM?
+ case Node::DOCUMENT_TYPE_NODE:
+ param->hasDoctype = true;
+ default:
+ // For other type node, call default action.
+ saveHTMLContentToBuffer(createMarkup(node), param);
+ break;
+ }
+}
+
+WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame,
+ bool recursiveSerialization,
+ WebPageSerializerClient* client,
+ const WebVector<WebURL>& links,
+ const WebVector<WebString>& localPaths,
+ const WebString& localDirectoryName)
+ : m_client(client)
+ , m_recursiveSerialization(recursiveSerialization)
+ , m_framesCollected(false)
+ , m_localDirectoryName(localDirectoryName)
+ , m_htmlEntities(false)
+ , m_xmlEntities(true)
+{
+ // Must specify available webframe.
+ ASSERT(frame);
+ m_specifiedWebFrameImpl = static_cast<WebFrameImpl*>(frame);
+ // Make sure we have non 0 client.
+ ASSERT(client);
+ // Build local resources map.
+ ASSERT(links.size() == localPaths.size());
+ for (size_t i = 0; i < links.size(); i++) {
+ KURL url = links[i];
+ ASSERT(!m_localLinks.contains(url.string()));
+ m_localLinks.set(url.string(), localPaths[i]);
+ }
+
+ ASSERT(!m_dataBuffer.length());
+}
+
+void WebPageSerializerImpl::collectTargetFrames()
+{
+ ASSERT(!m_framesCollected);
+ m_framesCollected = true;
+
+ // First, process main frame.
+ m_frames.append(m_specifiedWebFrameImpl);
+ // Return now if user only needs to serialize specified frame, not including
+ // all sub-frames.
+ if (!m_recursiveSerialization)
+ return;
+ // Collect all frames inside the specified frame.
+ for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) {
+ WebFrameImpl* currentFrame = m_frames[i];
+ // Get current using document.
+ Document* currentDoc = currentFrame->frame()->document();
+ // Go through sub-frames.
+ RefPtr<HTMLAllCollection> all = currentDoc->all();
+ for (Node* node = all->firstItem(); node; node = all->nextItem()) {
+ if (!node->isHTMLElement())
+ continue;
+ Element* element = static_cast<Element*>(node);
+ WebFrameImpl* webFrame =
+ WebFrameImpl::fromFrameOwnerElement(element);
+ if (webFrame)
+ m_frames.append(webFrame);
+ }
+ }
+}
+
+bool WebPageSerializerImpl::serialize()
+{
+ // Collect target frames.
+ if (!m_framesCollected)
+ collectTargetFrames();
+ bool didSerialization = false;
+ // Get KURL for main frame.
+ KURL mainPageURL = m_specifiedWebFrameImpl->frame()->loader()->url();
+
+ // Go through all frames for serializing DOM for whole page, include
+ // sub-frames.
+ for (int i = 0; i < static_cast<int>(m_frames.size()); ++i) {
+ // Get current serializing frame.
+ WebFrameImpl* currentFrame = m_frames[i];
+ // Get current using document.
+ Document* currentDoc = currentFrame->frame()->document();
+ // Get current frame's URL.
+ const KURL& currentFrameURL = currentFrame->frame()->loader()->url();
+
+ // Check whether we have done this document.
+ if (m_localLinks.contains(currentFrameURL.string())) {
+ // A new document, we will serialize it.
+ didSerialization = true;
+ // Get target encoding for current document.
+ String encoding = currentFrame->frame()->loader()->encoding();
+ // Create the text encoding object with target encoding.
+ TextEncoding textEncoding(encoding);
+ // Construct serialize parameter for late processing document.
+ SerializeDomParam param(currentFrameURL,
+ encoding.length() ? textEncoding : UTF8Encoding(),
+ currentDoc,
+ currentFrameURL == mainPageURL ? m_localDirectoryName : "");
+
+ // Process current document.
+ Element* rootElement = currentDoc->documentElement();
+ if (rootElement)
+ buildContentForNode(rootElement, ¶m);
+
+ // Flush the remainder data and finish serializing current frame.
+ encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished,
+ ¶m,
+ 1);
+ }
+ }
+
+ // We have done call frames, so we send message to embedder to tell it that
+ // frames are finished serializing.
+ ASSERT(!m_dataBuffer.length());
+ m_client->didSerializeDataForFrame(KURL(),
+ WebCString("", 0),
+ WebPageSerializerClient::AllFramesAreFinished);
+ return didSerialization;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebPageSerializerImpl.h b/WebKit/chromium/src/WebPageSerializerImpl.h
new file mode 100644
index 0000000..8f6a99f
--- /dev/null
+++ b/WebKit/chromium/src/WebPageSerializerImpl.h
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPageSerializerImpl_h
+#define WebPageSerializerImpl_h
+
+#include "PlatformString.h"
+#include "StringBuilder.h"
+#include "StringHash.h"
+#include <wtf/HashMap.h>
+#include <wtf/Vector.h>
+
+#include "WebEntities.h"
+#include "WebPageSerializer.h"
+#include "WebPageSerializerClient.h"
+#include "WebString.h"
+#include "WebURL.h"
+
+namespace WebCore {
+class Document;
+class Element;
+class Node;
+class String;
+class TextEncoding;
+}
+
+namespace WebKit {
+class WebFrameImpl;
+
+// Get html data by serializing all frames of current page with lists
+// which contain all resource links that have local copy.
+// contain all saved auxiliary files included all sub frames and resources.
+// This function will find out all frames and serialize them to HTML data.
+// We have a data buffer to temporary saving generated html data. We will
+// sequentially call WebViewDelegate::SendSerializedHtmlData once the data
+// buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData
+// for getting more information.
+class WebPageSerializerImpl {
+public:
+ // Do serialization action. Return false means no available frame has been
+ // serialized, otherwise return true.
+ bool serialize();
+
+ // The parameter specifies which frame need to be serialized.
+ // The parameter recursive_serialization specifies whether we need to
+ // serialize all sub frames of the specified frame or not.
+ // The parameter delegate specifies the pointer of interface
+ // DomSerializerDelegate provide sink interface which can receive the
+ // individual chunks of data to be saved.
+ // The parameter links contain original URLs of all saved links.
+ // The parameter local_paths contain corresponding local file paths of all
+ // saved links, which matched with vector:links one by one.
+ // The parameter local_directory_name is relative path of directory which
+ // contain all saved auxiliary files included all sub frames and resources.
+ WebPageSerializerImpl(WebFrame* frame,
+ bool recursive,
+ WebPageSerializerClient* client,
+ const WebVector<WebURL>& links,
+ const WebVector<WebString>& localPaths,
+ const WebString& localDirectoryName);
+
+private:
+ // Specified frame which need to be serialized;
+ WebFrameImpl* m_specifiedWebFrameImpl;
+ // Pointer of WebPageSerializerClient
+ WebPageSerializerClient* m_client;
+ // This hash map is used to map resource URL of original link to its local
+ // file path.
+ typedef HashMap<WebCore::String, WebCore::String> LinkLocalPathMap;
+ // local_links_ include all pair of local resource path and corresponding
+ // original link.
+ LinkLocalPathMap m_localLinks;
+ // Data buffer for saving result of serialized DOM data.
+ WebCore::StringBuilder m_dataBuffer;
+ // Passing true to recursive_serialization_ indicates we will serialize not
+ // only the specified frame but also all sub-frames in the specific frame.
+ // Otherwise we only serialize the specified frame excluded all sub-frames.
+ bool m_recursiveSerialization;
+ // Flag indicates whether we have collected all frames which need to be
+ // serialized or not;
+ bool m_framesCollected;
+ // Local directory name of all local resource files.
+ WebCore::String m_localDirectoryName;
+ // Vector for saving all frames which need to be serialized.
+ Vector<WebFrameImpl*> m_frames;
+
+ // Web entities conversion maps.
+ WebEntities m_htmlEntities;
+ WebEntities m_xmlEntities;
+
+ struct SerializeDomParam {
+ // Frame URL of current processing document presented by GURL
+ const WebCore::KURL& currentFrameURL;
+ // Current using text encoding object.
+ const WebCore::TextEncoding& textEncoding;
+
+ // Document object of current frame.
+ WebCore::Document* doc;
+ // Local directory name of all local resource files.
+ const WebCore::String& directoryName;
+
+ // Flag indicates current doc is html document or not. It's a cache value
+ // of Document.isHTMLDocument().
+ bool isHTMLDocument;
+ // Flag which indicate whether we have met document type declaration.
+ bool hasDoctype;
+ // Flag which indicate whether will process meta issue.
+ bool hasCheckedMeta;
+ // This meta element need to be skipped when serializing DOM.
+ const WebCore::Element* skipMetaElement;
+ // Flag indicates we are in script or style tag.
+ bool isInScriptOrStyleTag;
+ // Flag indicates whether we have written xml document declaration.
+ // It is only used in xml document
+ bool hasDocDeclaration;
+ // Flag indicates whether we have added additional contents before end tag.
+ // This flag will be re-assigned in each call of function
+ // PostActionAfterSerializeOpenTag and it could be changed in function
+ // PreActionBeforeSerializeEndTag if the function adds new contents into
+ // serialization stream.
+ bool hasAddedContentsBeforeEnd;
+
+ // Constructor.
+ SerializeDomParam(const WebCore::KURL& currentFrameURL,
+ const WebCore::TextEncoding& textEncoding,
+ WebCore::Document* doc,
+ const WebCore::String& directoryName);
+ };
+
+ // Collect all target frames which need to be serialized.
+ void collectTargetFrames();
+ // Before we begin serializing open tag of a element, we give the target
+ // element a chance to do some work prior to add some additional data.
+ WebCore::String preActionBeforeSerializeOpenTag(const WebCore::Element* element,
+ SerializeDomParam* param,
+ bool* needSkip);
+ // After we finish serializing open tag of a element, we give the target
+ // element a chance to do some post work to add some additional data.
+ WebCore::String postActionAfterSerializeOpenTag(const WebCore::Element* element,
+ SerializeDomParam* param);
+ // Before we begin serializing end tag of a element, we give the target
+ // element a chance to do some work prior to add some additional data.
+ WebCore::String preActionBeforeSerializeEndTag(const WebCore::Element* element,
+ SerializeDomParam* param,
+ bool* needSkip);
+ // After we finish serializing end tag of a element, we give the target
+ // element a chance to do some post work to add some additional data.
+ WebCore::String postActionAfterSerializeEndTag(const WebCore::Element* element,
+ SerializeDomParam* param);
+ // Save generated html content to data buffer.
+ void saveHTMLContentToBuffer(const WebCore::String& content,
+ SerializeDomParam* param);
+ // Flushes the content buffer by encoding and sending the content to the
+ // WebPageSerializerClient. Content is not flushed if the buffer is not full
+ // unless force is 1.
+ void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus status,
+ SerializeDomParam* param,
+ bool force);
+ // Serialize open tag of an specified element.
+ void openTagToString(const WebCore::Element* element,
+ SerializeDomParam* param);
+ // Serialize end tag of an specified element.
+ void endTagToString(const WebCore::Element* element,
+ SerializeDomParam* param);
+ // Build content for a specified node
+ void buildContentForNode(const WebCore::Node* node,
+ SerializeDomParam* param);
+};
+
+} // namespace WebKit
+
+#endif
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list