2014-01-22 19:06:46 +00: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/. */
|
2014-01-15 14:28:04 +00:00
|
|
|
|
2015-09-15 18:19:45 +00:00
|
|
|
var browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
|
|
|
var isMulet = "ResponsiveUI" in browserWindow;
|
2014-08-12 06:43:00 +00:00
|
|
|
|
2014-03-19 12:38:59 +00:00
|
|
|
// Enable touch event shim on desktop that translates mouse events
|
|
|
|
// into touch ones
|
|
|
|
function enableTouch() {
|
2015-10-13 23:18:43 +00:00
|
|
|
let require = Cu.import('resource://devtools/shared/Loader.jsm', {})
|
2014-01-15 14:28:04 +00:00
|
|
|
.devtools.require;
|
2015-09-21 17:04:18 +00:00
|
|
|
let { TouchEventSimulator } = require('devtools/shared/touch/simulator');
|
2015-07-16 06:12:50 +00:00
|
|
|
let touchEventSimulator = new TouchEventSimulator(shell.contentBrowser);
|
|
|
|
touchEventSimulator.start();
|
2014-03-19 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
2015-11-19 17:51:22 +00:00
|
|
|
// Some additional buttons are displayed on simulators to fake hardware buttons.
|
2014-03-19 12:38:59 +00:00
|
|
|
function setupButtons() {
|
2015-11-19 17:51:22 +00:00
|
|
|
let link = document.createElement('link');
|
|
|
|
link.type = 'text/css';
|
|
|
|
link.rel = 'stylesheet';
|
|
|
|
link.href = 'chrome://b2g/content/desktop.css';
|
|
|
|
document.head.appendChild(link);
|
|
|
|
|
|
|
|
let footer = document.createElement('footer');
|
|
|
|
footer.id = 'controls';
|
|
|
|
document.body.appendChild(footer);
|
|
|
|
let homeButton = document.createElement('button');
|
|
|
|
homeButton.id = 'home-button';
|
|
|
|
footer.appendChild(homeButton);
|
|
|
|
let rotateButton = document.createElement('button');
|
|
|
|
rotateButton.id = 'rotate-button';
|
|
|
|
footer.appendChild(rotateButton);
|
|
|
|
|
2015-08-04 19:25:00 +00:00
|
|
|
homeButton.addEventListener('mousedown', function() {
|
2014-11-18 03:13:00 +00:00
|
|
|
let window = shell.contentBrowser.contentWindow;
|
|
|
|
let e = new window.KeyboardEvent('keydown', {key: 'Home'});
|
|
|
|
window.dispatchEvent(e);
|
2014-03-19 12:38:59 +00:00
|
|
|
homeButton.classList.add('active');
|
|
|
|
});
|
2015-08-04 19:25:00 +00:00
|
|
|
homeButton.addEventListener('mouseup', function() {
|
2014-11-18 03:13:00 +00:00
|
|
|
let window = shell.contentBrowser.contentWindow;
|
|
|
|
let e = new window.KeyboardEvent('keyup', {key: 'Home'});
|
|
|
|
window.dispatchEvent(e);
|
2014-03-19 12:38:59 +00:00
|
|
|
homeButton.classList.remove('active');
|
|
|
|
});
|
2014-03-19 12:38:59 +00:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/GlobalSimulatorScreen.jsm");
|
2015-08-04 19:25:00 +00:00
|
|
|
rotateButton.addEventListener('mousedown', function() {
|
2014-03-19 12:38:59 +00:00
|
|
|
rotateButton.classList.add('active');
|
|
|
|
});
|
2015-08-04 19:25:00 +00:00
|
|
|
rotateButton.addEventListener('mouseup', function() {
|
2014-03-19 12:38:59 +00:00
|
|
|
GlobalSimulatorScreen.flipScreen();
|
|
|
|
rotateButton.classList.remove('active');
|
|
|
|
});
|
2014-03-19 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 07:24:00 +00:00
|
|
|
function setupStorage() {
|
|
|
|
let directory = null;
|
|
|
|
|
|
|
|
// Get the --storage-path argument from the command line.
|
|
|
|
try {
|
|
|
|
let service = Cc['@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds'].getService(Ci.nsISupports);
|
|
|
|
let args = service.wrappedJSObject.cmdLine;
|
|
|
|
if (args) {
|
|
|
|
let path = args.handleFlagWithParam('storage-path', false);
|
|
|
|
directory = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsIFile);
|
|
|
|
directory.initWithPath(path);
|
|
|
|
}
|
|
|
|
} catch(e) {
|
|
|
|
directory = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, default to 'storage' folder within current profile.
|
|
|
|
if (!directory) {
|
|
|
|
directory = Services.dirsvc.get('ProfD', Ci.nsIFile);
|
|
|
|
directory.append('storage');
|
|
|
|
if (!directory.exists()) {
|
|
|
|
directory.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dump("Set storage path to: " + directory.path + "\n");
|
|
|
|
|
|
|
|
// This is the magic, where we override the default location for the storages.
|
|
|
|
Services.prefs.setCharPref('device.storage.overrideRootDir', directory.path);
|
|
|
|
}
|
|
|
|
|
2014-03-24 15:15:00 +00:00
|
|
|
function checkDebuggerPort() {
|
|
|
|
// XXX: To be removed once bug 942756 lands.
|
|
|
|
// We are hacking 'unix-domain-socket' pref by setting a tcp port (number).
|
2014-12-11 02:55:51 +00:00
|
|
|
// SocketListener.open detects that it isn't a file path (string), and starts
|
|
|
|
// listening on the tcp port given here as command line argument.
|
2014-03-24 15:15:00 +00:00
|
|
|
|
2014-08-28 08:10:00 +00:00
|
|
|
// Get the command line arguments that were passed to the b2g client
|
|
|
|
let args;
|
|
|
|
try {
|
|
|
|
let service = Cc["@mozilla.org/commandlinehandler/general-startup;1?type=b2gcmds"].getService(Ci.nsISupports);
|
|
|
|
args = service.wrappedJSObject.cmdLine;
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (!args) {
|
2014-04-10 07:38:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-24 15:15:00 +00:00
|
|
|
let dbgport;
|
|
|
|
try {
|
|
|
|
dbgport = args.handleFlagWithParam('start-debugger-server', false);
|
|
|
|
} catch(e) {}
|
|
|
|
|
|
|
|
if (dbgport) {
|
|
|
|
dump('Opening debugger server on ' + dbgport + '\n');
|
|
|
|
Services.prefs.setCharPref('devtools.debugger.unix-domain-socket', dbgport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 06:43:00 +00:00
|
|
|
|
|
|
|
function initResponsiveDesign() {
|
2015-10-13 23:18:43 +00:00
|
|
|
Cu.import('resource://devtools/client/responsivedesign/responsivedesign.jsm');
|
2014-08-12 06:43:00 +00:00
|
|
|
ResponsiveUIManager.on('on', function(event, {tab:tab}) {
|
2015-01-20 05:57:00 +00:00
|
|
|
let responsive = ResponsiveUIManager.getResponsiveUIForTab(tab);
|
2014-08-12 06:43:00 +00:00
|
|
|
let document = tab.ownerDocument;
|
|
|
|
|
|
|
|
// Only tweak reponsive mode for shell.html tabs.
|
|
|
|
if (tab.linkedBrowser.contentWindow != window) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-23 23:28:54 +00:00
|
|
|
// Disable transition as they mess up with screen size handler
|
|
|
|
responsive.transitionsEnabled = false;
|
|
|
|
|
2014-08-12 06:43:00 +00:00
|
|
|
responsive.buildPhoneUI();
|
|
|
|
|
|
|
|
responsive.rotatebutton.addEventListener('command', function (evt) {
|
|
|
|
GlobalSimulatorScreen.flipScreen();
|
|
|
|
evt.stopImmediatePropagation();
|
|
|
|
evt.preventDefault();
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
// Enable touch events
|
2015-01-20 05:57:00 +00:00
|
|
|
responsive.enableTouch();
|
2014-08-12 06:43:00 +00:00
|
|
|
});
|
|
|
|
|
2015-02-05 15:04:00 +00:00
|
|
|
|
2014-08-12 06:43:00 +00:00
|
|
|
let mgr = browserWindow.ResponsiveUI.ResponsiveUIManager;
|
|
|
|
mgr.toggle(browserWindow, browserWindow.gBrowser.selectedTab);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function openDevtools() {
|
|
|
|
// Open devtool panel while maximizing its size according to screen size
|
|
|
|
Services.prefs.setIntPref('devtools.toolbox.sidebar.width',
|
|
|
|
browserWindow.outerWidth - 550);
|
|
|
|
Services.prefs.setCharPref('devtools.toolbox.host', 'side');
|
2015-10-13 23:18:43 +00:00
|
|
|
let {gDevTools} = Cu.import('resource://devtools/client/framework/gDevTools.jsm', {});
|
|
|
|
let {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
2014-08-12 06:43:00 +00:00
|
|
|
let target = devtools.TargetFactory.forTab(browserWindow.gBrowser.selectedTab);
|
|
|
|
gDevTools.showToolbox(target);
|
|
|
|
}
|
|
|
|
|
2014-03-19 12:38:59 +00:00
|
|
|
window.addEventListener('ContentStart', function() {
|
2014-08-12 06:43:00 +00:00
|
|
|
// On Firefox Mulet, touch events are enabled within the responsive mode
|
|
|
|
if (!isMulet) {
|
|
|
|
enableTouch();
|
|
|
|
}
|
2015-11-19 17:51:22 +00:00
|
|
|
if (Services.prefs.getBoolPref('b2g.software-buttons')) {
|
|
|
|
setupButtons();
|
|
|
|
}
|
2014-03-24 15:15:00 +00:00
|
|
|
checkDebuggerPort();
|
2014-12-15 07:24:00 +00:00
|
|
|
setupStorage();
|
2014-08-12 06:43:00 +00:00
|
|
|
// On Firefox mulet, we automagically enable the responsive mode
|
|
|
|
// and show the devtools
|
|
|
|
if (isMulet) {
|
|
|
|
initResponsiveDesign(browserWindow);
|
|
|
|
openDevtools();
|
|
|
|
}
|
2014-01-15 14:28:04 +00:00
|
|
|
});
|