Title: [89504] trunk/Source
Revision
89504
Author
[email protected]
Date
2011-06-22 17:39:10 -0700 (Wed, 22 Jun 2011)

Log Message

2011-06-22  Adam Barth  <[email protected]>

        Reviewed by Darin Fisher.

        [Chromium] Add WebDocument APIs for the functions moving from WebFrame
        https://bugs.webkit.org/show_bug.cgi?id=62831

        * dom/Document.cpp:
        (WebCore::Document::openSearchDescriptionURL):
            - This function exists to service a Chromium WebKit API, but it's
              generally purpose and might be useful to other ports.  The
              algorithm has some strange early exits, which I've marked with
              FIXME comments.
        * dom/Document.h:
2011-06-22  Adam Barth  <[email protected]>

        Reviewed by Darin Fisher.

        [Chromium] Add WebDocument APIs for the functions moving from WebFrame
        https://bugs.webkit.org/show_bug.cgi?id=62831

        The next phase will be to change all the callers and then remove all
        the code inside the ifdef.

        * public/WebDocument.h:
            - Add new APIs.
        * public/WebFrame.h:
            - These two APIs were too disgusting.  I could not, in good
              conscience, touch them.
        * public/WebSecurityOrigin.h:
            - Turns out this API is supposed to be on WebSecurityOrigin, not
              WebDocument.
        * src/WebDocument.cpp:
            - Implement the APIs.
        (WebKit::WebDocument::url):
        (WebKit::WebDocument::securityOrigin):
        (WebKit::WebDocument::encoding):
        (WebKit::WebDocument::openSearchDescriptionURL):
        (WebKit::WebDocument::forms):
        (WebKit::WebDocument::insertStyleText):
        * src/WebFrameImpl.cpp:
            - Change these implements to just be stubs that call into the real
              implementations in WebDocument.
        (WebKit::WebFrameImpl::url):
        (WebKit::WebFrameImpl::openSearchDescriptionURL):
        (WebKit::WebFrameImpl::encoding):
        (WebKit::WebFrameImpl::forms):
        (WebKit::WebFrameImpl::securityOrigin):
        (WebKit::WebFrameImpl::grantUniversalAccess):
        (WebKit::WebFrameImpl::insertStyleText):
        (WebKit::WebFrameImpl::contentAsMarkup):
        * src/WebSecurityOrigin.cpp:
        (WebKit::WebSecurityOrigin::grantUniversalAccess):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (89503 => 89504)


--- trunk/Source/WebCore/ChangeLog	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebCore/ChangeLog	2011-06-23 00:39:10 UTC (rev 89504)
@@ -1,3 +1,18 @@
+2011-06-22  Adam Barth  <[email protected]>
+
+        Reviewed by Darin Fisher.
+
+        [Chromium] Add WebDocument APIs for the functions moving from WebFrame
+        https://bugs.webkit.org/show_bug.cgi?id=62831
+
+        * dom/Document.cpp:
+        (WebCore::Document::openSearchDescriptionURL):
+            - This function exists to service a Chromium WebKit API, but it's
+              generally purpose and might be useful to other ports.  The
+              algorithm has some strange early exits, which I've marked with
+              FIXME comments.
+        * dom/Document.h:
+
 2011-06-22  Nate Chapin  <[email protected]>
 
         Reviewed by Adam Barth.

Modified: trunk/Source/WebCore/dom/Document.cpp (89503 => 89504)


--- trunk/Source/WebCore/dom/Document.cpp	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-06-23 00:39:10 UTC (rev 89504)
@@ -3950,6 +3950,37 @@
     return command(this, commandName).value();
 }
 
