Changeset 121145 in webkit
- Timestamp:
- Jun 25, 2012 2:43:07 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r121141 r121145 1 2012-06-25 Kent Tamura <tkent@chromium.org> 2 3 Change the serialization format of form control state to make the code simple 4 https://bugs.webkit.org/show_bug.cgi?id=89847 5 6 Reviewed by Hajime Morita. 7 8 * fast/forms/state-restore-broken-state-expected.txt: 9 Apply the serialization format change. 10 * fast/forms/state-restore-various-values-expected.txt: Added. 11 * fast/forms/state-restore-various-values.html: Added. 12 1 13 2012-06-24 Kristóf Kosztyó <kkristof@inf.u-szeged.hu> 2 14 -
trunk/LayoutTests/fast/forms/state-restore-broken-state-expected.txt
r120895 r121145 1 CONSOLE MESSAGE: line 5: Generated state: [name1,text, 1,modified]1 CONSOLE MESSAGE: line 5: Generated state: [name1,text,,modified] 2 2 The value was modified in the first load of state-restore-broken-state-1.html, but it should not be restored because the state-restore-broken-state-2.html breaks the state. 3 3 -
trunk/Source/WTF/ChangeLog
r121140 r121145 1 2012-06-25 Kent Tamura <tkent@chromium.org> 2 3 Change the serialization format of form control state to make the code simple 4 https://bugs.webkit.org/show_bug.cgi?id=89847 5 6 Reviewed by Hajime Morita. 7 8 * wtf/text/StringBuilder.h: 9 (WTF::StringBuilder::appendEscaped): Added. This function adds the 10 escaped form of the input string. e.g. if stiring="foo,bar" escape='\' 11 special=',', the appended string is foo\,bar. 12 1 13 2012-06-24 Adam Barth <abarth@webkit.org> 2 14 -
trunk/Source/WTF/wtf/text/StringBuilder.h
r111778 r121145 131 131 } 132 132 133 void appendEscaped(const String& string, UChar escape, UChar special) 134 { 135 if (string.isEmpty()) 136 return; 137 unsigned requiredSize = length() + string.length(); 138 if (capacity() < requiredSize) 139 reserveCapacity(requiredSize); 140 for (unsigned i = 0; i < string.length(); ++i) { 141 UChar ch = string[i]; 142 if (ch == escape || ch == special) 143 append(escape); 144 append(ch); 145 } 146 } 147 133 148 String toString() 134 149 { -
trunk/Source/WebCore/ChangeLog
r121144 r121145 1 2012-06-25 Kent Tamura <tkent@chromium.org> 2 3 Change the serialization format of form control state to make the code simple 4 https://bugs.webkit.org/show_bug.cgi?id=89847 5 6 Reviewed by Hajime Morita. 7 8 We used multiple strings to represent state of single form control. It 9 made the code complex. We change the serialization format so that one 10 CSV string represents state. 11 12 Examples in the old format: 13 "0" 14 "1", "value" 15 "3", "value1", "value2,value2", "value3" 16 17 Examples in the new format: 18 "" 19 ",value" 20 ",value1,value2\,value2,value3" 21 22 Test: fast/forms/state-restore-various-values.html 23 24 * html/FormController.cpp: 25 (WebCore::FormControlState::serialize): 26 Generate comma-separated string. 27 ',' in a value is serialized as "\,". 28 We changed the signature because we don't need the out-argument. 29 (WebCore::FormControlState::deserialize): 30 Parses the input comma-separated string. 31 We changed the signature because we don't need multiple input strings. 32 (formStateSignature): 33 Bump up the version because of the representation change. 34 (WebCore::FormController::formElementsState): 35 The new serialized format occupies just one string for one control. 36 - Expected size is now 3n+1. 37 - Use FormControlState::serialize(). 38 (WebCore::FormController::setStateForNewFormElements): 39 The new serialized format occupies just one string for one control. 40 So we can check the vector size before the iteration. 41 * html/FormController.h: 42 (FormControlState): Change the function signatures. 43 44 * html/shadow/CalendarPickerElement.cpp: 45 (WebCore::addJavaScriptString): Use StringBuilder::appendEscaped(). 46 1 47 2012-06-22 Yury Semikhatsky <yurys@chromium.org> 2 48 -
trunk/Source/WebCore/html/FormController.cpp
r121128 r121145 23 23 24 24 #include "HTMLFormControlElementWithState.h" 25 #include <wtf/text/StringBuilder.h> 25 26 26 27 namespace WebCore { … … 31 32 32 33 // Serilized form of FormControlState: 33 // (',' means strings around it are separated in stateVector.)34 34 // 35 35 // SerializedControlState ::= SkipState | RestoreState 36 // SkipState ::= '0' 37 // RestoreState ::= UnsignedNumber, ControlValue+ 38 // UnsignedNumber ::= [0-9]+ 39 // ControlValue ::= arbitrary string 40 // 41 // RestoreState has a sequence of ControlValues. The length of the 42 // sequence is represented by UnsignedNumber. 43 44 void FormControlState::serializeTo(Vector<String>& stateVector) const 36 // SkipState ::= '' 37 // RestoreState ::= (',' EscapedValue )+ 38 // EscapedValue ::= ('\\' | '\,' | [^\,])+ 39 40 String FormControlState::serialize() const 45 41 { 46 42 ASSERT(!isFailure()); 47 stateVector.append(String::number(m_values.size())); 43 if (!m_values.size()) 44 return emptyString(); 45 46 size_t enoughSize = 0; 48 47 for (size_t i = 0; i < m_values.size(); ++i) 49 stateVector.append(m_values[i].isNull() ? emptyString() : m_values[i]); 50 } 51 52 FormControlState FormControlState::deserialize(const Vector<String>& stateVector, size_t& index) 53 { 54 if (index >= stateVector.size()) 48 enoughSize += 1 + m_values[i].length() * 2; 49 StringBuilder builder; 50 builder.reserveCapacity(enoughSize); 51 for (size_t i = 0; i < m_values.size(); ++i) { 52 builder.append(','); 53 builder.appendEscaped(m_values[i], '\\', ','); 54 } 55 return builder.toString(); 56 } 57 58 FormControlState FormControlState::deserialize(const String& escaped) 59 { 60 if (!escaped.length()) 61 return FormControlState(); 62 if (escaped[0] != ',') 55 63 return FormControlState(TypeFailure); 56 size_t valueSize = stateVector[index++].toUInt(); 57 if (!valueSize) 58 return FormControlState(); 59 if (index + valueSize > stateVector.size()) 60 return FormControlState(TypeFailure); 64 65 size_t valueSize = 1; 66 for (unsigned i = 1; i < escaped.length(); ++i) { 67 if (escaped[i] == '\\') { 68 if (++i >= escaped.length()) 69 return FormControlState(TypeFailure); 70 } else if (escaped[i] == ',') 71 valueSize++; 72 } 73 61 74 FormControlState state; 62 75 state.m_values.reserveCapacity(valueSize); 63 for (size_t i = 0; i < valueSize; ++i) 64 state.append(stateVector[index++]); 76 StringBuilder builder; 77 for (unsigned i = 1; i < escaped.length(); ++i) { 78 if (escaped[i] == '\\') { 79 if (++i >= escaped.length()) 80 return FormControlState(TypeFailure); 81 builder.append(escaped[i]); 82 } else if (escaped[i] == ',') { 83 state.append(builder.toString()); 84 builder.clear(); 85 } else 86 builder.append(escaped[i]); 87 } 88 state.append(builder.toString()); 65 89 return state; 66 90 } … … 82 106 // attribute value of a form control. The following string literal should 83 107 // contain some characters which are rarely used for name attribute values. 84 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 3\n\r=&"));108 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 4 \n\r=&")); 85 109 return signature; 86 110 } … … 89 113 { 90 114 Vector<String> stateVector; 91 stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4+ 1);115 stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 3 + 1); 92 116 stateVector.append(formStateSignature()); 93 117 typedef FormElementListHashSet::const_iterator Iterator; … … 99 123 stateVector.append(elementWithState->name().string()); 100 124 stateVector.append(elementWithState->formControlType().string()); 101 elementWithState->saveFormControlState().serializeTo(stateVector);125 stateVector.append(elementWithState->saveFormControlState().serialize()); 102 126 } 103 127 return stateVector; … … 114 138 m_formElementsWithState.clear(); 115 139 116 size_t i = 0; 117 if (stateVector.size() < 1 || stateVector[i++] != formStateSignature()) 140 if (stateVector.size() < 1 || stateVector[0] != formStateSignature()) 118 141 return; 119 120 while (i + 2 < stateVector.size()) { 121 AtomicString name = stateVector[i++]; 122 AtomicString type = stateVector[i++]; 123 FormControlState state = FormControlState::deserialize(stateVector, i); 142 if ((stateVector.size() - 1) % 3) 143 return; 144 145 for (size_t i = 1; i < stateVector.size(); i += 3) { 146 AtomicString name = stateVector[i]; 147 AtomicString type = stateVector[i + 1]; 148 FormControlState state = FormControlState::deserialize(stateVector[i + 2]); 124 149 if (type.isEmpty() || type.impl()->find(isNotFormControlTypeCharacter) != notFound || state.isFailure()) 125 150 break; … … 135 160 } 136 161 } 137 if (i != stateVector.size())138 m_stateForNewFormElements.clear();139 162 } 140 163 -
trunk/Source/WebCore/html/FormController.h
r121004 r121145 79 79 FormControlState() : m_type(TypeSkip) { } 80 80 explicit FormControlState(const String& value) : m_type(TypeRestore) { m_values.append(value); } 81 static FormControlState deserialize(const Vector<String>& stateVector, size_t& index);81 static FormControlState deserialize(const String&); 82 82 FormControlState(const FormControlState& another) : m_type(another.m_type), m_values(another.m_values) { } 83 83 FormControlState& operator=(const FormControlState&); … … 87 87 const String& operator[](size_t i) const { return m_values[i]; } 88 88 void append(const String&); 89 void serializeTo(Vector<String>& stateVector) const;89 String serialize() const; 90 90 91 91 private: -
trunk/Source/WebCore/html/shadow/CalendarPickerElement.cpp
r120313 r121145 152 152 addLiteral("\"", writer); 153 153 StringBuilder builder; 154 builder.reserveCapacity(str.length()); 155 for (unsigned i = 0; i < str.length(); ++i) { 156 if (str[i] == '\\' || str[i] == '"') 157 builder.append('\\'); 158 builder.append(str[i]); 159 } 154 builder.appendEscaped(str, '\\', '"'); 160 155 addString(builder.toString(), writer); 161 156 addLiteral("\"", writer);
Note: See TracChangeset
for help on using the changeset viewer.