Title: [128133] trunk/Source/WebKit/chromium
Revision
128133
Author
[email protected]
Date
2012-09-10 17:22:06 -0700 (Mon, 10 Sep 2012)

Log Message

[chromium, android] Reloading a page with a different user agent can cause the page to be zoomed in
https://bugs.webkit.org/show_bug.cgi?id=90222

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

When reloading a page with an overridden URL, the page's scroll and zoom
state will be restored once the reload is complete.  This is problematic
in situations when switching between mobile and desktop versions of the
same site because it will zoom back in on a random part of alternate page.
This CL just avoids that situation by resetting the zoom and scale whenever
this type of reload occurs.

Chromium half: https://chromiumcodereview.appspot.com/10889019

* public/WebView.h:
(WebView):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::resetScrollAndScaleState):
(WebKit):
* src/WebViewImpl.h:
(WebViewImpl):

Modified Paths

Diff

Modified: trunk/Source/WebKit/chromium/ChangeLog (128132 => 128133)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-09-11 00:12:38 UTC (rev 128132)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-09-11 00:22:06 UTC (rev 128133)
@@ -1,3 +1,27 @@
+2012-09-10  Dan Alcantara  <[email protected]>
+
+        [chromium, android] Reloading a page with a different user agent can cause the page to be zoomed in
+        https://bugs.webkit.org/show_bug.cgi?id=90222
+
+        Reviewed by Adam Barth.
+
+        When reloading a page with an overridden URL, the page's scroll and zoom
+        state will be restored once the reload is complete.  This is problematic
+        in situations when switching between mobile and desktop versions of the
+        same site because it will zoom back in on a random part of alternate page.
+        This CL just avoids that situation by resetting the zoom and scale whenever
+        this type of reload occurs.
+
+        Chromium half: https://chromiumcodereview.appspot.com/10889019
+
+        * public/WebView.h:
+        (WebView):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::resetScrollAndScaleState):
+        (WebKit):
+        * src/WebViewImpl.h:
+        (WebViewImpl):
+
 2012-09-10  Adam Barth  <[email protected]>
 
         [V8] V8AuxiliaryContext used by IDB leaks memory

Modified: trunk/Source/WebKit/chromium/public/WebView.h (128132 => 128133)


--- trunk/Source/WebKit/chromium/public/WebView.h	2012-09-11 00:12:38 UTC (rev 128132)
+++ trunk/Source/WebKit/chromium/public/WebView.h	2012-09-11 00:22:06 UTC (rev 128133)
@@ -257,10 +257,14 @@
     // overwrites the previously saved scroll and scale state.
     virtual void saveScrollAndScaleState() = 0;
 
-    // Restore the previously saved scroll and scale state. After restroing the
+    // Restore the previously saved scroll and scale state. After restoring the
     // state, this function deletes any saved scroll and scale state.
     virtual void restoreScrollAndScaleState() = 0;
 
+    // Reset the scroll and scale state and clobber any previously saved values for
+    // these parameters.
+    virtual void resetScrollAndScaleState() = 0;
+
     // Prevent the web page from setting a maximum scale via the viewport meta
     // tag. This is an accessibility feature that lets folks zoom in to web
     // pages even if the web page tries to block scaling.

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (128132 => 128133)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-09-11 00:12:38 UTC (rev 128132)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp	2012-09-11 00:22:06 UTC (rev 128133)
@@ -2928,6 +2928,18 @@
     m_savedScrollOffset = IntSize();
 }
 
+void WebViewImpl::resetScrollAndScaleState()
+{
+    page()->setPageScaleFactor(0, IntPoint());
+    m_pageScaleFactorIsSet = false;
+
+    // Clobber saved scales and scroll offsets.
+    if (FrameView* view = page()->mainFrame()->document()->view())
+        view->cacheCurrentScrollPosition();
+    resetSavedScrollAndScaleState();
+    page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
+}
+
 WebSize WebViewImpl::fixedLayoutSize() const
 {
     if (!page())

Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (128132 => 128133)


--- trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-09-11 00:12:38 UTC (rev 128132)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h	2012-09-11 00:22:06 UTC (rev 128133)
@@ -227,6 +227,7 @@
     virtual float maximumPageScaleFactor() const;
     virtual void saveScrollAndScaleState();
     virtual void restoreScrollAndScaleState();
+    virtual void resetScrollAndScaleState();
     virtual void setIgnoreViewportTagMaximumScale(bool);
 
     virtual float deviceScaleFactor() const;

Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (128132 => 128133)


--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2012-09-11 00:12:38 UTC (rev 128132)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp	2012-09-11 00:22:06 UTC (rev 128133)
@@ -422,6 +422,45 @@
     webView->close();
 }
 
+TEST_F(WebViewTest, ResetScrollAndScaleState)
+{
+    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("hello_world.html"));
+    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "hello_world.html"));
+    webViewImpl->resize(WebSize(640, 480));
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
+
+    // Make the page scale and scroll with the given paremeters.
+    webViewImpl->setPageScaleFactor(2.0f, WebPoint(116, 84));
+    EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
+    EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height);
+    webViewImpl->page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
+
+    // Confirm that restoring the page state restores the parameters.
+    webViewImpl->setPageScaleFactor(1.5f, WebPoint(16, 24));
+    EXPECT_EQ(1.5f, webViewImpl->pageScaleFactor());
+    EXPECT_EQ(16, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(24, webViewImpl->mainFrame()->scrollOffset().height);
+    webViewImpl->page()->mainFrame()->loader()->history()->restoreScrollPositionAndViewState();
+    EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor());
+    EXPECT_EQ(116, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(84, webViewImpl->mainFrame()->scrollOffset().height);
+    webViewImpl->page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
+
+    // Confirm that resetting the page state resets both the scale and scroll position, as well
+    // as overwrites the original parameters that were saved to the HistoryController.
+    webViewImpl->resetScrollAndScaleState();
+    EXPECT_EQ(0.0f, webViewImpl->pageScaleFactor());
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
+    webViewImpl->page()->mainFrame()->loader()->history()->restoreScrollPositionAndViewState();
+    EXPECT_EQ(0.0f, webViewImpl->pageScaleFactor());
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().width);
+    EXPECT_EQ(0, webViewImpl->mainFrame()->scrollOffset().height);
+    webViewImpl->close();
+}
+
 class ContentDetectorClient : public WebViewClient {
 public:
     ContentDetectorClient() { reset(); }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to