From b63b53aa1f30664da1fe81df6f8e61ec3aa87de9 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Wed, 14 Dec 2011 11:17:51 +0100 Subject: [PATCH] Bug 709013 - Handle the MozApplicationManifest event in b2g/. r=cjones --HG-- extra : rebase_source : 56149e16c771d1aa40f9ecc6edfdbab0be8b145d --- b2g/app/b2g.js | 6 +----- b2g/chrome/content/shell.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 230de4f418da..c9b7c7ab2241 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -65,11 +65,7 @@ pref("browser.cache.memory.capacity", 1024); // kilobytes 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); diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 0e7f83c6c772..01996bb115e7 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -68,6 +68,7 @@ function startupHttpd(baseDir, port) { Services.scriptloader.loadSubScript(httpdURL, httpd); let server = new httpd.nsHttpServer(); server.registerDirectory('/', new LocalFile(baseDir)); + server.registerContentType('appcache', 'text/cache-manifest'); server.start(port); } @@ -114,6 +115,7 @@ var shell = { window.controllers.appendController(this); window.addEventListener('keypress', this); + window.addEventListener('MozApplicationManifest', this); this.home.addEventListener('load', this, true); try { @@ -147,6 +149,7 @@ var shell = { stop: function shell_stop() { window.controllers.removeController(this); window.removeEventListener('keypress', this); + window.removeEventListener('MozApplicationManifest', this); }, supportsCommand: function shell_supportsCommand(cmd) { @@ -195,6 +198,29 @@ var shell = { 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) {