Bug 538588 - Split offline storage into http and offline cache in advanced network preferences dialog
authorMichal Novotny <michal.novotny@gmail.com>
Fri, 16 Dec 2011 23:36:09 +0100
changeset 84820 fee072b482c9cdb13c9c06550a42de1e4d4fa7cd
parent 84819 4b701b24223fd692892a901dab766c9231733eb1
child 84821 b88bac3a29ba8e1807e681a473b32195882a0745
push id114
push userffxbld
push dateFri, 09 Mar 2012 01:01:18 +0000
treeherdermozilla-release@c081ebf13261 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs538588
milestone11.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 538588 - Split offline storage into http and offline cache in advanced network preferences dialog
browser/base/content/sanitize.js
browser/components/preferences/advanced.js
browser/components/preferences/advanced.xul
browser/locales/en-US/chrome/browser/preferences/advanced.dtd
browser/locales/en-US/chrome/browser/preferences/preferences.properties
browser/modules/Makefile.in
browser/modules/offlineAppCache.jsm
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -199,34 +199,23 @@ Sanitizer.prototype = {
       {
         return true;
       }
     },
 
     offlineApps: {
       clear: function ()
       {
-        const Cc = Components.classes;
-        const Ci = Components.interfaces;
-        var cacheService = Cc["@mozilla.org/network/cache-service;1"].
-                           getService(Ci.nsICacheService);
-        try {
-          // Offline app data is "timeless", and doesn't respect
-          // the setting of timespan, it always clears everything
-          cacheService.evictEntries(Ci.nsICache.STORE_OFFLINE);
-        } catch(er) {}
-
-        var storageManagerService = Cc["@mozilla.org/dom/storagemanager;1"].
-                                    getService(Ci.nsIDOMStorageManager);
-        storageManagerService.clearOfflineApps();
+        Components.utils.import("resource:///modules/offlineAppCache.jsm");
+        OfflineAppCacheHelper.clear();
       },
 
       get canClear()
       {
-          return true;
+        return true;
       }
     },
 
     history: {
       clear: function ()
       {
         var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
                                       .getService(Components.interfaces.nsIBrowserHistory);
--- a/browser/components/preferences/advanced.js
+++ b/browser/components/preferences/advanced.js
@@ -63,17 +63,18 @@ var gAdvancedPane = {
 
 #ifdef MOZ_UPDATER
     this.updateReadPrefs();
 #endif
     this.updateOfflineApps();
 #ifdef MOZ_CRASHREPORTER
     this.initSubmitCrashes();
 #endif
-    this.updateActualCacheSize();
+    this.updateActualCacheSize("disk");
+    this.updateActualCacheSize("offline");
   },
 
   /**
    * Stores the identity of the current tab in preferences so that the selected
    * tab can be persisted between openings of the preferences window.
    */
   tabSelectionChanged: function ()
   {
@@ -197,40 +198,45 @@ var gAdvancedPane = {
    * Displays a dialog in which proxy settings may be changed.
    */
   showConnections: function ()
   {
     document.documentElement.openSubDialog("chrome://browser/content/preferences/connection.xul",
                                            "", null);
   },
  
-  // Retrieves the amount of space currently used by disk cache
-  updateActualCacheSize: function ()
+  // Retrieves the amount of space currently used by disk or offline cache
+  updateActualCacheSize: function (device)
   {
     var visitor = {
       visitDevice: function (deviceID, deviceInfo)
       {
-        if (deviceID == "disk") {
-          var actualSizeLabel = document.getElementById("actualCacheSize");
+        if (deviceID == device) {
+          var actualSizeLabel = document.getElementById(device == "disk" ?
+                                                        "actualDiskCacheSize" :
+                                                        "actualAppCacheSize");
           var sizeStrings = DownloadUtils.convertByteUnits(deviceInfo.totalSize);
           var prefStrBundle = document.getElementById("bundlePreferences");
-          var sizeStr = prefStrBundle.getFormattedString("actualCacheSize",
-                                                          sizeStrings);
+          var sizeStr = prefStrBundle.getFormattedString(device == "disk" ?
+                                                         "actualDiskCacheSize" :
+                                                         "actualAppCacheSize",
+                                                         sizeStrings);
           actualSizeLabel.value = sizeStr;
         }
         // Do not enumerate entries
         return false;
       },
 
       visitEntry: function (deviceID, entryInfo)
       {
         // Do not enumerate entries.
         return false;
       }
     };
+
     var cacheService =
       Components.classes["@mozilla.org/network/cache-service;1"]
                 .getService(Components.interfaces.nsICacheService);
     cacheService.visitEntries(visitor);
   },
 
   updateCacheSizeUI: function (smartSizeEnabled)
   {
@@ -269,21 +275,33 @@ var gAdvancedPane = {
   },
 
   /**
    * Clears the cache.
    */
   clearCache: function ()
   {
     var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
-                         	       .getService(Components.interfaces.nsICacheService);
+                                 .getService(Components.interfaces.nsICacheService);
     try {
       cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE);
     } catch(ex) {}
-    this.updateActualCacheSize();
+    this.updateActualCacheSize("disk");
+  },
+
+  /**
+   * Clears the application cache.
+   */
+  clearOfflineAppCache: function ()
+  {
+    Components.utils.import("resource:///modules/offlineAppCache.jsm");
+    OfflineAppCacheHelper.clear();
+
+    this.updateActualCacheSize("offline");
+    this.updateOfflineApps();
   },
 
   readOfflineNotify: function()
   {
     var pref = document.getElementById("browser.offline-apps.notify");
     var button = document.getElementById("offlineNotifyExceptions");
     button.disabled = !pref.value;
     return pref.value;
@@ -427,16 +445,17 @@ var gAdvancedPane = {
                        .getService(Components.interfaces.nsIPermissionManager);
     pm.remove(host, "offline-app",
               Components.interfaces.nsIPermissionManager.ALLOW_ACTION);
     pm.remove(host, "offline-app",
               Components.interfaces.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
 
     list.removeChild(item);
     gAdvancedPane.offlineAppSelected();
+    this.updateActualCacheSize("offline");
   },
 
   // UPDATE TAB
 
   /*
    * Preferences:
    *
    * app.update.enabled
--- a/browser/components/preferences/advanced.xul
+++ b/browser/components/preferences/advanced.xul
@@ -229,22 +229,22 @@
             <hbox align="center">
               <description flex="1" control="connectionSettings">&connectionDesc.label;</description>
               <button id="connectionSettings" icon="network" label="&connectionSettings.label;"
                       accesskey="&connectionSettings.accesskey;"
                       oncommand="gAdvancedPane.showConnections();"/>
             </hbox>
           </groupbox>
 
-          <!-- Cache/Offline apps -->
-          <groupbox id="offlineGroup">
-            <caption label="&offlineStorage.label;"/>
- 
+          <!-- Cache -->
+          <groupbox id="cacheGroup">
+            <caption label="&httpCache.label;"/>
+
             <hbox align="center">
-              <label id="actualCacheSize" flex="1"/>
+              <label id="actualDiskCacheSize" flex="1"/>
               <button id="clearCacheButton" icon="clear"
                       label="&clearCacheNow.label;" accesskey="&clearCacheNow.accesskey;"
                       oncommand="gAdvancedPane.clearCache();"/>
             </hbox>
             <checkbox preference="browser.cache.disk.smart_size.enabled"
                       id="allowSmartSize" flex="1"
                       onsyncfrompreference="return gAdvancedPane.readSmartSizeEnabled();"
                       label="&overrideSmartCacheSize.label;" 
@@ -255,29 +255,41 @@
                      value="&limitCacheSizeBefore.label;"/>
               <textbox id="cacheSize" type="number" size="4" max="1024"
                        preference="browser.cache.disk.capacity"
                        onsyncfrompreference="return gAdvancedPane.readCacheSize();"
                        onsynctopreference="return gAdvancedPane.writeCacheSize();"
                        aria-labelledby="useCacheBefore cacheSize useCacheAfter"/>
               <label id="useCacheAfter" flex="1">&limitCacheSizeAfter.label;</label>
             </hbox>
+          </groupbox>
+
+          <!-- Offline apps -->
+          <groupbox id="offlineGroup">
+            <caption label="&offlineStorage2.label;"/>
+
+            <hbox align="center">
+              <label id="actualAppCacheSize" flex="1"/>
+              <button id="clearOfflineAppCacheButton" icon="clear"
+                      label="&clearOfflineAppCacheNow.label;" accesskey="&clearOfflineAppCacheNow.accesskey;"
+                      oncommand="gAdvancedPane.clearOfflineAppCache();"/>
+            </hbox>
             <hbox align="center">
               <checkbox id="offlineNotify" flex="1"
                         label="&offlineNotify.label;" accesskey="&offlineNotify.accesskey;"
                         preference="browser.offline-apps.notify"
                         onsyncfrompreference="return gAdvancedPane.readOfflineNotify();"/>
               <button id="offlineNotifyExceptions"
                       label="&offlineNotifyExceptions.label;"
                       accesskey="&offlineNotifyExceptions.accesskey;"
                       oncommand="gAdvancedPane.showOfflineExceptions();"/>
             </hbox>
             <hbox>
               <vbox flex="1">
-                <label id="offlineAppsListLabel">&offlineAppsList.label;</label>
+                <label id="offlineAppsListLabel">&offlineAppsList2.label;</label>
                 <listbox id="offlineAppsList"
                          style="height: &offlineAppsList.height;;"
                          flex="1"
                          aria-labelledby="offlineAppsListLabel"
                          onselect="gAdvancedPane.offlineAppSelected(event);">
                 </listbox>
               </vbox>
               <vbox pack="end">
--- a/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
+++ b/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
@@ -35,29 +35,33 @@
 <!ENTITY networkTab.label                "Network">
 
 <!ENTITY connection.label                "Connection">
 
 <!ENTITY connectionDesc.label            "Configure how &brandShortName; connects to the Internet">
 <!ENTITY connectionSettings.label        "Settings…">
 <!ENTITY connectionSettings.accesskey    "e">
 
-<!ENTITY offlineStorage.label            "Offline Storage">
+<!ENTITY httpCache.label                 "Cached Web Content">
+
+<!ENTITY offlineStorage2.label           "Offline Web Content and User Data">
 
 <!-- LOCALIZATION NOTE:
   The entities limitCacheSizeBefore.label and limitCacheSizeAfter.label appear on a single
   line in preferences as follows:
 
   &limitCacheSizeBefore.label [textbox for cache size in MB] &limitCacheSizeAfter.label;
 -->
 <!ENTITY limitCacheSizeBefore.label      "Limit cache to">
 <!ENTITY limitCacheSizeBefore.accesskey  "L">
 <!ENTITY limitCacheSizeAfter.label       "MB of space">
 <!ENTITY clearCacheNow.label             "Clear Now">
 <!ENTITY clearCacheNow.accesskey         "C">
+<!ENTITY clearOfflineAppCacheNow.label   "Clear Now">
+<!ENTITY clearOfflineAppCacheNow.accesskey "N">
 <!ENTITY overrideSmartCacheSize.label    "Override automatic cache management">
 <!ENTITY overrideSmartCacheSize.accesskey "O">
 
 <!ENTITY updateTab.label                 "Update">
 
 <!ENTITY updateApp.label                 "&brandShortName; updates:">
 <!ENTITY updateAuto.label                "Automatically install updates (recommended: improved security)">
 <!ENTITY updateAuto.accesskey            "A">
@@ -79,17 +83,17 @@
 <!ENTITY enableSearchUpdate.label        "Search Engines">
 <!ENTITY enableSearchUpdate.accesskey    "E">
 
 <!ENTITY offlineNotify.label             "Tell me when a website asks to store data for offline use">
 <!ENTITY offlineNotify.accesskey         "T">
 <!ENTITY offlineNotifyExceptions.label   "Exceptions…">
 <!ENTITY offlineNotifyExceptions.accesskey "x">
 
-<!ENTITY offlineAppsList.label           "The following websites have stored data for offline use:">
+<!ENTITY offlineAppsList2.label          "The following websites are allowed to store data for offline use:">
 <!ENTITY offlineAppsList.height          "7em">
 <!ENTITY offlineAppsListRemove.label     "Remove…">
 <!ENTITY offlineAppsListRemove.accesskey "R">
 <!ENTITY offlineAppRemove.confirm        "Remove offline data">
 
 <!ENTITY encryptionTab.label             "Encryption">
 
 <!ENTITY protocols.label                 "Protocols">
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -100,17 +100,24 @@ offlineAppRemoveConfirm=Remove offline d
 #   %1$S = size (in bytes or megabytes, ...)
 #   %2$S = unit of measure (bytes, KB, MB, ...)
 offlineAppUsage=%1$S %2$S
 
 offlinepermissionstext=The following websites are not allowed to store data for offline use:
 offlinepermissionstitle=Offline Data
 
 ####Preferences::Advanced::Network
-#LOCALIZATION NOTE: The next string is for the disk usage of the http cache.
-#   e.g., "Your cache is currently using 200 MB"
+#LOCALIZATION NOTE: The next string is for the disk usage of the web content cache.
+#   e.g., "Your web content cache is currently using 200 MB"
 #   %1$S = size
 #   %2$S = unit (MB, KB, etc.)
-actualCacheSize=Your cache is currently using %1$S %2$S of disk space
+actualDiskCacheSize=Your web content cache is currently using %1$S %2$S of disk space
+
+####Preferences::Advanced::Network
+#LOCALIZATION NOTE: The next string is for the disk usage of the application cache.
+#   e.g., "Your application cache is currently using 200 MB"
+#   %1$S = size
+#   %2$S = unit (MB, KB, etc.)
+actualAppCacheSize=Your application cache is currently using %1$S %2$S of disk space
 
 syncUnlink.title=Do you want to unlink your device?
 syncUnlink.label=This device will no longer be associated with your Sync account. All of your personal data, both on this device and in your Sync account, will remain intact.
 syncUnlinkConfirm.label=Unlink
--- a/browser/modules/Makefile.in
+++ b/browser/modules/Makefile.in
@@ -46,16 +46,17 @@ include $(topsrcdir)/config/config.mk
 
 ifdef ENABLE_TESTS
 DIRS += test
 endif
 
 EXTRA_JS_MODULES = \
 	openLocationLastURL.jsm \
 	NetworkPrioritizer.jsm \
+	offlineAppCache.jsm \
 	$(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows) 
 EXTRA_JS_MODULES += \
 	WindowsPreviewPerTab.jsm \
 	WindowsJumpLists.jsm \
 	$(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/browser/modules/offlineAppCache.jsm
@@ -0,0 +1,54 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Honza Bambas <honzab.moz@firemni.cz>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+ 
+let EXPORTED_SYMBOLS = ["OfflineAppCacheHelper"];
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+let OfflineAppCacheHelper = {
+  clear: function() {
+    var cacheService = Cc["@mozilla.org/network/cache-service;1"].
+                       getService(Ci.nsICacheService);
+    try {
+      cacheService.evictEntries(Ci.nsICache.STORE_OFFLINE);
+    } catch(er) {}
+
+    var storageManagerService = Cc["@mozilla.org/dom/storagemanager;1"].
+                                getService(Ci.nsIDOMStorageManager);
+    storageManagerService.clearOfflineApps();
+  }
+};