+KURL Document::openSearchDescriptionURL()
+{
+    static const char* const openSearchMIMEType = "application/opensearchdescription+xml";
+    static const char* const openSearchRelation = "search";
+
+    // FIXME: Why do only top-level frames have openSearchDescriptionURLs?
+    if (!frame() || frame()->tree()->parent())
+        return KURL();
+
+    // FIXME: Why do we need to wait for FrameStateComplete?
+    if (frame()->loader()->state() != FrameStateComplete)
+        return KURL();
+
+    if (!head())
+        return KURL();
+
+    RefPtr<HTMLCollection> children = head()->children();
+    for (Node* child = children->firstItem(); child; child = children->nextItem()) {
+        if (!child->isHTMLElement() || !static_cast<HTMLElement*>(child)->hasTagName(linkTag))
+            continue;
+        HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(child);
+        if (!equalIgnoringCase(linkElement->type(), openSearchMIMEType) || !equalIgnoringCase(linkElement->rel(), openSearchRelation))
+            continue;
+        if (linkElement->href().isEmpty())
+            continue;
+        return linkElement->href();
+    }
+
+    return KURL();
+}
+
 #if ENABLE(XSLT)
 
 void Document::applyXSLTransform(ProcessingInstruction* pi)

Modified: trunk/Source/WebCore/dom/Document.h (89503 => 89504)


--- trunk/Source/WebCore/dom/Document.h	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebCore/dom/Document.h	2011-06-23 00:39:10 UTC (rev 89504)
@@ -860,7 +860,9 @@
     bool queryCommandState(const String& command);
     bool queryCommandSupported(const String& command);
     String queryCommandValue(const String& command);
-    
+
+    KURL openSearchDescriptionURL();
+
     // designMode support
     enum InheritedBool { off = false, on = true, inherit };    
     void setDesignMode(InheritedBool value);

Modified: trunk/Source/WebKit/chromium/ChangeLog (89503 => 89504)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-06-23 00:39:10 UTC (rev 89504)
@@ -1,3 +1,43 @@
+2011-06-22  Adam Barth  <[email protected]>
+
+        Reviewed by Darin Fisher.
+
+        [Chromium] Add WebDocument APIs for the functions moving from WebFrame
+        https://bugs.webkit.org/show_bug.cgi?id=62831
+
+        The next phase will be to change all the callers and then remove all
+        the code inside the ifdef.
+
+        * public/WebDocument.h:
+            - Add new APIs.
+        * public/WebFrame.h:
+            - These two APIs were too disgusting.  I could not, in good
+              conscience, touch them.
+        * public/WebSecurityOrigin.h:
+            - Turns out this API is supposed to be on WebSecurityOrigin, not
+              WebDocument.
+        * src/WebDocument.cpp:
+            - Implement the APIs.
+        (WebKit::WebDocument::url):
+        (WebKit::WebDocument::securityOrigin):
+        (WebKit::WebDocument::encoding):
+        (WebKit::WebDocument::openSearchDescriptionURL):
+        (WebKit::WebDocument::forms):
+        (WebKit::WebDocument::insertStyleText):
+        * src/WebFrameImpl.cpp:
+            - Change these implements to just be stubs that call into the real
+              implementations in WebDocument.
+        (WebKit::WebFrameImpl::url):
+        (WebKit::WebFrameImpl::openSearchDescriptionURL):
+        (WebKit::WebFrameImpl::encoding):
+        (WebKit::WebFrameImpl::forms):
+        (WebKit::WebFrameImpl::securityOrigin):
+        (WebKit::WebFrameImpl::grantUniversalAccess):
+        (WebKit::WebFrameImpl::insertStyleText):
+        (WebKit::WebFrameImpl::contentAsMarkup):
+        * src/WebSecurityOrigin.cpp:
+        (WebKit::WebSecurityOrigin::grantUniversalAccess):
+
 2011-06-22  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r89489.

Modified: trunk/Source/WebKit/chromium/public/WebDocument.h (89503 => 89504)


--- trunk/Source/WebKit/chromium/public/WebDocument.h	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/public/WebDocument.h	2011-06-23 00:39:10 UTC (rev 89504)
@@ -31,7 +31,9 @@
 #ifndef WebDocument_h
 #define WebDocument_h
 
+#include "WebFormElement.h"
 #include "WebNode.h"
+#include "WebSecurityOrigin.h"
 
 #if WEBKIT_IMPLEMENTATION
 namespace WebCore {
@@ -64,6 +66,15 @@
     }
     void assign(const WebDocument& e) { WebNode::assign(e); }
 
