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

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

Issue 19510005: [oilpan] Completely move HTMLFormControlElement's hierarchy to the managed heap Base URL: svn://svn.chromium.org/blink/branches/oilpan
Patch Set: Created 7 years, 5 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
« no previous file with comments | « Source/core/html/FormController.h ('k') | Source/core/html/HTMLAttributeNames.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
25 #include "core/html/HTMLFormElement.h" 25 #include "core/html/HTMLFormElement.h"
26 #include "core/html/HTMLInputElement.h" 26 #include "core/html/HTMLInputElement.h"
27 #include "core/platform/FileChooser.h" 27 #include "core/platform/FileChooser.h"
28 #include <wtf/FastMalloc.h> 28 #include <wtf/FastMalloc.h>
29 #include <wtf/text/StringBuilder.h> 29 #include <wtf/text/StringBuilder.h>
30 30
31 namespace WebCore { 31 namespace WebCore {
32 32
33 using namespace HTMLNames; 33 using namespace HTMLNames;
34 34
35 static inline HTMLFormElement* ownerFormForState(const HTMLFormControlElementWit hState& control) 35 static inline HTMLFormElement* ownerFormForState(Handle<const HTMLFormControlEle mentWithState> control)
36 { 36 {
37 // Assume controls with form attribute have no owners because we restore 37 // Assume controls with form attribute have no owners because we restore
38 // state during parsing and form owners of such controls might be 38 // state during parsing and form owners of such controls might be
39 // indeterminate. 39 // indeterminate.
40 return control.fastHasAttribute(formAttr) ? 0 : control.form(); 40 return control->fastHasAttribute(formAttr) ? 0 : control->form();
41 } 41 }
42 42
43 // ---------------------------------------------------------------------------- 43 // ----------------------------------------------------------------------------
44 44
45 // Serilized form of FormControlState: 45 // Serilized form of FormControlState:
46 // (',' means strings around it are separated in stateVector.) 46 // (',' means strings around it are separated in stateVector.)
47 // 47 //
48 // SerializedControlState ::= SkipState | RestoreState 48 // SerializedControlState ::= SkipState | RestoreState
49 // SkipState ::= '0' 49 // SkipState ::= '0'
50 // RestoreState ::= UnsignedNumber, ControlValue+ 50 // RestoreState ::= UnsignedNumber, ControlValue+
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 286 }
287 287
288 // ---------------------------------------------------------------------------- 288 // ----------------------------------------------------------------------------
289 289
290 class FormKeyGenerator { 290 class FormKeyGenerator {
291 WTF_MAKE_NONCOPYABLE(FormKeyGenerator); 291 WTF_MAKE_NONCOPYABLE(FormKeyGenerator);
292 WTF_MAKE_FAST_ALLOCATED; 292 WTF_MAKE_FAST_ALLOCATED;
293 293
294 public: 294 public:
295 static PassOwnPtr<FormKeyGenerator> create() { return adoptPtr(new FormKeyGe nerator); } 295 static PassOwnPtr<FormKeyGenerator> create() { return adoptPtr(new FormKeyGe nerator); }
296 AtomicString formKey(const HTMLFormControlElementWithState&); 296 AtomicString formKey(Handle<const HTMLFormControlElementWithState>);
297 void willDeleteForm(HTMLFormElement*); 297 void willDeleteForm(HTMLFormElement*);
298 298
299 void clearWeakPointers(Visitor*); 299 void clearWeakPointers(Visitor*);
300 300
301 private: 301 private:
302 FormKeyGenerator() { } 302 FormKeyGenerator() { }
303 303
304 typedef HashMap<HTMLFormElement*, AtomicString> FormToKeyMap; 304 typedef HashMap<HTMLFormElement*, AtomicString> FormToKeyMap;
305 typedef HashMap<String, unsigned> FormSignatureToNextIndexMap; 305 typedef HashMap<String, unsigned> FormSignatureToNextIndexMap;
306 FormToKeyMap m_formToKeyMap; 306 FormToKeyMap m_formToKeyMap;
307 FormSignatureToNextIndexMap m_formSignatureToNextIndexMap; 307 FormSignatureToNextIndexMap m_formSignatureToNextIndexMap;
308 }; 308 };
309 309
310 static inline void recordFormStructure(const HTMLFormElement& form, StringBuilde r& builder) 310 static inline void recordFormStructure(const HTMLFormElement& form, StringBuilde r& builder)
311 { 311 {
312 // 2 is enough to distinguish forms in webkit.org/b/91209#c0 312 // 2 is enough to distinguish forms in webkit.org/b/91209#c0
313 const size_t namedControlsToBeRecorded = 2; 313 const size_t namedControlsToBeRecorded = 2;
314 const Vector<FormAssociatedElement*>& controls = form.associatedElements(); 314 const Vector<FormAssociatedElement*>& controls = form.associatedElements();
315 builder.append(" ["); 315 builder.append(" [");
316 for (size_t i = 0, namedControls = 0; i < controls.size() && namedControls < namedControlsToBeRecorded; ++i) { 316 for (size_t i = 0, namedControls = 0; i < controls.size() && namedControls < namedControlsToBeRecorded; ++i) {
317 if (!controls[i]->isFormControlElementWithState()) 317 if (!controls[i]->isFormControlElementWithState())
318 continue; 318 continue;
319 HTMLFormControlElementWithState* control = static_cast<HTMLFormControlEl ementWithState*>(controls[i]); 319 Handle<HTMLFormControlElementWithState> control(static_cast<HTMLFormCont rolElementWithState*>(controls[i]));
320 if (!ownerFormForState(*control)) 320 if (!ownerFormForState(control))
321 continue; 321 continue;
322 AtomicString name = control->name(); 322 AtomicString name = control->name();
323 if (name.isEmpty()) 323 if (name.isEmpty())
324 continue; 324 continue;
325 namedControls++; 325 namedControls++;
326 builder.append(name); 326 builder.append(name);
327 builder.append(" "); 327 builder.append(" ");
328 } 328 }
329 builder.append("]"); 329 builder.append("]");
330 } 330 }
331 331
332 static inline String formSignature(const HTMLFormElement& form) 332 static inline String formSignature(const HTMLFormElement& form)
333 { 333 {
334 KURL actionURL = form.getURLAttribute(actionAttr); 334 KURL actionURL = form.getURLAttribute(actionAttr);
335 // Remove the query part because it might contain volatile parameters such 335 // Remove the query part because it might contain volatile parameters such
336 // as a session key. 336 // as a session key.
337 actionURL.setQuery(String()); 337 actionURL.setQuery(String());
338 StringBuilder builder; 338 StringBuilder builder;
339 if (!actionURL.isEmpty()) 339 if (!actionURL.isEmpty())
340 builder.append(actionURL.string()); 340 builder.append(actionURL.string());
341 341
342 recordFormStructure(form, builder); 342 recordFormStructure(form, builder);
343 return builder.toString(); 343 return builder.toString();
344 } 344 }
345 345
346 AtomicString FormKeyGenerator::formKey(const HTMLFormControlElementWithState& co ntrol) 346 AtomicString FormKeyGenerator::formKey(Handle<const HTMLFormControlElementWithSt ate> control)
347 { 347 {
348 HTMLFormElement* form = ownerFormForState(control); 348 HTMLFormElement* form = ownerFormForState(control);
349 if (!form) { 349 if (!form) {
350 DEFINE_STATIC_LOCAL(AtomicString, formKeyForNoOwner, ("No owner", Atomic String::ConstructFromLiteral)); 350 DEFINE_STATIC_LOCAL(AtomicString, formKeyForNoOwner, ("No owner", Atomic String::ConstructFromLiteral));
351 return formKeyForNoOwner; 351 return formKeyForNoOwner;
352 } 352 }
353 FormToKeyMap::const_iterator it = m_formToKeyMap.find(form); 353 FormToKeyMap::const_iterator it = m_formToKeyMap.find(form);
354 if (it != m_formToKeyMap.end()) 354 if (it != m_formToKeyMap.end())
355 return it->value; 355 return it->value;
356 356
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // contain some characters which are rarely used for name attribute values. 395 // contain some characters which are rarely used for name attribute values.
396 DEFINE_STATIC_LOCAL(String, signature, (ASCIILiteral("\n\r?% WebKit serializ ed form state version 8 \n\r=&"))); 396 DEFINE_STATIC_LOCAL(String, signature, (ASCIILiteral("\n\r?% WebKit serializ ed form state version 8 \n\r=&")));
397 return signature; 397 return signature;
398 } 398 }
399 399
400 PassOwnPtr<FormController::SavedFormStateMap> FormController::createSavedFormSta teMap(const FormElementListHashSet& controlList) 400 PassOwnPtr<FormController::SavedFormStateMap> FormController::createSavedFormSta teMap(const FormElementListHashSet& controlList)
401 { 401 {
402 OwnPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create(); 402 OwnPtr<FormKeyGenerator> keyGenerator = FormKeyGenerator::create();
403 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap); 403 OwnPtr<SavedFormStateMap> stateMap = adoptPtr(new SavedFormStateMap);
404 for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) { 404 for (FormElementListHashSet::const_iterator it = controlList.begin(); it != controlList.end(); ++it) {
405 HTMLFormControlElementWithState* control = *it; 405 Handle<HTMLFormControlElementWithState> control = Handle<HTMLFormControl ElementWithState>(*it); // FIXME(oilpan): Remove Handle<>().
406 if (!control->shouldSaveAndRestoreFormControlState()) 406 if (!control->shouldSaveAndRestoreFormControlState())
407 continue; 407 continue;
408 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(*control).impl(), nullptr); 408 SavedFormStateMap::AddResult result = stateMap->add(keyGenerator->formKe y(control).impl(), nullptr);
409 if (result.isNewEntry) 409 if (result.isNewEntry)
410 result.iterator->value = SavedFormState::create(); 410 result.iterator->value = SavedFormState::create();
411 result.iterator->value->appendControlState(control->name(), control->typ e(), control->saveFormControlState()); 411 result.iterator->value->appendControlState(control->name(), control->typ e(), control->saveFormControlState());
412 } 412 }
413 return stateMap.release(); 413 return stateMap.release();
414 } 414 }
415 415
416 Vector<String> FormController::formElementsState() const 416 Vector<String> FormController::formElementsState() const
417 { 417 {
418 OwnPtr<SavedFormStateMap> stateMap = createSavedFormStateMap(m_formElementsW ithState); 418 OwnPtr<SavedFormStateMap> stateMap = createSavedFormStateMap(m_formElementsW ithState);
419 Vector<String> stateVector; 419 Vector<String> stateVector;
420 stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4); 420 stateVector.reserveInitialCapacity(m_formElementsWithState.size() * 4);
421 stateVector.append(formStateSignature()); 421 stateVector.append(formStateSignature());
422 for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMa p->end(); ++it) { 422 for (SavedFormStateMap::const_iterator it = stateMap->begin(); it != stateMa p->end(); ++it) {
423 stateVector.append(it->key.get()); 423 stateVector.append(it->key.get());
424 it->value->serializeTo(stateVector); 424 it->value->serializeTo(stateVector);
425 } 425 }
426 bool hasOnlySignature = stateVector.size() == 1; 426 bool hasOnlySignature = stateVector.size() == 1;
427 if (hasOnlySignature) 427 if (hasOnlySignature)
428 stateVector.clear(); 428 stateVector.clear();
429 return stateVector; 429 return stateVector;
430 } 430 }
431 431
432 void FormController::setStateForNewFormElements(const Vector<String>& stateVecto r) 432 void FormController::setStateForNewFormElements(const Vector<String>& stateVecto r)
433 { 433 {
434 formStatesFromStateVector(stateVector, m_savedFormStateMap); 434 formStatesFromStateVector(stateVector, m_savedFormStateMap);
435 } 435 }
436 436
437 FormControlState FormController::takeStateForFormElement(const HTMLFormControlEl ementWithState& control) 437 FormControlState FormController::takeStateForFormElement(Handle<const HTMLFormCo ntrolElementWithState> control)
438 { 438 {
439 if (m_savedFormStateMap.isEmpty()) 439 if (m_savedFormStateMap.isEmpty())
440 return FormControlState(); 440 return FormControlState();
441 if (!m_formKeyGenerator) 441 if (!m_formKeyGenerator)
442 m_formKeyGenerator = FormKeyGenerator::create(); 442 m_formKeyGenerator = FormKeyGenerator::create();
443 SavedFormStateMap::iterator it = m_savedFormStateMap.find(m_formKeyGenerator ->formKey(control).impl()); 443 SavedFormStateMap::iterator it = m_savedFormStateMap.find(m_formKeyGenerator ->formKey(control).impl());
444 if (it == m_savedFormStateMap.end()) 444 if (it == m_savedFormStateMap.end())
445 return FormControlState(); 445 return FormControlState();
446 FormControlState state = it->value->takeControlState(control.name(), control .type()); 446 FormControlState state = it->value->takeControlState(control->name(), contro l->type());
447 if (it->value->isEmpty()) 447 if (it->value->isEmpty())
448 m_savedFormStateMap.remove(it); 448 m_savedFormStateMap.remove(it);
449 return state; 449 return state;
450 } 450 }
451 451
452 void FormController::formStatesFromStateVector(const Vector<String>& stateVector , SavedFormStateMap& map) 452 void FormController::formStatesFromStateVector(const Vector<String>& stateVector , SavedFormStateMap& map)
453 { 453 {
454 map.clear(); 454 map.clear();
455 455
456 size_t i = 0; 456 size_t i = 0;
(...skipping 12 matching lines...) Expand all
469 if (i != stateVector.size()) 469 if (i != stateVector.size())
470 map.clear(); 470 map.clear();
471 } 471 }
472 472
473 void FormController::willDeleteForm(HTMLFormElement* form) 473 void FormController::willDeleteForm(HTMLFormElement* form)
474 { 474 {
475 if (m_formKeyGenerator) 475 if (m_formKeyGenerator)
476 m_formKeyGenerator->willDeleteForm(form); 476 m_formKeyGenerator->willDeleteForm(form);
477 } 477 }
478 478
479 void FormController::restoreControlStateFor(HTMLFormControlElementWithState& con trol) 479 void FormController::restoreControlStateFor(Handle<HTMLFormControlElementWithSta te> control)
480 { 480 {
481 // We don't save state of a control with shouldSaveAndRestoreFormControlStat e() 481 // We don't save state of a control with shouldSaveAndRestoreFormControlStat e()
482 // == false. But we need to skip restoring process too because a control in 482 // == false. But we need to skip restoring process too because a control in
483 // another form might have the same pair of name and type and saved its stat e. 483 // another form might have the same pair of name and type and saved its stat e.
484 if (!control.shouldSaveAndRestoreFormControlState()) 484 if (!control->shouldSaveAndRestoreFormControlState())
485 return; 485 return;
486 if (ownerFormForState(control)) 486 if (ownerFormForState(control))
487 return; 487 return;
488 FormControlState state = takeStateForFormElement(control); 488 FormControlState state = takeStateForFormElement(control);
489 if (state.valueSize() > 0) 489 if (state.valueSize() > 0)
490 control.restoreFormControlState(state); 490 control->restoreFormControlState(state);
491 } 491 }
492 492
493 void FormController::restoreControlStateIn(HTMLFormElement& form) 493 void FormController::restoreControlStateIn(HTMLFormElement& form)
494 { 494 {
495 const Vector<FormAssociatedElement*>& elements = form.associatedElements(); 495 const Vector<FormAssociatedElement*>& elements = form.associatedElements();
496 for (size_t i = 0; i < elements.size(); ++i) { 496 for (size_t i = 0; i < elements.size(); ++i) {
497 if (!elements[i]->isFormControlElementWithState()) 497 if (!elements[i]->isFormControlElementWithState())
498 continue; 498 continue;
499 HTMLFormControlElementWithState* control = static_cast<HTMLFormControlEl ementWithState*>(elements[i]); 499 Handle<HTMLFormControlElementWithState> control(static_cast<HTMLFormCont rolElementWithState*>(elements[i]));
500 if (!control->shouldSaveAndRestoreFormControlState()) 500 if (!control->shouldSaveAndRestoreFormControlState())
501 continue; 501 continue;
502 if (ownerFormForState(*control) != &form) 502 if (ownerFormForState(control) != &form)
503 continue; 503 continue;
504 FormControlState state = takeStateForFormElement(*control); 504 FormControlState state = takeStateForFormElement(control);
505 if (state.valueSize() > 0) 505 if (state.valueSize() > 0)
506 control->restoreFormControlState(state); 506 control->restoreFormControlState(state);
507 } 507 }
508 } 508 }
509 509
510 Vector<String> FormController::getReferencedFilePaths(const Vector<String>& stat eVector) 510 Vector<String> FormController::getReferencedFilePaths(const Vector<String>& stat eVector)
511 { 511 {
512 Vector<String> toReturn; 512 Vector<String> toReturn;
513 SavedFormStateMap map; 513 SavedFormStateMap map;
514 formStatesFromStateVector(stateVector, map); 514 formStatesFromStateVector(stateVector, map);
515 for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++ it) 515 for (SavedFormStateMap::const_iterator it = map.begin(); it != map.end(); ++ it)
516 toReturn.append(it->value->getReferencedFilePaths()); 516 toReturn.append(it->value->getReferencedFilePaths());
517 return toReturn; 517 return toReturn;
518 } 518 }
519 519
520 void FormController::clearWeakPointers(Visitor* visitor) 520 void FormController::clearWeakPointers(Visitor* visitor)
521 { 521 {
522 clearWeakSet(visitor, m_formElementsWithState); 522 clearWeakSet(visitor, m_formElementsWithState);
523 if (m_formKeyGenerator) 523 if (m_formKeyGenerator)
524 m_formKeyGenerator->clearWeakPointers(visitor); 524 m_formKeyGenerator->clearWeakPointers(visitor);
525 } 525 }
526 526
527 } // namespace WebCore 527 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/FormController.h ('k') | Source/core/html/HTMLAttributeNames.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698