| 1 | /* |
| 2 | * Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "RadioButtonGroups.h" |
| 25 | #include <wtf/Forward.h> |
| 26 | #include <wtf/ListHashSet.h> |
| 27 | #include <wtf/Vector.h> |
| 28 | #include <wtf/text/WTFString.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class FormKeyGenerator; |
| 33 | class HTMLFormControlElementWithState; |
| 34 | class HTMLFormElement; |
| 35 | class SavedFormState; |
| 36 | |
| 37 | using FormControlState = Vector<String>; |
| 38 | |
| 39 | class FormController { |
| 40 | WTF_MAKE_FAST_ALLOCATED; |
| 41 | public: |
| 42 | FormController(); |
| 43 | ~FormController(); |
| 44 | |
| 45 | RadioButtonGroups& radioButtonGroups() { return m_radioButtonGroups; } |
| 46 | |
| 47 | void registerFormElementWithState(HTMLFormControlElementWithState&); |
| 48 | void unregisterFormElementWithState(HTMLFormControlElementWithState&); |
| 49 | |
| 50 | unsigned formElementsCharacterCount() const; |
| 51 | |
| 52 | Vector<String> formElementsState() const; |
| 53 | void setStateForNewFormElements(const Vector<String>&); |
| 54 | |
| 55 | void willDeleteForm(HTMLFormElement&); |
| 56 | void restoreControlStateFor(HTMLFormControlElementWithState&); |
| 57 | void restoreControlStateIn(HTMLFormElement&); |
| 58 | bool hasFormStateToRestore() const; |
| 59 | |
| 60 | WEBCORE_EXPORT static Vector<String> referencedFilePaths(const Vector<String>& stateVector); |
| 61 | |
| 62 | private: |
| 63 | typedef ListHashSet<RefPtr<HTMLFormControlElementWithState>> FormElementListHashSet; |
| 64 | typedef HashMap<RefPtr<AtomicStringImpl>, std::unique_ptr<SavedFormState>> SavedFormStateMap; |
| 65 | |
| 66 | static std::unique_ptr<SavedFormStateMap> createSavedFormStateMap(const FormElementListHashSet&); |
| 67 | FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&); |
| 68 | static void formStatesFromStateVector(const Vector<String>&, SavedFormStateMap&); |
| 69 | |
| 70 | RadioButtonGroups m_radioButtonGroups; |
| 71 | FormElementListHashSet m_formElementsWithState; |
| 72 | SavedFormStateMap m_savedFormStateMap; |
| 73 | std::unique_ptr<FormKeyGenerator> m_formKeyGenerator; |
| 74 | }; |
| 75 | |
| 76 | } // namespace WebCore |
| 77 | |