Bug 894840, part 2 - Get rid of the nsFilePickerShownCallback ctor's aMulti argument by exposing nsIFilePicker.mode. r=mounir
authorJonathan Watt <jwatt@jwatt.org>
Mon, 22 Jul 2013 13:46:27 +0100
changeset 142515 02cccbd90395c49fa85de4e3c6c8d806e747854f
parent 142514 c3b9c515d846f603918d9fc652c662b2b7928c53
child 142516 4bae09cea372b12b1195920b38a62f644f80e84d
push id32437
push userjwatt@jwatt.org
push dateWed, 14 Aug 2013 09:51:31 +0000
treeherdermozilla-inbound@1d64db569ebf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs894840
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 894840, part 2 - Get rid of the nsFilePickerShownCallback ctor's aMulti argument by exposing nsIFilePicker.mode. r=mounir
b2g/components/FilePicker.js
content/html/content/src/HTMLInputElement.cpp
content/html/content/src/HTMLInputElement.h
mobile/android/components/FilePicker.js
toolkit/components/filepicker/nsFilePicker.js
widget/nsIFilePicker.idl
widget/xpwidgets/nsBaseFilePicker.cpp
widget/xpwidgets/nsBaseFilePicker.h
--- a/b2g/components/FilePicker.js
+++ b/b2g/components/FilePicker.js
@@ -50,16 +50,17 @@ FilePicker.prototype = {
   mFilterTypes: [],
   mFileEnumerator: undefined,
   mFilePickerShownCallback: undefined,
 
   /* methods */
 
   init: function(parent, title, mode) {
     this.mParent = parent;
+    this.mMode = mode;
 
     if (mode != Ci.nsIFilePicker.modeOpen &&
         mode != Ci.nsIFilePicker.modeOpenMultiple) {
       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
     }
   },
 
   /* readonly attribute nsILocalFile file - not implemented; */
@@ -69,16 +70,20 @@ FilePicker.prototype = {
   get domfiles() {
     return this.mFilesEnumerator;
   },
 
   get domfile() {
     return this.mFilesEnumerator ? this.mFilesEnumerator.mFiles[0] : null;
   },
 
+  get mode() {
+    return this.mMode;
+  },
+
   appendFilters: function(filterMask) {
     // Ci.nsIFilePicker.filterHTML is not supported
     // Ci.nsIFilePicker.filterText is not supported
 
     if (filterMask & Ci.nsIFilePicker.filterImages) {
       this.mFilterTypes = this.mFilterTypes.concat(IMAGE_FILTERS);
     }
 
--- a/content/html/content/src/HTMLInputElement.cpp
+++ b/content/html/content/src/HTMLInputElement.cpp
@@ -258,20 +258,19 @@ class HTMLInputElementState MOZ_FINAL : 
     bool mChecked;
     bool mCheckedSet;
 };
 
 NS_IMPL_ISUPPORTS1(HTMLInputElementState, HTMLInputElementState)
 NS_DEFINE_STATIC_IID_ACCESSOR(HTMLInputElementState, NS_INPUT_ELEMENT_STATE_IID)
 
 HTMLInputElement::nsFilePickerShownCallback::nsFilePickerShownCallback(
-  HTMLInputElement* aInput, nsIFilePicker* aFilePicker, bool aMulti)
+  HTMLInputElement* aInput, nsIFilePicker* aFilePicker)
   : mFilePicker(aFilePicker)
   , mInput(aInput)
-  , mMulti(aMulti)
 {
 }
 
 NS_IMPL_ISUPPORTS1(UploadLastDir::ContentPrefCallback, nsIContentPrefCallback2)
 
 NS_IMETHODIMP
 UploadLastDir::ContentPrefCallback::HandleCompletion(uint16_t aReason)
 {
@@ -314,19 +313,23 @@ UploadLastDir::ContentPrefCallback::Hand
 
 NS_IMETHODIMP
 HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
 {
   if (aResult == nsIFilePicker::returnCancel) {
     return NS_OK;
   }
 
+  int16_t mode;
+  mFilePicker->GetMode(&mode);
+  bool multi = mode == static_cast<int16_t>(nsIFilePicker::modeOpenMultiple);
+
   // Collect new selected filenames
   nsCOMArray<nsIDOMFile> newFiles;
-  if (mMulti) {
+  if (multi) {
     nsCOMPtr<nsISimpleEnumerator> iter;
     nsresult rv = mFilePicker->GetDomfiles(getter_AddRefs(iter));
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (!iter) {
       return NS_OK;
     }
 
@@ -576,17 +579,17 @@ HTMLInputElement::InitFilePicker()
   }
 
   // Set default directry and filename
   nsAutoString defaultName;
 
   const nsCOMArray<nsIDOMFile>& oldFiles = GetFilesInternal();
 
   nsCOMPtr<nsIFilePickerShownCallback> callback =
-    new HTMLInputElement::nsFilePickerShownCallback(this, filePicker, multi);
+    new HTMLInputElement::nsFilePickerShownCallback(this, filePicker);
 
   if (oldFiles.Count()) {
     nsString path;
 
     oldFiles[0]->GetMozFullPathInternal(path);
 
     nsCOMPtr<nsIFile> localFile;
     rv = NS_NewLocalFile(path, false, getter_AddRefs(localFile));
--- a/content/html/content/src/HTMLInputElement.h
+++ b/content/html/content/src/HTMLInputElement.h
@@ -1237,28 +1237,26 @@ private:
     bool mIsTrusted; 
   };
 
   class nsFilePickerShownCallback
     : public nsIFilePickerShownCallback
   {
   public:
     nsFilePickerShownCallback(HTMLInputElement* aInput,
-                              nsIFilePicker* aFilePicker,
-                              bool aMulti);
+                              nsIFilePicker* aFilePicker);
     virtual ~nsFilePickerShownCallback()
     { }
 
     NS_DECL_ISUPPORTS
 
     NS_IMETHOD Done(int16_t aResult) MOZ_OVERRIDE;
 
   private:
     nsCOMPtr<nsIFilePicker> mFilePicker;
     nsRefPtr<HTMLInputElement> mInput;
-    bool mMulti;
   };
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/mobile/android/components/FilePicker.js
+++ b/mobile/android/components/FilePicker.js
@@ -21,16 +21,17 @@ FilePicker.prototype = {
   _defaultExtension: null,
   _displayDirectory: null,
   _filePath: null,
   _promptActive: false,
   _filterIndex: 0,
 
   init: function(aParent, aTitle, aMode) {
     this._domWin = aParent;
+    this._mode = aMode;
     Services.obs.addObserver(this, "FilePicker:Result", false);
 
     let idService = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); 
     this.guid = idService.generateUUID().toString();
 
     if (aMode != Ci.nsIFilePicker.modeOpen && aMode != Ci.nsIFilePicker.modeOpenMultiple)
       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
   },
@@ -151,16 +152,20 @@ FilePicker.prototype = {
   get addToRecentDocs() {
     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
   },
 
   set addToRecentDocs(val) {
     throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
   },
 
+  get mode() {
+    return this._mode;
+  },
+
   show: function() {
     if (this._domWin) {
       PromptUtils.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
       let winUtils = this._domWin.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
       winUtils.enterModalState();
     }
 
     this._promptActive = true;
--- a/toolkit/components/filepicker/nsFilePicker.js
+++ b/toolkit/components/filepicker/nsFilePicker.js
@@ -161,16 +161,19 @@ nsFilePicker.prototype = {
   /* attribute long filterIndex; */
   set filterIndex(a) { this.mFilterIndex = a; },
   get filterIndex() { return this.mFilterIndex; },
 
   /* attribute boolean addToRecentDocs; */
   set addToRecentDocs(a) {},
   get addToRecentDocs()  { return false; },
 
+  /* readonly attribute short mode; */
+  get mode() { return mMode; },
+
   /* members */
   mFilesEnumerator: undefined,
   mDOMFilesEnumerator: undefined,
   mParentWindow: null,
 
   /* methods */
   init: function(parent, title, mode) {
     this.mParentWindow = parent;
--- a/widget/nsIFilePicker.idl
+++ b/widget/nsIFilePicker.idl
@@ -19,17 +19,17 @@ interface nsIFilePickerShownCallback : n
   * Callback which is called when a filepicker is shown and a result
   * is returned.
   *
   * @param aResult One of returnOK, returnCancel, or returnReplace
   */
   void done(in short aResult);
 };
 
-[scriptable, uuid(a6a24df3-d20a-4b6a-96d4-4736b10a51b7)]
+[scriptable, uuid(f93509a0-0434-11e3-8ffd-0800200c9a66)]
 interface nsIFilePicker : nsISupports
 {
   const short modeOpen        = 0;              // Load a file or directory
   const short modeSave        = 1;              // Save a file or directory
   const short modeGetFolder   = 2;              // Select a folder/directory
   const short modeOpenMultiple= 3;              // Load multiple files
 
   const short returnOK        = 0;              // User hit Ok, process selection
@@ -175,9 +175,14 @@ interface nsIFilePicker : nsISupports
 
 
  /**
   * Opens the file dialog asynchrounously.
   * The passed in object's done method will be called upon completion.
   */
   void open(in nsIFilePickerShownCallback aFilePickerShownCallback);
 
+ /**
+  * The picker's mode, as set by the 'mode' argument passed to init()
+  * (one of the modeOpen et. al. constants specified above).
+  */
+  readonly attribute short mode;
 };
--- a/widget/xpwidgets/nsBaseFilePicker.cpp
+++ b/widget/xpwidgets/nsBaseFilePicker.cpp
@@ -287,16 +287,23 @@ nsBaseFilePicker::GetAddToRecentDocs(boo
 NS_IMETHODIMP
 nsBaseFilePicker::SetAddToRecentDocs(bool aFlag)
 {
   mAddToRecentDocs = aFlag;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsBaseFilePicker::GetMode(int16_t* aMode)
+{
+  *aMode = mMode;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsBaseFilePicker::GetDomfile(nsIDOMFile** aDomfile)
 {
   nsCOMPtr<nsIFile> localFile;
   nsresult rv = GetFile(getter_AddRefs(localFile));
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (!localFile) {
     *aDomfile = nullptr;
--- a/widget/xpwidgets/nsBaseFilePicker.h
+++ b/widget/xpwidgets/nsBaseFilePicker.h
@@ -29,16 +29,17 @@ public:
   NS_IMETHOD AppendFilters(int32_t filterMask);
   NS_IMETHOD GetFilterIndex(int32_t *aFilterIndex);
   NS_IMETHOD SetFilterIndex(int32_t aFilterIndex);
   NS_IMETHOD GetFiles(nsISimpleEnumerator **aFiles);
   NS_IMETHOD GetDisplayDirectory(nsIFile * *aDisplayDirectory);
   NS_IMETHOD SetDisplayDirectory(nsIFile * aDisplayDirectory);
   NS_IMETHOD GetAddToRecentDocs(bool *aFlag);
   NS_IMETHOD SetAddToRecentDocs(bool aFlag);
+  NS_IMETHOD GetMode(int16_t *aMode);
 
   NS_IMETHOD GetDomfile(nsIDOMFile** aDomfile);
   NS_IMETHOD GetDomfiles(nsISimpleEnumerator** aDomfiles);
 
 protected:
 
   virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle) = 0;