2010-09-26 Adam Barth <abarth@webkit.org>
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Sep 2010 22:22:59 +0000 (22:22 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 26 Sep 2010 22:22:59 +0000 (22:22 +0000)
        Reviewed by Dimitri Glazkov.

        Implement location.origin and HTMLAnchorElement.origin
        https://bugs.webkit.org/show_bug.cgi?id=46558

        Test the origin attribute of Location and HTMLAnchorElement.

        * fast/dom/anchor-origin-expected.txt: Added.
        * fast/dom/anchor-origin.html: Added.
        * http/tests/misc/location-origin-expected.txt: Added.
        * http/tests/misc/location-origin.html: Added.
2010-09-26  Adam Barth  <abarth@webkit.org>

        Reviewed by Dimitri Glazkov.

        Implement location.origin and HTMLAnchorElement.origin
        https://bugs.webkit.org/show_bug.cgi?id=46558

        These attributes are part of my proposed URL API:
        https://docs.google.com/document/edit?id=1r_VTFKApVOaNIkocrg0z-t7lZgzisTuGTXkdzAk4gLU&hl=en

        Hixie thought we should implement as much of this API as makes sense on
        Location and HTMLAnchorElement as well.  I'm starting with the origin
        attribute, because that seems like the biggest bang for the buck.

        Tests: fast/dom/anchor-origin.html
               http/tests/misc/location-origin.html

        * WebCore.xcodeproj/project.pbxproj:
        * html/HTMLAnchorElement.cpp:
        (WebCore::HTMLAnchorElement::origin):
        * html/HTMLAnchorElement.h:
        * html/HTMLAnchorElement.idl:
        * page/Location.cpp:
        (WebCore::Location::origin):
        * page/Location.h:
        * page/Location.idl:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@68354 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/window-appendages-cleared-expected.txt
LayoutTests/fast/dom/Window/window-properties-expected.txt
LayoutTests/fast/dom/anchor-origin-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/anchor-origin.html [new file with mode: 0644]
LayoutTests/fast/dom/prototype-inheritance-2-expected.txt
LayoutTests/http/tests/misc/location-origin-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/misc/location-origin.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLAnchorElement.cpp
WebCore/html/HTMLAnchorElement.h
WebCore/html/HTMLAnchorElement.idl
WebCore/page/Location.cpp
WebCore/page/Location.h
WebCore/page/Location.idl

index 80eb4f620c926fefb53242d3ffe65800c3ad8049..b347d4c454775cca94bdea6157c2ea2f89f95114 100644 (file)
@@ -1,3 +1,17 @@
+2010-09-26  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Implement location.origin and HTMLAnchorElement.origin
+        https://bugs.webkit.org/show_bug.cgi?id=46558
+
+        Test the origin attribute of Location and HTMLAnchorElement.
+
+        * fast/dom/anchor-origin-expected.txt: Added.
+        * fast/dom/anchor-origin.html: Added.
+        * http/tests/misc/location-origin-expected.txt: Added.
+        * http/tests/misc/location-origin.html: Added.
+
 2010-09-26  Mark Hahnenberg  <mhahnenb@gmail.com>
 
         Reviewed by Oliver Hunt.
index 272aa7ff4d0d8604f522e2fd9e0bcf41a0eb5b2b..8506efa0ca2e1d08872b9723ebcda40eb3f67528 100644 (file)
@@ -9,6 +9,7 @@ PASS location.hash == "LEFTOVER" is false
 PASS location.host == "LEFTOVER" is false
 PASS location.hostname == "LEFTOVER" is false
 PASS location.href == "LEFTOVER" is false
+PASS location.origin == "LEFTOVER" is false
 PASS location.pathname == "LEFTOVER" is false
 PASS location.port == "LEFTOVER" is false
 PASS location.protocol == "LEFTOVER" is false
index 8d03e817715b460b6589ababa3d5a64280bd0e46..b5455de35f29060d343a4dd8413df297c7452af3 100644 (file)
@@ -2224,6 +2224,7 @@ window.location.hash [string]
 window.location.host [string]
 window.location.hostname [string]
 window.location.href [string]
+window.location.origin [string]
 window.location.pathname [string]
 window.location.port [string]
 window.location.protocol [string]
diff --git a/LayoutTests/fast/dom/anchor-origin-expected.txt b/LayoutTests/fast/dom/anchor-origin-expected.txt
new file mode 100644 (file)
index 0000000..bd782a8
--- /dev/null
@@ -0,0 +1,13 @@
+Link
+Link
+Link
+Link
+Link
+Link
+http://example.com/foo/bar => http://example.com
+HTTP://example.com/foo/bar => http://example.com
+https://example.com/ttt?ggg => https://example.com
+ftp://example.com/ttt?ggg => ftp://example.com
+file:///home/abarth => file://
+data:text/html,%3Cb%3Efoo%3C/b%3E => null
+
diff --git a/LayoutTests/fast/dom/anchor-origin.html b/LayoutTests/fast/dom/anchor-origin.html
new file mode 100644 (file)
index 0000000..4b3483e
--- /dev/null
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+var cases = [
+    "http://example.com/foo/bar",
+    "HTTP://example.com/foo/bar",
+    "https://example.com/ttt?ggg",
+    "ftp://example.com/ttt?ggg",
+    "file:///home/abarth",
+    "data:text/html,<b>foo</b>"
+];
+
+for (var i = 0; i < cases.length; ++i)
+    document.write('<a href="' + cases[i] + '">Link</a><br>');
+
+var elmts = document.getElementsByTagName('a');
+for (var i = 0; i < elmts.length; ++i)
+    document.write(elmts[i].href + ' => ' + elmts[i].origin + '<br>');
+</script>
+</body>
+</html>
index 205575a33675a653443920ddcd5cd56419fcaba4..1d1f5c5731347d9e12bba978832d9ced85701aac 100644 (file)
@@ -81,7 +81,7 @@ PASS DOMWindow from inner
 PASS DOMWindowPrototype from inner.document.forms.testForm.0.ownerDocument.defaultView.__proto__
 PASS DocumentPrototype from inner.document.forms.testForm.0.ownerDocument.__proto__.__proto__
 PASS ElementPrototype from inner.document.forms.testForm.0.__proto__.__proto__.__proto__
-FAIL Function from inner.document.location.pathname.constructor
+FAIL Function from inner.document.location.protocol.constructor
 PASS HTMLAnchorElement from inner.document.forms.testForm.0.parentNode.firstElementChild
 PASS HTMLAnchorElementConstructor from inner.document.forms.testForm.0.parentNode.firstElementChild.constructor
 PASS HTMLAnchorElementPrototype from inner.document.forms.testForm.0.parentNode.firstElementChild.__proto__
@@ -189,7 +189,7 @@ PASS ScreenPrototype from inner.document.forms.testForm.0.ownerDocument.defaultV
 PASS Storage from inner.document.forms.testForm.0.ownerDocument.defaultView.localStorage
 PASS StorageConstructor from inner.document.forms.testForm.0.ownerDocument.defaultView.localStorage.constructor
 PASS StoragePrototype from inner.document.forms.testForm.0.ownerDocument.defaultView.localStorage.__proto__
-FAIL String from inner.document.location.pathname
+FAIL String from inner.document.location.protocol
 PASS StyleMedia from inner.document.forms.testForm.0.ownerDocument.defaultView.styleMedia
 PASS StyleMediaConstructor from inner.document.forms.testForm.0.ownerDocument.defaultView.styleMedia.constructor
 PASS StyleMediaPrototype from inner.document.forms.testForm.0.ownerDocument.defaultView.styleMedia.__proto__
diff --git a/LayoutTests/http/tests/misc/location-origin-expected.txt b/LayoutTests/http/tests/misc/location-origin-expected.txt
new file mode 100644 (file)
index 0000000..3d47df2
--- /dev/null
@@ -0,0 +1,3 @@
+http://127.0.0.1:8000
+http://127.0.0.1:8000
+
diff --git a/LayoutTests/http/tests/misc/location-origin.html b/LayoutTests/http/tests/misc/location-origin.html
new file mode 100644 (file)
index 0000000..a1fcee4
--- /dev/null
@@ -0,0 +1,7 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.write(window.location.origin + '<br>');
+document.write(document.location.origin + '<br>');
+</script>
index bfdc733cf7446bd4ed22235926e269cb513536e6..c5b8ab8a4070b36a7de09434d010c111b259593c 100644 (file)
@@ -1,3 +1,30 @@
+2010-09-26  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Implement location.origin and HTMLAnchorElement.origin
+        https://bugs.webkit.org/show_bug.cgi?id=46558
+
+        These attributes are part of my proposed URL API:
+        https://docs.google.com/document/edit?id=1r_VTFKApVOaNIkocrg0z-t7lZgzisTuGTXkdzAk4gLU&hl=en
+
+        Hixie thought we should implement as much of this API as makes sense on
+        Location and HTMLAnchorElement as well.  I'm starting with the origin
+        attribute, because that seems like the biggest bang for the buck.
+
+        Tests: fast/dom/anchor-origin.html
+               http/tests/misc/location-origin.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::origin):
+        * html/HTMLAnchorElement.h:
+        * html/HTMLAnchorElement.idl:
+        * page/Location.cpp:
+        (WebCore::Location::origin):
+        * page/Location.h:
+        * page/Location.idl:
+
 2010-09-26  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r68343.
