<https://webkit.org/b/118553> Hash navigation doesn't affect history when the page...
authorzherczeg@webkit.org <zherczeg@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Sep 2013 06:38:55 +0000 (06:38 +0000)
committerzherczeg@webkit.org <zherczeg@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Sep 2013 06:38:55 +0000 (06:38 +0000)
Reviewed by Darin Adler.

Source/WebCore:

A new flag called keepInHistory is added to allow keeping
certain pages in the history even if they have substitute data.

Test: http/tests/appcache/history-test.html

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::urlForHistory):
* loader/SubstituteData.h:
(WebCore::SubstituteData::SubstituteData):
(WebCore::SubstituteData::shouldRevealToSessionHistory):
(WebCore::SubstituteData::setShouldRevealToSessionHistory):
* loader/appcache/ApplicationCacheHost.cpp:
(WebCore::ApplicationCacheHost::maybeLoadMainResource):

LayoutTests:

* http/tests/appcache/history-test-expected.txt: Added.
* http/tests/appcache/history-test.html: Added.
* http/tests/appcache/resources/history-test.html: Added.
* http/tests/appcache/resources/history-test.manifest: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/appcache/history-test-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/appcache/history-test.html [new file with mode: 0644]
LayoutTests/http/tests/appcache/resources/history-test.html [new file with mode: 0644]
LayoutTests/http/tests/appcache/resources/history-test.manifest [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.cpp
Source/WebCore/loader/SubstituteData.h
Source/WebCore/loader/appcache/ApplicationCacheHost.cpp

index 9860c5b..b371d80 100644 (file)
@@ -1,3 +1,14 @@
+2013-09-04  Zoltan Herczeg  <zherczeg@webkit.org>
+
+        <https://webkit.org/b/118553> Hash navigation doesn't affect history when the page is retrieved from appcache
+
+        Reviewed by Darin Adler.
+
+        * http/tests/appcache/history-test-expected.txt: Added.
+        * http/tests/appcache/history-test.html: Added.
+        * http/tests/appcache/resources/history-test.html: Added.
+        * http/tests/appcache/resources/history-test.manifest: Added.
+
 2013-09-04  Mihai Tica  <mitica@adobe.com>
 
         Test background blend modes with animated gif background layers.
diff --git a/LayoutTests/http/tests/appcache/history-test-expected.txt b/LayoutTests/http/tests/appcache/history-test-expected.txt
new file mode 100644 (file)
index 0000000..b2562a5
--- /dev/null
@@ -0,0 +1,3 @@
+Test whether window.history.back() is supported in application cache.
+
+PASS: Returning to the original page.
diff --git a/LayoutTests/http/tests/appcache/history-test.html b/LayoutTests/http/tests/appcache/history-test.html
new file mode 100644 (file)
index 0000000..e19ec44
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+<body>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+window.location.assign("resources/history-test.html");
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/appcache/resources/history-test.html b/LayoutTests/http/tests/appcache/resources/history-test.html
new file mode 100644 (file)
index 0000000..0600044
--- /dev/null
@@ -0,0 +1,23 @@
+<html manifest="history-test.manifest">
+<body>
+<p>Test whether window.history.back() is supported in application cache.</p>
+
+<script>
+
+if (document.cookie) {
+    document.write("<p>PASS: Returning to the original page.</p>");
+    if (window.testRunner)
+        testRunner.notifyDone();
+} else {
+    document.write("<p>START: Redirecting to other page.</p>");
+    document.cookie = 'cookie1=testcookie';
+
+    // Give time to the history manager to cache this page.
+    setTimeout(function () {
+        window.location.assign("/navigation/resources/go-back.html");
+    }, 200);
+}
+
+</script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/appcache/resources/history-test.manifest b/LayoutTests/http/tests/appcache/resources/history-test.manifest
new file mode 100644 (file)
index 0000000..7392ec6
--- /dev/null
@@ -0,0 +1,5 @@
+CACHE MANIFEST
+history-test.html
+
+NETWORK:
+*
index 40fc8eb..ad879cb 100644 (file)
@@ -1,3 +1,23 @@
+2013-09-04  Zoltan Herczeg  <zherczeg@webkit.org>
+
+        <https://webkit.org/b/118553> Hash navigation doesn't affect history when the page is retrieved from appcache
+
+        Reviewed by Darin Adler.
+
+        A new flag called keepInHistory is added to allow keeping
+        certain pages in the history even if they have substitute data.
+
+        Test: http/tests/appcache/history-test.html
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::urlForHistory):
+        * loader/SubstituteData.h:
+        (WebCore::SubstituteData::SubstituteData):
+        (WebCore::SubstituteData::shouldRevealToSessionHistory):
+        (WebCore::SubstituteData::setShouldRevealToSessionHistory):
+        * loader/appcache/ApplicationCacheHost.cpp:
+        (WebCore::ApplicationCacheHost::maybeLoadMainResource):
+
 2013-09-04  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
 
         Remove deprecated markersForNode(Node* node).
