diff options
author | Moonchild <moonchild@palemoon.org> | 2021-02-21 10:32:47 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2021-02-21 10:32:47 +0000 |
commit | 98f6ad61f4f3c66209036db4bc7a4ae6ff4d1d3d (patch) | |
tree | 5d194dc3e53b4f5a4fa6b31b7756bf426fbe3cb9 /widget/windows | |
parent | 2b6effbf29cb4f7aa85e4f697c79c473cc4c9ea4 (diff) | |
download | uxp-98f6ad61f4f3c66209036db4bc7a4ae6ff4d1d3d.tar.gz |
[widget] Require user interaction when picking files or folders v2
Now with extra sauce to make it work cross-platform and cross-versions and
for HTML input elements only.
Diffstat (limited to 'widget/windows')
-rw-r--r-- | widget/windows/nsFilePicker.cpp | 23 | ||||
-rw-r--r-- | widget/windows/nsFilePicker.h | 4 |
2 files changed, 23 insertions, 4 deletions
diff --git a/widget/windows/nsFilePicker.cpp b/widget/windows/nsFilePicker.cpp index 78656165d9..59ae152ec6 100644 --- a/widget/windows/nsFilePicker.cpp +++ b/widget/windows/nsFilePicker.cpp @@ -29,6 +29,7 @@ #include "GeckoProfiler.h" using mozilla::IsWin8OrLater; +using mozilla::IsWin10OrLater; using mozilla::MakeUnique; using mozilla::mscom::EnsureMTA; using mozilla::UniquePtr; @@ -193,11 +194,13 @@ nsFilePicker::~nsFilePicker() NS_IMPL_ISUPPORTS(nsFilePicker, nsIFilePicker) -NS_IMETHODIMP nsFilePicker::Init(mozIDOMWindowProxy *aParent, const nsAString& aTitle, int16_t aMode) +NS_IMETHODIMP nsFilePicker::Init(mozIDOMWindowProxy *aParent, const nsAString& aTitle, int16_t aMode, + bool aRequireInteraction) { nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aParent); nsIDocShell* docShell = window ? window->GetDocShell() : nullptr; mLoadContext = do_QueryInterface(docShell); + mRequireInteraction = aRequireInteraction; return nsBaseFilePicker::Init(aParent, aTitle, aMode); } @@ -360,7 +363,14 @@ nsFilePicker::ShowFolderPicker(const nsString& aInitialDir) dialog->Advise(this, &mFDECookie); // options - FILEOPENDIALOGOPTIONS fos = FOS_PICKFOLDERS | FOS_OKBUTTONNEEDSINTERACTION; + FILEOPENDIALOGOPTIONS fos = FOS_PICKFOLDERS; + // Require interaction if the folder picker is triggered by an element that + // is potentially unsafe to use the default value in. + // Win 10+ only, because this dialog flag is broken in earlier versions. + if (IsWin10OrLater() && mRequireInteraction) { + fos |= FOS_OKBUTTONNEEDSINTERACTION; + } + dialog->SetOptions(fos); // initial strings @@ -459,7 +469,14 @@ nsFilePicker::ShowFilePicker(const nsString& aInitialDir) FILEOPENDIALOGOPTIONS fos = 0; fos |= FOS_SHAREAWARE | FOS_OVERWRITEPROMPT | - FOS_FORCEFILESYSTEM | FOS_OKBUTTONNEEDSINTERACTION; + FOS_FORCEFILESYSTEM; + + // Require interaction if the file picker is triggered by an element that + // is potentially unsafe to use the default value in. + // Win 10+ only, because this dialog flag is broken in earlier versions. + if (IsWin10OrLater() && mRequireInteraction) { + fos |= FOS_OKBUTTONNEEDSINTERACTION; + } // Handle add to recent docs settings if (IsPrivacyModeEnabled() || !mAddToRecentDocs) { diff --git a/widget/windows/nsFilePicker.h b/widget/windows/nsFilePicker.h index 740f07a7d8..7a3fbbe073 100644 --- a/widget/windows/nsFilePicker.h +++ b/widget/windows/nsFilePicker.h @@ -49,7 +49,8 @@ class nsFilePicker : public: nsFilePicker(); - NS_IMETHOD Init(mozIDOMWindowProxy *aParent, const nsAString& aTitle, int16_t aMode); + NS_IMETHOD Init(mozIDOMWindowProxy *aParent, const nsAString& aTitle, int16_t aMode, + bool aRequireInteraction = false); NS_DECL_ISUPPORTS @@ -101,6 +102,7 @@ protected: nsString mUnicodeFile; static char16_t *mLastUsedUnicodeDirectory; HWND mDlgWnd; + bool mRequireInteraction; class ComDlgFilterSpec { |