mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1852839 - Part 1: Add nsIFilePicker.isModeSupported method. r=spohl
Differential Revision: https://phabricator.services.mozilla.com/D188131
This commit is contained in:
parent
6c0040ad81
commit
88ab9ee914
@ -16,6 +16,7 @@
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "mozilla/dom/Directory.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "WidgetUtils.h"
|
||||
#include "nsSimpleEnumerator.h"
|
||||
@ -25,6 +26,7 @@
|
||||
|
||||
using namespace mozilla::widget;
|
||||
using namespace mozilla::dom;
|
||||
using mozilla::ErrorResult;
|
||||
|
||||
#define FILEPICKER_TITLES "chrome://global/locale/filepicker.properties"
|
||||
#define FILEPICKER_FILTERS "chrome://global/content/filepicker.properties"
|
||||
@ -165,6 +167,29 @@ NS_IMETHODIMP nsBaseFilePicker::Init(mozIDOMWindowProxy* aParent,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseFilePicker::IsModeSupported(nsIFilePicker::Mode aMode, JSContext* aCx,
|
||||
Promise** aPromise) {
|
||||
MOZ_ASSERT(aCx);
|
||||
MOZ_ASSERT(aPromise);
|
||||
|
||||
nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aCx);
|
||||
if (NS_WARN_IF(!globalObject)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
RefPtr<Promise> promise = Promise::Create(globalObject, result);
|
||||
if (NS_WARN_IF(result.Failed())) {
|
||||
return result.StealNSResult();
|
||||
}
|
||||
|
||||
promise->MaybeResolve(true);
|
||||
promise.forget(aPromise);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseFilePicker::Open(nsIFilePickerShownCallback* aCallback) {
|
||||
nsCOMPtr<nsIRunnable> filePickerEvent =
|
||||
|
@ -27,7 +27,8 @@ class nsBaseFilePicker : public nsIFilePicker {
|
||||
|
||||
NS_IMETHOD Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
|
||||
nsIFilePicker::Mode aMode) override;
|
||||
|
||||
NS_IMETHOD IsModeSupported(nsIFilePicker::Mode aMode, JSContext* aCx,
|
||||
mozilla::dom::Promise** aPromise) override;
|
||||
NS_IMETHOD Open(nsIFilePickerShownCallback* aCallback) override;
|
||||
NS_IMETHOD AppendFilters(int32_t filterMask) override;
|
||||
NS_IMETHOD AppendRawFilter(const nsAString& aFilter) override;
|
||||
|
@ -73,6 +73,18 @@ interface nsIFilePicker : nsISupports
|
||||
*/
|
||||
void init(in mozIDOMWindowProxy parent, in AString title, in nsIFilePicker_Mode mode);
|
||||
|
||||
/**
|
||||
* Returns a Promise that resolves to true if the passed nsIFilePicker mode
|
||||
* is supported on the current platform, and false otherwise. The Promise may
|
||||
* reject if something unexpected occurs while trying to determine if the mode
|
||||
* is supported.
|
||||
*
|
||||
* @param mode
|
||||
* @return Promise<boolean>
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
Promise isModeSupported(in nsIFilePicker_Mode mode);
|
||||
|
||||
/**
|
||||
* Append to the filter list with things from the predefined list
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user