Bug 709013 - Handle the MozApplicationManifest event in b2g/. r=cjones
authorVivien Nicolas <21@vingtetun.org>
Wed, 14 Dec 2011 11:17:51 +0100
changeset 84530 c7ffe35493891b03a83cd6326910d17e21460baa
parent 84529 7c621c7bfea34f5a9ec5eb09b23c5ae7be1c8294
child 84531 ffea93b21d4d78de21b1ba5e6933698cbd6a6480
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)
reviewerscjones
bugs709013
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 709013 - Handle the MozApplicationManifest event in b2g/. r=cjones
b2g/app/b2g.js
b2g/chrome/content/shell.js
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -60,21 +60,17 @@ pref("browser.cache.disk.smart_size.firs
 
 pref("browser.cache.memory.enable", true);
 pref("browser.cache.memory.capacity", 1024); // kilobytes
 
 /* image cache prefs */
 pref("image.cache.size", 1048576); // bytes
 
 /* offline cache prefs */
-pref("browser.offline-apps.notify", true);
-pref("browser.cache.offline.enable", true);
-pref("browser.cache.offline.capacity", 5120); // kilobytes
-pref("offline-apps.quota.max", 2048); // kilobytes
-pref("offline-apps.quota.warn", 1024); // kilobytes
+pref("browser.offline-apps.notify", false);
 
 /* protocol warning prefs */
 pref("network.protocol-handler.warn-external.tel", false);
 pref("network.protocol-handler.warn-external.mailto", false);
 pref("network.protocol-handler.warn-external.vnd.youtube", false);
 
 /* http prefs */
 pref("network.http.pipelining", true);
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -63,16 +63,17 @@ XPCOMUtils.defineLazyGetter(Services, 'f
 // a local http server listening on http://127.0.0.1:8888 and
 // http://localhost:8888.
 function startupHttpd(baseDir, port) {
   const httpdURL = 'chrome://browser/content/httpd.js';
   let httpd = {};
   Services.scriptloader.loadSubScript(httpdURL, httpd);
   let server = new httpd.nsHttpServer();
   server.registerDirectory('/', new LocalFile(baseDir));
+  server.registerContentType('appcache', 'text/cache-manifest');
   server.start(port);
 }
 
 // XXX until we have a security model, just let the pre-installed
 // app used indexedDB.
 function allowIndexedDB(url) {
   let uri = Services.io.newURI(url, null, null);
   Services.perms.add(uri, 'indexedDB', Ci.nsIPermissionManager.ALLOW_ACTION);
@@ -109,16 +110,17 @@ var shell = {
     let homeURL = this.homeURL;
     if (!homeURL) {
       let msg = 'Fatal error during startup: [No homescreen found]';
       return alert(msg);
     }
 
     window.controllers.appendController(this);
     window.addEventListener('keypress', this);
+    window.addEventListener('MozApplicationManifest', this);
     this.home.addEventListener('load', this, true);
 
     try {
       Services.io.offline = false;
 
       let fileScheme = 'file://';
       if (homeURL.substring(0, fileScheme.length) == fileScheme) {
         homeURL = homeURL.replace(fileScheme, '');
@@ -142,16 +144,17 @@ var shell = {
     let browser = this.home;
     browser.homePage = homeURL;
     browser.goHome();
   },
 
   stop: function shell_stop() {
     window.controllers.removeController(this);
     window.removeEventListener('keypress', this);
+    window.removeEventListener('MozApplicationManifest', this);
   },
 
   supportsCommand: function shell_supportsCommand(cmd) {
     let isSupported = false;
     switch (cmd) {
       case 'cmd_close':
         isSupported = true;
         break;
@@ -190,16 +193,39 @@ var shell = {
             this.doCommand('cmd_close');
             break;
         }
         break;
       case 'load':
         this.home.removeEventListener('load', this, true);
         this.sendEvent(window, 'ContentStart');
         break;
+      case 'MozApplicationManifest':
+        try {
+          let contentWindow = evt.originalTarget.defaultView;
+          let documentElement = contentWindow.document.documentElement;
+          if (!documentElement)
+            return;
+
+          let manifest = documentElement.getAttribute("manifest");
+          if (!manifest)
+            return;
+
+          let documentURI = contentWindow.document.documentURIObject;
+          let manifestURI = Services.io.newURI(manifest, null, documentURI);
+          Services.perms.add(documentURI, 'offline-app',
+                             Ci.nsIPermissionManager.ALLOW_ACTION);
+
+          let updateService = Cc['@mozilla.org/offlinecacheupdate-service;1']
+                              .getService(Ci.nsIOfflineCacheUpdateService);
+          updateService.scheduleUpdate(manifestURI, documentURI, window);
+        } catch (e) {
+          dump('Error while creating offline cache: ' + e + '\n');
+        }
+        break;
     }
   },
   sendEvent: function shell_sendEvent(content, type, details) {
     let event = content.document.createEvent('CustomEvent');
     event.initCustomEvent(type, true, true, details ? details : {});
     content.dispatchEvent(event);
   }
 };