Commits

Anonymous committed 26440e8

Bug 651093 - Don't let the file picker on Windows add to the recent doc list when in privacy mode. Also expose a prop on the interface that gives devs control over 'add to recent docs' behavior. r=dougt, sr=gavin a=mak

  • Participants
  • Parent commits ead02ed

Comments (0)

Files changed (9)

dom/ipc/ContentParent.cpp

 bool
 ContentParent::RecvShowFilePicker(const PRInt16& mode,
                                   const PRInt16& selectedType,
+                                  const PRBool& addToRecentDocs,
                                   const nsString& title,
                                   const nsString& defaultFile,
                                   const nsString& defaultExtension,
     *result = filePicker->Init(window, title, mode);
     if (NS_FAILED(*result))
         return true;
-    
+
+    filePicker->SetAddToRecentDocs(addToRecentDocs);
+
     PRUint32 count = filters.Length();
     for (PRUint32 i = 0; i < count; ++i) {
         filePicker->AppendFilter(filterNames[i], filters[i]);

dom/ipc/ContentParent.h

     
     virtual bool RecvShowFilePicker(const PRInt16& mode,
                                     const PRInt16& selectedType,
+                                    const PRBool& addToRecentDocs,
                                     const nsString& title,
                                     const nsString& defaultFile,
                                     const nsString& defaultExtension,

dom/ipc/PContent.ipdl

     async SetURITitle(URI uri, nsString title);
     
     // filepicker remoting
-    sync ShowFilePicker(PRInt16 mode, PRInt16 selectedType, 
+    sync ShowFilePicker(PRInt16 mode, PRInt16 selectedType, PRBool addToRecentDocs,
                         nsString title, nsString defaultFile, nsString defaultExtension,
                         nsString[] filters, nsString[] filterNames)
         returns (nsString[] files, PRInt16 retValue, nsresult result);

toolkit/components/filepicker/nsFilePicker.js

   set filterIndex(a) { this.mFilterIndex = a; },
   get filterIndex() { return this.mFilterIndex; },
 
+  /* attribute boolean addToRecentDocs; */
+  set addToRecentDocs(a) {},
+  get addToRecentDocs()  { return false; },
+
   /* members */
   mFilesEnumerator: undefined,
   mParentWindow: null,

widget/public/nsIFilePicker.idl

 interface nsIDOMWindow;
 interface nsISimpleEnumerator;
 
-[scriptable, uuid(d24ef0aa-d555-4117-84af-9cbbb7406909)]
+[scriptable, uuid(f2c0e216-5d07-4df4-bbcb-37683077ae7e)]
 interface nsIFilePicker : nsISupports
 {
   const short modeOpen        = 0;              // Load a file or directory
   readonly attribute nsISimpleEnumerator files;
 
  /**
+  * Controls whether the chosen file(s) should be added to the system's recent
+  * documents list. This attribute will be ignored if the system has no "Recent
+  * Docs" concept, or if the application is in private browsing mode (in which
+  * case the file will not be added). Defaults to true.
+  */
+  attribute boolean addToRecentDocs;
+
+ /**
   * Show File Dialog. The dialog is displayed modally.
   *
   * @return returnOK if the user selects OK, returnCancel if the user selects cancel

widget/src/windows/nsFilePicker.cpp

 #include "nsIServiceManager.h"
 #include "nsIPlatformCharset.h"
 #include "nsICharsetConverterManager.h"
+#include "nsIPrivateBrowsingService.h"
 #include "nsFilePicker.h"
 #include "nsILocalFile.h"
 #include "nsIURL.h"
 
 #define MAX_EXTENSION_LENGTH 10
 
-//-------------------------------------------------------------------------
-//
-// nsFilePicker constructor
-//
-//-------------------------------------------------------------------------
 nsFilePicker::nsFilePicker()
 {
   mSelectedType   = 1;
 }
 
-//-------------------------------------------------------------------------
-//
-// nsFilePicker destructor
-//
-//-------------------------------------------------------------------------
 nsFilePicker::~nsFilePicker()
 {
   if (mLastUsedUnicodeDirectory) {
   }
 }
 
-//-------------------------------------------------------------------------
-//
 // Show - Display the file dialog
-//
-//-------------------------------------------------------------------------
-
 int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
 {
   if (uMsg == BFFM_INITIALIZED)
     ofn.lpstrFile    = fileBuffer;
     ofn.nMaxFile     = FILE_BUFFER_SIZE;
 
-    ofn.Flags = OFN_NOCHANGEDIR | OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
+    ofn.Flags = OFN_NOCHANGEDIR | OFN_SHAREAWARE |
+                OFN_LONGNAMES | OFN_OVERWRITEPROMPT |
+                OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
+
+    // Handle add to recent docs settings
+    nsCOMPtr<nsIPrivateBrowsingService> pbs =
+      do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
+    PRBool privacyModeEnabled = PR_FALSE;
+    if (pbs) {
+      pbs->GetPrivateBrowsingEnabled(&privacyModeEnabled);
+    }
+    if (privacyModeEnabled || !mAddToRecentDocs) {
+      ofn.Flags |= OFN_DONTADDTORECENT;
+    }
 
     if (!mDefaultExtension.IsEmpty()) {
       ofn.lpstrDefExt = mDefaultExtension.get();
   return NS_OK;
 }
 
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsFilePicker::GetFileURL(nsIURI **aFileURL)
 {
   *aFileURL = nsnull;
   return NS_NewArrayEnumerator(aFiles, mFiles);
 }
 
-//-------------------------------------------------------------------------
-//
 // Get the file + path
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsFilePicker::SetDefaultString(const nsAString& aString)
 {
   mDefault = aString;
   return NS_ERROR_FAILURE;
 }
 
-//-------------------------------------------------------------------------
-//
 // The default extension to use for files
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsFilePicker::GetDefaultExtension(nsAString& aExtension)
 {
   aExtension = mDefaultExtension;
   return NS_OK;
 }
 
-//-------------------------------------------------------------------------
-//
 // Set the filter index
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
 {
   // Windows' filter index is 1-based, we use a 0-based system.
   return NS_OK;
 }
 
-//-------------------------------------------------------------------------
 void nsFilePicker::InitNative(nsIWidget *aParent,
                               const nsAString& aTitle,
                               PRInt16 aMode)

widget/src/xpwidgets/nsBaseFilePicker.cpp

 #define FILEPICKER_TITLES "chrome://global/locale/filepicker.properties"
 #define FILEPICKER_FILTERS "chrome://global/content/filepicker.properties"
 
-nsBaseFilePicker::nsBaseFilePicker()
+nsBaseFilePicker::nsBaseFilePicker() :
+  mAddToRecentDocs(PR_TRUE)
 {
 
 }
 
 }
 
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsBaseFilePicker::Init(nsIDOMWindow *aParent,
                                      const nsAString& aTitle,
                                      PRInt16 aMode)
   return NS_OK;
 }
 
-//-------------------------------------------------------------------------
-//
 // Set the filter index
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
 {
   *aFilterIndex = 0;
 }
 
 #ifdef BASEFILEPICKER_HAS_DISPLAYDIRECTORY
-//-------------------------------------------------------------------------
-//
+
 // Set the display directory
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsBaseFilePicker::SetDisplayDirectory(nsILocalFile *aDirectory)
 {
   if (!aDirectory) {
   return rv;
 }
 
-//-------------------------------------------------------------------------
-//
 // Get the display directory
-//
-//-------------------------------------------------------------------------
 NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsILocalFile **aDirectory)
 {
   *aDirectory = nsnull;
   return CallQueryInterface(directory, aDirectory);
 }
 #endif
+
+NS_IMETHODIMP
+nsBaseFilePicker::GetAddToRecentDocs(PRBool *aFlag)
+{
+  *aFlag = mAddToRecentDocs;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsBaseFilePicker::SetAddToRecentDocs(PRBool aFlag)
+{
+  mAddToRecentDocs = aFlag;
+  return NS_OK;
+}

widget/src/xpwidgets/nsBaseFilePicker.h

   NS_IMETHOD GetDisplayDirectory(nsILocalFile * *aDisplayDirectory);
   NS_IMETHOD SetDisplayDirectory(nsILocalFile * aDisplayDirectory);
 #endif
+  NS_IMETHOD GetAddToRecentDocs(PRBool *aFlag);
+  NS_IMETHOD SetAddToRecentDocs(PRBool aFlag);
 
 protected:
 
   virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle,
                           PRInt16 aMode) = 0;
 
+  PRBool mAddToRecentDocs;
 #ifdef BASEFILEPICKER_HAS_DISPLAYDIRECTORY 
   nsCOMPtr<nsILocalFile> mDisplayDirectory;
 #endif

widget/src/xpwidgets/nsFilePickerProxy.cpp

     InfallibleTArray<nsString> filePaths;
     
     nsresult rv;
-    cc->SendShowFilePicker(mMode, mSelectedType, mTitle,
+    cc->SendShowFilePicker(mMode, mSelectedType,
+                           mAddToRecentDocs, mTitle,
                            mDefault, mDefaultExtension,
                            mFilters, mFilterNames,
                            &filePaths, aReturn, &rv);