index 2d0b4d4..42f6176 100644 (file)
@@ -1213,9 +1213,9 @@ void DocumentLoader::setTitle(const StringWithDirection& title)
 KURL DocumentLoader::urlForHistory() const
 {
     // Return the URL to be used for history and B/F list.
-    // Returns nil for WebDataProtocol URLs that aren't alternates 
+    // Returns nil for WebDataProtocol URLs that aren't alternates
     // for unreachable URLs, because these can't be stored in history.
-    if (m_substituteData.isValid())
+    if (m_substituteData.isValid() && !m_substituteData.shouldRevealToSessionHistory())
         return unreachableURL();
 
     return m_originalRequestCopy.url();
index cf20a29..520ef58 100644 (file)
@@ -35,18 +35,27 @@ namespace WebCore {
 
     class SubstituteData {
     public:
-        SubstituteData() { }
+        SubstituteData()
+            : m_shouldRevealToSessionHistory(false)
+        {
+        }
 
-        SubstituteData(PassRefPtr<SharedBuffer> content, const String& mimeType, const String& textEncoding, const KURL& failingURL, const KURL& responseURL = KURL())
+        SubstituteData(PassRefPtr<SharedBuffer> content, const String& mimeType,
+                       const String& textEncoding, const KURL& failingURL,
+                       const KURL& responseURL = KURL(), bool shouldRevealToSessionHistory = false)
             : m_content(content)
             , m_mimeType(mimeType)
             , m_textEncoding(textEncoding)
             , m_failingURL(failingURL)
             , m_responseURL(responseURL)
+            , m_shouldRevealToSessionHistory(shouldRevealToSessionHistory)
         {
         }
 
+        static const bool ShouldRevealToSessionHistory = true;
+
         bool isValid() const { return m_content != 0; }
+        bool shouldRevealToSessionHistory() const { return m_shouldRevealToSessionHistory; }
 
         const SharedBuffer* content() const { return m_content.get(); }
         const String& mimeType() const { return m_mimeType; }
@@ -60,6 +69,7 @@ namespace WebCore {
         String m_textEncoding;
         KURL m_failingURL;
         KURL m_responseURL;
+        bool m_shouldRevealToSessionHistory;
     };
 
 }
index 164aec3..4c69809 100644 (file)
@@ -83,9 +83,12 @@ void ApplicationCacheHost::maybeLoadMainResource(ResourceRequest& request, Subst
         if (m_mainResourceApplicationCache) {
             // Get the resource from the application cache. By definition, cacheForMainRequest() returns a cache that contains the resource.
             ApplicationCacheResource* resource = m_mainResourceApplicationCache->resourceForRequest(request);
-            substituteData = SubstituteData(resource->data(), 
+            substituteData = SubstituteData(resource->data(),
                                             resource->response().mimeType(),
-                                            resource->response().textEncodingName(), KURL());
+                                            resource->response().textEncodingName(),
+                                            KURL(),
+                                            KURL(),
+                                            SubstituteData::ShouldRevealToSessionHistory);
         }
     }
 }