index 7684716d6e1eb1ec20fa089d7cdbcf9eade4a274..8beccc24c62bb101a1580df38ac785a1732a5b6c 100644 (file)
@@ -442,6 +442,12 @@ String HTMLAnchorElement::search() const
     return query.isEmpty() ? "" : "?" + query;
 }
 
+String HTMLAnchorElement::origin() const
+{
+    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(href());
+    return origin->toString();
+}
+
 void HTMLAnchorElement::setSearch(const String& value)
 {
     KURL url = href();
index 707d7c4838b79ae4555400d1acc9ca1115ac1463..a7e7eec54283a71a6cf328dd4837cd4b6b7aec83 100644 (file)
@@ -82,6 +82,8 @@ public:
     String search() const;
     void setSearch(const String&);
 
+    String origin() const;
+
     String text() const;
 
     String toString() const;
index f5e1bd901e0b6d0cd00df4931c34bab943435283..c918fde30d82ec7f41a9091dbd65687965aedec5 100644 (file)
@@ -49,6 +49,8 @@ module html {
         attribute [ConvertNullToNullString] DOMString port;
         attribute [ConvertNullToNullString] DOMString protocol;
         attribute [ConvertNullToNullString] DOMString search;
+
+        readonly attribute [ConvertNullToNullString] DOMString origin;
 #endif
 
         readonly attribute DOMString text;
index 5754357890df7cc8da698c005e2db3e29e543862..c02304c4a433de89a8f16db955b6c886d68c7515 100644 (file)
@@ -120,6 +120,15 @@ String Location::search() const
     return url.query().isEmpty() ? "" : "?" + url.query();
 }
 
+String Location::origin() const
+{
+    if (!m_frame)
+        return String();
+
+    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url());
+    return origin->toString();
+}
+
 String Location::hash() const
 {
     if (!m_frame)
index 808eff9494f2932b96c082099cc56fa630678545..a4bc407556337a9604145fdf5d281cdb9b05de06 100644 (file)
@@ -55,6 +55,7 @@ namespace WebCore {
         String pathname() const;
         String search() const;
         String hash() const;
+        String origin() const;
 
         String toString() const;
 
index aad90abb1b5dd13845b163c0f2491ae46dd70ca8..1668e05e629aa56f76e41a9fe463ec680d24af90 100644 (file)
@@ -58,6 +58,8 @@ module window {
                  attribute [CustomSetter] DOMString pathname;
                  attribute [CustomSetter] DOMString search;
                  attribute [CustomSetter] DOMString hash;
+
+                 readonly attribute DOMString origin;
 #endif
 
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT