forked from mirrors/gecko-dev
		
	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:
		
							parent
							
								
									fa4832237d
								
							
						
					
					
						commit
						7b51dc72b7
					
				
					 10 changed files with 43 additions and 23 deletions
				
			
		|  | @ -181,10 +181,10 @@ static const nsAttrValue::EnumTable* kInputDefaultType = | ||||||
|     &kInputTypeTable[ArrayLength(kInputTypeTable) - 2]; |     &kInputTypeTable[ArrayLength(kInputTypeTable) - 2]; | ||||||
| 
 | 
 | ||||||
| static const nsAttrValue::EnumTable kCaptureTable[] = { | static const nsAttrValue::EnumTable kCaptureTable[] = { | ||||||
|     {"user", static_cast<int16_t>(nsIFilePicker::captureUser)}, |     {"user", nsIFilePicker::captureUser}, | ||||||
|     {"environment", static_cast<int16_t>(nsIFilePicker::captureEnv)}, |     {"environment", nsIFilePicker::captureEnv}, | ||||||
|     {"", static_cast<int16_t>(nsIFilePicker::captureDefault)}, |     {"", nsIFilePicker::captureDefault}, | ||||||
|     {nullptr, static_cast<int16_t>(nsIFilePicker::captureNone)}}; |     {nullptr, nsIFilePicker::captureNone}}; | ||||||
| 
 | 
 | ||||||
| static const nsAttrValue::EnumTable* kCaptureDefault = &kCaptureTable[2]; | static const nsAttrValue::EnumTable* kCaptureDefault = &kCaptureTable[2]; | ||||||
| 
 | 
 | ||||||
