Skip to content

Commit

Permalink
Revert "disable devtools to work around #132"
Browse files Browse the repository at this point in the history
This reverts commit e11d9f4.
  • Loading branch information
mykmelez committed Mar 16, 2018
1 parent e874454 commit 922e847
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 120 deletions.
54 changes: 25 additions & 29 deletions bin/install-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require('promise.prototype.finally').shim();
const chalk = require('chalk');
const cli = require('cli');
const decompress = require('decompress');
// const extract = require('extract-zip');
const extract = require('extract-zip');
const fs = require('fs-extra');
const https = require('https');
const os = require('os');
Expand Down Expand Up @@ -61,9 +61,9 @@ const downloadOS = (() => {
const downloadURL = `https://download.mozilla.org/?product=firefox-nightly-latest-ssl&lang=en-US&os=${downloadOS}`;
const distDir = path.join(__dirname, '..', 'dist', process.platform);
const installDir = path.join(distDir, process.platform === 'darwin' ? 'Runtime.app' : 'runtime');
// const resourcesDir = process.platform === 'darwin' ? path.join(installDir, 'Contents', 'Resources') : installDir;
const resourcesDir = process.platform === 'darwin' ? path.join(installDir, 'Contents', 'Resources') : installDir;
const executableDir = process.platform === 'darwin' ? path.join(installDir, 'Contents', 'MacOS') : installDir;
// const browserJAR = path.join(resourcesDir, 'browser', 'omni.ja');
const browserJAR = path.join(resourcesDir, 'browser', 'omni.ja');

const fileExtensions = {
'application/x-apple-diskimage': 'dmg',
Expand Down Expand Up @@ -197,38 +197,34 @@ function installRuntime() {
.then(() => {
return installXULApp();
})
.then(() => {
// Expand the browser xulapp's JAR archive so we can access its devtools.
// We have to expand it into a subdirectory of qbrt's xulapp directory,
// because chrome manifests can't reference super-directories.

// DISABLED because https://bugzilla.mozilla.org/show_bug.cgi?id=1352595
// breaks decompression with extract-zip too.
// .then(() => {
// // Expand the browser xulapp's JAR archive so we can access its devtools.
// // We have to expand it into a subdirectory of qbrt's xulapp directory,
// // because chrome manifests can't reference super-directories.

// // TODO: limit expansion to browser files that are necessary for devtools.

// const targetDir = path.join(resourcesDir, 'qbrt', 'browser');
// TODO: limit expansion to browser files that are necessary for devtools.

// // "decompress" fails silently on omni.ja, so we use extract-zip here instead.
// // TODO: figure out the issue with "decompress" (f.e. that the .ja file
// // extension is unrecognized or that the chrome.manifest file in the archive
// // conflicts with the one already on disk).
// return pify(extract)(browserJAR, { dir: targetDir });
// })
// .then(() => {
// // Copy devtools pref files from browser to qbrt.
const targetDir = path.join(resourcesDir, 'qbrt', 'browser');

// const sourceDir = path.join(resourcesDir, 'qbrt', 'browser', 'defaults', 'preferences');
// const targetDir = path.join(resourcesDir, 'qbrt', 'defaults', 'preferences');
// "decompress" fails silently on omni.ja, so we use extract-zip here instead.
// TODO: figure out the issue with "decompress" (f.e. that the .ja file
// extension is unrecognized or that the chrome.manifest file in the archive
// conflicts with the one already on disk).
return pify(extract)(browserJAR, { dir: targetDir });
})
.then(() => {
// Copy devtools pref files from browser to qbrt.

// const prefFiles = [
// 'debugger.js',
// 'devtools.js',
// ];
const sourceDir = path.join(resourcesDir, 'qbrt', 'browser', 'defaults', 'preferences');
const targetDir = path.join(resourcesDir, 'qbrt', 'defaults', 'preferences');

// return Promise.all(prefFiles.map(file => pify(fs.copy)(path.join(sourceDir, file), path.join(targetDir, file))));
// })
const prefFiles = [
'debugger.js',
'devtools.js',
];

return Promise.all(prefFiles.map(file => pify(fs.copy)(path.join(sourceDir, file), path.join(targetDir, file))));
})
.then(() => {
// Copy and configure the stub executable.

Expand Down
179 changes: 88 additions & 91 deletions modules/Runtime.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -48,94 +48,91 @@ this.Runtime = {
},

openDevTools(target) {
dump('DevTools disabled due to https://github.com/mozilla/qbrt/issues/132\n');
return;

// // TODO: When tools can be opened inside the target window, support
// // `detach` option to force into a new window instead.

// // Ensure DevTools core modules are loaded, including support for the about
// // URL below which is registered dynamically.
// const { loader } = Cu.import('resource://devtools/shared/Loader.jsm', {});
// loader.require('devtools/client/framework/devtools-browser');

// // The current approach below avoids the need for a container window
// // wrapping a tools frame, but it does replicate close handling, etc.
// // Historically we would have used toolbox-hosts.js to handle this,
// // but DevTools will be moving away from that, and so it seems fine
// // to experiment with toolbox management here.

// // Determine the target's type, id, and associated application window
// // (which could be the target itself). Currently we support targets
// // that are <xul:browser> elements (i.e. have a outerWindowID property)
// // and those that are ChromeWindow (i.e. don't have such a property).
// //
// // We also distinguish between <xul:browser> elements that are
// // type="content*" and those that are not (and therefore chrome),
// // as the latter need their type set to "window", because:
// // http://searchfox.org/mozilla-central/rev/fcd9f14/devtools/server/actors/webbrowser.js#329-333.
// //
// const [type, id, appWindow] = 'outerWindowID' in target ?
// target.getAttribute('type').startsWith('content') ?
// ['tab', target.outerWindowID, target.ownerGlobal] :
// ['window', target.outerWindowID, target.ownerGlobal] :
// ['window', getOuterWindowID(target), target];

// const url = `about:devtools-toolbox?type=${type}&id=${id}`;

// const features = 'chrome,resizable,centerscreen,width=1024,height=768';
// const toolsWindow = Services.ww.openWindow(null, url, null, features, null);

// const onLoad = () => {
// global.devToolsOpened.set(target, toolsWindow);
// toolsWindow.removeEventListener('load', onLoad);
// toolsWindow.addEventListener('unload', onUnload);
// };

// const onUnload = () => {
// global.devToolsOpened.delete(target);
// toolsWindow.removeEventListener('unload', onUnload);
// toolsWindow.removeEventListener('message', onMessage);
// };

// // Close the DevTools window if the target window closes.
// const onTargetClose = () => {
// toolsWindow.close();
// };

// // Listen for the toolbox's built-in close button, which sends a message
// // asking the toolbox's opener how to handle things. In this case, just
// // close the toolbox.
// const onMessage = ({ data }) => {
// // Sometimes `data` is a String (f.e. on toolbox-title or toolbox-close),
// // while other times it's an Object (f.e. on set-host-title), which feels
// // like an upstream bug. Anyway, for now we parse it conditionally.
// if (typeof data === 'string') {
// data = JSON.parse(data);
// }

// switch (data.name) {
// case 'toolbox-close':
// toolsWindow.close();
// onUnload();
// break;
// // We get both set-host-title and toolbox-title, and they provide
// // the same title, although their semantics vary. Weird, but we simply
// // ignore one and use the other.
// case 'set-host-title':
// toolsWindow.document.title = data.title;
// break;
// // case 'toolbox-title':
// // toolsWindow.document.title = data.data.value;
// // break;
// }
// };

// toolsWindow.addEventListener('message', onMessage);
// toolsWindow.addEventListener('load', onLoad);
// appWindow.addEventListener('close', onTargetClose);

// return toolsWindow;
// TODO: When tools can be opened inside the target window, support
// `detach` option to force into a new window instead.

// Ensure DevTools core modules are loaded, including support for the about
// URL below which is registered dynamically.
const { loader } = Cu.import('resource://devtools/shared/Loader.jsm', {});
loader.require('devtools/client/framework/devtools-browser');

// The current approach below avoids the need for a container window
// wrapping a tools frame, but it does replicate close handling, etc.
// Historically we would have used toolbox-hosts.js to handle this,
// but DevTools will be moving away from that, and so it seems fine
// to experiment with toolbox management here.

// Determine the target's type, id, and associated application window
// (which could be the target itself). Currently we support targets
// that are <xul:browser> elements (i.e. have a outerWindowID property)
// and those that are ChromeWindow (i.e. don't have such a property).
//
// We also distinguish between <xul:browser> elements that are
// type="content*" and those that are not (and therefore chrome),
// as the latter need their type set to "window", because:
// http://searchfox.org/mozilla-central/rev/fcd9f14/devtools/server/actors/webbrowser.js#329-333.
//
const [type, id, appWindow] = 'outerWindowID' in target ?
target.getAttribute('type').startsWith('content') ?
['tab', target.outerWindowID, target.ownerGlobal] :
['window', target.outerWindowID, target.ownerGlobal] :
['window', getOuterWindowID(target), target];

const url = `about:devtools-toolbox?type=${type}&id=${id}`;

const features = 'chrome,resizable,centerscreen,width=1024,height=768';
const toolsWindow = Services.ww.openWindow(null, url, null, features, null);

const onLoad = () => {
global.devToolsOpened.set(target, toolsWindow);
toolsWindow.removeEventListener('load', onLoad);
toolsWindow.addEventListener('unload', onUnload);
};

const onUnload = () => {
global.devToolsOpened.delete(target);
toolsWindow.removeEventListener('unload', onUnload);
toolsWindow.removeEventListener('message', onMessage);
};

// Close the DevTools window if the target window closes.
const onTargetClose = () => {
toolsWindow.close();
};

// Listen for the toolbox's built-in close button, which sends a message
// asking the toolbox's opener how to handle things. In this case, just
// close the toolbox.
const onMessage = ({ data }) => {
// Sometimes `data` is a String (f.e. on toolbox-title or toolbox-close),
// while other times it's an Object (f.e. on set-host-title), which feels
// like an upstream bug. Anyway, for now we parse it conditionally.
if (typeof data === 'string') {
data = JSON.parse(data);
}

switch (data.name) {
case 'toolbox-close':
toolsWindow.close();
onUnload();
break;
// We get both set-host-title and toolbox-title, and they provide
// the same title, although their semantics vary. Weird, but we simply
// ignore one and use the other.
case 'set-host-title':
toolsWindow.document.title = data.title;
break;
// case 'toolbox-title':
// toolsWindow.document.title = data.data.value;
// break;
}
};

toolsWindow.addEventListener('message', onMessage);
toolsWindow.addEventListener('load', onLoad);
appWindow.addEventListener('close', onTargetClose);

return toolsWindow;
},

closeDevTools(target) {
Expand Down Expand Up @@ -175,6 +172,6 @@ function registerChromePrefix(appDir) {
tempFile.remove(false);
}

// function getOuterWindowID(window) {
// return window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
// }
function getOuterWindowID(window) {
return window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
}
File renamed without changes.

0 comments on commit 922e847

Please sign in to comment.