Title: [121434] trunk/Source
Revision
121434
Author
[email protected]
Date
2012-06-28 09:05:43 -0700 (Thu, 28 Jun 2012)

Log Message

[chromium] Introduce way to reload a page using the original request URL
https://bugs.webkit.org/show_bug.cgi?id=89788

Patch by Dan Alcantara <[email protected]> on 2012-06-28
Reviewed by Adam Barth.

Adds a new reload method for cases where we need to override the URL
when reloading a page. This is needed for situations where a server
redirects navigation based on information that may have changed since
the last time the page was loaded.

User agents, for example, can cause a server to redirect to the mobile
version of a page.  Changing to the desktop version by switching user agents
requires loading a URL from before the redirect occurred.

Also adds a unit test to confirm that scroll position and page scale are
saved when the reload occurs.

* public/WebFrame.h:
(WebFrame):
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::reloadWithGivenURL):
(WebKit):
* src/WebFrameImpl.h:
(WebFrameImpl):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::WebViewImpl):
(WebKit::WebViewImpl::setClearPageScaleFactorOnLoad):
(WebKit):
(WebKit::WebViewImpl::didCommitLoad):
* src/WebViewImpl.h:
(WebViewImpl):

Modified Paths

Diff

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (121433 => 121434)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2012-06-28 16:05:43 UTC (rev 121434)
@@ -1438,6 +1438,19 @@
     loadWithDocumentLoader(loader.get(), FrameLoadTypeReload, 0);
 }
 
+void FrameLoader::reloadWithOverrideURL(const KURL& overrideUrl, bool endToEndReload)
+{
+    if (!m_documentLoader)
+        return;
+
+    if (overrideUrl.isEmpty())
+        return;
+
+    ResourceRequest request = m_documentLoader->request();
+    request.setURL(overrideUrl);
+    reloadWithRequest(request, endToEndReload);
+}
+
 void FrameLoader::reload(bool endToEndReload)
 {
     if (!m_documentLoader)
@@ -1448,13 +1461,19 @@
     if (m_documentLoader->request().url().isEmpty())
         return;
 
+    // Replace error-page URL with the URL we were trying to reach.
     ResourceRequest initialRequest = m_documentLoader->request();
-
-    // Replace error-page URL with the URL we were trying to reach.
     KURL unreachableURL = m_documentLoader->unreachableURL();
     if (!unreachableURL.isEmpty())
         initialRequest.setURL(unreachableURL);
-    
+
+    reloadWithRequest(initialRequest, endToEndReload);
+}
+
+void FrameLoader::reloadWithRequest(const ResourceRequest& initialRequest, bool endToEndReload)
+{
+    ASSERT(m_documentLoader);
+
     // Create a new document loader for the reload, this will become m_documentLoader eventually,
     // but first it has to be the "policy" document loader, and then the "provisional" document loader.
     RefPtr<DocumentLoader> loader = m_client->createDocumentLoader(initialRequest, defaultSubstituteDataForURL(initialRequest.url()));

Modified: trunk/Source/WebCore/loader/FrameLoader.h (121433 => 121434)


--- trunk/Source/WebCore/loader/FrameLoader.h	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2012-06-28 16:05:43 UTC (rev 121434)
@@ -115,6 +115,7 @@
 
     void reload(bool endToEndReload = false);
     void reloadWithOverrideEncoding(const String& overrideEncoding);
+    void reloadWithOverrideURL(const KURL& overrideUrl, bool endToEndReload = false);
 
     void open(CachedFrameBase&);
     void loadItem(HistoryItem*, FrameLoadType);
@@ -344,6 +345,8 @@
     void loadURL(const KURL&, const String& referrer, const String& frameName,          // Called by loadFrameRequest, calls loadWithNavigationAction or dispatches to navigation policy delegate
         bool lockHistory, FrameLoadType, PassRefPtr<Event>, PassRefPtr<FormState>);                                                         
 
+    void reloadWithRequest(const ResourceRequest&, bool endToEndReload);
+
     bool shouldReload(const KURL& currentURL, const KURL& destinationURL);
 
     void requestFromDelegate(ResourceRequest&, unsigned long& identifier, ResourceError&);

Modified: trunk/Source/WebKit/chromium/ChangeLog (121433 => 121434)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-06-28 16:05:43 UTC (rev 121434)
@@ -1,3 +1,37 @@
+2012-06-28  Dan Alcantara  <[email protected]>
+
+        [chromium] Introduce way to reload a page using the original request URL
+        https://bugs.webkit.org/show_bug.cgi?id=89788
+
+        Reviewed by Adam Barth.
+
+        Adds a new reload method for cases where we need to override the URL
+        when reloading a page. This is needed for situations where a server
+        redirects navigation based on information that may have changed since
+        the last time the page was loaded.
+        
+        User agents, for example, can cause a server to redirect to the mobile
+        version of a page.  Changing to the desktop version by switching user agents
+        requires loading a URL from before the redirect occurred.
+
+        Also adds a unit test to confirm that scroll position and page scale are
+        saved when the reload occurs.
+
+        * public/WebFrame.h:
+        (WebFrame):
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::reloadWithGivenURL):
+        (WebKit):
+        * src/WebFrameImpl.h:
+        (WebFrameImpl):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::WebViewImpl):
+        (WebKit::WebViewImpl::setClearPageScaleFactorOnLoad):
+        (WebKit):
+        (WebKit::WebViewImpl::didCommitLoad):
+        * src/WebViewImpl.h:
+        (WebViewImpl):
+
 2012-06-28  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r121395.

