mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 215405. Restore scroll position, but not form state, on no-store and SSL no-cache sites. r+sr=bzbarsky
This commit is contained in:
parent
6143e25f3a
commit
db7058c5de
@ -1519,7 +1519,7 @@ nsHTMLSelectElement::RestoreState(nsPresState* aState)
|
||||
nsCOMPtr<nsISupports> state;
|
||||
nsresult rv = aState->GetStatePropertyAsSupports(NS_LITERAL_STRING("selecteditems"),
|
||||
getter_AddRefs(state));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (rv == NS_STATE_PROPERTY_EXISTS) {
|
||||
RestoreStateTo((nsSelectState*)(nsISupports*)state);
|
||||
|
||||
// Don't flush, if the frame doesn't exist yet it doesn't care if
|
||||
|
@ -8490,11 +8490,6 @@ NS_IMETHODIMP nsDocShell::PersistLayoutHistoryState()
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mOSHE) {
|
||||
PRBool shouldSave;
|
||||
GetShouldSaveLayoutState(&shouldSave);
|
||||
if (!shouldSave)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
rv = GetPresShell(getter_AddRefs(shell));
|
||||
if (NS_SUCCEEDED(rv) && shell) {
|
||||
|
@ -350,8 +350,10 @@ NS_IMETHODIMP nsSHEntry::GetLayoutHistoryState(nsILayoutHistoryState** aResult)
|
||||
|
||||
NS_IMETHODIMP nsSHEntry::SetLayoutHistoryState(nsILayoutHistoryState* aState)
|
||||
{
|
||||
NS_ENSURE_STATE(mSaveLayoutState || !aState);
|
||||
mLayoutHistoryState = aState;
|
||||
if (mLayoutHistoryState)
|
||||
mLayoutHistoryState->SetScrollPositionOnly(!mSaveLayoutState);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -425,11 +427,8 @@ NS_IMETHODIMP nsSHEntry::GetSaveLayoutStateFlag(PRBool * aFlag)
|
||||
NS_IMETHODIMP nsSHEntry::SetSaveLayoutStateFlag(PRBool aFlag)
|
||||
{
|
||||
mSaveLayoutState = aFlag;
|
||||
|
||||
// if we are not allowed to hold layout history state, then make sure
|
||||
// that we are not holding it!
|
||||
if (!mSaveLayoutState)
|
||||
mLayoutHistoryState = nsnull;
|
||||
if (mLayoutHistoryState)
|
||||
mLayoutHistoryState->SetScrollPositionOnly(!aFlag);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
14
docshell/test/chrome/215405_nocache.html
Normal file
14
docshell/test/chrome/215405_nocache.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html style="height: 100%">
|
||||
<head>
|
||||
<title>test1</title>
|
||||
</head>
|
||||
<body style="height: 100%">
|
||||
<input type="text" id="inp" value="">
|
||||
</input>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%; width: 300%">Some more text</div>
|
||||
</body>
|
||||
</html>
|
1
docshell/test/chrome/215405_nocache.html^headers^
Normal file
1
docshell/test/chrome/215405_nocache.html^headers^
Normal file
@ -0,0 +1 @@
|
||||
Cache-control: no-cache
|
14
docshell/test/chrome/215405_nostore.html
Normal file
14
docshell/test/chrome/215405_nostore.html
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html style="height: 100%">
|
||||
<head>
|
||||
<title>test1</title>
|
||||
</head>
|
||||
<body style="height: 100%">
|
||||
<input type="text" id="inp" value="">
|
||||
</input>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%">Some text</div>
|
||||
<div style="height: 50%; width: 350%">Some more text</div>
|
||||
</body>
|
||||
</html>
|
1
docshell/test/chrome/215405_nostore.html^headers^
Normal file
1
docshell/test/chrome/215405_nostore.html^headers^
Normal file
@ -0,0 +1 @@
|
||||
Cache-control: no-store
|
@ -48,6 +48,10 @@ _HTTP_FILES = \
|
||||
92598_nostore.html^headers^ \
|
||||
112564_nocache.html \
|
||||
112564_nocache.html^headers^ \
|
||||
215405_nostore.html \
|
||||
215405_nostore.html^headers^ \
|
||||
215405_nocache.html \
|
||||
215405_nocache.html^headers^ \
|
||||
$(NULL)
|
||||
|
||||
_TEST_FILES = \
|
||||
@ -58,6 +62,8 @@ _TEST_FILES = \
|
||||
bug112564_window.xul \
|
||||
test_bug113934.xul \
|
||||
bug113934_window.xul \
|
||||
test_bug215405.xul \
|
||||
bug215405_window.xul \
|
||||
test_bug364461.xul \
|
||||
bug364461_window.xul \
|
||||
test_bug396519.xul \
|
||||
|
194
docshell/test/chrome/bug215405_window.xul
Normal file
194
docshell/test/chrome/bug215405_window.xul
Normal file
@ -0,0 +1,194 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!-- ***** BEGIN LICENSE BLOCK *****
|
||||
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
-
|
||||
- The contents of this file are subject to the Mozilla Public License Version
|
||||
- 1.1 (the "License"); you may not use this file except in compliance with
|
||||
- the License. You may obtain a copy of the License at
|
||||
- http://www.mozilla.org/MPL/
|
||||
-
|
||||
- Software distributed under the License is distributed on an "AS IS" basis,
|
||||
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
- for the specific language governing rights and limitations under the
|
||||
- License.
|
||||
-
|
||||
- The Original Code is bug 215405 test code
|
||||
-
|
||||
- The Initial Developer of the Original Code is
|
||||
- Graeme McCutcheon <graememcc_firefox@graeme-online.co.uk>.
|
||||
- Portions created by the Initial Developer are Copyright (C) 2008
|
||||
- the Initial Developer. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the terms of
|
||||
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
- in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
- of those above. If you wish to allow use of your version of this file only
|
||||
- under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
- use your version of this file under the terms of the MPL, indicate your
|
||||
- decision by deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the LGPL or the GPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this file under
|
||||
- the terms of any one of the MPL, the GPL or the LGPL.
|
||||
-
|
||||
- ***** END LICENSE BLOCK ***** -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
|
||||
<window id="215405Test"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
width="600"
|
||||
height="600"
|
||||
onload="onLoad();"
|
||||
title="215405 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
var imports = [ "SimpleTest", "is", "isnot", "ok"];
|
||||
for each (var import in imports) {
|
||||
window[import] = window.opener.wrappedJSObject[import];
|
||||
}
|
||||
|
||||
const text="MOZILLA";
|
||||
const nostoreURI = "http://localhost:8888/tests/docshell/test/chrome/" +
|
||||
"215405_nostore.html";
|
||||
const nocacheURI = "https://example.com:443/tests/docshell/test/chrome/" +
|
||||
"215405_nocache.html";
|
||||
|
||||
var gBrowser;
|
||||
var gTestsIterator;
|
||||
var scrollX = 0;
|
||||
var scrollY = 0;
|
||||
|
||||
function finish() {
|
||||
gBrowser.removeEventListener("pageshow", eventListener, true);
|
||||
window.close();
|
||||
window.opener.wrappedJSObject.SimpleTest.finish();
|
||||
}
|
||||
|
||||
function onLoad(e) {
|
||||
gBrowser = document.getElementById("content");
|
||||
gBrowser.addEventListener("pageshow", eventListener, true);
|
||||
|
||||
gTestsIterator = testsIterator();
|
||||
nextTest();
|
||||
}
|
||||
|
||||
function eventListener(event) {
|
||||
setTimeout(nextTest, 0);
|
||||
}
|
||||
|
||||
function nextTest() {
|
||||
try {
|
||||
gTestsIterator.next();
|
||||
} catch (err if err instanceof StopIteration) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
function testsIterator() {
|
||||
// No-store tests
|
||||
var testName = "[nostore]";
|
||||
|
||||
// Load a page with a no-store header
|
||||
gBrowser.loadURI(nostoreURI);
|
||||
yield;
|
||||
|
||||
|
||||
// Now that the page has loaded, amend the form contents
|
||||
var form = gBrowser.contentDocument.getElementById("inp");
|
||||
form.value = text;
|
||||
|
||||
// Attempt to scroll the page
|
||||
var originalXPosition = gBrowser.contentWindow.scrollX;
|
||||
var originalYPosition = gBrowser.contentWindow.scrollY;
|
||||
var scrollToX = gBrowser.contentWindow.scrollMaxX;
|
||||
var scrollToY = gBrowser.contentWindow.scrollMaxY;
|
||||
gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
|
||||
|
||||
// Save the scroll position for future comparison
|
||||
scrollX = gBrowser.contentWindow.scrollX;
|
||||
scrollY = gBrowser.contentWindow.scrollY;
|
||||
isnot(scrollX, originalXPosition,
|
||||
testName + " failed to scroll window horizontally");
|
||||
isnot(scrollY, originalYPosition,
|
||||
testName + " failed to scroll window vertically");
|
||||
|
||||
// Load a new document into the browser
|
||||
var simple = "data:text/html,<html><head><title>test2</title></head>" +
|
||||
"<body>test2</body></html>";
|
||||
gBrowser.loadURI(simple);
|
||||
yield;
|
||||
|
||||
|
||||
// Now go back in history. First page should not have been cached.
|
||||
gBrowser.goBack();
|
||||
yield;
|
||||
|
||||
|
||||
// First uncacheable page will now be reloaded. Check scroll position
|
||||
// restored, and form contents not
|
||||
is(gBrowser.contentWindow.scrollX, scrollX, testName +
|
||||
" horizontal axis scroll position not correctly restored");
|
||||
is(gBrowser.contentWindow.scrollY, scrollY, testName +
|
||||
" vertical axis scroll position not correctly restored");
|
||||
var formValue = gBrowser.contentDocument.getElementById("inp").value;
|
||||
isnot(formValue, text, testName + " form value incorrectly restored");
|
||||
|
||||
|
||||
// https no-cache
|
||||
testName = "[nocache]";
|
||||
|
||||
// Load a page with a no-cache header
|
||||
gBrowser.loadURI(nocacheURI);
|
||||
yield;
|
||||
|
||||
|
||||
// Now that the page has loaded, amend the form contents
|
||||
form = gBrowser.contentDocument.getElementById("inp");
|
||||
form.value = text;
|
||||
|
||||
// Attempt to scroll the page
|
||||
originalXPosition = gBrowser.contentWindow.scrollX;
|
||||
originalYPosition = gBrowser.contentWindow.scrollY;
|
||||
scrollToX = gBrowser.contentWindow.scrollMaxX;
|
||||
scrollToY = gBrowser.contentWindow.scrollMaxY;
|
||||
gBrowser.contentWindow.scrollBy(scrollToX, scrollToY);
|
||||
|
||||
// Save the scroll position for future comparison
|
||||
scrollX = gBrowser.contentWindow.scrollX;
|
||||
scrollY = gBrowser.contentWindow.scrollY;
|
||||
isnot(scrollX, originalXPosition,
|
||||
testName + " failed to scroll window horizontally");
|
||||
isnot(scrollY, originalYPosition,
|
||||
testName + " failed to scroll window vertically");
|
||||
|
||||
gBrowser.loadURI(simple);
|
||||
yield;
|
||||
|
||||
|
||||
// Now go back in history. First page should not have been cached.
|
||||
gBrowser.goBack();
|
||||
yield;
|
||||
|
||||
|
||||
// First uncacheable page will now be reloaded. Check scroll position
|
||||
// restored, and form contents not
|
||||
is(gBrowser.contentWindow.scrollX, scrollX, testName +
|
||||
" horizontal axis scroll position not correctly restored");
|
||||
is(gBrowser.contentWindow.scrollY, scrollY, testName +
|
||||
" vertical axis scroll position not correctly restored");
|
||||
var formValue = gBrowser.contentDocument.getElementById("inp").value;
|
||||
isnot(formValue, text, testName + " form value incorrectly restored");
|
||||
|
||||
// nextTest has to be called from here, as no events are fired in this
|
||||
// step
|
||||
setTimeout(nextTest, 0);
|
||||
yield;
|
||||
}
|
||||
]]></script>
|
||||
|
||||
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
||||
</window>
|
42
docshell/test/chrome/test_bug215405.xul
Normal file
42
docshell/test/chrome/test_bug215405.xul
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=215405
|
||||
-->
|
||||
<window title="Mozilla Bug 215405"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<title>Test for Bug 215405</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=215405">Mozilla Bug 215405</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 215405 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
window.open("bug215405_window.xul", "bug215405",
|
||||
"chrome,width=600,height=600");
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
@ -1967,12 +1967,8 @@ DocumentViewerImpl::Hide(void)
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
|
||||
if (docShell) {
|
||||
PRBool saveLayoutState = PR_FALSE;
|
||||
docShell->GetShouldSaveLayoutState(&saveLayoutState);
|
||||
if (saveLayoutState) {
|
||||
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
||||
mPresShell->CaptureHistoryState(getter_AddRefs(layoutState), PR_TRUE);
|
||||
}
|
||||
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
||||
mPresShell->CaptureHistoryState(getter_AddRefs(layoutState), PR_TRUE);
|
||||
}
|
||||
|
||||
mPresShell->Destroy();
|
||||
|
@ -1635,7 +1635,7 @@ nsFrameManager::RestoreFrameStateFor(nsIFrame* aFrame,
|
||||
return;
|
||||
}
|
||||
|
||||
// Only capture state for stateful frames
|
||||
// Only restore state for stateful frames
|
||||
nsIStatefulFrame* statefulFrame;
|
||||
CallQueryInterface(aFrame, &statefulFrame);
|
||||
if (!statefulFrame) {
|
||||
|
@ -50,8 +50,8 @@
|
||||
class nsPresState;
|
||||
|
||||
#define NS_ILAYOUTHISTORYSTATE_IID \
|
||||
{ 0x99003f0f, 0x7ade, 0x44a1, \
|
||||
{ 0x81, 0x74, 0xe3, 0x6a, 0xa5, 0xbb, 0x6b, 0x10 } }
|
||||
{ 0x003919e2, 0x5e6b, 0x4d76, \
|
||||
{ 0xa9, 0x4f, 0xbc, 0x5d, 0x15, 0x5b, 0x1c, 0x67 } }
|
||||
|
||||
class nsILayoutHistoryState : public nsISupports {
|
||||
public:
|
||||
@ -79,6 +79,12 @@ class nsILayoutHistoryState : public nsISupports {
|
||||
* Check whether this history has any states in it
|
||||
*/
|
||||
NS_IMETHOD_(PRBool) HasStates() const = 0;
|
||||
|
||||
/**
|
||||
* Sets whether this history can contain only scroll position history
|
||||
* or all possible history
|
||||
*/
|
||||
NS_IMETHOD SetScrollPositionOnly(const PRBool aFlag) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsILayoutHistoryState,
|
||||
|
@ -59,10 +59,12 @@ public:
|
||||
NS_IMETHOD GetState(const nsCString& aKey, nsPresState** aState);
|
||||
NS_IMETHOD RemoveState(const nsCString& aKey);
|
||||
NS_IMETHOD_(PRBool) HasStates() const;
|
||||
NS_IMETHOD SetScrollPositionOnly(const PRBool aFlag);
|
||||
|
||||
|
||||
private:
|
||||
~nsLayoutHistoryState() {}
|
||||
PRBool mScrollPositionOnly;
|
||||
|
||||
nsClassHashtable<nsCStringHashKey,nsPresState> mStates;
|
||||
};
|
||||
@ -95,6 +97,7 @@ NS_IMPL_ISUPPORTS2(nsLayoutHistoryState,
|
||||
nsresult
|
||||
nsLayoutHistoryState::Init()
|
||||
{
|
||||
mScrollPositionOnly = PR_FALSE;
|
||||
return mStates.Init() ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -107,7 +110,13 @@ nsLayoutHistoryState::AddState(const nsCString& aStateKey, nsPresState* aState)
|
||||
NS_IMETHODIMP
|
||||
nsLayoutHistoryState::GetState(const nsCString& aKey, nsPresState** aState)
|
||||
{
|
||||
mStates.Get(aKey, aState);
|
||||
PRBool entryExists = mStates.Get(aKey, aState);
|
||||
|
||||
if (entryExists && mScrollPositionOnly) {
|
||||
// Ensure any state that shouldn't be restored is removed
|
||||
(*aState)->ClearNonScrollState();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -123,3 +132,10 @@ nsLayoutHistoryState::HasStates() const
|
||||
{
|
||||
return mStates.Count() != 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsLayoutHistoryState::SetScrollPositionOnly(const PRBool aFlag)
|
||||
{
|
||||
mScrollPositionOnly = aFlag;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -108,8 +108,10 @@ nsPresState::GetStatePropertyAsSupports(const nsAString& aName,
|
||||
nsISupports** aResult)
|
||||
{
|
||||
// Retrieve from hashtable.
|
||||
mPropertyTable.Get(aName, aResult);
|
||||
return NS_OK;
|
||||
if (mPropertyTable.Get(aName, aResult))
|
||||
return NS_STATE_PROPERTY_EXISTS;
|
||||
|
||||
return NS_STATE_PROPERTY_NOT_THERE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
@ -144,6 +146,12 @@ nsPresState::GetScrollState()
|
||||
return *mScrollState;
|
||||
}
|
||||
|
||||
void
|
||||
nsPresState::ClearNonScrollState()
|
||||
{
|
||||
mPropertyTable.Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewPresState(nsPresState** aState)
|
||||
{
|
||||
|
@ -71,7 +71,9 @@ public:
|
||||
|
||||
NS_HIDDEN_(nsresult) SetScrollState(const nsRect& aState);
|
||||
|
||||
nsRect GetScrollState();
|
||||
nsRect GetScrollState();
|
||||
|
||||
NS_HIDDEN_(void) ClearNonScrollState();
|
||||
|
||||
// MEMBER VARIABLES
|
||||
protected:
|
||||
|
@ -76,6 +76,7 @@
|
||||
#include "nsNodeInfoManager.h"
|
||||
#include "nsContentCreatorFunctions.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsLayoutErrors.h"
|
||||
|
||||
nsIFrame*
|
||||
NS_NewIsIndexFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
||||
@ -552,6 +553,7 @@ nsIsIndexFrame::RestoreState(nsPresState* aState)
|
||||
nsresult res = aState->GetStateProperty(NS_LITERAL_STRING("value"), stateString);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
||||
SetInputValue(stateString);
|
||||
if (res == NS_STATE_PROPERTY_EXISTS)
|
||||
SetInputValue(stateString);
|
||||
return NS_OK;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user