From d92ef717a64dcbc370dffade26b3adf03b006a48 Mon Sep 17 00:00:00 2001 From: Razvan Maries Date: Mon, 16 Nov 2020 18:49:34 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1338637) for perma failures on test_webkitdirectory.html. CLOSED TREE Backed out changeset 5bddcb99f650 (bug 1338637) Backed out changeset 5c29fd30af97 (bug 1338637) --- .../base/content/test/tabPrompts/browser.ini | 1 - .../tabPrompts/browser_confirmFolderUpload.js | 140 ------------------ .../components/prompts/PromptCollection.jsm | 42 ------ dom/html/HTMLInputElement.cpp | 32 ---- dom/locales/en-US/chrome/dom/dom.properties | 4 - .../components/geckoview/PromptCollection.jsm | 5 - .../specialpowers/content/MockFilePicker.jsm | 2 +- .../windowwatcher/nsIPromptCollection.idl | 13 -- 8 files changed, 1 insertion(+), 238 deletions(-) delete mode 100644 browser/base/content/test/tabPrompts/browser_confirmFolderUpload.js diff --git a/browser/base/content/test/tabPrompts/browser.ini b/browser/base/content/test/tabPrompts/browser.ini index ad88b7306081..b6b2223b0127 100644 --- a/browser/base/content/test/tabPrompts/browser.ini +++ b/browser/base/content/test/tabPrompts/browser.ini @@ -2,7 +2,6 @@ support-files = file_beforeunload_stop.html [browser_closeTabSpecificPanels.js] skip-if = verify && debug && (os == 'linux') -[browser_confirmFolderUpload.js] [browser_multiplePrompts.js] [browser_openPromptInBackgroundTab.js] support-files = openPromptOffTimeout.html diff --git a/browser/base/content/test/tabPrompts/browser_confirmFolderUpload.js b/browser/base/content/test/tabPrompts/browser_confirmFolderUpload.js deleted file mode 100644 index e9231647f9ed..000000000000 --- a/browser/base/content/test/tabPrompts/browser_confirmFolderUpload.js +++ /dev/null @@ -1,140 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - http://creativecommons.org/publicdomain/zero/1.0/ */ - -"use strict"; - -const { PromptTestUtils } = ChromeUtils.import( - "resource://testing-common/PromptTestUtils.jsm" -); - -/** - * Create a temporary test directory that will be cleaned up on test shutdown. - * @returns {String} - absolute directory path. - */ -function getTestDirectory() { - let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile); - tmpDir.append("testdir"); - if (!tmpDir.exists()) { - tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); - registerCleanupFunction(() => { - tmpDir.remove(true); - }); - } - - let file1 = tmpDir.clone(); - file1.append("foo.txt"); - if (!file1.exists()) { - file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600); - } - - let file2 = tmpDir.clone(); - file2.append("bar.txt"); - if (!file2.exists()) { - file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600); - } - - return tmpDir.path; -} - -add_task(async function setup() { - await SpecialPowers.pushPrefEnv({ - set: [ - // Allow using our MockFilePicker in the content process. - ["dom.filesystem.pathcheck.disabled", true], - ["dom.webkitBlink.dirPicker.enabled", true], - ], - }); -}); - -/** - * Create a file input, select a folder and wait for the upload confirmation - * prompt to open. - * @param {boolean} confirmUpload - Whether to accept (true) or cancel the - * prompt (false). - * @returns {Promise} - Resolves once the prompt has been closed. - */ -async function testUploadPrompt(confirmUpload) { - await BrowserTestUtils.withNewTab("http://example.com", async browser => { - // Create file input element - await ContentTask.spawn(browser, null, () => { - let input = content.document.createElement("input"); - input.id = "filepicker"; - input.setAttribute("type", "file"); - input.setAttribute("webkitdirectory", ""); - content.document.body.appendChild(input); - }); - - // If we're confirming the dialog, register a "change" listener on the - // file input. - let changePromise; - if (confirmUpload) { - changePromise = ContentTask.spawn(browser, null, async () => { - let input = content.document.getElementById("filepicker"); - return ContentTaskUtils.waitForEvent(input, "change").then( - e => e.target.files.length - ); - }); - } - - // Register prompt promise - let promptPromise = PromptTestUtils.waitForPrompt(browser, { - modalType: Services.prompt.MODAL_TYPE_TAB, - promptType: "confirmEx", - }); - - // Open filepicker - let path = getTestDirectory(); - await ContentTask.spawn(browser, { path }, args => { - let MockFilePicker = content.SpecialPowers.MockFilePicker; - MockFilePicker.init( - content, - "A Mock File Picker", - content.SpecialPowers.Ci.nsIFilePicker.modeGetFolder - ); - MockFilePicker.useDirectory(args.path); - - let input = content.document.getElementById("filepicker"); - input.click(); - }); - - // Wait for confirmation prompt - let prompt = await promptPromise; - ok(prompt, "Shown upload confirmation prompt"); - is(prompt.ui.button0.label, "Upload", "Accept button label"); - ok(prompt.ui.button1.hasAttribute("default"), "Cancel is default button"); - - // Close confirmation prompt - await PromptTestUtils.handlePrompt(prompt, { - buttonNumClick: confirmUpload ? 0 : 1, - }); - - // If we accepted, wait for the input elements "change" event - if (changePromise) { - let fileCount = await changePromise; - is(fileCount, 2, "Should have selected 2 files"); - } else { - let fileCount = await ContentTask.spawn(browser, null, () => { - return content.document.getElementById("filepicker").files.length; - }); - - is(fileCount, 0, "Should not have selected any files"); - } - - // Cleanup - await ContentTask.spawn(browser, null, () => { - content.SpecialPowers.MockFilePicker.cleanup(); - }); - }); -} - -// Tests the confirmation prompt that shows after the user picked a folder. - -// Confirm the prompt -add_task(async function test_confirm() { - await testUploadPrompt(true); -}); - -// Cancel the prompt -add_task(async function test_cancel() { - await testUploadPrompt(false); -}); diff --git a/browser/components/prompts/PromptCollection.jsm b/browser/components/prompts/PromptCollection.jsm index 17d8af070b2d..bca4eb99b5e4 100644 --- a/browser/components/prompts/PromptCollection.jsm +++ b/browser/components/prompts/PromptCollection.jsm @@ -131,48 +131,6 @@ class PromptCollection { result.QueryInterface(Ci.nsIPropertyBag2).get("buttonNumClicked") == 0 ); } - - confirmFolderUpload(browsingContext, directoryName) { - let title; - let message; - let acceptLabel; - - try { - title = this.stringBundles.dom.GetStringFromName( - "FolderUploadPrompt.title" - ); - message = this.stringBundles.dom.formatStringFromName( - "FolderUploadPrompt.message", - [directoryName] - ); - acceptLabel = this.stringBundles.dom.GetStringFromName( - "FolderUploadPrompt.acceptButtonLabel" - ); - } catch (exception) { - Cu.reportError("Failed to get strings from dom.properties"); - return false; - } - - let buttonFlags = - Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 + - Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1 + - Services.prompt.BUTTON_POS_1_DEFAULT; - - return ( - Services.prompt.confirmExBC( - browsingContext, - Services.prompt.MODAL_TYPE_TAB, - title, - message, - buttonFlags, - acceptLabel, - null, - null, - null, - {} - ) === 0 - ); - } } const BUNDLES = { diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index b1057a0adfe4..8c647c7509e1 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -54,7 +54,6 @@ #include "nsError.h" #include "nsIEditor.h" #include "nsAttrValueOrString.h" -#include "nsIPromptCollection.h" #include "mozilla/PresState.h" #include "nsLinebreakConverter.h" //to strip out carriage returns @@ -481,37 +480,6 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult) { mode == static_cast(nsIFilePicker::modeGetFolder)); nsCOMPtr tmp; nsresult rv = mFilePicker->GetDomFileOrDirectory(getter_AddRefs(tmp)); - - // Show a prompt to get user confirmation before allowing folder access. - // This is to prevent sites from tricking the user into uploading files. - // See Bug 1338637. - if (mode == static_cast(nsIFilePicker::modeGetFolder)) { - nsCOMPtr prompter = - do_GetService("@mozilla.org/embedcomp/prompt-collection;1"); - if (!prompter) { - return NS_ERROR_NOT_AVAILABLE; - } - - bool confirmed = false; - BrowsingContext* bc = mInput->OwnerDoc()->GetBrowsingContext(); - - // Get directory name - RefPtr directory = static_cast(tmp.get()); - nsAutoString directoryName; - ErrorResult error; - directory->GetName(directoryName, error); - if (NS_WARN_IF(error.Failed())) { - return error.StealNSResult(); - } - - rv = prompter->ConfirmFolderUpload(bc, directoryName, &confirmed); - NS_ENSURE_SUCCESS(rv, rv); - if (!confirmed) { - // User aborted upload - return NS_OK; - } - } - NS_ENSURE_SUCCESS(rv, rv); RefPtr blob = do_QueryObject(tmp); diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 34c3980ab134..9e93f1f6666a 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -401,7 +401,3 @@ RequestStorageAccessNested=document.requestStorageAccess() may not be called in RequestStorageAccessUserGesture=document.requestStorageAccess() may only be requested from inside a short running user-generated event handler. # LOCALIZATION NOTE: Do not translate "Location" and "History". LocChangeFloodingPrevented=Too many calls to Location or History APIs within a short timeframe. -FolderUploadPrompt.title = Confirm Upload -# LOCALIZATION NOTE: %S is the name of the folder the user selected in the file picker. -FolderUploadPrompt.message = Are you sure you want to upload all files from ā€œ%Sā€? Only do this if you trust the site. -FolderUploadPrompt.acceptButtonLabel = Upload diff --git a/mobile/android/components/geckoview/PromptCollection.jsm b/mobile/android/components/geckoview/PromptCollection.jsm index b396705bcbcb..d02ac250950f 100644 --- a/mobile/android/components/geckoview/PromptCollection.jsm +++ b/mobile/android/components/geckoview/PromptCollection.jsm @@ -38,11 +38,6 @@ class PromptCollection { prompter.asyncShowPrompt(msg, resolve); }).then(result => !!result?.allow); } - - confirmFolderUpload() { - // Folder upload is not supported by GeckoView yet, see Bug 1674428. - return false; - } } PromptCollection.prototype.QueryInterface = ChromeUtils.generateQI([ diff --git a/testing/specialpowers/content/MockFilePicker.jsm b/testing/specialpowers/content/MockFilePicker.jsm index 2b331cf6c521..733a3fb52e4b 100644 --- a/testing/specialpowers/content/MockFilePicker.jsm +++ b/testing/specialpowers/content/MockFilePicker.jsm @@ -183,7 +183,7 @@ function MockFilePickerInstance(window) { MockFilePickerInstance.prototype = { QueryInterface: ChromeUtils.generateQI(["nsIFilePicker"]), init(aParent, aTitle, aMode) { - this.mode = aMode; + MockFilePicker.mode = aMode; this.filterIndex = MockFilePicker.filterIndex; this.parent = aParent; }, diff --git a/toolkit/components/windowwatcher/nsIPromptCollection.idl b/toolkit/components/windowwatcher/nsIPromptCollection.idl index 3e3e104407ae..dfd99942e8c9 100644 --- a/toolkit/components/windowwatcher/nsIPromptCollection.idl +++ b/toolkit/components/windowwatcher/nsIPromptCollection.idl @@ -33,17 +33,4 @@ interface nsIPromptCollection : nsISupports * @return true if the page should be allowed to repost data. */ boolean confirmRepost(in BrowsingContext aBrowsingContext); - - /** - * Ask the user for confirmation to upload a selected folder. - * - * @param aBrowsingContext - * The browsing context the prompt should be opened for. - * @param aDirectoryName - * Name of the folder that will be uploaded. - * - * @return true if the user confirmed the upload, false otherwise. - */ - boolean confirmFolderUpload(in BrowsingContext aBrowsingContext, - in AString aDirectoryName); };