Implement Location.ancestorOrigins
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 06:35:40 +0000 (06:35 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Apr 2012 06:35:40 +0000 (06:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83493

Reviewed by David Levin.

Source/WebCore:

Test: fast/dom/Window/Location/ancestor-origins.html

This patch implements Location.ancestorOrigins(), which returns a list
of the origins of the enclosing frames.  This API has been discussed
both on webkit-dev (see discussion following
https://lists.webkit.org/pipermail/webkit-dev/2012-March/020090.html)
and on the whatwg list (see discussion following
http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-March/035188.html).

* page/Location.cpp:
(WebCore::Location::ancestorOrigins):
(WebCore):
* page/Location.h:
(Location):
* page/Location.idl:

LayoutTests:

* fast/dom/Window/Location/ancestor-origins-expected.txt: Added.
* fast/dom/Window/Location/ancestor-origins.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/Location/ancestor-origins-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Window/Location/ancestor-origins.html [new file with mode: 0644]
LayoutTests/fast/dom/Window/window-appendages-cleared-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/page/Location.cpp
Source/WebCore/page/Location.h
Source/WebCore/page/Location.idl

index c3ad52a..42e65d1 100644 (file)
@@ -1,3 +1,13 @@
+2012-04-11  Adam Barth  <abarth@webkit.org>
+
+        Implement Location.ancestorOrigins
+        https://bugs.webkit.org/show_bug.cgi?id=83493
+
+        Reviewed by David Levin.
+
+        * fast/dom/Window/Location/ancestor-origins-expected.txt: Added.
+        * fast/dom/Window/Location/ancestor-origins.html: Added.
+
 2012-04-11  Antonio Gomes  <agomes@rim.com>
 
         Unreviewed rebaseline.
diff --git a/LayoutTests/fast/dom/Window/Location/ancestor-origins-expected.txt b/LayoutTests/fast/dom/Window/Location/ancestor-origins-expected.txt
new file mode 100644 (file)
index 0000000..c4ea9a3
--- /dev/null
@@ -0,0 +1,7 @@
+ancestorOrigins.length = 0 
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+ancestorOrigins.length = 1
+ancestorOrigins[0] = file://
diff --git a/LayoutTests/fast/dom/Window/Location/ancestor-origins.html b/LayoutTests/fast/dom/Window/Location/ancestor-origins.html
new file mode 100644 (file)
index 0000000..265e964
--- /dev/null
@@ -0,0 +1,16 @@
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.dumpChildFramesAsText();
+}
+
+var origins = location.ancestorOrigins;
+document.write('ancestorOrigins.length = ' + origins.length);
+</script>
+<iframe srcdoc="
+  <script>
+  var origins = location.ancestorOrigins;
+  document.write('ancestorOrigins.length = ' + origins.length + '<br>');
+  document.write('ancestorOrigins[0] = ' + origins[0]);
+  </script>
+"></iframe>
index 7b7614c..09ba9d7 100644 (file)
@@ -5,6 +5,7 @@ PASS history.length == "LEFTOVER" is false
 PASS history.pushState == "LEFTOVER" is false
 PASS history.replaceState == "LEFTOVER" is false
 PASS history.state == "LEFTOVER" is false
+PASS location.ancestorOrigins == "LEFTOVER" is false
 PASS location.assign == "LEFTOVER" is false
 PASS location.hash == "LEFTOVER" is false
 PASS location.host == "LEFTOVER" is false
index 3f6bd48..a091d8c 100644 (file)
@@ -1,3 +1,26 @@
+2012-04-11  Adam Barth  <abarth@webkit.org>
+
+        Implement Location.ancestorOrigins
+        https://bugs.webkit.org/show_bug.cgi?id=83493
+
+        Reviewed by David Levin.
+
+        Test: fast/dom/Window/Location/ancestor-origins.html
+
+        This patch implements Location.ancestorOrigins(), which returns a list
+        of the origins of the enclosing frames.  This API has been discussed
+        both on webkit-dev (see discussion following
+        https://lists.webkit.org/pipermail/webkit-dev/2012-March/020090.html)
+        and on the whatwg list (see discussion following
+        http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2012-March/035188.html).
+
+        * page/Location.cpp:
+        (WebCore::Location::ancestorOrigins):
+        (WebCore):
+        * page/Location.h:
+        (Location):
+        * page/Location.idl:
+
 2012-04-11  Raymond Liu  <raymond.liu@intel.com>
 
         AudioContext createChannelSplitter() method should have optional argument for number of outputs
index 1a2d2db..b356bbc 100644 (file)
@@ -124,6 +124,16 @@ String Location::origin() const
     return SecurityOrigin::create(url())->toString();
 }
 
+PassRefPtr<DOMStringList> Location::ancestorOrigins() const
+{
+    RefPtr<DOMStringList> origins = DOMStringList::create();
+    if (!m_frame)
+        return origins.release();
+    for (Frame* frame = m_frame->tree()->parent(true); frame; frame = frame->tree()->parent(true))
+        origins->append(frame->document()->securityOrigin()->toString());
+    return origins.release();
+}
+
 String Location::hash() const
 {
     if (!m_frame)
index b882671..85f4b41 100644 (file)
@@ -29,6 +29,7 @@
 #ifndef Location_h
 #define Location_h
 
+#include "DOMStringList.h"
 #include "DOMWindowProperty.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -71,6 +72,8 @@ public:
 
     String toString() const { return href(); }
 
+    PassRefPtr<DOMStringList> ancestorOrigins() const;
+
 private:
     explicit Location(Frame*);
 
index 4f196fc..1f1703a 100644 (file)
@@ -64,6 +64,8 @@ module window {
                  readonly attribute DOMString origin;
 #endif
 
+        readonly attribute DOMStringList ancestorOrigins;
+
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
         [NotEnumerable, Custom, V8Unforgeable, V8ReadOnly, ImplementedAs=toStringFunction] DOMString toString();
 #endif