Bug 1134553 - Disable downloads in guest session. r=rnewman, a=lsblakk
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Thu, 12 Mar 2015 11:26:12 -0700
changeset 250377 6df5a4ea72f3
parent 250376 4f9eeb2285b0
child 250378 ff5485e89210
push id4569
push userryanvm@gmail.com
push date2015-03-13 20:45 +0000
treeherdermozilla-beta@b31df8fa73a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, lsblakk
bugs1134553
milestone37.0
Bug 1134553 - Disable downloads in guest session. r=rnewman, a=lsblakk
mobile/android/modules/DownloadNotifications.jsm
--- a/mobile/android/modules/DownloadNotifications.jsm
+++ b/mobile/android/modules/DownloadNotifications.jsm
@@ -11,16 +11,19 @@ const { classes: Cc, interfaces: Ci, uti
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads", "resource://gre/modules/Downloads.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/FileUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
 
+XPCOMUtils.defineLazyServiceGetter(this, "ParentalControls",
+  "@mozilla.org/parental-controls-service;1", "nsIParentalControlsService");
+
 let Log = Cu.import("resource://gre/modules/AndroidLog.jsm", {}).AndroidLog.i.bind(null, "DownloadNotifications"); 
 
 XPCOMUtils.defineLazyGetter(this, "strings",
                             () => Services.strings.createBundle("chrome://browser/locale/browser.properties"));
 
 /**
  * CID of Downloads.jsm's implementation of nsITransfer.
  */
@@ -71,16 +74,23 @@ var DownloadNotifications = {
   onDownloadAdded: function (download) {
     // Don't create notifications for pre-existing succeeded downloads.
     // We still add notifications for canceled downloads in case the
     // user decides to retry the download.
     if (download.succeeded && !this._viewAdded) {
       return;
     }
 
+    if (!ParentalControls.isAllowed(ParentalControls.DOWNLOAD)) {
+      download.cancel().catch(Cu.reportError);
+      download.removePartialData().catch(Cu.reportError);
+      window.NativeWindow.toast.show(strings.GetStringFromName("downloads.disabledInGuest"), "long");
+      return;
+    }
+
     let notification = new DownloadNotification(download);
     notifications.set(download, notification);
     notification.showOrUpdate();
 
     // If this is a new download, show a toast as well.
     if (this._viewAdded) {
       window.NativeWindow.toast.show(strings.GetStringFromName("alertDownloadsToast"), "long");
     }