|
Lines 173-180
class SavedFormState {
a/Source/WebCore/html/FormController.cpp_sec1
|
| 173 |
WTF_MAKE_FAST_ALLOCATED; |
173 |
WTF_MAKE_FAST_ALLOCATED; |
| 174 |
|
174 |
|
| 175 |
public: |
175 |
public: |
| 176 |
static OwnPtr<SavedFormState> create(); |
176 |
SavedFormState() |
| 177 |
static OwnPtr<SavedFormState> deserialize(const Vector<String>&, size_t& index); |
177 |
: m_controlStateCount(0) |
|
|
178 |
{ |
| 179 |
} |
| 180 |
|
| 181 |
static std::unique_ptr<SavedFormState> deserialize(const Vector<String>&, size_t& index); |
| 178 |
void serializeTo(Vector<String>&) const; |
182 |
void serializeTo(Vector<String>&) const; |
| 179 |
bool isEmpty() const { return m_stateForNewFormElements.isEmpty(); } |
183 |
bool isEmpty() const { return m_stateForNewFormElements.isEmpty(); } |
| 180 |
void appendControlState(const AtomicString& name, const AtomicString& type, const FormControlState&); |
184 |
void appendControlState(const AtomicString& name, const AtomicString& type, const FormControlState&); |
|
Lines 183-206
public:
a/Source/WebCore/html/FormController.cpp_sec2
|
| 183 |
Vector<String> getReferencedFilePaths() const; |
187 |
Vector<String> getReferencedFilePaths() const; |
| 184 |
|
188 |
|
| 185 |
private: |
189 |
private: |
| 186 |
SavedFormState() : m_controlStateCount(0) { } |
|
|
| 187 |
|
| 188 |
typedef HashMap<FormElementKey, Deque<FormControlState>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap; |
190 |
typedef HashMap<FormElementKey, Deque<FormControlState>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap; |
| 189 |
FormElementStateMap m_stateForNewFormElements; |
191 |
FormElementStateMap m_stateForNewFormElements; |
| 190 |
size_t m_controlStateCount; |
192 |
size_t m_controlStateCount; |
| 191 |
}; |
193 |
}; |
| 192 |
|
194 |
|
| 193 |
OwnPtr<SavedFormState> SavedFormState::create() |
|
|
| 194 |
{ |
| 195 |
return adoptPtr(new SavedFormState); |
| 196 |
} |
| 197 |
|
| 198 |
static bool isNotFormControlTypeCharacter(UChar ch) |
195 |
static bool isNotFormControlTypeCharacter(UChar ch) |
| 199 |
{ |
196 |
{ |
| 200 |
return ch != '-' && (ch > 'z' || ch < 'a'); |
197 |
return ch != '-' && (ch > 'z' || ch < 'a'); |
| 201 |
} |
198 |
} |
| 202 |
|
199 |
|
| 203 |
OwnPtr<SavedFormState> SavedFormState::deserialize(const Vector<String>& stateVector, size_t& index) |
200 |
std::unique_ptr<SavedFormState> SavedFormState::deserialize(const Vector<String>& stateVector, size_t& index) |
| 204 |
{ |
201 |
{ |
| 205 |
if (index >= stateVector.size()) |
202 |
if (index >= stateVector.size()) |
| 206 |
return nullptr; |
203 |
return nullptr; |
|
Lines 208-214
OwnPtr<SavedFormState> SavedFormState::deserialize(const Vector<String>& stateVe
a/Source/WebCore/html/FormController.cpp_sec3
|
| 208 |
size_t itemCount = stateVector[index++].toUInt(); |
205 |
size_t itemCount = stateVector[index++].toUInt(); |
| 209 |
if (!itemCount) |
206 |
if (!itemCount) |
| 210 |
return nullptr; |
207 |
return nullptr; |
| 211 |
OwnPtr<SavedFormState> savedFormState = adoptPtr(new SavedFormState); |
208 |
auto savedFormState = std::make_unique<SavedFormState>(); |
| 212 |
while (itemCount--) { |
209 |
while (itemCount--) { |
| 213 |
if (index + 1 >= stateVector.size()) |
210 |
if (index + 1 >= stateVector.size()) |
| 214 |
return nullptr; |
211 |
return nullptr; |
|
Lines 219-225
OwnPtr<SavedFormState> SavedFormState::deserialize(const Vector<String>& stateVe
a/Source/WebCore/html/FormController.cpp_sec4
|
| 219 |
return nullptr; |
216 |
return nullptr; |
| 220 |
savedFormState->appendControlState(name, type, state); |
217 |
savedFormState->appendControlState(name, type, state); |
| 221 |
} |
218 |
} |
| 222 |
return savedFormState.release(); |
219 |
return std::move(savedFormState); |
| 223 |
} |
220 |
} |
| 224 |
|
221 |
|
| 225 |
void SavedFormState::serializeTo(Vector<String>& stateVector) const |
222 |
void SavedFormState::serializeTo(Vector<String>& stateVector) const |
|
Lines 289-301
class FormKeyGenerator {
a/Source/WebCore/html/FormController.cpp_sec5
|
| 289 |
WTF_MAKE_FAST_ALLOCATED; |
286 |
WTF_MAKE_FAST_ALLOCATED; |
| 290 |
|
287 |
|
| 291 |
public: |
288 |
public: |
| 292 |
static OwnPtr<FormKeyGenerator> create() { return adoptPtr(new FormKeyGenerator); } |
289 |
FormKeyGenerator() = default; |
| 293 |
AtomicString formKey(const HTMLFormControlElementWithState&); |
290 |
AtomicString formKey(const HTMLFormControlElementWithState&); |
| 294 |
void willDeleteForm(HTMLFormElement*); |
291 |
void willDeleteForm(HTMLFormElement*); |
| 295 |
|
292 |
|
| 296 |
private: |
293 |
private: |
| 297 |
FormKeyGenerator() { } |
|
|
| 298 |
|
| 299 |
typedef HashMap<HTMLFormElement*, AtomicString> FormToKeyMap; |
294 |
typedef HashMap<HTMLFormElement*, AtomicString> FormToKeyMap; |
| 300 |
typedef HashMap<String, unsigned> FormSignatureToNextIndexMap; |
295 |
typedef HashMap<String, unsigned> FormSignatureToNextIndexMap; |
| 301 |
FormToKeyMap m_formToKeyMap; |
296 |
FormToKeyMap m_formToKeyMap; |
|
Lines 399-423
static String formStateSignature()
a/Source/WebCore/html/FormController.cpp_sec6
|
| 399 |
return signature; |
394 |
return signature; |
| 400 |
} |
395 |
} |
| 401 |
|
396 |
|
| 402 |
OwnPtr<FormController::SavedFormStateMap> FormController::createSavedFormStateMap(const FormElementListHashSet& controlList) |
397 |
std::unique_ptr<FormController::SavedFormStateMap> FormController::createSavedFormStateMap(const FormElementListHashSet& controlList) |
| 403 |
{ |
398 |
{ |
| 404 |
OwnPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create(); |
399 |
auto keyGenerator = std::make_unique<FormKeyGenerator>(); |
| 405 |
OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap); |
400 |
auto stateMap = std::make_unique<SavedFormStateMap>(); |
| 406 |
for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) { |
401 |
for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) { |
| 407 |
HTMLFormControlElementWithState* control = it->get(); |
402 |
HTMLFormControlElementWithState* control = it->get(); |
| 408 |
if (!control->shouldSaveAndRestoreFormControlState()) |
403 |
if (!control->shouldSaveAndRestoreFormControlState()) |
| 409 |
continue; |
404 |
continue; |
| 410 |
SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKey(*control).impl(), nullptr); |
405 |
auto& formState = stateMap->add(keyGenerator->formKey(*control).impl(), nullptr).iterator->value; |
| 411 |
if (result.isNewEntry) |
406 |
if (!formState) |
| 412 |
result.iterator->value = SavedFormState::create(); |
407 |
formState = std::make_unique<SavedFormState>(); |
| 413 |
result.iterator->value->appendControlState(control->name(), control->type(), control->saveFormControlState()); |
408 |
formState->appendControlState(control->name(), control->type(), control->saveFormControlState()); |
| 414 |
} |
409 |
} |
| 415 |
return stateMap.release(); |
410 |
return std::move(stateMap); |
| 416 |
} |
411 |
} |
| 417 |
|
412 |
|
| 418 |
Vector<String> FormController::formElementsState() const |
413 |
Vector<String> FormController::formElementsState() const |
| 419 |
{ |
414 |
{ |
| 420 |
OwnPtr<SavedFormStateMap> stateMap = createSavedFormStateMap(m_formElementsWithState); |
415 |
std::unique_ptr<SavedFormStateMap> stateMap = createSavedFormStateMap(m_formElementsWithState); |
| 421 |
Vector<String> stateVector; |
416 |
Vector<String> stateVector; |
| 422 |
stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4); |
417 |
stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4); |
| 423 |
stateVector.append(formStateSignature()); |
418 |
stateVector.append(formStateSignature()); |
|
Lines 441-447
FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl
a/Source/WebCore/html/FormController.cpp_sec7
|
| 441 |
if (m_savedFormStateMap.isEmpty()) |
436 |
if (m_savedFormStateMap.isEmpty()) |
| 442 |
return FormControlState(); |
437 |
return FormControlState(); |
| 443 |
if (!m_formKeyGenerator) |
438 |
if (!m_formKeyGenerator) |
| 444 |
m_formKeyGenerator = FormKeyGenerator::create(); |
439 |
m_formKeyGenerator = std::make_unique<FormKeyGenerator>(); |
| 445 |
SavedFormStateMap::iterator it = m_savedFormStateMap.find(m_formKeyGenerator->formKey(control).impl()); |
440 |
SavedFormStateMap::iterator it = m_savedFormStateMap.find(m_formKeyGenerator->formKey(control).impl()); |
| 446 |
if (it == m_savedFormStateMap.end()) |
441 |
if (it == m_savedFormStateMap.end()) |
| 447 |
return FormControlState(); |
442 |
return FormControlState(); |
|
Lines 461-472
void FormController::formStatesFromStateVector(const Vector<String>& stateVector
a/Source/WebCore/html/FormController.cpp_sec8
|
| 461 |
|
456 |
|
| 462 |
while (i + 1 < stateVector.size()) { |
457 |
while (i + 1 < stateVector.size()) { |
| 463 |
AtomicString formKey = stateVector[i++]; |
458 |
AtomicString formKey = stateVector[i++]; |
| 464 |
OwnPtr<SavedFormState> state = SavedFormState::deserialize(stateVector, i); |
459 |
std::unique_ptr<SavedFormState> state = SavedFormState::deserialize(stateVector, i); |
| 465 |
if (!state) { |
460 |
if (!state) { |
| 466 |
i = 0; |
461 |
i = 0; |
| 467 |
break; |
462 |
break; |
| 468 |
} |
463 |
} |
| 469 |
map.add(formKey.impl(), state.release()); |
464 |
map.add(formKey.impl(), std::move(state)); |
| 470 |
} |
465 |
} |
| 471 |
if (i != stateVector.size()) |
466 |
if (i != stateVector.size()) |
| 472 |
map.clear(); |
467 |
map.clear(); |