+    WEBKIT_API WebURL url() const;
+    // Note: Security checks should use the securityOrigin(), not url().
+    WEBKIT_API WebSecurityOrigin securityOrigin() const;
+
+    WEBKIT_API WebString encoding() const;
+
+    // The url of the OpenSearch Desription Document (if any).
+    WEBKIT_API WebURL openSearchDescriptionURL() const;
+
     // Returns the frame the document belongs to or 0 if the document is frameless.
     WEBKIT_API WebFrame* frame() const;
     WEBKIT_API bool isHTMLDocument() const;
@@ -76,12 +87,20 @@
     WEBKIT_API WebElement head();
     WEBKIT_API WebString title() const;
     WEBKIT_API WebNodeCollection all();
+    WEBKIT_API void forms(WebVector<WebFormElement>&) const;
     WEBKIT_API WebURL completeURL(const WebString&) const;
     WEBKIT_API WebElement getElementById(const WebString&) const;
     WEBKIT_API WebNode focusedNode() const;
     WEBKIT_API WebDocumentType doctype() const;
     WEBKIT_API WebAccessibilityObject accessibilityObject() const;
 
+    // Insert the given text as a STYLE element at the beginning of the
+    // document. |elementId| can be empty, but if specified then it is used
+    // as the id for the newly inserted element (replacing an existing one
+    // with the same id, if any).
+    WEBKIT_API bool insertStyleText(const WebString& styleText,
+                                    const WebString& elementId);
+
 #if WEBKIT_IMPLEMENTATION
     WebDocument(const WTF::PassRefPtr<WebCore::Document>&);
     WebDocument& operator=(const WTF::PassRefPtr<WebCore::Document>&);

Modified: trunk/Source/WebKit/chromium/public/WebFrame.h (89503 => 89504)


--- trunk/Source/WebKit/chromium/public/WebFrame.h	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/public/WebFrame.h	2011-06-23 00:39:10 UTC (rev 89504)
@@ -579,7 +579,6 @@
 
     // Utility -------------------------------------------------------------
 
-#if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
     // Returns the contents of this frame as a string.  If the text is
     // longer than maxChars, it will be clipped to that length.  WARNING:
     // This function may be slow depending on the number of characters
@@ -593,7 +592,6 @@
     // Returns HTML text for the contents of this frame.  This is generated
     // from the DOM.
     virtual WebString contentAsMarkup() const = 0;
-#endif
 
     // Returns a text representation of the render tree.  This method is used
     // to support layout tests.

Modified: trunk/Source/WebKit/chromium/public/WebSecurityOrigin.h (89503 => 89504)


--- trunk/Source/WebKit/chromium/public/WebSecurityOrigin.h	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/public/WebSecurityOrigin.h	2011-06-23 00:39:10 UTC (rev 89504)
@@ -96,6 +96,10 @@
     // passwords stored in password manager.
     WEBKIT_API bool canAccessPasswordManager() const;
 
+    // This grants the associated document access to all security
+    // origins (including file URLs). Use with care.
+    WEBKIT_API void grantUniversalAccess();
+
 #if WEBKIT_IMPLEMENTATION
     WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>&);
     WebSecurityOrigin& operator=(const WTF::PassRefPtr<WebCore::SecurityOrigin>&);

Modified: trunk/Source/WebKit/chromium/src/WebDocument.cpp (89503 => 89504)


--- trunk/Source/WebKit/chromium/src/WebDocument.cpp	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/src/WebDocument.cpp	2011-06-23 00:39:10 UTC (rev 89504)
@@ -33,13 +33,16 @@
 
 #include "AXObjectCache.h"
 #include "Document.h"
+#include "DocumentLoader.h"
 #include "DocumentType.h"
 #include "Element.h"
 #include "HTMLAllCollection.h"
 #include "HTMLBodyElement.h"
 #include "HTMLCollection.h"
 #include "HTMLElement.h"
+#include "HTMLFormElement.h"
 #include "HTMLHeadElement.h"
+#include "HTMLNames.h"
 #include "NodeList.h"
 
 #include "WebAccessibilityObject.h"