|  | @ -831,7 +831,8 @@ nsresult HTMLInputElement::InitFilePicker(FilePickerType aType) { | ||||||
|       const nsAttrValue* captureVal = |       const nsAttrValue* captureVal = | ||||||
|           GetParsedAttr(nsGkAtoms::capture, kNameSpaceID_None); |           GetParsedAttr(nsGkAtoms::capture, kNameSpaceID_None); | ||||||
|       if (captureVal) { |       if (captureVal) { | ||||||
|         filePicker->SetCapture(captureVal->GetEnumValue()); |         filePicker->SetCapture(static_cast<nsIFilePicker::CaptureTarget>( | ||||||
|  |             captureVal->GetEnumValue())); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } else { |   } else { | ||||||
|  |  | ||||||
|  | @ -17,6 +17,13 @@ struct ParamTraits<nsIFilePicker::Mode> | ||||||
|           nsIFilePicker::Mode, nsIFilePicker::Mode::modeOpen, |           nsIFilePicker::Mode, nsIFilePicker::Mode::modeOpen, | ||||||
|           nsIFilePicker::Mode::modeGetFolder> {}; |           nsIFilePicker::Mode::modeGetFolder> {}; | ||||||
| 
 | 
 | ||||||
|  | template <> | ||||||
|  | struct ParamTraits<nsIFilePicker::CaptureTarget> | ||||||
|  |     : public ContiguousEnumSerializerInclusive< | ||||||
|  |           nsIFilePicker::CaptureTarget, | ||||||
|  |           nsIFilePicker::CaptureTarget::captureNone, | ||||||
|  |           nsIFilePicker::CaptureTarget::captureEnv> {}; | ||||||
|  | 
 | ||||||
| template <> | template <> | ||||||
| struct ParamTraits<nsIFilePicker::ResultCode> | struct ParamTraits<nsIFilePicker::ResultCode> | ||||||
|     : public ContiguousEnumSerializerInclusive< |     : public ContiguousEnumSerializerInclusive< | ||||||
|  |  | ||||||
|  | @ -242,7 +242,7 @@ mozilla::ipc::IPCResult FilePickerParent::RecvOpen( | ||||||
|     nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames, |     nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames, | ||||||
|     nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory, |     nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory, | ||||||
|     const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel, |     const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel, | ||||||
|     const int16_t& aCapture) { |     const nsIFilePicker::CaptureTarget& aCapture) { | ||||||
|   if (!CreateFilePicker()) { |   if (!CreateFilePicker()) { | ||||||
|     Unused << Send__delete__(this, void_t(), nsIFilePicker::returnCancel); |     Unused << Send__delete__(this, void_t(), nsIFilePicker::returnCancel); | ||||||
|     return IPC_OK(); |     return IPC_OK(); | ||||||
|  |  | ||||||
|  | @ -42,7 +42,7 @@ class FilePickerParent : public PFilePickerParent { | ||||||
|       nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames, |       nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames, | ||||||
|       nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory, |       nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory, | ||||||
|       const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel, |       const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel, | ||||||
|       const int16_t& aCapture); |       const nsIFilePicker::CaptureTarget& aCapture); | ||||||
| 
 | 
 | ||||||
|   virtual void ActorDestroy(ActorDestroyReason aWhy) override; |   virtual void ActorDestroy(ActorDestroyReason aWhy) override; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ include IPCBlob; | ||||||
| include "mozilla/dom/FilePickerMessageUtils.h"; | include "mozilla/dom/FilePickerMessageUtils.h"; | ||||||
| 
 | 
 | ||||||
| using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; | using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; | ||||||
|  | using nsIFilePicker::CaptureTarget from "nsIFilePicker.h"; | ||||||
| using nsIFilePicker::ResultCode from "nsIFilePicker.h"; | using nsIFilePicker::ResultCode from "nsIFilePicker.h"; | ||||||
| 
 | 
 | ||||||
| namespace mozilla { | namespace mozilla { | ||||||
|  | @ -43,7 +44,7 @@ parent: | ||||||
|                nsString defaultExtension, nsString[] filters, nsString[] filterNames, |                nsString defaultExtension, nsString[] filters, nsString[] filterNames, | ||||||
|                nsString[] rawFilters, nsString displayDirectory, |                nsString[] rawFilters, nsString displayDirectory, | ||||||
|                nsString displaySpecialDirectory, nsString okButtonLabel, |                nsString displaySpecialDirectory, nsString okButtonLabel, | ||||||
|                int16_t capture); |                CaptureTarget capture); | ||||||
| 
 | 
 | ||||||
| child: | child: | ||||||
|     async __delete__(MaybeInputData data, ResultCode result); |     async __delete__(MaybeInputData data, ResultCode result); | ||||||
|  |  | ||||||
|  | @ -245,12 +245,16 @@ NS_IMETHODIMP nsBaseFilePicker::AppendRawFilter(const nsAString& aFilter) { | ||||||
|   return NS_OK; |   return NS_OK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NS_IMETHODIMP nsBaseFilePicker::GetCapture(int16_t* aCapture) { | NS_IMETHODIMP nsBaseFilePicker::GetCapture( | ||||||
|   *aCapture = 0; |     nsIFilePicker::CaptureTarget* aCapture) { | ||||||
|  |   *aCapture = nsIFilePicker::CaptureTarget::captureNone; | ||||||
|   return NS_OK; |   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
 | // Set the filter index
 | ||||||
| NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(int32_t* aFilterIndex) { | NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(int32_t* aFilterIndex) { | ||||||
|  |  | ||||||
|  | @ -31,8 +31,8 @@ class nsBaseFilePicker : public nsIFilePicker { | ||||||
|   NS_IMETHOD Open(nsIFilePickerShownCallback* aCallback) override; |   NS_IMETHOD Open(nsIFilePickerShownCallback* aCallback) override; | ||||||
|   NS_IMETHOD AppendFilters(int32_t filterMask) override; |   NS_IMETHOD AppendFilters(int32_t filterMask) override; | ||||||
|   NS_IMETHOD AppendRawFilter(const nsAString& aFilter) override; |   NS_IMETHOD AppendRawFilter(const nsAString& aFilter) override; | ||||||
|   NS_IMETHOD GetCapture(int16_t* aCapture) override; |   NS_IMETHOD GetCapture(nsIFilePicker::CaptureTarget* aCapture) override; | ||||||
|   NS_IMETHOD SetCapture(int16_t aCapture) override; |   NS_IMETHOD SetCapture(nsIFilePicker::CaptureTarget aCapture) override; | ||||||
|   NS_IMETHOD GetFilterIndex(int32_t* aFilterIndex) override; |   NS_IMETHOD GetFilterIndex(int32_t* aFilterIndex) override; | ||||||
|   NS_IMETHOD SetFilterIndex(int32_t aFilterIndex) override; |   NS_IMETHOD SetFilterIndex(int32_t aFilterIndex) override; | ||||||
|   NS_IMETHOD GetFiles(nsISimpleEnumerator** aFiles) override; |   NS_IMETHOD GetFiles(nsISimpleEnumerator** aFiles) override; | ||||||
|  |  | ||||||
|  | @ -54,13 +54,13 @@ nsFilePickerProxy::AppendFilter(const nsAString& aTitle, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NS_IMETHODIMP | NS_IMETHODIMP | ||||||
| nsFilePickerProxy::GetCapture(int16_t* aCapture) { | nsFilePickerProxy::GetCapture(nsIFilePicker::CaptureTarget* aCapture) { | ||||||
|   *aCapture = mCapture; |   *aCapture = mCapture; | ||||||
|   return NS_OK; |   return NS_OK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| NS_IMETHODIMP | NS_IMETHODIMP | ||||||
| nsFilePickerProxy::SetCapture(int16_t aCapture) { | nsFilePickerProxy::SetCapture(nsIFilePicker::CaptureTarget aCapture) { | ||||||
|   mCapture = aCapture; |   mCapture = aCapture; | ||||||
|   return NS_OK; |   return NS_OK; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -37,8 +37,8 @@ class nsFilePickerProxy : public nsBaseFilePicker, | ||||||
|                   nsIFilePicker::Mode aMode) override; |                   nsIFilePicker::Mode aMode) override; | ||||||
|   NS_IMETHOD AppendFilter(const nsAString& aTitle, |   NS_IMETHOD AppendFilter(const nsAString& aTitle, | ||||||
|                           const nsAString& aFilter) override; |                           const nsAString& aFilter) override; | ||||||
|   NS_IMETHOD GetCapture(int16_t* aCapture) override; |   NS_IMETHOD GetCapture(nsIFilePicker::CaptureTarget* aCapture) override; | ||||||
|   NS_IMETHOD SetCapture(int16_t aCapture) override; |   NS_IMETHOD SetCapture(nsIFilePicker::CaptureTarget aCapture) override; | ||||||
|   NS_IMETHOD GetDefaultString(nsAString& aDefaultString) override; |   NS_IMETHOD GetDefaultString(nsAString& aDefaultString) override; | ||||||
|   NS_IMETHOD SetDefaultString(const nsAString& aDefaultString) override; |   NS_IMETHOD SetDefaultString(const nsAString& aDefaultString) override; | ||||||
|   NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension) override; |   NS_IMETHOD GetDefaultExtension(nsAString& aDefaultExtension) override; | ||||||
|  | @ -74,7 +74,7 @@ class nsFilePickerProxy : public nsBaseFilePicker, | ||||||
|   nsString mFile; |   nsString mFile; | ||||||
|   nsString mDefault; |   nsString mDefault; | ||||||
|   nsString mDefaultExtension; |   nsString mDefaultExtension; | ||||||
|   int16_t mCapture; |   nsIFilePicker::CaptureTarget mCapture; | ||||||
| 
 | 
 | ||||||
|   bool mIPCActive; |   bool mIPCActive; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -53,10 +53,12 @@ interface nsIFilePicker : nsISupports | ||||||
|                                                 // *.rm; *.rmvb; *.smil; *.webm; |                                                 // *.rm; *.rmvb; *.smil; *.webm; | ||||||
|                                                 // *.wmv; *.xvid |                                                 // *.wmv; *.xvid | ||||||
| 
 | 
 | ||||||
|   const short captureNone     = 0;              // No capture target specified. |   cenum CaptureTarget: 8 { | ||||||
|   const short captureDefault  = 1;              // Missing/invalid value default. |     captureNone     = 0,                        // No capture target specified. | ||||||
|   const short captureUser     = 2;              // "user" capture target specified. |     captureDefault  = 1,                        // Missing/invalid value default. | ||||||
|   const short captureEnv      = 3;              // "environment" capture target specified. |     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 |   * Initialize the file picker widget.  The file picker is not valid until this | ||||||
|  | @ -206,7 +208,12 @@ interface nsIFilePicker : nsISupports | ||||||
|    */ |    */ | ||||||
|   attribute AString okButtonLabel; |   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)] | [scriptable, function, uuid(0d79adad-b244-49A5-9997-2a8cad93fc44)] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Ray Kraesig
						Ray Kraesig