зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1816740 [5/6] - convert nsIFilePicker::capture* to a proper enum r=ipc-reviewers,karlt,mstange,handyman,nika
Convert the various capture* constants in nsIFilePicker into a proper enum, and perform validation when passing it across IPC. Additionally, unlike the previous two enums, reduce the size of CaptureTarget to 8 bits. This is a workaround for its use with nsAttrValue, which at present very specifically requires that parseable enums' values fit within an `int16_t` -- and a `uint16_t` does not. Differential Revision: https://phabricator.services.mozilla.com/D169854
This commit is contained in:
Родитель
fa4832237d
Коммит
7b51dc72b7
|
@ -181,10 +181,10 @@ static const nsAttrValue::EnumTable* kInputDefaultType =
|
|||
&kInputTypeTable[ArrayLength(kInputTypeTable) - 2];
|
||||
|
||||
static const nsAttrValue::EnumTable kCaptureTable[] = {
|
||||
{"user", static_cast<int16_t>(nsIFilePicker::captureUser)},
|
||||
{"environment", static_cast<int16_t>(nsIFilePicker::captureEnv)},
|
||||
{"", static_cast<int16_t>(nsIFilePicker::captureDefault)},
|
||||
{nullptr, static_cast<int16_t>(nsIFilePicker::captureNone)}};
|
||||
{"user", nsIFilePicker::captureUser},
|
||||
{"environment", nsIFilePicker::captureEnv},
|
||||
{"", nsIFilePicker::captureDefault},
|
||||
{nullptr, nsIFilePicker::captureNone}};
|
||||
|
||||
static const nsAttrValue::EnumTable* kCaptureDefault = &kCaptureTable[2];
|
||||
|
||||
|
@ -831,7 +831,8 @@ nsresult HTMLInputElement::InitFilePicker(FilePickerType aType) {
|
|||
const nsAttrValue* captureVal =
|
||||
GetParsedAttr(nsGkAtoms::capture, kNameSpaceID_None);
|
||||
if (captureVal) {
|
||||
filePicker->SetCapture(captureVal->GetEnumValue());
|
||||
filePicker->SetCapture(static_cast<nsIFilePicker::CaptureTarget>(
|
||||
captureVal->GetEnumValue()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -17,6 +17,13 @@ struct ParamTraits<nsIFilePicker::Mode>
|
|||
nsIFilePicker::Mode, nsIFilePicker::Mode::modeOpen,
|
||||
nsIFilePicker::Mode::modeGetFolder> {};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<nsIFilePicker::CaptureTarget>
|
||||
: public ContiguousEnumSerializerInclusive<
|
||||
nsIFilePicker::CaptureTarget,
|
||||
nsIFilePicker::CaptureTarget::captureNone,
|
||||
nsIFilePicker::CaptureTarget::captureEnv> {};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<nsIFilePicker::ResultCode>
|
||||
: public ContiguousEnumSerializerInclusive<
|
||||
|
|
|
@ -242,7 +242,7 @@ mozilla::ipc::IPCResult FilePickerParent::RecvOpen(
|
|||
nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames,
|
||||
nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory,
|
||||
const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel,
|
||||
const int16_t& aCapture) {
|
||||
const nsIFilePicker::CaptureTarget& aCapture) {
|
||||
if (!CreateFilePicker()) {
|
||||
Unused << Send__delete__(this, void_t(), nsIFilePicker::returnCancel);
|
||||
return IPC_OK();
|
||||
|
|
|
@ -42,7 +42,7 @@ class FilePickerParent : public PFilePickerParent {
|
|||
nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames,
|
||||
nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory,
|
||||
const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel,
|
||||
const int16_t& aCapture);
|
||||
const nsIFilePicker::CaptureTarget& aCapture);
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ include IPCBlob;
|
|||
include "mozilla/dom/FilePickerMessageUtils.h";
|
||||
|
||||
using struct mozilla::void_t from "mozilla/ipc/IPCCore.h";
|
||||
using nsIFilePicker::CaptureTarget from "nsIFilePicker.h";
|
||||
using nsIFilePicker::ResultCode from "nsIFilePicker.h";
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -43,7 +44,7 @@ parent:
|
|||
nsString defaultExtension, nsString[] filters, nsString[] filterNames,
|
||||
nsString[] rawFilters, nsString displayDirectory,
|
||||
nsString displaySpecialDirectory, nsString okButtonLabel,
|
||||
int16_t capture);
|
||||
CaptureTarget capture);
|
||||
|
||||
child:
|
||||
async __delete__(MaybeInputData data, ResultCode result);
|
||||
|
|
|
@ -245,12 +245,16 @@ NS_IMETHODIMP nsBaseFilePicker::AppendRawFilter(const nsAString& aFilter) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBaseFilePicker::GetCapture(int16_t* aCapture) {
|
||||
*aCapture = 0;
|
||||
NS_IMETHODIMP nsBaseFilePicker::GetCapture(
|
||||
nsIFilePicker::CaptureTarget* aCapture) {
|
||||
*aCapture = nsIFilePicker::CaptureTarget::captureNone;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBaseFilePicker::SetCapture(int16_t aCapture) { return NS_OK; }
|
||||
NS_IMETHODIMP nsBaseFilePicker::SetCapture(
|
||||
nsIFilePicker::CaptureTarget aCapture) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Set the filter index
|
||||
NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(int32_t* aFilterIndex) {
|
||||
|
|
|
@ -31,8 +31,8 @@ class nsBaseFilePicker : public nsIFilePicker {
|
|||
NS_IMETHOD Open(nsIFilePickerShownCallback* aCallback) override;
|
||||
NS_IMETHOD AppendFilters(int32_t filterMask) override;
|
||||
NS_IMETHOD AppendRawFilter(const nsAString& aFilter) override;
|
||||
NS_IMETHOD GetCapture(int16_t* aCapture) override;
|
||||
NS_IMETHOD SetCapture(int16_t aCapture) override;
|
||||
NS_IMETHOD GetCapture(nsIFilePicker::CaptureTarget* aCapture) override;
|
||||
NS_IMETHOD SetCapture(nsIFilePicker::CaptureTarget aCapture) override;
|
||||
NS_IMETHOD GetFilterIndex(int32_t* aFilterIndex) override;
|
||||
NS_IMETHOD SetFilterIndex(int32_t aFilterIndex) override;
|
||||
NS_IMETHOD GetFiles(nsISimpleEnumerator** aFiles) override;
|
||||
|
|
|
@ -54,13 +54,13 @@ nsFilePickerProxy::AppendFilter(const nsAString& aTitle,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePickerProxy::GetCapture(int16_t* aCapture) {
|
||||
nsFilePickerProxy::GetCapture(nsIFilePicker::CaptureTarget* aCapture) {
|
||||
*aCapture = mCapture;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePickerProxy::SetCapture(int16_t aCapture) {
|
||||
nsFilePickerProxy::SetCapture(nsIFilePicker::CaptureTarget aCapture) {
|
||||
mCapture = aCapture;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ class nsFilePickerProxy : public nsBaseFilePicker,
|
|||
nsIFilePicker::Mode aMode) override;
|
||||
NS_IMETHOD AppendFilter(const nsAString& aTitle,
|
||||
const nsAString& aFilter) override;
|
||||
NS_IMETHOD GetCapture(int16_t* aCapture) override;
|
||||
NS_IMETHOD SetCapture(int16_t aCapture) override;
|
||||
NS_IMETHOD GetCapture(nsIFilePicker::CaptureTarget* aCapture) override;
|
||||
NS_IMETHOD SetCapture(nsIFilePicker::CaptureTarget aCapture) override;
|
||||
NS_IMETHOD GetDefaultString(nsAString& aDefaultString) override;
|
||||
NS_IMETHOD SetDefaultString(const nsAString& aDefaultString) override;
|
||||
NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension) override;
|
||||
|
@ -74,7 +74,7 @@ class nsFilePickerProxy : public nsBaseFilePicker,
|
|||
nsString mFile;
|
||||
nsString mDefault;
|
||||
nsString mDefaultExtension;
|
||||
int16_t mCapture;
|
||||
nsIFilePicker::CaptureTarget mCapture;
|
||||
|
||||
bool mIPCActive;
|
||||
|
||||
|
|
|
@ -53,10 +53,12 @@ interface nsIFilePicker : nsISupports
|
|||
// *.rm; *.rmvb; *.smil; *.webm;
|
||||
// *.wmv; *.xvid
|
||||
|
||||
const short captureNone = 0; // No capture target specified.
|
||||
const short captureDefault = 1; // Missing/invalid value default.
|
||||
const short captureUser = 2; // "user" capture target specified.
|
||||
const short captureEnv = 3; // "environment" capture target specified.
|
||||
cenum CaptureTarget: 8 {
|
||||
captureNone = 0, // No capture target specified.
|
||||
captureDefault = 1, // Missing/invalid value default.
|
||||
captureUser = 2, // "user" capture target specified.
|
||||
captureEnv = 3, // "environment" capture target specified.
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the file picker widget. The file picker is not valid until this
|
||||
|
@ -206,7 +208,12 @@ interface nsIFilePicker : nsISupports
|
|||
*/
|
||||
attribute AString okButtonLabel;
|
||||
|
||||
attribute short capture;
|
||||
/**
|
||||
* Implementation of HTMLInputElement's `capture` property.
|
||||
*
|
||||
* Not used by Firefox Desktop.
|
||||
*/
|
||||
attribute nsIFilePicker_CaptureTarget capture;
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(0d79adad-b244-49A5-9997-2a8cad93fc44)]
|
||||
|
|
Загрузка…
Ссылка в новой задаче