diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs index 4b34381cbd4c..602986e52930 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -3332,16 +3332,8 @@ var SessionStoreInternal = { }, getClosedTabDataForWindow: function ssi_getClosedTabDataForWindow(aWindow) { - // We need to enable wrapping reflectors in order to allow the cloning of - // objects containing FormDatas, which could be stored by - // form-associated custom elements. - let options = { wrapReflectors: true }; if ("__SSi" in aWindow) { - return Cu.cloneInto( - this._windows[aWindow.__SSi]._closedTabs, - {}, - options - ); + return Cu.cloneInto(this._windows[aWindow.__SSi]._closedTabs, {}); } if (!DyingWindowCache.has(aWindow)) { @@ -3352,7 +3344,7 @@ var SessionStoreInternal = { } let data = DyingWindowCache.get(aWindow); - return Cu.cloneInto(data._closedTabs, {}, options); + return Cu.cloneInto(data._closedTabs, {}); }, undoCloseTab: function ssi_undoCloseTab(aWindow, aIndex) { @@ -6194,13 +6186,6 @@ var SessionStoreInternal = { ); break; } - if ( - value.hasOwnProperty("value") && - value.hasOwnProperty("state") - ) { - root.addCustomElement(isXpath, key, value.value, value.state); - break; - } if ( key === "sessionData" && ["about:sessionrestore", "about:welcomeback"].includes( diff --git a/browser/components/sessionstore/test/browser.ini b/browser/components/sessionstore/test/browser.ini index 2ffacb9f1fa6..85e0c4044843 100644 --- a/browser/components/sessionstore/test/browser.ini +++ b/browser/components/sessionstore/test/browser.ini @@ -269,7 +269,6 @@ https_first_disabled = true skip-if = verify && debug [browser_formdata_cc.js] -[browser_formdata_face.js] [browser_formdata_format.js] skip-if = !debug && (os == "linux") # Bug 1535645 [browser_formdata_max_size.js] diff --git a/browser/components/sessionstore/test/browser_formdata_face.js b/browser/components/sessionstore/test/browser_formdata_face.js deleted file mode 100644 index 5c383388714e..000000000000 --- a/browser/components/sessionstore/test/browser_formdata_face.js +++ /dev/null @@ -1,168 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -/** - * This test ensures that collecting form data for form-associated custom - * elements works as expected. - */ -add_task(async function test_face_restore() { - const URL = `data:text/html;charset=utf-8, -

mozilla

- -
- - - - - - -
`; - - // Load a tab with a FACE. - let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, URL)); - let browser = tab.linkedBrowser; - await promiseBrowserLoaded(browser); - - // Set the FACE state and value. - await SpecialPowers.spawn(browser, ["c-e"], selector => { - function formDataWith(...entries) { - const formData = new content.FormData(); - for (let [key, value] of entries) { - formData.append(key, value); - } - return formData; - } - const states = [ - "test state", - new content.File(["state"], "state.txt"), - formDataWith(["1", "state"], ["2", new content.Blob(["state_blob"])]), - null, - undefined, - null, - ]; - const values = [ - "test value", - new content.File(["value"], "value.txt"), - formDataWith(["1", "value"], ["2", new content.Blob(["value_blob"])]), - "null state", - "both value and state", - null, - ]; - - [...content.document.querySelectorAll(selector)].forEach((node, i) => { - node.internals.setFormValue(values[i], states[i]); - }); - }); - - // Close and restore the tab. - await promiseRemoveTabAndSessionState(tab); - - { - let [ - { - state: { formdata }, - }, - ] = ss.getClosedTabDataForWindow(window); - - is(formdata.id.test1.value, "test value", "String value should be stored"); - is(formdata.id.test1.state, "test state", "String state should be stored"); - - let storedFile = formdata.id.test2.value; - is(storedFile.name, "value.txt", "File value name should be stored"); - is(await storedFile.text(), "value", "File value text should be stored"); - storedFile = formdata.id.test2.state; - is(storedFile.name, "state.txt", "File state name should be stored"); - is(await storedFile.text(), "state", "File state text should be stored"); - - let storedFormData = formdata.id.test3.value; - is( - storedFormData.get("1"), - "value", - "FormData value string should be stored" - ); - is( - await storedFormData.get("2").text(), - "value_blob", - "Form value blob should be stored" - ); - storedFormData = formdata.id.test3.state; - is( - storedFormData.get("1"), - "state", - "FormData state string should be stored" - ); - is( - await storedFormData.get("2").text(), - "state_blob", - "Form state blob should be stored" - ); - - is(formdata.id.test4.state, null, "Null state stored"); - is(formdata.id.test4.value, "null state", "Value with null state stored"); - - is( - formdata.id.test5.value, - "both value and state", - "Undefined state should be set to value" - ); - is( - formdata.id.test5.state, - "both value and state", - "Undefined state should be set to value" - ); - - ok( - !("test6" in formdata.id), - "Completely null values should not be stored" - ); - } - - tab = ss.undoCloseTab(window, 0); - browser = tab.linkedBrowser; - await promiseTabRestored(tab); - - // Check that the FACE state was restored. - await SpecialPowers.spawn(browser, ["restoredStates"], async prop => { - let restoredStates = content.wrappedJSObject[prop]; - is(restoredStates.test1, "test state", "String should be stored"); - - let storedFile = restoredStates.test2; - is(storedFile.name, "state.txt", "File name should be stored"); - is(await storedFile.text(), "state", "File text should be stored"); - - const storedFormData = restoredStates.test3; - is(storedFormData.get("1"), "state", "Form data string should be stored"); - is( - await storedFormData.get("2").text(), - "state_blob", - "Form data blob should be stored" - ); - - ok(!("test4" in restoredStates), "Null values don't get restored"); - - is( - restoredStates.test5, - "both value and state", - "Undefined state should be set to value" - ); - }); - - // Cleanup. - gBrowser.removeTab(tab); -}); diff --git a/dom/base/FormData.cpp b/dom/base/FormData.cpp index 50986f6f9c38..33be8f2232a1 100644 --- a/dom/base/FormData.cpp +++ b/dom/base/FormData.cpp @@ -6,7 +6,6 @@ #include "FormData.h" #include "nsIInputStream.h" -#include "mozilla/dom/CustomElementTypes.h" #include "mozilla/dom/File.h" #include "mozilla/dom/Directory.h" #include "mozilla/dom/HTMLFormElement.h" @@ -389,21 +388,3 @@ nsresult FormData::CopySubmissionDataTo( return NS_OK; } - -CustomElementFormValue FormData::ConvertToCustomElementFormValue() { - nsTArray formValue; - ForEach([&formValue](const nsString& aName, - const OwningBlobOrDirectoryOrUSVString& aValue) -> bool { - if (aValue.IsBlob()) { - FormDataValue value(WrapNotNull(aValue.GetAsBlob()->Impl())); - formValue.AppendElement(mozilla::dom::FormDataTuple(aName, value)); - } else if (aValue.IsUSVString()) { - formValue.AppendElement( - mozilla::dom::FormDataTuple(aName, aValue.GetAsUSVString())); - } else { - MOZ_ASSERT_UNREACHABLE("Can't save FormData entry Directory value!"); - } - return true; - }); - return formValue; -} diff --git a/dom/base/FormData.h b/dom/base/FormData.h index 59c275d66ce7..9078c7782b30 100644 --- a/dom/base/FormData.h +++ b/dom/base/FormData.h @@ -21,7 +21,6 @@ class ErrorResult; namespace dom { -class CustomElementFormValue; class HTMLFormElement; class GlobalObject; @@ -128,17 +127,18 @@ class FormData final : public nsISupports, virtual nsresult AddNameDirectoryPair(const nsAString& aName, Directory* aDirectory) override; + using FormDataEntryCallback = + bool (*)(const nsString& aName, + const OwningBlobOrDirectoryOrUSVString& aValue, void* aClosure); + uint32_t Length() const { return mFormData.Length(); } // Stops iteration and returns false if any invocation of callback returns // false. Returns true otherwise. - // Accepts callbacks of the form `bool(const nsString&, const - // OwningBlobOrDirectoryOrUSVString&)`. - template - bool ForEach(F&& aCallback) { + bool ForEach(FormDataEntryCallback aFunc, void* aClosure) { for (uint32_t i = 0; i < mFormData.Length(); ++i) { FormDataTuple& tuple = mFormData[i]; - if (!aCallback(tuple.name, tuple.value)) { + if (!aFunc(tuple.name, tuple.value, aClosure)) { return false; } } @@ -154,8 +154,6 @@ class FormData final : public nsISupports, Element* GetSubmitterElement() const { return mSubmitter.get(); } - CustomElementFormValue ConvertToCustomElementFormValue(); - private: nsCOMPtr mOwner; diff --git a/dom/base/StructuredCloneHolder.cpp b/dom/base/StructuredCloneHolder.cpp index 558cee20917b..6a0e127698f4 100644 --- a/dom/base/StructuredCloneHolder.cpp +++ b/dom/base/StructuredCloneHolder.cpp @@ -896,36 +896,52 @@ bool WriteFormData(JSStructuredCloneWriter* aWriter, FormData* aFormData, return false; } - auto write = [aWriter, aHolder]( - const nsString& aName, - const OwningBlobOrDirectoryOrUSVString& aValue) { - if (!StructuredCloneHolder::WriteString(aWriter, aName)) { - return false; - } + class MOZ_STACK_CLASS Closure final { + JSStructuredCloneWriter* mWriter; + StructuredCloneHolder* mHolder; - if (aValue.IsBlob()) { - if (!JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB, - aHolder->BlobImpls().Length())) { + public: + Closure(JSStructuredCloneWriter* aWriter, StructuredCloneHolder* aHolder) + : mWriter(aWriter), mHolder(aHolder) {} + + static bool Write(const nsString& aName, + const OwningBlobOrDirectoryOrUSVString& aValue, + void* aClosure) { + Closure* closure = static_cast(aClosure); + if (!StructuredCloneHolder::WriteString(closure->mWriter, aName)) { return false; } - RefPtr blobImpl = aValue.GetAsBlob()->Impl(); + if (aValue.IsBlob()) { + if (!JS_WriteUint32Pair(closure->mWriter, SCTAG_DOM_BLOB, + closure->mHolder->BlobImpls().Length())) { + return false; + } + + RefPtr blobImpl = aValue.GetAsBlob()->Impl(); + + closure->mHolder->BlobImpls().AppendElement(blobImpl); + return true; + } + + if (aValue.IsDirectory()) { + Directory* directory = aValue.GetAsDirectory(); + return WriteDirectory(closure->mWriter, directory); + } + + size_t charSize = sizeof(nsString::char_type); + if (!JS_WriteUint32Pair(closure->mWriter, 0, + aValue.GetAsUSVString().Length()) || + !JS_WriteBytes(closure->mWriter, aValue.GetAsUSVString().get(), + aValue.GetAsUSVString().Length() * charSize)) { + return false; + } - aHolder->BlobImpls().AppendElement(blobImpl); return true; } - - if (aValue.IsDirectory()) { - Directory* directory = aValue.GetAsDirectory(); - return WriteDirectory(aWriter, directory); - } - - const size_t charSize = sizeof(nsString::char_type); - return JS_WriteUint32Pair(aWriter, 0, aValue.GetAsUSVString().Length()) && - JS_WriteBytes(aWriter, aValue.GetAsUSVString().get(), - aValue.GetAsUSVString().Length() * charSize); }; - return aFormData->ForEach(write); + Closure closure(aWriter, aHolder); + return aFormData->ForEach(Closure::Write, &closure); } JSObject* ReadWasmModule(JSContext* aCx, uint32_t aIndex, diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 8a2405f600ec..993ab6248066 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -150,7 +150,6 @@ #include "mozilla/dom/ContentParent.h" #include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/CustomElementRegistryBinding.h" -#include "mozilla/dom/CustomElementTypes.h" #include "mozilla/dom/DOMArena.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMExceptionBinding.h" @@ -169,10 +168,8 @@ #include "mozilla/dom/FileBlobImpl.h" #include "mozilla/dom/FileSystemSecurity.h" #include "mozilla/dom/FilteredNodeIterator.h" -#include "mozilla/dom/FormData.h" #include "mozilla/dom/FragmentOrElement.h" #include "mozilla/dom/FromParser.h" -#include "mozilla/dom/HTMLElement.h" #include "mozilla/dom/HTMLFormElement.h" #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLTextAreaElement.h" @@ -9924,78 +9921,6 @@ void nsContentUtils::EnqueueLifecycleCallback( aDefinition); } -/* static */ -CustomElementFormValue nsContentUtils::ConvertToCustomElementFormValue( - const Nullable& aState) { - if (aState.IsNull()) { - return void_t{}; - } - const auto& state = aState.Value(); - if (state.IsFile()) { - RefPtr impl = state.GetAsFile()->Impl(); - return {std::move(impl)}; - } - if (state.IsUSVString()) { - return state.GetAsUSVString(); - } - return state.GetAsFormData()->ConvertToCustomElementFormValue(); -} - -/* static */ -Nullable -nsContentUtils::ExtractFormAssociatedCustomElementValue( - nsIGlobalObject* aGlobal, - const mozilla::dom::CustomElementFormValue& aCEValue) { - MOZ_ASSERT(aGlobal); - - OwningFileOrUSVStringOrFormData value; - switch (aCEValue.type()) { - case CustomElementFormValue::TBlobImpl: { - RefPtr file = File::Create(aGlobal, aCEValue.get_BlobImpl()); - if (NS_WARN_IF(!file)) { - return {}; - } - value.SetAsFile() = file; - } break; - - case CustomElementFormValue::TnsString: - value.SetAsUSVString() = aCEValue.get_nsString(); - break; - - case CustomElementFormValue::TArrayOfFormDataTuple: { - const auto& array = aCEValue.get_ArrayOfFormDataTuple(); - auto formData = MakeRefPtr(); - - for (auto i = 0ul; i < array.Length(); ++i) { - const auto& item = array.ElementAt(i); - switch (item.value().type()) { - case FormDataValue::TnsString: - formData->AddNameValuePair(item.name(), - item.value().get_nsString()); - break; - - case FormDataValue::TBlobImpl: { - auto blobImpl = item.value().get_BlobImpl(); - auto* blob = Blob::Create(aGlobal, blobImpl); - formData->AddNameBlobPair(item.name(), blob); - } break; - - default: - continue; - } - } - - value.SetAsFormData() = formData; - } break; - case CustomElementFormValue::Tvoid_t: - return {}; - default: - NS_WARNING("Invalid CustomElementContentData type!"); - return {}; - } - return value; -} - /* static */ void nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo( Document* aDocument, nsTArray& aElements) { diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 1d3b5fc0b7bb..124daf9f427a 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -174,7 +174,6 @@ class ContentChild; class ContentFrameMessageManager; class ContentParent; struct CustomElementDefinition; -class CustomElementFormValue; class CustomElementRegistry; class DataTransfer; class Document; @@ -183,7 +182,6 @@ class DOMArena; class Element; class Event; class EventTarget; -class HTMLElement; class HTMLInputElement; class IPCTransferable; class IPCTransferableData; @@ -192,7 +190,6 @@ class IPCTransferableDataItem; struct LifecycleCallbackArgs; class MessageBroadcaster; class NodeInfo; -class OwningFileOrUSVStringOrFormData; class Selection; struct StructuredSerializeOptions; class WorkerPrivate; @@ -3052,15 +3049,6 @@ class nsContentUtils { const mozilla::dom::LifecycleCallbackArgs& aArgs, mozilla::dom::CustomElementDefinition* aDefinition = nullptr); - static mozilla::dom::CustomElementFormValue ConvertToCustomElementFormValue( - const mozilla::dom::Nullable< - mozilla::dom::OwningFileOrUSVStringOrFormData>& aState); - - static mozilla::dom::Nullable - ExtractFormAssociatedCustomElementValue( - nsIGlobalObject* aGlobal, - const mozilla::dom::CustomElementFormValue& aCEValue); - /** * Appends all "document level" native anonymous content subtree roots for * aDocument to aElements. Document level NAC subtrees are those created diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h index 151f6ec56197..63cbeed34031 100644 --- a/dom/base/nsIContent.h +++ b/dom/base/nsIContent.h @@ -455,20 +455,14 @@ class nsIContent : public nsINode { */ static inline bool RequiresDoneCreatingElement(int32_t aNamespace, nsAtom* aName) { - if (aNamespace == kNameSpaceID_XHTML) { - if (aName == nsGkAtoms::input || aName == nsGkAtoms::button || - aName == nsGkAtoms::audio || aName == nsGkAtoms::video) { - MOZ_ASSERT(!RequiresDoneAddingChildren(aNamespace, aName), - "Both DoneCreatingElement and DoneAddingChildren on a " - "same element isn't supported."); - return true; - } - if (aName->IsDynamic()) { - // This could be a form-associated custom element, so check if its - // name includes a -. - nsDependentString name(aName->GetUTF16String()); - return name.Contains('-'); - } + if (aNamespace == kNameSpaceID_XHTML && + (aName == nsGkAtoms::input || aName == nsGkAtoms::button || + aName == nsGkAtoms::audio || aName == nsGkAtoms::video)) { + MOZ_ASSERT( + !RequiresDoneAddingChildren(aNamespace, aName), + "Both DoneCreatingElement and DoneAddingChildren on a same element " + "isn't supported."); + return true; } return false; } diff --git a/dom/chrome-webidl/SessionStoreUtils.webidl b/dom/chrome-webidl/SessionStoreUtils.webidl index 5aa477dcc419..9032c784c4b6 100644 --- a/dom/chrome-webidl/SessionStoreUtils.webidl +++ b/dom/chrome-webidl/SessionStoreUtils.webidl @@ -144,15 +144,7 @@ dictionary CollectedNonMultipleSelectValue required DOMString value; }; -[GenerateConversionToJS, GenerateInit] -dictionary CollectedCustomElementValue -{ - (File or USVString or FormData)? value = null; - (File or USVString or FormData)? state = null; -}; - // object contains either a CollectedFileListValue or a CollectedNonMultipleSelectValue or Sequence -// or a CollectedCustomElementValue typedef (DOMString or boolean or object) CollectedFormDataValue; dictionary CollectedData diff --git a/dom/html/ElementInternals.cpp b/dom/html/ElementInternals.cpp index 9d64e0550351..62101f2922de 100644 --- a/dom/html/ElementInternals.cpp +++ b/dom/html/ElementInternals.cpp @@ -49,8 +49,7 @@ ElementInternals::ElementInternals(HTMLElement* aTarget) : nsIFormControl(FormControlType::FormAssociatedCustomElement), mTarget(aTarget), mForm(nullptr), - mFieldSet(nullptr), - mControlNumber(-1) {} + mFieldSet(nullptr) {} nsISupports* ElementInternals::GetParentObject() { return ToSupports(mTarget); } @@ -458,26 +457,4 @@ DocGroup* ElementInternals::GetDocGroup() { return mTarget->OwnerDoc()->GetDocGroup(); } -void ElementInternals::RestoreFormValue( - Nullable&& aValue, - Nullable&& aState) { - mSubmissionValue = aValue; - mState = aState; - - if (!mState.IsNull()) { - nsContentUtils::EnqueueLifecycleCallback( - ElementCallbackType::eFormStateRestore, mTarget, - { - .mState = mState, - .mReason = RestoreReason::Restore, - }); - } -} - -void ElementInternals::InitializeControlNumber() { - MOZ_ASSERT(mControlNumber == -1, - "FACE control number should only be initialized once!"); - mControlNumber = mTarget->OwnerDoc()->GetNextControlNumber(); -} - } // namespace mozilla::dom diff --git a/dom/html/ElementInternals.h b/dom/html/ElementInternals.h index 9e5aac9702e1..191437c29562 100644 --- a/dom/html/ElementInternals.h +++ b/dom/html/ElementInternals.h @@ -82,33 +82,11 @@ class ElementInternals final : public nsIFormControl, NS_IMETHOD Reset() override; NS_IMETHOD SubmitNamesValues(mozilla::dom::FormData* aFormData) override; bool AllowDrop() override { return true; } - int32_t GetParserInsertedControlNumberForStateKey() const override { - return mControlNumber; - } void SetFieldSet(mozilla::dom::HTMLFieldSetElement* aFieldSet) { mFieldSet = aFieldSet; } - const Nullable& GetFormSubmissionValue() - const { - return mSubmissionValue; - } - - const Nullable& GetFormState() const { - return mState; - } - - void RestoreFormValue(Nullable&& aValue, - Nullable&& aState); - - const nsCString& GetStateKey() const { return mStateKey; } - void SetStateKey(nsCString&& key) { - MOZ_ASSERT(mStateKey.IsEmpty(), "FACE state key should only be set once!"); - mStateKey = key; - } - void InitializeControlNumber(); - void UpdateFormOwner(); void UpdateBarredFromConstraintValidation(); @@ -188,8 +166,8 @@ class ElementInternals final : public nsIFormControl, Nullable mSubmissionValue; // https://html.spec.whatwg.org/#face-state - // TODO: Bug 1734841 - Figure out how to support autocomplete for - // form-associated custom element. + // TODO: Bug 1734841 - Figure out how to support form restoration or + // autocomplete for form-associated custom element Nullable mState; // https://html.spec.whatwg.org/#face-validation-message @@ -199,15 +177,6 @@ class ElementInternals final : public nsIFormControl, RefPtr mValidationAnchor; AttrArray mAttrs; - - // Used to store the key to a form-associated custom element in the current - // session. Is empty until element has been upgraded. - nsCString mStateKey; - - // A number for a form-associated custom element that is unique within its - // owner document. This is only set to a number for elements inserted into the - // document by the parser from the network. Otherwise, it is -1. - int32_t mControlNumber; }; } // namespace mozilla::dom diff --git a/dom/html/HTMLElement.cpp b/dom/html/HTMLElement.cpp index 19e941ad6fe0..b033ceee71ec 100644 --- a/dom/html/HTMLElement.cpp +++ b/dom/html/HTMLElement.cpp @@ -6,27 +6,18 @@ #include "mozilla/dom/HTMLElement.h" -#include "mozilla/EventDispatcher.h" -#include "mozilla/PresState.h" #include "mozilla/dom/CustomElementRegistry.h" -#include "mozilla/dom/ElementInternalsBinding.h" -#include "mozilla/dom/FormData.h" #include "mozilla/dom/HTMLElementBinding.h" +#include "mozilla/EventDispatcher.h" #include "nsContentUtils.h" -#include "nsGenericHTMLElement.h" -#include "nsILayoutHistoryState.h" namespace mozilla::dom { -HTMLElement::HTMLElement(already_AddRefed&& aNodeInfo, - FromParser aFromParser) +HTMLElement::HTMLElement(already_AddRefed&& aNodeInfo) : nsGenericHTMLFormElement(std::move(aNodeInfo)) { if (NodeInfo()->Equals(nsGkAtoms::bdi)) { AddStatesSilently(ElementState::HAS_DIR_ATTR_LIKE_AUTO); } - if (aFromParser & FROM_PARSER_NETWORK) { - SetFlags(HTML_ELEMENT_FROM_PARSER_NETWORK); - } } NS_IMPL_CYCLE_COLLECTION_INHERITED(HTMLElement, nsGenericHTMLFormElement) @@ -82,89 +73,6 @@ void HTMLElement::UnbindFromTree(bool aNullParent) { UpdateBarredFromConstraintValidation(); } -void HTMLElement::DoneCreatingElement() { - if (MOZ_UNLIKELY(IsFormAssociatedElement())) { - MaybeRestoreFormAssociatedCustomElementState(); - } -} - -void HTMLElement::SaveState() { - if (MOZ_LIKELY(!IsFormAssociatedElement())) { - return; - } - - auto* internals = GetElementInternals(); - - nsCString stateKey = internals->GetStateKey(); - if (stateKey.IsEmpty()) { - return; - } - - nsCOMPtr history = GetLayoutHistory(false); - if (!history) { - return; - } - - // Get the pres state for this key, if it doesn't exist, create one. - PresState* result = history->GetState(stateKey); - if (!result) { - UniquePtr newState = NewPresState(); - result = newState.get(); - history->AddState(stateKey, std::move(newState)); - } - - const auto& state = internals->GetFormState(); - const auto& value = internals->GetFormSubmissionValue(); - result->contentData() = CustomElementTuple( - nsContentUtils::ConvertToCustomElementFormValue(value), - nsContentUtils::ConvertToCustomElementFormValue(state)); -} - -void HTMLElement::MaybeRestoreFormAssociatedCustomElementState() { - MOZ_ASSERT(IsFormAssociatedElement()); - - auto* internals = GetElementInternals(); - if (internals->GetStateKey().IsEmpty()) { - Document* doc = GetUncomposedDoc(); - nsCString stateKey; - nsContentUtils::GenerateStateKey(this, doc, stateKey); - internals->SetStateKey(std::move(stateKey)); - - RestoreFormAssociatedCustomElementState(); - } -} - -void HTMLElement::RestoreFormAssociatedCustomElementState() { - MOZ_ASSERT(IsFormAssociatedElement()); - - auto* internals = GetElementInternals(); - - const nsCString& stateKey = internals->GetStateKey(); - if (stateKey.IsEmpty()) { - return; - } - nsCOMPtr history = GetLayoutHistory(true); - if (!history) { - return; - } - PresState* result = history->GetState(stateKey); - if (!result) { - return; - } - auto& content = result->contentData(); - if (content.type() != PresContentData::TCustomElementTuple) { - return; - } - - auto& ce = content.get_CustomElementTuple(); - nsCOMPtr global = GetOwnerDocument()->GetOwnerGlobal(); - internals->RestoreFormValue( - nsContentUtils::ExtractFormAssociatedCustomElementValue(global, - ce.value()), - nsContentUtils::ExtractFormAssociatedCustomElementValue(global, - ce.state())); -} - void HTMLElement::SetCustomElementDefinition( CustomElementDefinition* aDefinition) { nsGenericHTMLFormElement::SetCustomElementDefinition(aDefinition); @@ -176,15 +84,13 @@ void HTMLElement::SetCustomElementDefinition( aDefinition->mFormAssociated) { CustomElementData* data = GetCustomElementData(); MOZ_ASSERT(data); - auto* internals = data->GetOrCreateElementInternals(this); + data->GetOrCreateElementInternals(this); // This is for the case that script constructs a custom element directly, // e.g. via new MyCustomElement(), where the upgrade steps won't be ran to // update the disabled state in UpdateFormOwner(). if (data->mState == CustomElementData::State::eCustom) { UpdateDisabledState(true); - } else if (HasFlag(HTML_ELEMENT_FROM_PARSER_NETWORK)) { - internals->InitializeControlNumber(); } } } @@ -292,8 +198,6 @@ void HTMLElement::UpdateFormOwner() { UpdateFieldSet(true); UpdateDisabledState(true); UpdateBarredFromConstraintValidation(); - - MaybeRestoreFormAssociatedCustomElementState(); } bool HTMLElement::IsDisabledForEvents(WidgetEvent* aEvent) { @@ -434,7 +338,7 @@ nsGenericHTMLElement* NS_NewHTMLElement( mozilla::dom::FromParser aFromParser) { RefPtr nodeInfo(aNodeInfo); auto* nim = nodeInfo->NodeInfoManager(); - return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget(), aFromParser); + return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget()); } // Distinct from the above in order to have function pointer that compared @@ -444,5 +348,5 @@ nsGenericHTMLElement* NS_NewCustomElement( mozilla::dom::FromParser aFromParser) { RefPtr nodeInfo(aNodeInfo); auto* nim = nodeInfo->NodeInfoManager(); - return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget(), aFromParser); + return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget()); } diff --git a/dom/html/HTMLElement.h b/dom/html/HTMLElement.h index a59d3a6ca594..6943d46b6d38 100644 --- a/dom/html/HTMLElement.h +++ b/dom/html/HTMLElement.h @@ -13,8 +13,7 @@ namespace mozilla::dom { class HTMLElement final : public nsGenericHTMLFormElement { public: - explicit HTMLElement(already_AddRefed&& aNodeInfo, - FromParser aFromParser = NOT_FROM_PARSER); + explicit HTMLElement(already_AddRefed&& aNodeInfo); // nsISupports NS_DECL_ISUPPORTS_INHERITED @@ -31,7 +30,6 @@ class HTMLElement final : public nsGenericHTMLFormElement { // nsIContent nsresult BindToTree(BindContext&, nsINode& aParent) override; void UnbindFromTree(bool aNullParent = true) override; - void DoneCreatingElement() override; // Element void SetCustomElementDefinition( @@ -48,12 +46,9 @@ class HTMLElement final : public nsGenericHTMLFormElement { bool IsFormAssociatedElement() const override; void AfterClearForm(bool aUnbindOrDelete) override; void FieldSetDisabledChanged(bool aNotify) override; - void SaveState() override; void UpdateFormOwner(); - void MaybeRestoreFormAssociatedCustomElementState(); - protected: virtual ~HTMLElement() = default; @@ -80,9 +75,6 @@ class HTMLElement final : public nsGenericHTMLFormElement { void UpdateBarredFromConstraintValidation(); ElementInternals* GetElementInternals() const; - - MOZ_CAN_RUN_SCRIPT_BOUNDARY - void RestoreFormAssociatedCustomElementState(); }; } // namespace mozilla::dom diff --git a/dom/html/nsGenericHTMLElement.cpp b/dom/html/nsGenericHTMLElement.cpp index 1bc269b26a8a..8a7f14541dad 100644 --- a/dom/html/nsGenericHTMLElement.cpp +++ b/dom/html/nsGenericHTMLElement.cpp @@ -1833,9 +1833,6 @@ nsresult nsGenericHTMLFormElement::BindToTree(BindContext& aContext, } void nsGenericHTMLFormElement::UnbindFromTree(bool aNullParent) { - // Save state before doing anything else. - SaveState(); - if (IsFormAssociatedElement()) { if (HTMLFormElement* form = GetFormInternal()) { // Might need to unset form @@ -2243,12 +2240,6 @@ void nsGenericHTMLFormElement::FieldSetDisabledChanged(bool aNotify) { UpdateDisabledState(aNotify); } -void nsGenericHTMLFormElement::SaveSubtreeState() { - SaveState(); - - nsGenericHTMLElement::SaveSubtreeState(); -} - //---------------------------------------------------------------------- void nsGenericHTMLElement::Click(CallerType aCallerType) { @@ -2582,6 +2573,12 @@ nsINode* nsGenericHTMLFormControlElement::GetScopeChainParent() const { return mForm ? mForm : nsGenericHTMLElement::GetScopeChainParent(); } +void nsGenericHTMLFormControlElement::SaveSubtreeState() { + SaveState(); + + nsGenericHTMLFormElement::SaveSubtreeState(); +} + nsIContent::IMEState nsGenericHTMLFormControlElement::GetDesiredIMEState() { TextEditor* textEditor = GetTextEditorInternal(); if (!textEditor) { @@ -2595,6 +2592,12 @@ nsIContent::IMEState nsGenericHTMLFormControlElement::GetDesiredIMEState() { return state; } +void nsGenericHTMLFormControlElement::UnbindFromTree(bool aNullParent) { + // Save state before doing anything + SaveState(); + nsGenericHTMLFormElement::UnbindFromTree(aNullParent); +} + void nsGenericHTMLFormControlElement::GetAutocapitalize( nsAString& aValue) const { if (nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None, @@ -2959,7 +2962,7 @@ PresState* nsGenericHTMLFormControlElementWithState::GetPrimaryPresState() { } already_AddRefed -nsGenericHTMLFormElement::GetLayoutHistory(bool aRead) { +nsGenericHTMLFormControlElementWithState::GetLayoutHistory(bool aRead) { nsCOMPtr doc = GetUncomposedDoc(); if (!doc) { return nullptr; diff --git a/dom/html/nsGenericHTMLElement.h b/dom/html/nsGenericHTMLElement.h index 50314acc1602..43f944c4fac9 100644 --- a/dom/html/nsGenericHTMLElement.h +++ b/dom/html/nsGenericHTMLElement.h @@ -980,11 +980,10 @@ class HTMLFieldSetElement; enum { // Used to handle keyboard activation. HTML_ELEMENT_ACTIVE_FOR_KEYBOARD = HTML_ELEMENT_FLAG_BIT(0), - HTML_ELEMENT_FROM_PARSER_NETWORK = HTML_ELEMENT_FLAG_BIT(1), // Remaining bits are type specific. HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET = - ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 2, + ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 1, }; ASSERT_NODE_FLAGS_SPACE(HTML_ELEMENT_TYPE_SPECIFIC_BITS_OFFSET); @@ -1028,7 +1027,6 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement { already_AddRefed&& aNodeInfo); // nsIContent - void SaveSubtreeState() override; nsresult BindToTree(BindContext&, nsINode& aParent) override; void UnbindFromTree(bool aNullParent = true) override; @@ -1056,15 +1054,6 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement { void ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete); - /** - * Get the layout history object for a particular piece of content. - * - * @param aRead if true, won't return a layout history state if the - * layout history state is empty. - * @return the history state object - */ - already_AddRefed GetLayoutHistory(bool aRead); - protected: virtual ~nsGenericHTMLFormElement() = default; @@ -1158,13 +1147,6 @@ class nsGenericHTMLFormElement : public nsGenericHTMLElement { * See https://html.spec.whatwg.org/#form-associated-element. */ virtual bool IsFormAssociatedElement() const { return false; } - - /** - * Save to presentation state. The form element will determine whether it - * has anything to save and if so, create an entry in the layout history for - * its pres context. - */ - virtual void SaveState() {} }; class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement, @@ -1183,7 +1165,9 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement, bool IsHTMLFormControlElement() const final { return true; } // nsIContent + void SaveSubtreeState() override; IMEState GetDesiredIMEState() override; + void UnbindFromTree(bool aNullParent = true) override; // nsGenericHTMLElement // autocapitalize attribute support @@ -1227,6 +1211,13 @@ class nsGenericHTMLFormControlElement : public nsGenericHTMLFormElement, bool IsAutocapitalizeInheriting() const; + /** + * Save to presentation state. The form control will determine whether it + * has anything to save and if so, create an entry in the layout history for + * its pres context. + */ + virtual void SaveState() {} + nsresult SubmitDirnameDir(mozilla::dom::FormData* aFormData); /** The form that contains this control */ @@ -1280,6 +1271,15 @@ class nsGenericHTMLFormControlElementWithState */ mozilla::PresState* GetPrimaryPresState(); + /** + * Get the layout history object for a particular piece of content. + * + * @param aRead if true, won't return a layout history state if the + * layout history state is empty. + * @return the history state object + */ + already_AddRefed GetLayoutHistory(bool aRead); + /** * Called when we have been cloned and adopted, and the information of the * node has been changed. diff --git a/dom/html/test/forms/mochitest.ini b/dom/html/test/forms/mochitest.ini index 2d84628b5f49..ab67dc60911d 100644 --- a/dom/html/test/forms/mochitest.ini +++ b/dom/html/test/forms/mochitest.ini @@ -101,8 +101,6 @@ skip-if = os == "android" [test_radio_radionodelist.html] [test_required_attribute.html] [test_restore_form_elements.html] -[test_save_restore_custom_elements.html] -support-files = save_restore_custom_elements_sample.html [test_save_restore_radio_groups.html] [test_select_change_event.html] skip-if = os == 'mac' diff --git a/dom/html/test/forms/save_restore_custom_elements_sample.html b/dom/html/test/forms/save_restore_custom_elements_sample.html deleted file mode 100644 index 75dc4c388d1b..000000000000 --- a/dom/html/test/forms/save_restore_custom_elements_sample.html +++ /dev/null @@ -1,43 +0,0 @@ - -
- - - - - - - - - - -
- diff --git a/dom/html/test/forms/test_save_restore_custom_elements.html b/dom/html/test/forms/test_save_restore_custom_elements.html deleted file mode 100644 index 489ad0ca2f56..000000000000 --- a/dom/html/test/forms/test_save_restore_custom_elements.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - Test for Bug 1556358 - - - - - - Mozilla Bug 1556358 -

-
- -
- - - - diff --git a/dom/ipc/CustomElementTypes.ipdlh b/dom/ipc/CustomElementTypes.ipdlh deleted file mode 100644 index bdbf004ca995..000000000000 --- a/dom/ipc/CustomElementTypes.ipdlh +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */ -/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -include "mozilla/dom/IPCBlobUtils.h"; - -[RefCounted] using class mozilla::dom::BlobImpl from "mozilla/dom/BlobImpl.h"; -using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; - -namespace mozilla { -namespace dom { - -// Types used to store form-associated custom element state. -union FormDataValue { - BlobImpl; - nsString; -}; - -struct FormDataTuple { - nsString name; - FormDataValue value; -}; - -union CustomElementFormValue { - void_t; - nullable BlobImpl; - nsString; - FormDataTuple[]; -}; - -struct CustomElementTuple { - CustomElementFormValue value; - CustomElementFormValue state; -}; - -} // namespace dom -} // namespace mozilla diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 332461be3eca..79f8bbc6d8fd 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -167,7 +167,6 @@ PREPROCESSED_IPDL_SOURCES += [ ] IPDL_SOURCES += [ - "CustomElementTypes.ipdlh", "DOMTypes.ipdlh", "IPCTransferable.ipdlh", "MemoryReportTypes.ipdlh", diff --git a/layout/base/PresState.ipdlh b/layout/base/PresState.ipdlh index b04d7ed5f09c..18ef85e88afc 100644 --- a/layout/base/PresState.ipdlh +++ b/layout/base/PresState.ipdlh @@ -11,8 +11,6 @@ using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; using struct nsPoint from "nsPoint.h"; [RefCounted] using class mozilla::dom::BlobImpl from "mozilla/dom/BlobImpl.h"; -include CustomElementTypes; - namespace mozilla { struct SelectContentData { @@ -42,7 +40,6 @@ union PresContentData { // We can need to serialize blobs in order to transmit this type, so we need // to handle that in a custom handler. FileContentData[]; - CustomElementTuple; }; struct PresState { diff --git a/toolkit/components/sessionstore/SessionStoreRestoreData.cpp b/toolkit/components/sessionstore/SessionStoreRestoreData.cpp index fbb96e1b87ec..c7a92cf8ada9 100644 --- a/toolkit/components/sessionstore/SessionStoreRestoreData.cpp +++ b/toolkit/components/sessionstore/SessionStoreRestoreData.cpp @@ -5,10 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/BrowsingContext.h" -#include "mozilla/dom/CustomElementTypes.h" #include "mozilla/dom/Document.h" -#include "mozilla/dom/File.h" -#include "mozilla/dom/FormData.h" #include "mozilla/dom/SessionStoreUtils.h" #include "mozilla/dom/sessionstore/SessionStoreTypes.h" #include "mozilla/dom/WindowContext.h" @@ -173,27 +170,6 @@ SessionStoreRestoreData::AddMultipleSelect(bool aIsXPath, return NS_OK; } -NS_IMETHODIMP -SessionStoreRestoreData::AddCustomElement(bool aIsXPath, - const nsAString& aIdOrXPath, - JS::Handle aValue, - JS::Handle aState) { - AutoJSContext cx; - Nullable value; - if (!aValue.isNull() && !value.SetValue().Init(cx, aValue)) { - return NS_ERROR_FAILURE; - } - Nullable state; - if (!aState.isNull() && !state.SetValue().Init(cx, aState)) { - return NS_ERROR_FAILURE; - } - AddFormEntry(aIsXPath, aIdOrXPath, - CustomElementTuple( - nsContentUtils::ConvertToCustomElementFormValue(value), - nsContentUtils::ConvertToCustomElementFormValue(state))); - return NS_OK; -} - NS_IMETHODIMP SessionStoreRestoreData::AddChild(nsISessionStoreRestoreData* aChild, uint32_t aIndex) { diff --git a/toolkit/components/sessionstore/SessionStoreTypes.ipdlh b/toolkit/components/sessionstore/SessionStoreTypes.ipdlh index 331005b11ab0..c375fa0b3638 100644 --- a/toolkit/components/sessionstore/SessionStoreTypes.ipdlh +++ b/toolkit/components/sessionstore/SessionStoreTypes.ipdlh @@ -7,7 +7,6 @@ using struct CollectedInputDataValue from "mozilla/dom/SessionStoreMessageUtils.h"; using struct nsPoint from "nsPoint.h"; -include CustomElementTypes; include DOMTypes; namespace mozilla { @@ -41,7 +40,6 @@ union FormEntryValue { FileList; SingleSelect; MultipleSelect; - CustomElementTuple; }; struct FormEntry { diff --git a/toolkit/components/sessionstore/SessionStoreUtils.cpp b/toolkit/components/sessionstore/SessionStoreUtils.cpp index 43fd9ed2af57..010c71bb6847 100644 --- a/toolkit/components/sessionstore/SessionStoreUtils.cpp +++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp @@ -6,22 +6,15 @@ #include "js/Array.h" // JS::GetArrayLength, JS::IsArrayObject #include "js/JSON.h" -#include "js/Object.h" #include "js/PropertyAndElement.h" // JS_GetElement #include "js/TypeDecls.h" #include "jsapi.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/ErrorResult.h" #include "mozilla/PresShell.h" #include "mozilla/dom/AutocompleteInfoBinding.h" #include "mozilla/dom/CanonicalBrowsingContext.h" -#include "mozilla/dom/CustomElementTypes.h" -#include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/DocumentInlines.h" -#include "mozilla/dom/FormData.h" -#include "mozilla/dom/FragmentOrElement.h" -#include "mozilla/dom/HTMLElement.h" #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLSelectElement.h" #include "mozilla/dom/HTMLTextAreaElement.h" @@ -31,10 +24,6 @@ #include "mozilla/dom/SessionStoreChangeListener.h" #include "mozilla/dom/SessionStoreChild.h" #include "mozilla/dom/SessionStoreUtils.h" -#include "mozilla/dom/SessionStoreUtilsBinding.h" -#include "mozilla/dom/ToJSValue.h" -#include "mozilla/dom/UnionTypes.h" -#include "mozilla/dom/sessionstore/SessionStoreTypes.h" #include "mozilla/dom/txIXPathContext.h" #include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowProxyHolder.h" @@ -504,27 +493,6 @@ static void AppendValueToCollectedData(nsINode* aNode, const nsAString& aId, entry->mValue.SetAsObject() = &jsval.toObject(); } -/* For form-associated custom element state */ -static void AppendValueToCollectedData( - nsINode* aNode, const nsAString& aId, - const Nullable& aValue, - const Nullable& aState, - uint16_t& aGeneratedCount, JSContext* aCx, - Nullable& aRetVal) { - Record::EntryType* entry = - AppendEntryToCollectedData(aNode, aId, aGeneratedCount, aRetVal); - - CollectedCustomElementValue val; - val.mValue = aValue; - val.mState = aState; - JS::Rooted jsval(aCx); - if (!ToJSValue(aCx, val, &jsval)) { - JS_ClearPendingException(aCx); - return; - } - entry->mValue.SetAsObject() = &jsval.toObject(); -} - // This isn't size as in binary size, just a heuristic to not store too large // fields in session store. See StaticPrefs::browser_sessionstore_dom_form_limit static uint32_t SizeOfFormEntry(const FormEntryValue& aValue) { @@ -551,43 +519,6 @@ static uint32_t SizeOfFormEntry(const FormEntryValue& aValue) { } break; } - case FormEntryValue::TCustomElementTuple: { - auto customElementTupleSize = - [](const CustomElementFormValue& value) -> uint32_t { - switch (value.type()) { - case CustomElementFormValue::TBlobImpl: - return value.get_BlobImpl()->GetAllocationSize(); - case CustomElementFormValue::TnsString: - return value.get_nsString().Length(); - case CustomElementFormValue::TArrayOfFormDataTuple: { - uint32_t formDataSize = 0; - for (const auto& entry : value.get_ArrayOfFormDataTuple()) { - formDataSize += entry.name().Length(); - const auto& entryValue = entry.value(); - switch (entryValue.type()) { - case FormDataValue::TBlobImpl: - formDataSize += - entryValue.get_BlobImpl()->GetAllocationSize(); - break; - case FormDataValue::TnsString: - formDataSize += entryValue.get_nsString().Length(); - break; - default: - break; - } - } - return formDataSize; - } - default: - return 0; - } - }; - - auto ceTuple = aValue.get_CustomElementTuple(); - size += customElementTupleSize(ceTuple.value()); - size += customElementTupleSize(ceTuple.state()); - break; - } default: break; } @@ -809,51 +740,6 @@ static uint32_t CollectSelectElement(Document* aDocument, return size; } -static already_AddRefed GetFormAssociatedCustomElements( - nsINode* aRootNode) { - MOZ_ASSERT(aRootNode, "Content list has to have a root"); - - auto matchFunc = [](Element* aElement, int32_t aNamespace, nsAtom* aAtom, - void* aData) -> bool { - return aElement->HasCustomElementData() && - aElement->GetCustomElementData()->IsFormAssociated(); - }; - RefPtr list = - new nsContentList(aRootNode, matchFunc, nullptr, nullptr); - return list.forget(); -} - -static uint32_t CollectFormAssociatedCustomElement( - Document* aDocument, sessionstore::FormData& aFormData) { - uint32_t size = 0; - RefPtr faceList = GetFormAssociatedCustomElements(aDocument); - uint32_t length = faceList->Length(); - for (uint32_t i = 0; i < length; ++i) { - MOZ_ASSERT(faceList->Item(i), "null item in node list!"); - RefPtr element = Element::FromNode(faceList->Item(i)); - - nsAutoString id; - element->GetId(id); - if (id.IsEmpty() && (aFormData.xpath().Length() > kMaxTraversedXPaths)) { - continue; - } - - const auto* internals = - element->GetCustomElementData()->GetElementInternals(); - auto formState = internals->GetFormState(); - auto formValue = internals->GetFormSubmissionValue(); - if (formState.IsNull() && formValue.IsNull()) { - continue; - } - - CustomElementTuple entry; - entry.value() = nsContentUtils::ConvertToCustomElementFormValue(formValue); - entry.state() = nsContentUtils::ConvertToCustomElementFormValue(formState); - size += AppendEntry(element, id, entry, aFormData); - } - return size; -} - /* static */ uint32_t SessionStoreUtils::CollectFormData(Document* aDocument, sessionstore::FormData& aFormData) { @@ -862,7 +748,6 @@ uint32_t SessionStoreUtils::CollectFormData(Document* aDocument, size += CollectTextAreaElement(aDocument, aFormData); size += CollectInputElement(aDocument, aFormData); size += CollectSelectElement(aDocument, aFormData); - size += CollectFormAssociatedCustomElement(aDocument, aFormData); aFormData.hasData() = !aFormData.id().IsEmpty() || !aFormData.xpath().IsEmpty(); @@ -1051,34 +936,6 @@ void SessionStoreUtils::CollectFromSelectElement(Document& aDocument, } } -/* static */ -template -void SessionStoreUtils::CollectFromFormAssociatedCustomElement( - Document& aDocument, uint16_t& aGeneratedCount, ArgsT&&... args) { - RefPtr faceList = GetFormAssociatedCustomElements(&aDocument); - uint32_t length = faceList->Length(true); - for (uint32_t i = 0; i < length; ++i) { - MOZ_ASSERT(faceList->Item(i), "null item in node list!"); - RefPtr element = Element::FromNode(faceList->Item(i)); - - nsAutoString id; - element->GetId(id); - if (id.IsEmpty() && (aGeneratedCount > kMaxTraversedXPaths)) { - continue; - } - - auto* internals = element->GetCustomElementData()->GetElementInternals(); - const auto& state = internals->GetFormState(); - const auto& value = internals->GetFormSubmissionValue(); - if (state.IsNull() && value.IsNull()) { - continue; - } - - AppendValueToCollectedData(element, id, value, state, aGeneratedCount, - std::forward(args)...); - } -} - static void CollectCurrentFormData(JSContext* aCx, Document& aDocument, Nullable& aRetVal) { uint16_t generatedCount = 0; @@ -1091,9 +948,6 @@ static void CollectCurrentFormData(JSContext* aCx, Document& aDocument, /* select element */ SessionStoreUtils::CollectFromSelectElement(aDocument, generatedCount, aCx, aRetVal); - /* form-associated custom element */ - SessionStoreUtils::CollectFromFormAssociatedCustomElement( - aDocument, generatedCount, aCx, aRetVal); Element* bodyElement = aDocument.GetBody(); if (bodyElement && bodyElement->IsInDesignMode()) { @@ -1269,25 +1123,6 @@ static void SetElementAsObject(JSContext* aCx, Element* aElement, } SetElementAsMultiSelect(select, array); } - - // For Form-Associated Custom Element: - if (!aObject.isObject()) { - // Don't restore null values. - return; - } - - auto* data = aElement->GetCustomElementData(); - if (!data || !data->IsFormAssociated()) { - return; - } - auto* internals = data->GetElementInternals(); - - CollectedCustomElementValue value; - if (!value.Init(aCx, aObject)) { - JS_ClearPendingException(aCx); - return; - } - internals->RestoreFormValue(std::move(value.mValue), std::move(value.mState)); } MOZ_CAN_RUN_SCRIPT @@ -1472,20 +1307,6 @@ void RestoreFormEntry(Element* aNode, const FormEntryValue& aValue) { } break; } - case Type::TCustomElementTuple: { - const auto* data = aNode->GetCustomElementData(); - if (!data || !data->IsFormAssociated()) { - return; - } - auto* internals = data->GetElementInternals(); - nsCOMPtr global = aNode->GetOwnerGlobal(); - internals->RestoreFormValue( - nsContentUtils::ExtractFormAssociatedCustomElementValue( - global, aValue.get_CustomElementTuple().value()), - nsContentUtils::ExtractFormAssociatedCustomElementValue( - global, aValue.get_CustomElementTuple().state())); - break; - } default: MOZ_ASSERT_UNREACHABLE(); } @@ -1832,36 +1653,6 @@ nsresult SessionStoreUtils::ConstructFormDataValues( entry->mValue.SetAsObject() = &jsval.toObject(); break; } - case Type::TCustomElementTuple: { - nsCOMPtr global; - JS::Rooted globalObject(aCx, JS::CurrentGlobalOrNull(aCx)); - if (NS_WARN_IF(!globalObject)) { - break; - } - global = xpc::NativeGlobal(globalObject); - if (NS_WARN_IF(!global)) { - break; - } - - auto formState = - nsContentUtils::ExtractFormAssociatedCustomElementValue( - global, value.value().get_CustomElementTuple().state()); - auto formValue = - nsContentUtils::ExtractFormAssociatedCustomElementValue( - global, value.value().get_CustomElementTuple().value()); - MOZ_ASSERT(!formValue.IsNull() || !formState.IsNull(), - "Shouldn't be storing null values!"); - - CollectedCustomElementValue val; - val.mValue = formValue; - val.mState = formState; - JS::Rooted jsval(aCx); - if (!ToJSValue(aCx, val, &jsval)) { - return NS_ERROR_FAILURE; - } - entry->mValue.SetAsObject() = &jsval.toObject(); - break; - } default: break; } diff --git a/toolkit/components/sessionstore/SessionStoreUtils.h b/toolkit/components/sessionstore/SessionStoreUtils.h index e3028b0f29a4..27922f1b516d 100644 --- a/toolkit/components/sessionstore/SessionStoreUtils.h +++ b/toolkit/components/sessionstore/SessionStoreUtils.h @@ -94,10 +94,6 @@ class SessionStoreUtils { static void CollectFromSelectElement(Document& aDocument, uint16_t& aGeneratedCount, ArgsT&&... args); - template - static void CollectFromFormAssociatedCustomElement(Document& aDocument, - uint16_t& aGeneratedCount, - ArgsT&&... args); static void CollectFormData(const GlobalObject& aGlobal, WindowProxyHolder& aWindow, diff --git a/toolkit/components/sessionstore/nsISessionStoreRestoreData.idl b/toolkit/components/sessionstore/nsISessionStoreRestoreData.idl index eff070ef6a3e..8e8dc8b6364b 100644 --- a/toolkit/components/sessionstore/nsISessionStoreRestoreData.idl +++ b/toolkit/components/sessionstore/nsISessionStoreRestoreData.idl @@ -27,8 +27,6 @@ interface nsISessionStoreRestoreData : nsISupports { in unsigned long aSelectedIndex, in AString aValue); void addMultipleSelect(in boolean aIsXPath, in AString aIdOrXPath, in Array aValues); - void addCustomElement(in boolean aIsXPath, in AString aIdOrXPath, - in jsval aValue, in jsval aState); // Add a child data object to our children list. void addChild(in nsISessionStoreRestoreData aChild, in unsigned long aIndex);