diff --git a/b2g/chrome/content/shell.js b/b2g/chrome/content/shell.js index 18747463440..89b6001f5b8 100644 --- a/b2g/chrome/content/shell.js +++ b/b2g/chrome/content/shell.js @@ -84,6 +84,10 @@ var shell = { return Services.prefs.getCharPref('browser.homescreenURL'); }, + get manifestURL() { + return Services.prefs.getCharPref('browser.manifestURL'); + }, + start: function shell_start() { let homeURL = this.homeURL; if (!homeURL) { @@ -92,6 +96,21 @@ var shell = { return; } + let manifestURL = this.manifestURL; + // + let browserFrame = + document.createElementNS('http://www.w3.org/1999/xhtml', 'html:iframe'); + browserFrame.setAttribute('id', 'homescreen'); + browserFrame.setAttribute('mozbrowser', 'true'); + browserFrame.setAttribute('mozapp', manifestURL); + browserFrame.setAttribute('mozallowfullscreen', 'true'); + browserFrame.setAttribute('style', "overflow: hidden; -moz-box-flex: 1; border: none;"); + browserFrame.setAttribute('src', "data:text/html;charset=utf-8,%3C!DOCTYPE html>%3Cbody style='background:black;"); + document.getElementById('shell').appendChild(browserFrame); + ['keydown', 'keypress', 'keyup'].forEach((function listenKey(type) { window.addEventListener(type, this, false, true); window.addEventListener(type, this, true, true); @@ -100,7 +119,7 @@ var shell = { window.addEventListener('MozApplicationManifest', this); window.addEventListener('mozfullscreenchange', this); window.addEventListener('sizemodechange', this); - this.contentBrowser.addEventListener('load', this, true); + this.contentBrowser.addEventListener('mozbrowserloadstart', this, true); // Until the volume can be set from the content side, set it to a // a specific value when the device starts. This way the front-end @@ -120,14 +139,6 @@ var shell = { addPermissions(domains.split(",")); - // Load webapi.js as a frame script - let webapiUrl = 'chrome://browser/content/webapi.js'; - try { - messageManager.loadFrameScript(webapiUrl, true); - } catch (e) { - dump('shell.js: Error loading ' + webapiUrl + ' as a frame script: ' + e + '\n'); - } - CustomEventManager.init(); WebappsHelper.init(); @@ -140,9 +151,7 @@ var shell = { Services.prefs.setBoolPref("nglayout.debug.paint_flashing", value); }); - let browser = this.contentBrowser; - browser.homePage = homeURL; - browser.goHome(); + this.contentBrowser.src = homeURL; }, stop: function shell_stop() { @@ -151,11 +160,10 @@ var shell = { window.removeEventListener(type, this, true, true); }).bind(this)); - window.addEventListener('MozApplicationManifest', this); window.removeEventListener('MozApplicationManifest', this); window.removeEventListener('mozfullscreenchange', this); window.removeEventListener('sizemodechange', this); - this.contentBrowser.removeEventListener('load', this, true); + this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true); #ifndef MOZ_WIDGET_GONK delete Services.audioManager; @@ -186,6 +194,7 @@ var shell = { }, forwardKeyToContent: function shell_forwardKeyToContent(evt) { + let content = shell.contentBrowser.contentWindow; let generatedEvent = content.document.createEvent('KeyboardEvent'); generatedEvent.initKeyEvent(evt.type, true, true, evt.view, evt.ctrlKey, evt.altKey, evt.shiftKey, evt.metaKey, @@ -195,6 +204,7 @@ var shell = { }, handleEvent: function shell_handleEvent(evt) { + let content = this.contentBrowser.contentWindow; switch (evt.type) { case 'keydown': case 'keyup': @@ -233,13 +243,13 @@ var shell = { break; case 'sizemodechange': if (window.windowState == window.STATE_MINIMIZED) { - this.contentBrowser.docShell.isActive = false; + this.contentBrowser.setVisible(false); } else { - this.contentBrowser.docShell.isActive = true; + this.contentBrowser.setVisible(true); } break; - case 'load': - this.contentBrowser.removeEventListener('load', this, true); + case 'mozbrowserloadstart': + this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true); let chromeWindow = window.QueryInterface(Ci.nsIDOMChromeWindow); chromeWindow.browserDOMWindow = new nsBrowserAccess(); @@ -297,6 +307,7 @@ nsBrowserAccess.prototype = { openURI: function openURI(uri, opener, where, context) { // TODO This should be replaced by an 'open-browser-window' intent + let content = shell.contentBrowser.contentWindow; let contentWindow = content.wrappedJSObject; if (!('getApplicationManager' in contentWindow)) return null; @@ -368,6 +379,7 @@ nsBrowserAccess.prototype = { var CustomEventManager = { init: function custevt_init() { window.addEventListener("ContentStart", (function(evt) { + let content = shell.contentBrowser.contentWindow; content.addEventListener("mozContentEvent", this, false, true); }).bind(this), false); }, @@ -418,6 +430,7 @@ var AlertsHelper = { showAlertNotification: function alert_showAlertNotification(imageUrl, title, text, textClickable, cookie, alertListener, name) { let id = this.registerListener(cookie, alertListener); + let content = shell.contentBrowser.contentWindow; shell.sendEvent(content, "mozChromeEvent", { type: "desktop-notification", id: id, icon: imageUrl, title: title, text: text } ); } @@ -454,6 +467,7 @@ var WebappsHelper = { }, observe: function webapps_observe(subject, topic, data) { + let content = shell.contentBrowser.contentWindow; let json = JSON.parse(data); switch(topic) { case "webapps-launch": @@ -576,6 +590,7 @@ window.addEventListener('ContentStart', function(evt) { // detail.type set to 'saved-screenshot' and detail.filename set to // the filename. window.addEventListener('ContentStart', function ss_onContentStart() { + let content = shell.contentBrowser.contentWindow; content.addEventListener('mozContentEvent', function ss_onMozContentEvent(e) { if (e.detail.type !== 'save-screenshot') return; diff --git a/b2g/chrome/content/shell.xul b/b2g/chrome/content/shell.xul index 080dc817cbe..551604b8f08 100644 --- a/b2g/chrome/content/shell.xul +++ b/b2g/chrome/content/shell.xul @@ -16,15 +16,10 @@