Issue #2532 - Implement form[method=dialog]

See bug 1557303
This commit is contained in:
Moonchild 2024-06-15 10:11:00 +02:00 committed by roytam1
commit 6ee3f46900
11 changed files with 162 additions and 2 deletions

View file

@ -7,6 +7,7 @@
#define mozilla_dom_HTMLFormSubmission_h
#include "mozilla/Attributes.h"
#include "mozilla/dom/HTMLDialogElement.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
#include "nsNCRFallbackEncoderWrapper.h"
@ -121,6 +122,8 @@ public:
return mOriginatingElement.get();
}
virtual DialogFormSubmission* GetAsDialogSubmission() { return nullptr; }
protected:
/**
* Can only be constructed by subclasses.
@ -168,6 +171,50 @@ private:
nsNCRFallbackEncoderWrapper mEncoder;
};
class DialogFormSubmission final : public HTMLFormSubmission {
public:
DialogFormSubmission(nsAString& aResult,
const nsACString& aCharset, Element* aSubmitter,
HTMLDialogElement* aDialogElement)
: HTMLFormSubmission(aCharset, aSubmitter)
, mDialogElement(aDialogElement)
, mReturnValue(aResult) {
}
nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue) override {
MOZ_CRASH("This method should not be called");
return NS_OK;
}
nsresult AddNameBlobOrNullPair(const nsAString& aName, Blob* aBlob) override {
MOZ_CRASH("This method should not be called");
return NS_OK;
}
nsresult AddNameDirectoryPair(const nsAString& aName,
Directory* aDirectory) override {
MOZ_CRASH("This method should not be called");
return NS_OK;
}
nsresult GetEncodedSubmission(nsIURI* aURI, nsIInputStream** aPostDataStream) override {
MOZ_CRASH("This method should not be called");
return NS_OK;
}
DialogFormSubmission* GetAsDialogSubmission() override { return this; }
HTMLDialogElement* DialogElement() { return mDialogElement; }
nsString& ReturnValue() { return mReturnValue; }
private:
const RefPtr<HTMLDialogElement> mDialogElement;
nsString mReturnValue;
};
/**
* Handle multipart/form-data encoding, which does files as well as normal
* inputs. This always does POST.