2012-01-05 17:04:03 -08:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
2012-02-08 04:37:00 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-06 15:52:26 -08:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
2012-02-17 13:37:53 -08:00
|
|
|
const Cr = Components.results;
|
2011-12-06 15:52:26 -08:00
|
|
|
|
2011-12-08 17:16:03 -08:00
|
|
|
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
|
|
|
Cu.import('resource://gre/modules/Services.jsm');
|
2012-02-28 14:01:48 -08:00
|
|
|
Cu.import('resource://gre/modules/ContactService.jsm');
|
2012-06-04 16:12:24 -07:00
|
|
|
Cu.import('resource://gre/modules/SettingsChangeNotifier.jsm');
|
2012-03-16 15:23:28 -07:00
|
|
|
Cu.import('resource://gre/modules/Webapps.jsm');
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2012-05-04 11:02:05 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(Services, 'env',
|
|
|
|
'@mozilla.org/process/environment;1',
|
|
|
|
'nsIEnvironment');
|
2012-02-01 16:46:50 -08:00
|
|
|
|
2012-05-04 11:02:05 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(Services, 'ss',
|
|
|
|
'@mozilla.org/content/style-sheet-service;1',
|
|
|
|
'nsIStyleSheetService');
|
2012-02-17 13:37:53 -08:00
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-05-04 11:02:05 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(Services, 'audioManager',
|
|
|
|
'@mozilla.org/telephony/audiomanager;1',
|
|
|
|
'nsIAudioManager');
|
2012-04-11 10:05:35 -07:00
|
|
|
#else
|
2012-05-04 11:02:05 -07:00
|
|
|
Services.audioManager = {
|
|
|
|
'masterVolume': 0
|
|
|
|
};
|
2012-04-11 10:05:35 -07:00
|
|
|
#endif
|
2012-02-23 16:40:49 -08:00
|
|
|
|
2012-05-04 11:02:05 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(Services, 'fm',
|
|
|
|
'@mozilla.org/focus-manager;1',
|
|
|
|
'nsIFocusManager');
|
2012-03-02 15:32:46 -08:00
|
|
|
|
2012-03-16 09:50:45 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, 'DebuggerServer', function() {
|
|
|
|
Cu.import('resource://gre/modules/devtools/dbg-server.jsm');
|
|
|
|
return DebuggerServer;
|
|
|
|
});
|
|
|
|
|
2011-12-14 12:02:48 -08:00
|
|
|
// FIXME Bug 707625
|
|
|
|
// until we have a proper security model, add some rights to
|
2012-02-01 16:46:49 -08:00
|
|
|
// the pre-installed web applications
|
2012-02-06 22:48:50 -08:00
|
|
|
// XXX never grant 'content-camera' to non-gaia apps
|
2011-12-14 12:02:48 -08:00
|
|
|
function addPermissions(urls) {
|
2011-12-26 06:07:41 -08:00
|
|
|
let permissions = [
|
2012-04-04 17:55:08 -07:00
|
|
|
'indexedDB', 'indexedDB-unlimited', 'webapps-manage', 'offline-app', 'pin-app',
|
2012-03-26 14:49:38 -07:00
|
|
|
'websettings-read', 'websettings-readwrite',
|
2012-03-21 22:26:01 -07:00
|
|
|
'content-camera', 'webcontacts-manage', 'wifi-manage', 'desktop-notification',
|
2012-07-03 03:23:54 -07:00
|
|
|
'geolocation', 'device-storage'
|
2011-12-26 06:07:41 -08:00
|
|
|
];
|
2011-12-14 12:02:48 -08:00
|
|
|
urls.forEach(function(url) {
|
2012-03-23 16:39:15 -07:00
|
|
|
url = url.trim();
|
2011-12-14 12:02:48 -08:00
|
|
|
let uri = Services.io.newURI(url, null, null);
|
|
|
|
let allow = Ci.nsIPermissionManager.ALLOW_ACTION;
|
2012-02-01 16:46:49 -08:00
|
|
|
|
2011-12-14 12:02:48 -08:00
|
|
|
permissions.forEach(function(permission) {
|
|
|
|
Services.perms.add(uri, permission, allow);
|
|
|
|
});
|
|
|
|
});
|
2011-12-08 17:16:03 -08:00
|
|
|
}
|
|
|
|
|
2011-12-06 15:52:26 -08:00
|
|
|
var shell = {
|
2012-02-01 16:46:50 -08:00
|
|
|
get contentBrowser() {
|
|
|
|
delete this.contentBrowser;
|
|
|
|
return this.contentBrowser = document.getElementById('homescreen');
|
2011-12-06 15:52:26 -08:00
|
|
|
},
|
|
|
|
|
2011-12-08 17:16:03 -08:00
|
|
|
get homeURL() {
|
2011-12-06 15:52:26 -08:00
|
|
|
try {
|
2011-12-08 17:16:03 -08:00
|
|
|
let homeSrc = Services.env.get('B2G_HOMESCREEN');
|
2011-12-06 15:52:26 -08:00
|
|
|
if (homeSrc)
|
|
|
|
return homeSrc;
|
|
|
|
} catch (e) {}
|
|
|
|
|
2012-03-23 16:39:15 -07:00
|
|
|
return Services.prefs.getCharPref('browser.homescreenURL');
|
2011-12-06 15:52:26 -08:00
|
|
|
},
|
|
|
|
|
2012-06-20 12:25:23 -07:00
|
|
|
get manifestURL() {
|
|
|
|
return Services.prefs.getCharPref('browser.manifestURL');
|
|
|
|
},
|
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
start: function shell_start() {
|
2011-12-08 17:16:03 -08:00
|
|
|
let homeURL = this.homeURL;
|
|
|
|
if (!homeURL) {
|
2012-03-21 15:50:53 -07:00
|
|
|
let msg = 'Fatal error during startup: No homescreen found: try setting B2G_HOMESCREEN';
|
2012-04-11 10:05:35 -07:00
|
|
|
alert(msg);
|
|
|
|
return;
|
2011-12-08 17:16:03 -08:00
|
|
|
}
|
|
|
|
|
2012-06-20 12:25:23 -07:00
|
|
|
let manifestURL = this.manifestURL;
|
|
|
|
// <html:iframe id="homescreen"
|
|
|
|
// mozbrowser="true" mozallowfullscreen="true"
|
|
|
|
// style="overflow: hidden; -moz-box-flex: 1; border: none;"
|
|
|
|
// src="data:text/html;charset=utf-8,%3C!DOCTYPE html>%3Cbody style='background:black;'>"/>
|
|
|
|
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);
|
|
|
|
|
2012-06-26 08:18:10 -07:00
|
|
|
browserFrame.contentWindow
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.sessionHistory = Cc["@mozilla.org/browser/shistory;1"]
|
|
|
|
.createInstance(Ci.nsISHistory);
|
|
|
|
|
2012-03-05 10:09:05 -08:00
|
|
|
['keydown', 'keypress', 'keyup'].forEach((function listenKey(type) {
|
|
|
|
window.addEventListener(type, this, false, true);
|
|
|
|
window.addEventListener(type, this, true, true);
|
|
|
|
}).bind(this));
|
|
|
|
|
2011-12-14 02:17:51 -08:00
|
|
|
window.addEventListener('MozApplicationManifest', this);
|
2012-02-17 13:37:53 -08:00
|
|
|
window.addEventListener('mozfullscreenchange', this);
|
2012-04-04 23:03:00 -07:00
|
|
|
window.addEventListener('sizemodechange', this);
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.addEventListener('mozbrowserloadstart', this, true);
|
2011-12-06 15:52:26 -08:00
|
|
|
|
2012-03-05 10:09:05 -08:00
|
|
|
// 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
|
|
|
|
// can display a notification when the volume change and show a volume
|
|
|
|
// level modified from this point.
|
2012-04-18 10:42:20 -07:00
|
|
|
// try catch block must be used since the emulator fails here. bug 746429
|
|
|
|
try {
|
|
|
|
Services.audioManager.masterVolume = 0.5;
|
|
|
|
} catch(e) {
|
|
|
|
dump('Error setting master volume: ' + e + '\n');
|
|
|
|
}
|
2012-03-05 10:09:05 -08:00
|
|
|
|
2012-03-23 16:39:15 -07:00
|
|
|
let domains = "";
|
2011-12-08 17:16:03 -08:00
|
|
|
try {
|
2012-03-23 16:39:15 -07:00
|
|
|
domains = Services.prefs.getCharPref('b2g.privileged.domains');
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
addPermissions(domains.split(","));
|
2011-12-06 15:52:26 -08:00
|
|
|
|
2012-03-16 15:23:28 -07:00
|
|
|
CustomEventManager.init();
|
2012-03-16 15:23:28 -07:00
|
|
|
WebappsHelper.init();
|
|
|
|
|
2012-06-18 10:41:09 -07:00
|
|
|
// XXX could factor out into a settings->pref map. Not worth it yet.
|
|
|
|
SettingsListener.observe("debug.fps.enabled", false, function(value) {
|
|
|
|
Services.prefs.setBoolPref("layers.acceleration.draw-fps", value);
|
|
|
|
});
|
|
|
|
SettingsListener.observe("debug.paint-flashing.enabled", false, function(value) {
|
|
|
|
Services.prefs.setBoolPref("nglayout.debug.paint_flashing", value);
|
|
|
|
});
|
|
|
|
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.src = homeURL;
|
2011-12-06 15:52:26 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
stop: function shell_stop() {
|
2012-05-04 11:02:05 -07:00
|
|
|
['keydown', 'keypress', 'keyup'].forEach((function unlistenKey(type) {
|
|
|
|
window.removeEventListener(type, this, false, true);
|
|
|
|
window.removeEventListener(type, this, true, true);
|
|
|
|
}).bind(this));
|
|
|
|
|
2011-12-14 02:17:51 -08:00
|
|
|
window.removeEventListener('MozApplicationManifest', this);
|
2012-03-05 10:09:05 -08:00
|
|
|
window.removeEventListener('mozfullscreenchange', this);
|
2012-04-04 23:03:00 -07:00
|
|
|
window.removeEventListener('sizemodechange', this);
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true);
|
2012-05-04 11:02:05 -07:00
|
|
|
|
|
|
|
#ifndef MOZ_WIDGET_GONK
|
|
|
|
delete Services.audioManager;
|
|
|
|
#endif
|
2011-12-06 15:52:26 -08:00
|
|
|
},
|
2012-06-30 18:42:10 -07:00
|
|
|
|
2012-03-05 10:09:05 -08:00
|
|
|
changeVolume: function shell_changeVolume(delta) {
|
2012-02-16 10:20:23 -08:00
|
|
|
let steps = 10;
|
|
|
|
try {
|
|
|
|
steps = Services.prefs.getIntPref("media.volume.steps");
|
|
|
|
if (steps <= 0)
|
|
|
|
steps = 1;
|
|
|
|
} catch(e) {}
|
|
|
|
|
2012-03-05 10:09:05 -08:00
|
|
|
let audioManager = Services.audioManager;
|
|
|
|
if (!audioManager)
|
|
|
|
return;
|
|
|
|
|
2012-05-21 14:02:00 -07:00
|
|
|
let currentVolume = audioManager.masterVolume;
|
|
|
|
let newStep = Math.round(steps * Math.sqrt(currentVolume)) + delta;
|
|
|
|
let volume = (newStep / steps) * (newStep / steps);
|
|
|
|
|
2012-02-16 10:20:23 -08:00
|
|
|
if (volume > 1)
|
|
|
|
volume = 1;
|
|
|
|
if (volume < 0)
|
|
|
|
volume = 0;
|
|
|
|
audioManager.masterVolume = volume;
|
|
|
|
},
|
2012-02-08 12:43:49 -08:00
|
|
|
|
2012-06-06 19:18:29 -07:00
|
|
|
forwardKeyToContent: function shell_forwardKeyToContent(evt) {
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-03-05 10:09:05 -08:00
|
|
|
let generatedEvent = content.document.createEvent('KeyboardEvent');
|
|
|
|
generatedEvent.initKeyEvent(evt.type, true, true, evt.view, evt.ctrlKey,
|
|
|
|
evt.altKey, evt.shiftKey, evt.metaKey,
|
|
|
|
evt.keyCode, evt.charCode);
|
|
|
|
|
2012-06-06 19:18:29 -07:00
|
|
|
content.document.documentElement.dispatchEvent(generatedEvent);
|
2012-03-05 10:09:05 -08:00
|
|
|
},
|
|
|
|
|
2011-12-06 15:52:26 -08:00
|
|
|
handleEvent: function shell_handleEvent(evt) {
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = this.contentBrowser.contentWindow;
|
2011-12-06 15:52:26 -08:00
|
|
|
switch (evt.type) {
|
2012-03-05 10:09:05 -08:00
|
|
|
case 'keydown':
|
|
|
|
case 'keyup':
|
2011-12-06 15:52:26 -08:00
|
|
|
case 'keypress':
|
2012-03-05 10:09:05 -08:00
|
|
|
// For debug purposes and because some of the APIs are not yet exposed
|
|
|
|
// to the content, let's react on some of the keyup events.
|
2012-06-06 19:18:29 -07:00
|
|
|
if (evt.type == 'keyup' && evt.eventPhase == evt.BUBBLING_PHASE) {
|
2012-03-05 10:09:05 -08:00
|
|
|
switch (evt.keyCode) {
|
|
|
|
case evt.DOM_VK_PAGE_DOWN:
|
|
|
|
this.changeVolume(-1);
|
|
|
|
break;
|
2012-06-25 23:42:45 -07:00
|
|
|
|
2012-03-05 10:09:05 -08:00
|
|
|
case evt.DOM_VK_PAGE_UP:
|
|
|
|
this.changeVolume(1);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-07 21:22:34 -08:00
|
|
|
}
|
2012-06-06 19:18:29 -07:00
|
|
|
|
|
|
|
// Redirect the HOME key to System app and stop the applications from
|
|
|
|
// handling it.
|
|
|
|
let rootContentEvt = (evt.target.ownerDocument.defaultView == content);
|
|
|
|
if (!rootContentEvt && evt.eventPhase == evt.CAPTURING_PHASE &&
|
|
|
|
evt.keyCode == evt.DOM_VK_HOME) {
|
|
|
|
this.forwardKeyToContent(evt);
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopImmediatePropagation();
|
|
|
|
}
|
2012-02-07 21:22:34 -08:00
|
|
|
break;
|
2012-02-17 13:37:53 -08:00
|
|
|
|
|
|
|
case 'mozfullscreenchange':
|
|
|
|
// When the screen goes fullscreen make sure to set the focus to the
|
|
|
|
// main window so noboby can prevent the ESC key to get out fullscreen
|
|
|
|
// mode
|
|
|
|
if (document.mozFullScreen)
|
|
|
|
Services.fm.focusedWindow = window;
|
|
|
|
break;
|
2012-04-04 23:03:00 -07:00
|
|
|
case 'sizemodechange':
|
|
|
|
if (window.windowState == window.STATE_MINIMIZED) {
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.setVisible(false);
|
2012-04-04 23:03:00 -07:00
|
|
|
} else {
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.setVisible(true);
|
2012-04-04 23:03:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2012-06-20 12:25:23 -07:00
|
|
|
case 'mozbrowserloadstart':
|
2012-06-25 23:42:45 -07:00
|
|
|
if (content.document.location == 'about:blank')
|
|
|
|
return;
|
|
|
|
|
2012-06-20 12:25:23 -07:00
|
|
|
this.contentBrowser.removeEventListener('mozbrowserloadstart', this, true);
|
2012-02-01 16:46:49 -08:00
|
|
|
|
|
|
|
let chromeWindow = window.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
chromeWindow.browserDOMWindow = new nsBrowserAccess();
|
|
|
|
|
2011-12-06 15:52:26 -08:00
|
|
|
this.sendEvent(window, 'ContentStart');
|
|
|
|
break;
|
2011-12-14 02:17:51 -08:00
|
|
|
case 'MozApplicationManifest':
|
|
|
|
try {
|
2011-12-14 12:02:48 -08:00
|
|
|
if (!Services.prefs.getBoolPref('browser.cache.offline.enable'))
|
|
|
|
return;
|
|
|
|
|
2011-12-14 02:17:51 -08:00
|
|
|
let contentWindow = evt.originalTarget.defaultView;
|
|
|
|
let documentElement = contentWindow.document.documentElement;
|
|
|
|
if (!documentElement)
|
|
|
|
return;
|
|
|
|
|
2012-02-01 16:46:49 -08:00
|
|
|
let manifest = documentElement.getAttribute('manifest');
|
2011-12-14 02:17:51 -08:00
|
|
|
if (!manifest)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let documentURI = contentWindow.document.documentURIObject;
|
2011-12-14 12:02:48 -08:00
|
|
|
if (!Services.perms.testPermission(documentURI, 'offline-app')) {
|
|
|
|
if (Services.prefs.getBoolPref('browser.offline-apps.notify')) {
|
|
|
|
// FIXME Bug 710729 - Add a UI for offline cache notifications
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-14 02:17:51 -08:00
|
|
|
Services.perms.add(documentURI, 'offline-app',
|
|
|
|
Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
|
2011-12-14 12:02:48 -08:00
|
|
|
let manifestURI = Services.io.newURI(manifest, null, documentURI);
|
2011-12-14 02:17:51 -08:00
|
|
|
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;
|
2011-12-06 15:52:26 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
sendEvent: function shell_sendEvent(content, type, details) {
|
|
|
|
let event = content.document.createEvent('CustomEvent');
|
|
|
|
event.initCustomEvent(type, true, true, details ? details : {});
|
|
|
|
content.dispatchEvent(event);
|
2012-02-01 16:46:49 -08:00
|
|
|
}
|
2011-12-06 15:52:26 -08:00
|
|
|
};
|
|
|
|
|
2012-02-01 16:46:49 -08:00
|
|
|
function nsBrowserAccess() {
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBrowserAccess.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow]),
|
|
|
|
|
|
|
|
openURI: function openURI(uri, opener, where, context) {
|
|
|
|
// TODO This should be replaced by an 'open-browser-window' intent
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-02-01 16:46:49 -08:00
|
|
|
let contentWindow = content.wrappedJSObject;
|
|
|
|
if (!('getApplicationManager' in contentWindow))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let applicationManager = contentWindow.getApplicationManager();
|
|
|
|
if (!applicationManager)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
let url = uri ? uri.spec : 'about:blank';
|
|
|
|
let window = applicationManager.launch(url, where);
|
|
|
|
return window.contentWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
openURIInFrame: function openURIInFrame(uri, opener, where, context) {
|
|
|
|
throw new Error('Not Implemented');
|
|
|
|
},
|
|
|
|
|
|
|
|
isTabContentWindow: function isTabContentWindow(contentWindow) {
|
|
|
|
return contentWindow == window;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-02 17:16:55 -07:00
|
|
|
// Listen for system messages and relay them to Gaia.
|
|
|
|
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
|
|
|
let msg = JSON.parse(aData);
|
|
|
|
let origin = Services.io.newURI(msg.manifest, null, null).prePath;
|
|
|
|
shell.sendEvent(shell.contentBrowser.contentWindow,
|
|
|
|
"mozChromeEvent", { type: "open-app",
|
|
|
|
url: msg.uri,
|
|
|
|
origin: origin,
|
|
|
|
manifest: msg.manifest } );
|
|
|
|
}, "system-messages-open-app", false);
|
|
|
|
|
2012-02-17 13:37:53 -08:00
|
|
|
(function Repl() {
|
|
|
|
if (!Services.prefs.getBoolPref('b2g.remote-js.enabled')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const prompt = 'JS> ';
|
|
|
|
let output;
|
|
|
|
let reader = {
|
|
|
|
onInputStreamReady : function repl_readInput(input) {
|
|
|
|
let sin = Cc['@mozilla.org/scriptableinputstream;1']
|
|
|
|
.createInstance(Ci.nsIScriptableInputStream);
|
|
|
|
sin.init(input);
|
|
|
|
try {
|
|
|
|
let val = eval(sin.read(sin.available()));
|
|
|
|
let ret = (typeof val === 'undefined') ? 'undefined\n' : val + '\n';
|
|
|
|
output.write(ret, ret.length);
|
|
|
|
// TODO: check if socket has been closed
|
|
|
|
} catch (e) {
|
|
|
|
if (e.result === Cr.NS_BASE_STREAM_CLOSED ||
|
|
|
|
(typeof e === 'object' && e.result === Cr.NS_BASE_STREAM_CLOSED)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let message = (typeof e === 'object') ? e.message + '\n' : e + '\n';
|
|
|
|
output.write(message, message.length);
|
|
|
|
}
|
|
|
|
output.write(prompt, prompt.length);
|
|
|
|
input.asyncWait(reader, 0, 0, Services.tm.mainThread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let listener = {
|
|
|
|
onSocketAccepted: function repl_acceptConnection(serverSocket, clientSocket) {
|
|
|
|
dump('Accepted connection on ' + clientSocket.host + '\n');
|
|
|
|
let input = clientSocket.openInputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0)
|
|
|
|
.QueryInterface(Ci.nsIAsyncInputStream);
|
|
|
|
output = clientSocket.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
|
|
|
|
output.write(prompt, prompt.length);
|
|
|
|
input.asyncWait(reader, 0, 0, Services.tm.mainThread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let serverPort = Services.prefs.getIntPref('b2g.remote-js.port');
|
|
|
|
let serverSocket = Cc['@mozilla.org/network/server-socket;1']
|
|
|
|
.createInstance(Ci.nsIServerSocket);
|
|
|
|
serverSocket.init(serverPort, true, -1);
|
|
|
|
dump('Opened socket on ' + serverSocket.port + '\n');
|
|
|
|
serverSocket.asyncListen(listener);
|
|
|
|
})();
|
2012-02-17 13:37:53 -08:00
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
var CustomEventManager = {
|
2012-03-16 15:23:28 -07:00
|
|
|
init: function custevt_init() {
|
|
|
|
window.addEventListener("ContentStart", (function(evt) {
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-03-16 15:23:28 -07:00
|
|
|
content.addEventListener("mozContentEvent", this, false, true);
|
|
|
|
}).bind(this), false);
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function custevt_handleEvent(evt) {
|
|
|
|
let detail = evt.detail;
|
2012-07-02 17:16:55 -07:00
|
|
|
dump('XXX FIXME : Got a mozContentEvent: ' + detail.type + "\n");
|
2012-03-16 15:23:28 -07:00
|
|
|
|
|
|
|
switch(detail.type) {
|
2012-06-06 05:19:33 -07:00
|
|
|
case 'desktop-notification-click':
|
|
|
|
case 'desktop-notification-close':
|
2012-03-16 15:23:28 -07:00
|
|
|
AlertsHelper.handleEvent(detail);
|
|
|
|
break;
|
2012-06-06 05:19:33 -07:00
|
|
|
case 'webapps-install-granted':
|
|
|
|
case 'webapps-install-denied':
|
2012-03-20 14:25:37 -07:00
|
|
|
WebappsHelper.handleEvent(detail);
|
|
|
|
break;
|
2012-06-06 05:19:33 -07:00
|
|
|
case 'select-choicechange':
|
|
|
|
FormsHelper.handleEvent(detail);
|
|
|
|
break;
|
2012-03-16 15:23:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
var AlertsHelper = {
|
2012-03-16 15:23:28 -07:00
|
|
|
_listeners: {},
|
|
|
|
_count: 0,
|
|
|
|
|
|
|
|
handleEvent: function alert_handleEvent(detail) {
|
|
|
|
if (!detail || !detail.id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let listener = this._listeners[detail.id];
|
|
|
|
let topic = detail.type == "desktop-notification-click" ? "alertclickcallback" : "alertfinished";
|
|
|
|
listener.observer.observe(null, topic, listener.cookie);
|
|
|
|
|
|
|
|
// we're done with this notification
|
|
|
|
if (topic === "alertfinished")
|
|
|
|
delete this._listeners[detail.id];
|
|
|
|
},
|
|
|
|
|
|
|
|
registerListener: function alert_registerListener(cookie, alertListener) {
|
|
|
|
let id = "alert" + this._count++;
|
|
|
|
this._listeners[id] = { observer: alertListener, cookie: cookie };
|
|
|
|
return id;
|
|
|
|
},
|
|
|
|
|
2012-06-30 18:42:10 -07:00
|
|
|
showAlertNotification: function alert_showAlertNotification(imageUrl, title, text, textClickable,
|
2012-03-16 15:23:28 -07:00
|
|
|
cookie, alertListener, name) {
|
|
|
|
let id = this.registerListener(cookie, alertListener);
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-06-30 18:42:10 -07:00
|
|
|
shell.sendEvent(content, "mozChromeEvent", { type: "desktop-notification", id: id, icon: imageUrl,
|
2012-03-16 15:23:28 -07:00
|
|
|
title: title, text: text } );
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 15:23:28 -07:00
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
var WebappsHelper = {
|
2012-03-20 14:25:37 -07:00
|
|
|
_installers: {},
|
|
|
|
_count: 0,
|
|
|
|
|
2012-03-16 15:23:28 -07:00
|
|
|
init: function webapps_init() {
|
|
|
|
Services.obs.addObserver(this, "webapps-launch", false);
|
2012-03-20 14:25:37 -07:00
|
|
|
Services.obs.addObserver(this, "webapps-ask-install", false);
|
2012-06-29 13:46:21 -07:00
|
|
|
DOMApplicationRegistry.allAppsLaunchable = true;
|
2012-03-20 14:25:37 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
registerInstaller: function webapps_registerInstaller(data) {
|
|
|
|
let id = "installer" + this._count++;
|
|
|
|
this._installers[id] = data;
|
|
|
|
return id;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleEvent: function webapps_handleEvent(detail) {
|
|
|
|
if (!detail || !detail.id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let installer = this._installers[detail.id];
|
|
|
|
switch (detail.type) {
|
|
|
|
case "webapps-install-granted":
|
|
|
|
DOMApplicationRegistry.confirmInstall(installer);
|
|
|
|
break;
|
|
|
|
case "webapps-install-denied":
|
|
|
|
DOMApplicationRegistry.denyInstall(installer);
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 15:23:28 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
observe: function webapps_observe(subject, topic, data) {
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-03-16 15:23:28 -07:00
|
|
|
let json = JSON.parse(data);
|
2012-03-20 14:25:37 -07:00
|
|
|
switch(topic) {
|
|
|
|
case "webapps-launch":
|
|
|
|
DOMApplicationRegistry.getManifestFor(json.origin, function(aManifest) {
|
|
|
|
if (!aManifest)
|
|
|
|
return;
|
2012-03-16 15:23:28 -07:00
|
|
|
|
2012-03-20 14:25:37 -07:00
|
|
|
let manifest = new DOMApplicationManifest(aManifest, json.origin);
|
2012-05-04 11:02:05 -07:00
|
|
|
shell.sendEvent(content, "mozChromeEvent", {
|
|
|
|
"type": "webapps-launch",
|
|
|
|
"url": manifest.fullLaunchPath(json.startPoint),
|
|
|
|
"origin": json.origin
|
|
|
|
});
|
2012-03-20 14:25:37 -07:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "webapps-ask-install":
|
|
|
|
let id = this.registerInstaller(json);
|
|
|
|
shell.sendEvent(content, "mozChromeEvent", { type: "webapps-ask-install", id: id, app: json.app } );
|
|
|
|
break;
|
|
|
|
}
|
2012-03-16 15:23:28 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 09:50:45 -07:00
|
|
|
|
|
|
|
// Start the debugger server.
|
|
|
|
function startDebugger() {
|
|
|
|
if (!DebuggerServer.initialized) {
|
2012-06-01 08:28:13 -07:00
|
|
|
// Allow remote connections.
|
|
|
|
DebuggerServer.init(function () { return true; });
|
2012-03-16 09:50:45 -07:00
|
|
|
DebuggerServer.addActors('chrome://browser/content/dbg-browser-actors.js');
|
|
|
|
}
|
|
|
|
|
2012-06-08 00:00:46 -07:00
|
|
|
let port = Services.prefs.getIntPref('devtools.debugger.remote-port') || 6000;
|
2012-03-16 09:50:45 -07:00
|
|
|
try {
|
2012-06-20 06:31:50 -07:00
|
|
|
DebuggerServer.openListener(port);
|
2012-03-16 09:50:45 -07:00
|
|
|
} catch (e) {
|
|
|
|
dump('Unable to start debugger server: ' + e + '\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('ContentStart', function(evt) {
|
2012-06-08 00:00:46 -07:00
|
|
|
if (Services.prefs.getBoolPref('devtools.debugger.remote-enabled')) {
|
2012-03-16 09:50:45 -07:00
|
|
|
startDebugger();
|
|
|
|
}
|
2012-05-04 11:02:05 -07:00
|
|
|
});
|
|
|
|
|
2012-06-27 07:47:30 -07:00
|
|
|
// This is the backend for Gaia's screenshot feature. Gaia requests a
|
|
|
|
// screenshot by sending a mozContentEvent with detail.type set to
|
|
|
|
// 'take-screenshot'. Then we take a screenshot and send a
|
|
|
|
// mozChromeEvent with detail.type set to 'take-screenshot-success'
|
|
|
|
// and detail.file set to the an image/png blob
|
2012-06-15 00:20:44 -07:00
|
|
|
window.addEventListener('ContentStart', function ss_onContentStart() {
|
2012-06-20 12:25:23 -07:00
|
|
|
let content = shell.contentBrowser.contentWindow;
|
2012-06-15 00:20:44 -07:00
|
|
|
content.addEventListener('mozContentEvent', function ss_onMozContentEvent(e) {
|
2012-06-27 07:47:30 -07:00
|
|
|
if (e.detail.type !== 'take-screenshot')
|
2012-06-15 00:20:44 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var canvas = document.createElementNS('http://www.w3.org/1999/xhtml',
|
|
|
|
'canvas');
|
|
|
|
var width = window.innerWidth;
|
|
|
|
var height = window.innerHeight;
|
|
|
|
canvas.setAttribute('width', width);
|
|
|
|
canvas.setAttribute('height', height);
|
|
|
|
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
var flags =
|
|
|
|
context.DRAWWINDOW_DRAW_CARET |
|
|
|
|
context.DRAWWINDOW_DRAW_VIEW |
|
|
|
|
context.DRAWWINDOW_USE_WIDGET_LAYERS;
|
|
|
|
context.drawWindow(window, 0, 0, width, height,
|
|
|
|
'rgb(255,255,255)', flags);
|
|
|
|
|
|
|
|
shell.sendEvent(content, 'mozChromeEvent', {
|
2012-06-27 07:47:30 -07:00
|
|
|
type: 'take-screenshot-success',
|
|
|
|
file: canvas.mozGetAsFile('screenshot', 'image/png')
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
dump('exception while creating screenshot: ' + e + '\n');
|
|
|
|
shell.sendEvent(content, 'mozChromeEvent', {
|
|
|
|
type: 'take-screenshot-error',
|
2012-06-15 00:20:44 -07:00
|
|
|
error: String(e)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|