Modified: trunk/Source/WebKit/chromium/public/WebFrame.h (121433 => 121434)


--- trunk/Source/WebKit/chromium/public/WebFrame.h	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebKit/chromium/public/WebFrame.h	2012-06-28 16:05:43 UTC (rev 121434)
@@ -319,6 +319,9 @@
     // False |ignoreCache| revalidates any existing cache entries.
     virtual void reload(bool ignoreCache = false) = 0;
 
+    // This is used for situations where we want to reload a different URL because of a redirect.
+    virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache = false) = 0;
+
     // Load the given URL.
     virtual void loadRequest(const WebURLRequest&) = 0;
 

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (121433 => 121434)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-06-28 16:05:43 UTC (rev 121434)
@@ -978,6 +978,12 @@
     m_frame->loader()->reload(ignoreCache);
 }
 
+void WebFrameImpl::reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache)
+{
+    m_frame->loader()->history()->saveDocumentAndScrollState();
+    m_frame->loader()->reloadWithOverrideURL(overrideUrl, ignoreCache);
+}
+
 void WebFrameImpl::loadRequest(const WebURLRequest& request)
 {
     ASSERT(!request.isNull());

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.h (121433 => 121434)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2012-06-28 16:05:43 UTC (rev 121434)
@@ -136,6 +136,7 @@
                                                   bool isDirectory);
 #endif
     virtual void reload(bool ignoreCache);
+    virtual void reloadWithOverrideURL(const WebURL& overrideUrl, bool ignoreCache);
     virtual void loadRequest(const WebURLRequest&);
     virtual void loadHistoryItem(const WebHistoryItem&);
     virtual void loadData(

Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (121433 => 121434)


--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-06-28 15:43:36 UTC (rev 121433)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp	2012-06-28 16:05:43 UTC (rev 121434)
@@ -419,6 +419,40 @@
     webkit_support::ServeAsynchronousMockedRequests();
 }
 
+TEST_F(WebFrameTest, ReloadWithOverrideURLPreservesState)
+{
+    const std::string firstURL = "find.html";
+    const std::string secondURL = "form.html";
+    const std::string thirdURL = "history.html";
+    const float pageScaleFactor = 1.1684f;
+    const int pageWidth = 640;
+    const int pageHeight = 480;
+
+    registerMockedHttpURLLoad(firstURL);
+    registerMockedHttpURLLoad(secondURL);
+    registerMockedHttpURLLoad(thirdURL);
+
+    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + firstURL, true));
+    webViewImpl->resize(WebSize(pageWidth, pageHeight));
+    webViewImpl->mainFrame()->setScrollOffset(WebSize(pageWidth / 4, pageHeight / 4));
+    webViewImpl->setPageScaleFactorPreservingScrollOffset(pageScaleFactor);
+
+    WebSize previousOffset = webViewImpl->mainFrame()->scrollOffset();
+    float previousScale = webViewImpl->pageScaleFactor();
+
+    // Reload the page using the cache.
+    webViewImpl->mainFrame()->reloadWithOverrideURL(GURL(m_baseURL + secondURL), false);
+    webkit_support::ServeAsynchronousMockedRequests();
+    ASSERT_EQ(previousOffset, webViewImpl->mainFrame()->scrollOffset());
+    ASSERT_EQ(previousScale, webViewImpl->pageScaleFactor());
+
+    // Reload the page while ignoring the cache.
+    webViewImpl->mainFrame()->reloadWithOverrideURL(GURL(m_baseURL + thirdURL), true);
+    webkit_support::ServeAsynchronousMockedRequests();
+    ASSERT_EQ(previousOffset, webViewImpl->mainFrame()->scrollOffset());
+    ASSERT_EQ(previousScale, webViewImpl->pageScaleFactor());
+}
+
 TEST_F(WebFrameTest, IframeRedirect)
 {
     registerMockedHttpURLLoad("iframe_redirect.html");
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to