Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: Source/core/html/forms/FormController.cpp

Issue 239993011: Lazily generate HistoryItem's serialized form state (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 367 }
368 368
369 void FormKeyGenerator::willDeleteForm(HTMLFormElement* form) 369 void FormKeyGenerator::willDeleteForm(HTMLFormElement* form)
370 { 370 {
371 ASSERT(form); 371 ASSERT(form);
372 m_formToKeyMap.remove(form); 372 m_formToKeyMap.remove(form);
373 } 373 }
374 374
375 // ---------------------------------------------------------------------------- 375 // ----------------------------------------------------------------------------
376 376
377 FormController::FormController() 377 PassRefPtr<DocumentState> DocumentState::create()
378 {
379 return adoptRef(new DocumentState);
380 }
381
382 DocumentState::~DocumentState()
378 { 383 {
379 } 384 }
380 385
381 FormController::~FormController() 386 void DocumentState::addControl(HTMLFormControlElementWithState* control)
382 { 387 {
388 ASSERT(!m_formControls.contains(control));
389 m_formControls.add(control);
390 }
391
392 void DocumentState::removeControl(HTMLFormControlElementWithState* control)
393 {
394 RELEASE_ASSERT(m_formControls.contains(control));
abarth-chromium 2014/04/17 23:41:24 Why RELEASE_ASSERT and not just ASSERT?
Nate Chapin 2014/04/17 23:48:19 I copy/pasted it without understanding the history
395 m_formControls.remove(control);
383 } 396 }
384 397
385 static String formStateSignature() 398 static String formStateSignature()
386 { 399 {
387 // In the legacy version of serialized state, the first item was a name 400 // In the legacy version of serialized state, the first item was a name
388 // attribute value of a form control. The following string literal should 401 // attribute value of a form control. The following string literal should
389 // contain some characters which are rarely used for name attribute values. 402 // contain some characters which are rarely used for name attribute values.
390 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 8 \n\r=&")); 403 DEFINE_STATIC_LOCAL(String, signature, ("\n\r?% WebKit serialized form state version 8 \n\r=&"));
391 return signature; 404 return signature;
392 } 405 }
393 406
394 PassOwnPtr<FormController::SavedFormStateMap> FormController::createSavedFormSta teMap(const FormElementListHashSet& controlList) 407 Vector<String> DocumentState::toStateVector()
395 { 408 {
396 OwnPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create(); 409 OwnPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create();
397 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap); 410 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap);
398 for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) { 411 for (FormElementListHashSet::const_iterator it = m_formControls.begin(); it != m_formControls.end(); ++it) {
399 HTMLFormControlElementWithState* control = (*it).get(); 412 HTMLFormControlElementWithState* control = (*it).get();
400 ASSERT(control->inDocument()); 413 ASSERT(control->inDocument());
401 if (!control->shouldSaveAndRestoreFormControlState()) 414 if (!control->shouldSaveAndRestoreFormControlState())
402 continue; 415 continue;
403 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(*control), nullptr); 416 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(*control), nullptr);
404 if (result.isNewEntry) 417 if (result.isNewEntry)
405 result.storedValue->value = SavedFormState::create(); 418 result.storedValue->value = SavedFormState::create();
406 result.storedValue->value->appendControlState(control->name(), control-> type(), control->saveFormControlState()); 419 result.storedValue->value->appendControlState(control->name(), control-> type(), control->saveFormControlState());
407 } 420 }
408 return stateMap.release();
409 }
410 421
411 Vector<String> FormController::formElementsState() const
412 {
413 OwnPtr<SavedFormStateMap> stateMap = createSavedFormStateMap(m_formControls) ;
414 Vector<String> stateVector; 422 Vector<String> stateVector;
415 stateVector.reserveInitialCapacity(m_formControls.size() * 4); 423 stateVector.reserveInitialCapacity(m_formControls.size() * 4);
416 stateVector.append(formStateSignature()); 424 stateVector.append(formStateSignature());
417 for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMa p->end(); ++it) { 425 for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMa p->end(); ++it) {
418 stateVector.append(it->key); 426 stateVector.append(it->key);
419 it->value->serializeTo(stateVector); 427 it->value->serializeTo(stateVector);
420 } 428 }
421 bool hasOnlySignature = stateVector.size() == 1; 429 bool hasOnlySignature = stateVector.size() == 1;
422 if (hasOnlySignature) 430 if (hasOnlySignature)
423 stateVector.clear(); 431 stateVector.clear();
424 return stateVector; 432 return stateVector;
425 } 433 }
426 434
435 // ----------------------------------------------------------------------------
436
437 FormController::FormController()
438 : m_documentState(DocumentState::create())
439 {
440 }
441
442 FormController::~FormController()
443 {
444 }
445
446 DocumentState* FormController::formElementsState() const
447 {
448 return m_documentState.get();
449 }
450
427 void FormController::setStateForNewFormElements(const Vector<String>& stateVecto r) 451 void FormController::setStateForNewFormElements(const Vector<String>& stateVecto r)
428 { 452 {
429 formStatesFromStateVector(stateVector, m_savedFormStateMap); 453 formStatesFromStateVector(stateVector, m_savedFormStateMap);
430 } 454 }
431 455
432 FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl ementWithState& control) 456 FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl ementWithState& control)
433 { 457 {
434 if (m_savedFormStateMap.isEmpty()) 458 if (m_savedFormStateMap.isEmpty())
435 return FormControlState(); 459 return FormControlState();
436 if (!m_formKeyGenerator) 460 if (!m_formKeyGenerator)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 Vector<String> toReturn; 531 Vector<String> toReturn;
508 SavedFormStateMap map; 532 SavedFormStateMap map;
509 formStatesFromStateVector(stateVector, map); 533 formStatesFromStateVector(stateVector, map);
510 for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++ it) 534 for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++ it)
511 toReturn.appendVector(it->value->getReferencedFilePaths()); 535 toReturn.appendVector(it->value->getReferencedFilePaths());
512 return toReturn; 536 return toReturn;
513 } 537 }
514 538
515 void FormController::registerStatefulFormControl(HTMLFormControlElementWithState & control) 539 void FormController::registerStatefulFormControl(HTMLFormControlElementWithState & control)
516 { 540 {
517 ASSERT(!m_formControls.contains(&control)); 541 m_documentState->addControl(&control);
518 m_formControls.add(&control);
519 } 542 }
520 543
521 void FormController::unregisterStatefulFormControl(HTMLFormControlElementWithSta te& control) 544 void FormController::unregisterStatefulFormControl(HTMLFormControlElementWithSta te& control)
522 { 545 {
523 RELEASE_ASSERT(m_formControls.contains(&control)); 546 m_documentState->removeControl(&control);
524 m_formControls.remove(&control);
525 } 547 }
526 548
527 } // namespace WebCore 549 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698