diff --git a/mobile/android/components/BrowserCLH.js b/mobile/android/components/BrowserCLH.js index fa730fe7eb61..a51d4f09c45d 100644 --- a/mobile/android/components/BrowserCLH.js +++ b/mobile/android/components/BrowserCLH.js @@ -119,8 +119,33 @@ BrowserCLH.prototype = { } }, + /** + * Register resource://android as the APK root. + * + * Consumers can access Android assets using resource://android/assets/FILENAME. + */ + setResourceSubstitutions: function () { + let registry = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci["nsIChromeRegistry"]); + // Like jar:jar:file:///data/app/org.mozilla.fennec-2.apk!/assets/omni.ja!/chrome/chrome/content/aboutHome.xhtml + let url = registry.convertChromeURL(Services.io.newURI("chrome://browser/content/aboutHome.xhtml", null, null)).spec; + // Like jar:file:///data/app/org.mozilla.fennec-2.apk!/ + url = url.substring(4, url.indexOf("!/") + 2); + + let protocolHandler = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler); + protocolHandler.setSubstitution("android", Services.io.newURI(url, null, null)); + }, + + observe: function (subject, topic, data) { + switch (topic) { + case "app-startup": + this.setResourceSubstitutions(); + break; + } + }, + // QI - QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), + QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler, + Ci.nsIObserver]), // XPCOMUtils factory classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}") diff --git a/mobile/android/components/MobileComponents.manifest b/mobile/android/components/MobileComponents.manifest index 75d4622d2741..1da13011525d 100644 --- a/mobile/android/components/MobileComponents.manifest +++ b/mobile/android/components/MobileComponents.manifest @@ -66,6 +66,7 @@ category wakeup-request PromptService @mozilla.org/embedcomp/prompt-service;1,ns component {be623d20-d305-11de-8a39-0800200c9a66} BrowserCLH.js application={aa3c5121-dab2-40e2-81ca-7ea25febc110} contract @mozilla.org/browser/browser-clh;1 {be623d20-d305-11de-8a39-0800200c9a66} category command-line-handler x-browser @mozilla.org/browser/browser-clh;1 +category app-startup BrowserCLH @mozilla.org/browser/browser-clh;1 # ContentDispatchChooser.js component {5a072a22-1e66-4100-afc1-07aed8b62fc5} ContentDispatchChooser.js