@@ -56,6 +59,28 @@
 
 namespace WebKit {
 
+WebURL WebDocument::url() const
+{
+    return constUnwrap<Document>()->url();
+}
+
+WebSecurityOrigin WebDocument::securityOrigin() const 
+{
+    if (!constUnwrap<Document>())
+        return WebSecurityOrigin();
+    return WebSecurityOrigin(constUnwrap<Document>()->securityOrigin());
+}
+
+WebString WebDocument::encoding() const
+{
+    return constUnwrap<Document>()->loader()->writer()->encoding();
+}
+
+WebURL WebDocument::openSearchDescriptionURL() const
+{
+    return const_cast<Document*>(constUnwrap<Document>())->openSearchDescriptionURL();
+}
+
 WebFrame* WebDocument::frame() const
 {
     return WebFrameImpl::fromFrame(constUnwrap<Document>()->frame());
@@ -111,6 +136,21 @@
     return WebNodeCollection(unwrap<Document>()->all());
 }
 
+void WebDocument::forms(WebVector<WebFormElement>& results) const
+{
+    RefPtr<HTMLCollection> forms = const_cast<Document*>(constUnwrap<Document>())->forms();
+    size_t sourceLength = forms->length();
+    Vector<WebFormElement> temp;
+    temp.reserveCapacity(sourceLength);
+    for (size_t i = 0; i < sourceLength; ++i) {
+        Node* node = forms->item(i);
+        // Strange but true, sometimes node can be 0.
+        if (node && node->isHTMLElement())
+            temp.append(WebFormElement(static_cast<HTMLFormElement*>(node)));
+    }
+    results.assign(temp);
+}
+
 WebURL WebDocument::completeURL(const WebString& partialURL) const
 {
     return constUnwrap<Document>()->completeURL(partialURL);
@@ -138,6 +178,35 @@
         document->axObjectCache()->getOrCreate(document->renderer()));
 }
 
