From 89ac805e1ffedb28d13e624bece4cf8d7a5f4bfa Mon Sep 17 00:00:00 2001 From: "tkent@chromium.org" Date: Fri, 29 Jun 2012 06:12:22 +0000 Subject: [PATCH] REGRESSION(r106388): Form hidden element values being restored incorrectly for dynamically generated content https://bugs.webkit.org/show_bug.cgi?id=88685 Reviewed by Hajime Morita. Source/WebCore: We should not save value attribute updated during parsing. Test: fast/forms/state-restore-to-non-edited-controls.html * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::HTMLInputElement): Initialize m_valueAttributeWasUpdatedAfterParsing. (WebCore::HTMLInputElement::parseAttribute): Set true to m_valueAttributeWasUpdatedAfterParsing if value attribute is updated and it's not in parsing. * html/HTMLInputElement.h: (WebCore::HTMLInputElement::valueAttributeWasUpdatedAfterParsing): Added for HiddenInputType. * html/HiddenInputType.cpp: (WebCore::HiddenInputType::saveFormControlState): Save the value only if valueAttributeWasUpdatedAfterParsing() is true. LayoutTests: * fast/forms/state-restore-to-non-edited-controls-expected.txt: A failing test is fixed. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121519 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 11 ++++++++++ ...ate-restore-to-non-edited-controls-expected.txt | 2 +- Source/WebCore/ChangeLog | 25 ++++++++++++++++++++++ Source/WebCore/html/HTMLInputElement.cpp | 2 ++ Source/WebCore/html/HTMLInputElement.h | 4 +++- Source/WebCore/html/HiddenInputType.cpp | 7 ++++-- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 1d23383..b470e86 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2012-06-28 Kent Tamura + + REGRESSION(r106388): Form hidden element values being restored + incorrectly for dynamically generated content + https://bugs.webkit.org/show_bug.cgi?id=88685 + + Reviewed by Hajime Morita. + + * fast/forms/state-restore-to-non-edited-controls-expected.txt: + A failing test is fixed. + 2012-06-28 Kenichi Ishibashi [Chromium] unreviewed test expectations update after r121510. diff --git a/LayoutTests/fast/forms/state-restore-to-non-edited-controls-expected.txt b/LayoutTests/fast/forms/state-restore-to-non-edited-controls-expected.txt index 0a9b0d8..9c6ce97 100644 --- a/LayoutTests/fast/forms/state-restore-to-non-edited-controls-expected.txt +++ b/LayoutTests/fast/forms/state-restore-to-non-edited-controls-expected.txt @@ -1,7 +1,7 @@ Test to NOT save state for non-edited controls PASS document.getElementById("button").value is "2" -FAIL document.getElementById("hidden").value should be 2. Was 1. +PASS document.getElementById("hidden").value is "2" PASS document.getElementById("image").value is "2" PASS document.getElementById("reset").value is "2" PASS document.getElementById("submit1").value is "2" diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index fdefb59..0f34a3c 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,28 @@ +2012-06-28 Kent Tamura + + REGRESSION(r106388): Form hidden element values being restored + incorrectly for dynamically generated content + https://bugs.webkit.org/show_bug.cgi?id=88685 + + Reviewed by Hajime Morita. + + We should not save value attribute updated during parsing. + + Test: fast/forms/state-restore-to-non-edited-controls.html + + * html/HTMLInputElement.cpp: + (WebCore::HTMLInputElement::HTMLInputElement): + Initialize m_valueAttributeWasUpdatedAfterParsing. + (WebCore::HTMLInputElement::parseAttribute): + Set true to m_valueAttributeWasUpdatedAfterParsing if value + attribute is updated and it's not in parsing. + * html/HTMLInputElement.h: + (WebCore::HTMLInputElement::valueAttributeWasUpdatedAfterParsing): + Added for HiddenInputType. + * html/HiddenInputType.cpp: + (WebCore::HiddenInputType::saveFormControlState): + Save the value only if valueAttributeWasUpdatedAfterParsing() is true. + 2012-06-28 MORITA Hajime [Refactoring] NodeRenderingContext ctor could be built on top of the ComposedShadowTreeWalker diff --git a/Source/WebCore/html/HTMLInputElement.cpp b/Source/WebCore/html/HTMLInputElement.cpp index 6fcd158..e773284 100644 --- a/Source/WebCore/html/HTMLInputElement.cpp +++ b/Source/WebCore/html/HTMLInputElement.cpp @@ -95,6 +95,7 @@ HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* docum , m_isAutofilled(false) , m_stateRestored(false) , m_parsingInProgress(createdByParser) + , m_valueAttributeWasUpdatedAfterParsing(false) , m_wasModifiedByUser(false) , m_canReceiveDroppedFiles(false) , m_inputType(InputType::createText(this)) @@ -594,6 +595,7 @@ void HTMLInputElement::parseAttribute(const Attribute& attribute) } setFormControlValueMatchesRenderer(false); setNeedsValidityCheck(); + m_valueAttributeWasUpdatedAfterParsing = !m_parsingInProgress; } else if (attribute.name() == checkedAttr) { // Another radio button in the same group might be checked by state // restore. We shouldn't call setChecked() even if this has the checked diff --git a/Source/WebCore/html/HTMLInputElement.h b/Source/WebCore/html/HTMLInputElement.h index faeabff..1ec5ef0 100644 --- a/Source/WebCore/html/HTMLInputElement.h +++ b/Source/WebCore/html/HTMLInputElement.h @@ -238,11 +238,12 @@ public: HTMLInputElement* checkedRadioButtonForGroup() const; bool isInRequiredRadioButtonGroup() const; + // Functions for InputType classes. void setValueInternal(const String&, TextFieldEventBehavior); - bool isTextFormControlFocusable() const; bool isTextFormControlKeyboardFocusable(KeyboardEvent*) const; bool isTextFormControlMouseFocusable() const; + bool valueAttributeWasUpdatedAfterParsing() const { return m_valueAttributeWasUpdatedAfterParsing; } void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); } @@ -386,6 +387,7 @@ private: #endif bool m_stateRestored : 1; bool m_parsingInProgress : 1; + bool m_valueAttributeWasUpdatedAfterParsing : 1; bool m_wasModifiedByUser : 1; bool m_canReceiveDroppedFiles : 1; OwnPtr m_inputType; diff --git a/Source/WebCore/html/HiddenInputType.cpp b/Source/WebCore/html/HiddenInputType.cpp index 049637c..fb6f36a 100644 --- a/Source/WebCore/html/HiddenInputType.cpp +++ b/Source/WebCore/html/HiddenInputType.cpp @@ -54,8 +54,11 @@ const AtomicString& HiddenInputType::formControlType() const FormControlState HiddenInputType::saveFormControlState() const { - // FIXME: We should not always save the value. http://webkit.org/b/88685 - return FormControlState(element()->value()); + // valueAttributeWasUpdatedAfterParsing() never be true for form + // controls create by createElement() or cloneNode(). It's ok for + // now because we restore values only to form controls created by + // parsing. + return element()->valueAttributeWasUpdatedAfterParsing() ? FormControlState(element()->value()) : FormControlState(); } void HiddenInputType::restoreFormControlState(const FormControlState& state) -- 2.7.4