Bug 1279833 - Make less use of gBrowser and content tabs in devtools. r=jwalker

This commit is contained in:
Philipp Kewisch [:Fallen] 2016-06-28 11:07:09 +02:00
parent a07ebf7178
commit b3be6df2f8
7 changed files with 36 additions and 32 deletions

View File

@ -134,8 +134,10 @@ function Eyedropper(chromeWindow, opts = { copyOnSelect: true, context: "other"
height: CANVAS_WIDTH // height of canvas
};
let mm = this._contentTab.linkedBrowser.messageManager;
mm.loadFrameScript("resource://devtools/client/eyedropper/eyedropper-child.js", true);
if (this._contentTab) {
let mm = this._contentTab.linkedBrowser.messageManager;
mm.loadFrameScript("resource://devtools/client/eyedropper/eyedropper-child.js", true);
}
// record if this was opened via the picker or standalone
var telemetry = new Telemetry();
@ -192,7 +194,7 @@ Eyedropper.prototype = {
},
get _contentTab() {
return this._chromeWindow.gBrowser.selectedTab;
return this._chromeWindow.gBrowser && this._chromeWindow.gBrowser.selectedTab;
},
/**
@ -202,6 +204,10 @@ Eyedropper.prototype = {
* Promise that resolves with the screenshot as a dataURL
*/
getContentScreenshot: function () {
if (!this._contentTab) {
return promise.resolve(null);
}
let deferred = defer();
let mm = this._contentTab.linkedBrowser.messageManager;
@ -224,29 +230,29 @@ Eyedropper.prototype = {
// the eyedropper is aready open, don't create another panel.
return promise.resolve();
}
let deferred = defer();
this.isOpen = true;
this._showCrosshairs();
// Get screenshot of content so we can inspect colors
this.getContentScreenshot().then((dataURL) => {
this._contentImage = new this._chromeWindow.Image();
this._contentImage.src = dataURL;
return this.getContentScreenshot().then((dataURL) => {
// The data url may be null, e.g. if there is no content tab
if (dataURL) {
this._contentImage = new this._chromeWindow.Image();
this._contentImage.src = dataURL;
// Wait for screenshot to load
this._contentImage.onload = () => {
// Then start showing the eyedropper UI
this._chromeDocument.addEventListener("mousemove", this._onFirstMouseMove);
deferred.resolve();
this.isStarted = true;
this.emit("started");
};
// Wait for screenshot to load
let imageLoaded = promise.defer();
this._contentImage.onload = imageLoaded.resolve
return imageLoaded.promise;
}
}).then(() => {
// Then start showing the eyedropper UI
this._chromeDocument.addEventListener("mousemove", this._onFirstMouseMove);
this.isStarted = true;
this.emit("started");
});
return deferred.promise;
},
/**
@ -282,8 +288,9 @@ Eyedropper.prototype = {
* y-coordinate of mouse relative to browser window.
*/
_isInContent: function (clientX, clientY) {
let box = this._contentTab.linkedBrowser.getBoundingClientRect();
if (clientX > box.left &&
let box = this._contentTab && this._contentTab.linkedBrowser.getBoundingClientRect();
if (box &&
clientX > box.left &&
clientX < box.right &&
clientY > box.top &&
clientY < box.bottom) {

View File

@ -2061,9 +2061,8 @@ var Scratchpad = {
openDocumentationPage: function SP_openDocumentationPage()
{
let url = this.strings.GetStringFromName("help.openDocumentationPage");
let newTab = this.gBrowser.addTab(url);
this.browserWindow.openUILinkIn(url,"tab");
this.browserWindow.focus();
this.gBrowser.selectedTab = newTab;
},
};

View File

@ -297,8 +297,8 @@ AppCacheUtils.prototype = {
let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator);
let win = wm.getMostRecentWindow(gDevTools.chromeWindowType);
win.gBrowser.selectedTab = win.gBrowser.addTab(
"about:cache-entry?storage=appcache&context=&eid=&uri=" + key);
let url = "about:cache-entry?storage=appcache&context=&eid=&uri=" + key;
win.openUILinkIn(url, "tab");
},
clearAll: function ACU_clearAll() {

View File

@ -259,8 +259,7 @@ function MdnDocsWidget(tooltipDocument) {
this.elements.linkToMdn.addEventListener("click", function (e) {
e.stopPropagation();
e.preventDefault();
let link = e.target.href;
mainWindow.gBrowser.addTab(link);
mainWindow.openUILinkIn(e.target.href, "tab", { inBackground: true });
});
}

View File

@ -240,8 +240,7 @@ var UI = {
// Open a URL in a Firefox window
let mainWindow = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
if (mainWindow) {
let gBrowser = mainWindow.gBrowser;
gBrowser.selectedTab = gBrowser.addTab(url);
mainWindow.openUILinkIn(url, "tab");
mainWindow.focus()
} else {
window.open(url);

View File

@ -69,8 +69,8 @@ exports.items = [{
root.appendChild(link);
link.addEventListener("click", () => {
let gBrowser = context.environment.chromeWindow.gBrowser;
gBrowser.selectedTab = gBrowser.addTab(result.url);
let mainWindow = context.environment.chromeWindow;
mainWindow.openUILinkIn(result.url, "tab");
});
let summary = document.createElement("p");

View File

@ -153,8 +153,8 @@ exports.items = [
root.style.cursor = "pointer";
root.addEventListener("click", () => {
if (imageSummary.href) {
const gBrowser = context.environment.chromeWindow.gBrowser;
gBrowser.selectedTab = gBrowser.addTab(imageSummary.href);
let mainWindow = context.environment.chromeWindow;
mainWindow.openUILinkIn(imageSummary.href, "tab");
} else if (imageSummary.filename) {
const file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(imageSummary.filename);