+bool WebDocument::insertStyleText(const WebString& styleText, const WebString& elementId)
+{
+    RefPtr<Document> document = unwrap<Document>();
+    RefPtr<Element> documentElement = document->documentElement();
+    if (!documentElement)
+        return false;
+
+    ExceptionCode err = 0;
+
+    if (!elementId.isEmpty()) {
+        Element* oldElement = document->getElementById(elementId);
+        if (oldElement) {
+            Node* parent = oldElement->parentNode();
+            if (!parent)
+                return false;
+            parent->removeChild(oldElement, err);
+        }
+    }
+
+    RefPtr<Element> stylesheet = document->createElement(HTMLNames::styleTag, false);
+    if (!elementId.isEmpty())
+        stylesheet->setAttribute(HTMLNames::idAttr, elementId);
+    stylesheet->setTextContent(styleText, err);
+    ASSERT(!err);
+    bool success = documentElement->insertBefore(stylesheet, documentElement->firstChild(), err);
+    ASSERT(success);
+    return success;
+}
+
 WebDocument::WebDocument(const PassRefPtr<Document>& elem)
     : WebNode(elem)
 {

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (89503 => 89504)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2011-06-23 00:39:10 UTC (rev 89504)
@@ -188,9 +188,6 @@
 // Key for a StatsCounter tracking how many WebFrames are active.
 static const char* const webFrameActiveCount = "WebFrameActiveCount";
 
-static const char* const osdType = "application/opensearchdescription+xml";
-static const char* const osdRel = "search";
-
 // Backend for contentAsPlainText, this is a recursive function that gets
 // the text for the current frame and all of its subframes. It will append
 // the text of each frame in turn to the |output| up to |maxChars| length.
@@ -522,7 +519,7 @@
 #if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
 WebURL WebFrameImpl::url() const
 {
-    return m_frame->document()->url();
+    return document().url();
 }
 #endif
 
@@ -539,29 +536,12 @@
 #if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
 WebURL WebFrameImpl::openSearchDescriptionURL() const
 {
-    FrameLoader* frameLoader = m_frame->loader();
-    if (frameLoader->state() == FrameStateComplete
-        && m_frame->document() && m_frame->document()->head()
-        && !m_frame->tree()->parent()) {
-        HTMLHeadElement* head = m_frame->document()->head();
-        if (head) {
-            RefPtr<HTMLCollection> children = head->children();
-            for (Node* child = children->firstItem(); child; child = children->nextItem()) {
-                HTMLLinkElement* linkElement = toHTMLLinkElement(child);
-                if (linkElement
-                    && linkElement->type() == osdType
-                    && linkElement->rel() == osdRel
-                    && !linkElement->href().isEmpty())
-                    return linkElement->href();
-            }
-        }
-    }
-    return WebURL();
+    return document().openSearchDescriptionURL();
 }
 
 WebString WebFrameImpl::encoding() const
 {
-    return frame()->document()->loader()->writer()->encoding();
+    return document().encoding();
 }
 #endif
 
@@ -710,20 +690,7 @@
 #if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
 void WebFrameImpl::forms(WebVector<WebFormElement>& results) const
 {
-    if (!m_frame)
-        return;
-
-    RefPtr<HTMLCollection> forms = m_frame->document()->forms();
-    size_t sourceLength = forms->length();
-    Vector<WebFormElement> temp;
-    temp.reserveCapacity(sourceLength);
-    for (size_t i = 0; i < sourceLength; ++i) {
-        Node* node = forms->item(i);
-        // Strange but true, sometimes node can be 0.
-        if (node && node->isHTMLElement())
-            temp.append(WebFormElement(static_cast<HTMLFormElement*>(node)));
-    }
-    results.assign(temp);
+    document().forms(results);
 }
 #endif
 
@@ -743,17 +710,12 @@
 #if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
 WebSecurityOrigin WebFrameImpl::securityOrigin() const
 {
-    if (!m_frame || !m_frame->document())
-        return WebSecurityOrigin();
-
-    return WebSecurityOrigin(m_frame->document()->securityOrigin());
+    return document().securityOrigin();
 }
 
 void WebFrameImpl::grantUniversalAccess()
 {
-    ASSERT(m_frame && m_frame->document());
-    if (m_frame && m_frame->document())
-        m_frame->document()->securityOrigin()->grantUniversalAccess();
+    document().securityOrigin().grantUniversalAccess();
 }
 #endif
 
@@ -897,37 +859,9 @@
 #endif
 
 #if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
-bool WebFrameImpl::insertStyleText(
-    const WebString& css, const WebString& id) {
-    Document* document = frame()->document();
-    if (!document)
-        return false;
-    Element* documentElement = document->documentElement();
-    if (!documentElement)
-        return false;
-
-    ExceptionCode err = 0;
-
-    if (!id.isEmpty()) {
-        Element* oldElement = document->getElementById(id);
-        if (oldElement) {
-            Node* parent = oldElement->parentNode();
-            if (!parent)
-                return false;
-            parent->removeChild(oldElement, err);
-        }
-    }
-
-    RefPtr<Element> stylesheet = document->createElement(
-        HTMLNames::styleTag, false);
-    if (!id.isEmpty())
-        stylesheet->setAttribute(HTMLNames::idAttr, id);
-    stylesheet->setTextContent(css, err);
-    ASSERT(!err);
-    Node* first = documentElement->firstChild();
-    bool success = documentElement->insertBefore(stylesheet, first, err);
-    ASSERT(success);
-    return success;
+bool WebFrameImpl::insertStyleText(const WebString& styleText, const WebString& elementId)
+{
+    return document().insertStyleText(styleText, elementId);
 }
 #endif
 
@@ -1827,7 +1761,6 @@
     m_framesScopingCount = 0;
 }
 
-#if !defined(WEBKIT_FRAME_TO_DOCUMENT_API_MOVE)
 WebString WebFrameImpl::contentAsText(size_t maxChars) const
 {
     if (!m_frame)
@@ -1842,7 +1775,6 @@
 {
     return createFullMarkup(m_frame->document());
 }
-#endif
 
 WebString WebFrameImpl::renderTreeAsText(bool showDebugInfo) const
 {

Modified: trunk/Source/WebKit/chromium/src/WebSecurityOrigin.cpp (89503 => 89504)


--- trunk/Source/WebKit/chromium/src/WebSecurityOrigin.cpp	2011-06-23 00:28:56 UTC (rev 89503)
+++ trunk/Source/WebKit/chromium/src/WebSecurityOrigin.cpp	2011-06-23 00:39:10 UTC (rev 89504)
@@ -127,6 +127,12 @@
     return m_private->canAccessPasswordManager();
 }
 
+void WebSecurityOrigin::grantUniversalAccess()
+{
+    ASSERT(m_private);
+    m_private->grantUniversalAccess();
+}
+
 WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin)
     : m_private(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef()))
 {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to