2009-10-16 00:11:34 +00:00
|
|
|
/* vim: se cin sw=2 ts=2 et filetype=javascript :
|
2012-05-21 11:12:37 +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/. */
|
2009-10-06 04:26:15 +00:00
|
|
|
/*
|
|
|
|
* This module implements the front end behavior for AeroPeek. Starting in
|
|
|
|
* Windows Vista, the taskbar began showing live thumbnail previews of windows
|
|
|
|
* when the user hovered over the window icon in the taskbar. Starting with
|
|
|
|
* Windows 7, the taskbar allows an application to expose its tabbed interface
|
|
|
|
* in the taskbar by showing thumbnail previews rather than the default window
|
|
|
|
* preview. Additionally, when a user hovers over a thumbnail (tab or window),
|
|
|
|
* they are shown a live preview of the window (or tab + its containing window).
|
|
|
|
*
|
|
|
|
* In Windows 7, a title, icon, close button and optional toolbar are shown for
|
|
|
|
* each preview. This feature does not make use of the toolbar. For window
|
|
|
|
* previews, the title is the window title and the icon the window icon. For
|
|
|
|
* tab previews, the title is the page title and the page's favicon. In both
|
|
|
|
* cases, the close button "does the right thing."
|
|
|
|
*
|
|
|
|
* The primary objects behind this feature are nsITaskbarTabPreview and
|
|
|
|
* nsITaskbarPreviewController. Each preview has a controller. The controller
|
|
|
|
* responds to the user's interactions on the taskbar and provides the required
|
|
|
|
* data to the preview for determining the size of the tab and thumbnail. The
|
|
|
|
* PreviewController class implements this interface. The preview will request
|
|
|
|
* the controller to provide a thumbnail or preview when the user interacts with
|
|
|
|
* the taskbar. To reduce the overhead of drawing the tab area, the controller
|
|
|
|
* implementation caches the tab's contents in a <canvas> element. If no
|
|
|
|
* previews or thumbnails have been requested for some time, the controller will
|
|
|
|
* discard its cached tab contents.
|
|
|
|
*
|
|
|
|
* Screen real estate is limited so when there are too many thumbnails to fit
|
|
|
|
* on the screen, the taskbar stops displaying thumbnails and instead displays
|
|
|
|
* just the title, icon and close button in a similar fashion to previous
|
2016-02-03 22:22:33 +00:00
|
|
|
* versions of the taskbar. If there are still too many previews to fit on the
|
2009-10-06 04:26:15 +00:00
|
|
|
* screen, the taskbar resorts to a scroll up and scroll down button pair to let
|
|
|
|
* the user scroll through the list of tabs. Since this is undoubtedly
|
|
|
|
* inconvenient for users with many tabs, the AeroPeek objects turns off all of
|
|
|
|
* the tab previews. This tells the taskbar to revert to one preview per window.
|
|
|
|
* If the number of tabs falls below this magic threshold, the preview-per-tab
|
|
|
|
* behavior returns. There is no reliable way to determine when the scroll
|
|
|
|
* buttons appear on the taskbar, so a magic pref-controlled number determines
|
|
|
|
* when this threshold has been crossed.
|
|
|
|
*/
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["AeroPeek"];
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
2016-06-29 22:30:51 +00:00
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
2012-10-05 23:25:52 +00:00
|
|
|
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2016-06-29 22:30:51 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
// Pref to enable/disable preview-per-tab
|
2009-10-06 19:57:20 +00:00
|
|
|
const TOGGLE_PREF_NAME = "browser.taskbar.previews.enable";
|
2009-10-06 04:26:15 +00:00
|
|
|
// Pref to determine the magic auto-disable threshold
|
2009-10-06 19:57:20 +00:00
|
|
|
const DISABLE_THRESHOLD_PREF_NAME = "browser.taskbar.previews.max";
|
2009-10-06 04:26:15 +00:00
|
|
|
// Pref to control the time in seconds that tab contents live in the cache
|
2009-10-06 19:57:20 +00:00
|
|
|
const CACHE_EXPIRATION_TIME_PREF_NAME = "browser.taskbar.previews.cachetime";
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
const WINTASKBAR_CONTRACTID = "@mozilla.org/windows-taskbar;1";
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// Various utility properties
|
2009-10-06 04:26:15 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "imgTools",
|
|
|
|
"@mozilla.org/image/tools;1",
|
|
|
|
"imgITools");
|
2016-06-29 22:30:51 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PageThumbs",
|
|
|
|
"resource://gre/modules/PageThumbs.jsm");
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
// nsIURI -> imgIContainer
|
2016-06-29 22:30:51 +00:00
|
|
|
function _imageFromURI(uri, privateMode, callback) {
|
2016-04-25 13:06:40 +00:00
|
|
|
let channel = NetUtil.newChannel({
|
|
|
|
uri: uri,
|
|
|
|
loadUsingSystemPrincipal: true,
|
|
|
|
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE
|
|
|
|
});
|
|
|
|
|
2012-09-17 18:47:49 +00:00
|
|
|
try {
|
|
|
|
channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
|
|
|
|
channel.setPrivate(privateMode);
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore channels which do not support nsIPrivateBrowsingChannel
|
|
|
|
}
|
2015-05-22 02:51:40 +00:00
|
|
|
NetUtil.asyncFetch(channel, function(inputStream, resultCode) {
|
2009-10-16 00:11:34 +00:00
|
|
|
if (!Components.isSuccessCode(resultCode))
|
|
|
|
return;
|
|
|
|
try {
|
|
|
|
let out_img = { value: null };
|
|
|
|
imgTools.decodeImageData(inputStream, channel.contentType, out_img);
|
|
|
|
callback(out_img.value);
|
|
|
|
} catch (e) {
|
|
|
|
// We failed, so use the default favicon (only if this wasn't the default
|
|
|
|
// favicon).
|
2016-06-29 22:30:51 +00:00
|
|
|
let defaultURI = PlacesUtils.favicons.defaultFavicon;
|
2009-10-16 00:11:34 +00:00
|
|
|
if (!defaultURI.equals(uri))
|
2016-06-29 22:30:51 +00:00
|
|
|
_imageFromURI(defaultURI, privateMode, callback);
|
2009-10-16 00:11:34 +00:00
|
|
|
}
|
|
|
|
});
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// string? -> imgIContainer
|
2016-06-29 22:30:51 +00:00
|
|
|
function getFaviconAsImage(iconurl, privateMode, callback) {
|
|
|
|
if (iconurl) {
|
|
|
|
_imageFromURI(NetUtil.newURI(iconurl), privateMode, callback);
|
|
|
|
} else {
|
|
|
|
_imageFromURI(PlacesUtils.favicons.defaultFavicon, privateMode, callback);
|
|
|
|
}
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-19 23:06:00 +00:00
|
|
|
// Snaps the given rectangle to be pixel-aligned at the given scale
|
|
|
|
function snapRectAtScale(r, scale) {
|
|
|
|
let x = Math.floor(r.x * scale);
|
|
|
|
let y = Math.floor(r.y * scale);
|
|
|
|
let width = Math.ceil((r.x + r.width) * scale) - x;
|
|
|
|
let height = Math.ceil((r.y + r.height) * scale) - y;
|
|
|
|
|
|
|
|
r.x = x / scale;
|
|
|
|
r.y = y / scale;
|
|
|
|
r.width = width / scale;
|
|
|
|
r.height = height / scale;
|
|
|
|
}
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// PreviewController
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
/*
|
2016-01-12 17:08:33 +00:00
|
|
|
* This class manages the behavior of thumbnails and previews. It has the following
|
|
|
|
* responsibilities:
|
|
|
|
* 1) responding to requests from Windows taskbar for a thumbnail or window
|
|
|
|
* preview.
|
|
|
|
* 2) listens for dom events that result in a thumbnail or window preview needing
|
|
|
|
* to be refresh, and communicates this to the taskbar.
|
|
|
|
* 3) Handles querying and returning to the taskbar new thumbnail or window
|
|
|
|
* preview images through PageThumbs.
|
2009-10-06 04:26:15 +00:00
|
|
|
*
|
|
|
|
* @param win
|
|
|
|
* The TabWindow (see below) that owns the preview that this controls
|
|
|
|
* @param tab
|
|
|
|
* The <tab> that this preview is associated with
|
|
|
|
*/
|
|
|
|
function PreviewController(win, tab) {
|
|
|
|
this.win = win;
|
|
|
|
this.tab = tab;
|
|
|
|
this.linkedBrowser = tab.linkedBrowser;
|
2013-05-22 15:39:07 +00:00
|
|
|
this.preview = this.win.createTabPreview(this);
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2010-09-09 07:48:33 +00:00
|
|
|
this.tab.addEventListener("TabAttrModified", this, false);
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2010-06-10 02:08:00 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "canvasPreview", function () {
|
2016-01-12 17:08:33 +00:00
|
|
|
let canvas = PageThumbs.createCanvas();
|
2010-06-10 02:08:00 +00:00
|
|
|
canvas.mozOpaque = true;
|
|
|
|
return canvas;
|
|
|
|
});
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewController.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsITaskbarPreviewController,
|
|
|
|
Ci.nsIDOMEventListener]),
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
destroy: function () {
|
2010-09-09 07:48:33 +00:00
|
|
|
this.tab.removeEventListener("TabAttrModified", this, false);
|
2010-03-17 19:08:56 +00:00
|
|
|
|
|
|
|
// Break cycles, otherwise we end up leaking the window with everything
|
|
|
|
// attached to it.
|
|
|
|
delete this.win;
|
|
|
|
delete this.preview;
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
get wrappedJSObject() {
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Resizes the canvasPreview to 0x0, essentially freeing its memory.
|
2015-01-18 15:06:00 +00:00
|
|
|
resetCanvasPreview: function () {
|
2016-01-12 17:08:33 +00:00
|
|
|
this.canvasPreview.width = 0;
|
|
|
|
this.canvasPreview.height = 0;
|
2015-01-18 15:06:00 +00:00
|
|
|
},
|
2015-01-15 15:34:57 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
/**
|
|
|
|
* Set the canvas dimensions.
|
|
|
|
*/
|
|
|
|
resizeCanvasPreview: function (aRequestedWidth, aRequestedHeight) {
|
|
|
|
this.canvasPreview.width = aRequestedWidth;
|
|
|
|
this.canvasPreview.height = aRequestedHeight;
|
2015-01-15 15:34:57 +00:00
|
|
|
},
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2010-10-19 23:06:00 +00:00
|
|
|
get zoom() {
|
2013-04-09 16:01:13 +00:00
|
|
|
// Note that winutils.fullZoom accounts for "quantization" of the zoom factor
|
2014-07-09 21:27:49 +00:00
|
|
|
// from nsIContentViewer due to conversion through appUnits.
|
2013-04-09 16:01:13 +00:00
|
|
|
// We do -not- want screenPixelsPerCSSPixel here, because that would -also-
|
|
|
|
// incorporate any scaling that is applied due to hi-dpi resolution options.
|
2016-01-12 17:08:33 +00:00
|
|
|
return this.tab.linkedBrowser.fullZoom;
|
|
|
|
},
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
get screenPixelsPerCSSPixel() {
|
|
|
|
let chromeWin = this.tab.ownerGlobal;
|
|
|
|
let windowUtils = chromeWin.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
return windowUtils.screenPixelsPerCSSPixel;
|
|
|
|
},
|
2010-10-19 23:06:00 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
get browserDims() {
|
|
|
|
return this.tab.linkedBrowser.getBoundingClientRect();
|
|
|
|
},
|
|
|
|
|
|
|
|
cacheBrowserDims: function () {
|
|
|
|
let dims = this.browserDims;
|
|
|
|
this._cachedWidth = dims.width;
|
|
|
|
this._cachedHeight = dims.height;
|
|
|
|
},
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
testCacheBrowserDims: function () {
|
|
|
|
let dims = this.browserDims;
|
|
|
|
return this._cachedWidth == dims.width &&
|
|
|
|
this._cachedHeight == dims.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Capture a new thumbnail image for this preview. Called by the controller
|
|
|
|
* in response to a request for a new thumbnail image.
|
|
|
|
*/
|
|
|
|
updateCanvasPreview: function (aFullScale, aCallback) {
|
|
|
|
// Update our cached browser dims so that delayed resize
|
|
|
|
// events don't trigger another invalidation if this tab becomes active.
|
|
|
|
this.cacheBrowserDims();
|
|
|
|
PageThumbs.captureToCanvas(this.linkedBrowser, this.canvasPreview,
|
|
|
|
aCallback, { fullScale: aFullScale });
|
2009-10-06 04:26:15 +00:00
|
|
|
// If we're updating the canvas, then we're in the middle of a peek so
|
|
|
|
// don't discard the cache of previews.
|
|
|
|
AeroPeek.resetCacheTimer();
|
|
|
|
},
|
|
|
|
|
2010-01-17 14:04:00 +00:00
|
|
|
updateTitleAndTooltip: function () {
|
|
|
|
let title = this.win.tabbrowser.getWindowTitleForBrowser(this.linkedBrowser);
|
|
|
|
this.preview.title = title;
|
|
|
|
this.preview.tooltip = title;
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// nsITaskbarPreviewController
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
// window width and height, not browser
|
2009-10-06 04:26:15 +00:00
|
|
|
get width() {
|
|
|
|
return this.win.width;
|
|
|
|
},
|
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
// window width and height, not browser
|
2009-10-06 04:26:15 +00:00
|
|
|
get height() {
|
|
|
|
return this.win.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
get thumbnailAspectRatio() {
|
2016-01-12 17:08:33 +00:00
|
|
|
let browserDims = this.browserDims;
|
2009-10-06 04:26:15 +00:00
|
|
|
// Avoid returning 0
|
2016-01-12 17:08:33 +00:00
|
|
|
let tabWidth = browserDims.width || 1;
|
2009-10-06 04:26:15 +00:00
|
|
|
// Avoid divide by 0
|
2016-01-12 17:08:33 +00:00
|
|
|
let tabHeight = browserDims.height || 1;
|
2009-10-06 04:26:15 +00:00
|
|
|
return tabWidth / tabHeight;
|
|
|
|
},
|
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
/**
|
|
|
|
* Responds to taskbar requests for window previews. Returns the results asynchronously
|
|
|
|
* through updateCanvasPreview.
|
|
|
|
*
|
|
|
|
* @param aTaskbarCallback nsITaskbarPreviewCallback results callback
|
|
|
|
*/
|
|
|
|
requestPreview: function (aTaskbarCallback) {
|
|
|
|
// Grab a high res content preview
|
|
|
|
this.resetCanvasPreview();
|
|
|
|
this.updateCanvasPreview(true, (aPreviewCanvas) => {
|
|
|
|
let winWidth = this.win.width;
|
|
|
|
let winHeight = this.win.height;
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
let composite = PageThumbs.createCanvas();
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
// Use transparency, Aero glass is drawn black without it.
|
|
|
|
composite.mozOpaque = false;
|
|
|
|
|
|
|
|
let ctx = composite.getContext('2d');
|
|
|
|
let scale = this.screenPixelsPerCSSPixel / this.zoom;
|
|
|
|
|
|
|
|
composite.width = winWidth * scale;
|
|
|
|
composite.height = winHeight * scale;
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.scale(scale, scale);
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
// Draw chrome. Note we currently do not get scrollbars for remote frames
|
|
|
|
// in the image above.
|
|
|
|
ctx.drawWindow(this.win.win, 0, 0, winWidth, winHeight, "rgba(0,0,0,0)");
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
// Draw the content are into the composite canvas at the right location.
|
2016-01-12 17:08:33 +00:00
|
|
|
ctx.drawImage(aPreviewCanvas, this.browserDims.x, this.browserDims.y,
|
|
|
|
aPreviewCanvas.width, aPreviewCanvas.height);
|
2016-01-12 17:08:33 +00:00
|
|
|
ctx.restore();
|
|
|
|
|
|
|
|
// Deliver the resulting composite canvas to Windows
|
2016-01-12 17:08:33 +00:00
|
|
|
this.win.tabbrowser.previewTab(this.tab, function () {
|
|
|
|
aTaskbarCallback.done(composite, false);
|
|
|
|
});
|
2016-01-12 17:08:33 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responds to taskbar requests for tab thumbnails. Returns the results asynchronously
|
|
|
|
* through updateCanvasPreview.
|
|
|
|
*
|
|
|
|
* Note Windows requests a specific width and height here, if the resulting thumbnail
|
|
|
|
* does not match these dimensions thumbnail display will fail.
|
|
|
|
*
|
|
|
|
* @param aTaskbarCallback nsITaskbarPreviewCallback results callback
|
|
|
|
* @param aRequestedWidth width of the requested thumbnail
|
|
|
|
* @param aRequestedHeight height of the requested thumbnail
|
|
|
|
*/
|
|
|
|
requestThumbnail: function (aTaskbarCallback, aRequestedWidth, aRequestedHeight) {
|
|
|
|
this.resizeCanvasPreview(aRequestedWidth, aRequestedHeight);
|
|
|
|
this.updateCanvasPreview(false, (aThumbnailCanvas) => {
|
|
|
|
aTaskbarCallback.done(aThumbnailCanvas, false);
|
|
|
|
});
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// Event handling
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
onClose: function () {
|
|
|
|
this.win.tabbrowser.removeTab(this.tab);
|
|
|
|
},
|
|
|
|
|
|
|
|
onActivate: function () {
|
|
|
|
this.win.tabbrowser.selectedTab = this.tab;
|
|
|
|
|
|
|
|
// Accept activation - this will restore the browser window
|
|
|
|
// if it's minimized
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// nsIDOMEventListener
|
2009-10-06 04:26:15 +00:00
|
|
|
handleEvent: function (evt) {
|
|
|
|
switch (evt.type) {
|
2010-09-09 07:48:33 +00:00
|
|
|
case "TabAttrModified":
|
2010-01-17 14:04:00 +00:00
|
|
|
this.updateTitleAndTooltip();
|
2009-10-06 04:26:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyGetter(PreviewController.prototype, "canvasPreviewFlags",
|
|
|
|
function () { let canvasInterface = Ci.nsIDOMCanvasRenderingContext2D;
|
|
|
|
return canvasInterface.DRAWWINDOW_DRAW_VIEW
|
|
|
|
| canvasInterface.DRAWWINDOW_DRAW_CARET
|
2010-07-26 21:21:46 +00:00
|
|
|
| canvasInterface.DRAWWINDOW_ASYNC_DECODE_IMAGES
|
2009-10-06 04:26:15 +00:00
|
|
|
| canvasInterface.DRAWWINDOW_DO_NOT_FLUSH;
|
|
|
|
});
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// TabWindow
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This class monitors a browser window for changes to its tabs
|
|
|
|
*
|
|
|
|
* @param win
|
2016-01-12 17:08:33 +00:00
|
|
|
* The nsIDOMWindow browser window
|
2009-10-06 04:26:15 +00:00
|
|
|
*/
|
|
|
|
function TabWindow(win) {
|
|
|
|
this.win = win;
|
|
|
|
this.tabbrowser = win.gBrowser;
|
|
|
|
|
2013-09-25 13:22:31 +00:00
|
|
|
this.previews = new Map();
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2011-02-05 20:22:24 +00:00
|
|
|
for (let i = 0; i < this.tabEvents.length; i++)
|
|
|
|
this.tabbrowser.tabContainer.addEventListener(this.tabEvents[i], this, false);
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
for (let i = 0; i < this.winEvents.length; i++)
|
|
|
|
this.win.addEventListener(this.winEvents[i], this, false);
|
|
|
|
|
|
|
|
this.tabbrowser.addTabsProgressListener(this);
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
AeroPeek.windows.push(this);
|
2010-03-22 14:12:04 +00:00
|
|
|
let tabs = this.tabbrowser.tabs;
|
2009-10-06 04:26:15 +00:00
|
|
|
for (let i = 0; i < tabs.length; i++)
|
|
|
|
this.newTab(tabs[i]);
|
|
|
|
|
|
|
|
this.updateTabOrdering();
|
|
|
|
AeroPeek.checkPreviewCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
TabWindow.prototype = {
|
|
|
|
_enabled: false,
|
2016-01-19 22:37:58 +00:00
|
|
|
_cachedWidth: 0,
|
|
|
|
_cachedHeight: 0,
|
2011-02-05 20:22:24 +00:00
|
|
|
tabEvents: ["TabOpen", "TabClose", "TabSelect", "TabMove"],
|
2016-01-12 17:08:33 +00:00
|
|
|
winEvents: ["resize"],
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
destroy: function () {
|
2009-10-07 08:35:16 +00:00
|
|
|
this._destroying = true;
|
|
|
|
|
2010-03-22 14:12:04 +00:00
|
|
|
let tabs = this.tabbrowser.tabs;
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2010-03-17 19:08:56 +00:00
|
|
|
this.tabbrowser.removeTabsProgressListener(this);
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2016-01-19 22:37:58 +00:00
|
|
|
for (let i = 0; i < this.winEvents.length; i++)
|
|
|
|
this.win.removeEventListener(this.winEvents[i], this, false);
|
2016-01-12 17:08:33 +00:00
|
|
|
|
2011-02-05 20:22:24 +00:00
|
|
|
for (let i = 0; i < this.tabEvents.length; i++)
|
|
|
|
this.tabbrowser.tabContainer.removeEventListener(this.tabEvents[i], this, false);
|
2010-03-17 19:08:56 +00:00
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
for (let i = 0; i < tabs.length; i++)
|
2009-10-07 08:35:16 +00:00
|
|
|
this.removeTab(tabs[i]);
|
2009-10-06 04:26:15 +00:00
|
|
|
|
2009-10-06 19:09:49 +00:00
|
|
|
let idx = AeroPeek.windows.indexOf(this.win.gTaskbarTabGroup);
|
2009-10-06 04:26:15 +00:00
|
|
|
AeroPeek.windows.splice(idx, 1);
|
|
|
|
AeroPeek.checkPreviewCount();
|
|
|
|
},
|
|
|
|
|
|
|
|
get width () {
|
|
|
|
return this.win.innerWidth;
|
|
|
|
},
|
|
|
|
get height () {
|
|
|
|
return this.win.innerHeight;
|
|
|
|
},
|
|
|
|
|
2016-01-12 17:08:33 +00:00
|
|
|
cacheDims: function () {
|
|
|
|
this._cachedWidth = this.width;
|
|
|
|
this._cachedHeight = this.height;
|
|
|
|
},
|
|
|
|
|
|
|
|
testCacheDims: function () {
|
|
|
|
return this._cachedWidth == this.width && this._cachedHeight == this.height;
|
|
|
|
},
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
// Invoked when the given tab is added to this window
|
|
|
|
newTab: function (tab) {
|
|
|
|
let controller = new PreviewController(this, tab);
|
2013-05-22 15:39:07 +00:00
|
|
|
// It's OK to add the preview now while the favicon still loads.
|
2013-09-25 13:22:31 +00:00
|
|
|
this.previews.set(tab, controller.preview);
|
2013-05-22 15:39:07 +00:00
|
|
|
AeroPeek.addPreview(controller.preview);
|
|
|
|
// updateTitleAndTooltip relies on having controller.preview which is lazily resolved.
|
|
|
|
// Now that we've updated this.previews, it will resolve successfully.
|
|
|
|
controller.updateTitleAndTooltip();
|
|
|
|
},
|
|
|
|
|
|
|
|
createTabPreview: function (controller) {
|
2010-02-17 00:55:00 +00:00
|
|
|
let docShell = this.win
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell);
|
2011-02-13 03:48:41 +00:00
|
|
|
let preview = AeroPeek.taskbar.createTaskbarTabPreview(docShell, controller);
|
2009-10-06 04:26:15 +00:00
|
|
|
preview.visible = AeroPeek.enabled;
|
2013-05-22 15:39:07 +00:00
|
|
|
preview.active = this.tabbrowser.selectedTab == controller.tab;
|
2016-07-07 17:38:43 +00:00
|
|
|
this.onLinkIconAvailable(controller.tab.linkedBrowser,
|
|
|
|
controller.tab.getAttribute("image"));
|
2013-05-22 15:39:07 +00:00
|
|
|
return preview;
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Invoked when the given tab is closed
|
2009-10-07 08:35:16 +00:00
|
|
|
removeTab: function (tab) {
|
2009-10-06 04:26:15 +00:00
|
|
|
let preview = this.previewFromTab(tab);
|
|
|
|
preview.active = false;
|
|
|
|
preview.visible = false;
|
|
|
|
preview.move(null);
|
|
|
|
preview.controller.wrappedJSObject.destroy();
|
|
|
|
|
2013-09-25 13:22:31 +00:00
|
|
|
this.previews.delete(tab);
|
2009-10-06 04:26:15 +00:00
|
|
|
AeroPeek.removePreview(preview);
|
|
|
|
},
|
|
|
|
|
|
|
|
get enabled () {
|
|
|
|
return this._enabled;
|
|
|
|
},
|
|
|
|
|
2009-10-07 08:35:16 +00:00
|
|
|
set enabled (enable) {
|
2009-10-06 04:26:15 +00:00
|
|
|
this._enabled = enable;
|
|
|
|
// Because making a tab visible requires that the tab it is next to be
|
|
|
|
// visible, it is far simpler to unset the 'next' tab and recreate them all
|
|
|
|
// at once.
|
2016-11-03 11:51:48 +00:00
|
|
|
for (let [, preview] of this.previews) {
|
2009-10-06 04:26:15 +00:00
|
|
|
preview.move(null);
|
|
|
|
preview.visible = enable;
|
2013-09-25 13:22:31 +00:00
|
|
|
}
|
2009-10-06 04:26:15 +00:00
|
|
|
this.updateTabOrdering();
|
|
|
|
},
|
|
|
|
|
|
|
|
previewFromTab: function (tab) {
|
2013-09-25 13:22:31 +00:00
|
|
|
return this.previews.get(tab);
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateTabOrdering: function () {
|
2013-09-25 13:22:31 +00:00
|
|
|
let previews = this.previews;
|
|
|
|
let tabs = this.tabbrowser.tabs;
|
|
|
|
|
|
|
|
// Previews are internally stored using a map, so we need to iterate the
|
|
|
|
// tabbrowser's array of tabs to retrieve previews in the same order.
|
2015-12-17 18:31:08 +00:00
|
|
|
let inorder = [];
|
|
|
|
for (let t of tabs) {
|
|
|
|
if (previews.has(t)) {
|
|
|
|
inorder.push(previews.get(t));
|
|
|
|
}
|
|
|
|
}
|
2013-09-25 13:22:31 +00:00
|
|
|
|
2010-02-08 15:10:39 +00:00
|
|
|
// Since the internal taskbar array has not yet been updated we must force
|
|
|
|
// on it the sorting order of our local array. To do so we must walk
|
|
|
|
// the local array backwards, otherwise we would send move requests in the
|
|
|
|
// wrong order. See bug 522610 for details.
|
2013-09-25 13:22:31 +00:00
|
|
|
for (let i = inorder.length - 1; i >= 0; i--) {
|
|
|
|
inorder[i].move(inorder[i + 1] || null);
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// nsIDOMEventListener
|
2009-10-06 04:26:15 +00:00
|
|
|
handleEvent: function (evt) {
|
|
|
|
let tab = evt.originalTarget;
|
|
|
|
switch (evt.type) {
|
|
|
|
case "TabOpen":
|
|
|
|
this.newTab(tab);
|
|
|
|
this.updateTabOrdering();
|
|
|
|
break;
|
|
|
|
case "TabClose":
|
|
|
|
this.removeTab(tab);
|
|
|
|
this.updateTabOrdering();
|
|
|
|
break;
|
|
|
|
case "TabSelect":
|
|
|
|
this.previewFromTab(tab).active = true;
|
|
|
|
break;
|
|
|
|
case "TabMove":
|
|
|
|
this.updateTabOrdering();
|
|
|
|
break;
|
2016-01-12 17:08:33 +00:00
|
|
|
case "resize":
|
|
|
|
if (!AeroPeek._prefenabled)
|
|
|
|
return;
|
|
|
|
this.onResize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set or reset a timer that will invalidate visible thumbnails soon.
|
|
|
|
setInvalidationTimer: function () {
|
|
|
|
if (!this.invalidateTimer) {
|
|
|
|
this.invalidateTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
}
|
|
|
|
this.invalidateTimer.cancel();
|
|
|
|
|
|
|
|
// delay 1 second before invalidating
|
|
|
|
this.invalidateTimer.initWithCallback(() => {
|
|
|
|
// invalidate every preview. note the internal implementation of
|
|
|
|
// invalidate ignores thumbnails that aren't visible.
|
|
|
|
this.previews.forEach(function (aPreview) {
|
|
|
|
let controller = aPreview.controller.wrappedJSObject;
|
|
|
|
if (!controller.testCacheBrowserDims()) {
|
|
|
|
controller.cacheBrowserDims();
|
|
|
|
aPreview.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
},
|
|
|
|
|
|
|
|
onResize: function () {
|
|
|
|
// Specific to a window.
|
|
|
|
|
|
|
|
// Call invalidate on each tab thumbnail so that Windows will request an
|
|
|
|
// updated image. However don't do this repeatedly across multiple resize
|
|
|
|
// events triggered during window border drags.
|
|
|
|
|
|
|
|
if (this.testCacheDims()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the window dims on our TabWindow object.
|
|
|
|
this.cacheDims();
|
|
|
|
|
|
|
|
// invalidate soon
|
|
|
|
this.setInvalidationTimer();
|
|
|
|
},
|
|
|
|
|
|
|
|
invalidateTabPreview: function(aBrowser) {
|
|
|
|
for (let [tab, preview] of this.previews) {
|
|
|
|
if (aBrowser == tab.linkedBrowser) {
|
|
|
|
preview.invalidate();
|
|
|
|
break;
|
|
|
|
}
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// Browser progress listener
|
2016-01-12 17:08:33 +00:00
|
|
|
|
|
|
|
onLocationChange: function (aBrowser) {
|
|
|
|
// I'm not sure we need this, onStateChange does a really good job
|
|
|
|
// of picking up page changes.
|
2016-10-24 17:14:19 +00:00
|
|
|
// this.invalidateTabPreview(aBrowser);
|
2016-01-12 17:08:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
|
|
|
|
if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP &&
|
|
|
|
aStateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) {
|
|
|
|
this.invalidateTabPreview(aBrowser);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-29 22:30:51 +00:00
|
|
|
directRequestProtocols: new Set([
|
|
|
|
"file", "chrome", "resource", "about"
|
|
|
|
]),
|
2009-12-15 07:49:08 +00:00
|
|
|
onLinkIconAvailable: function (aBrowser, aIconURL) {
|
2016-07-07 17:38:43 +00:00
|
|
|
let requestURL = null;
|
|
|
|
if (aIconURL) {
|
|
|
|
let shouldRequestFaviconURL = true;
|
|
|
|
try {
|
2016-10-18 11:34:35 +00:00
|
|
|
let urlObject = NetUtil.newURI(aIconURL);
|
2016-07-07 17:38:43 +00:00
|
|
|
shouldRequestFaviconURL =
|
|
|
|
!this.directRequestProtocols.has(urlObject.scheme);
|
|
|
|
} catch (ex) {}
|
|
|
|
|
|
|
|
requestURL = shouldRequestFaviconURL ?
|
|
|
|
"moz-anno:favicon:" + aIconURL :
|
|
|
|
aIconURL;
|
2016-06-29 22:30:51 +00:00
|
|
|
}
|
2016-07-07 17:38:43 +00:00
|
|
|
let isDefaultFavicon = !requestURL;
|
2014-10-24 21:36:11 +00:00
|
|
|
getFaviconAsImage(
|
2016-06-29 22:30:51 +00:00
|
|
|
requestURL,
|
2016-01-12 17:08:33 +00:00
|
|
|
PrivateBrowsingUtils.isWindowPrivate(this.win),
|
2016-06-29 22:30:51 +00:00
|
|
|
img => {
|
|
|
|
let index = this.tabbrowser.browsers.indexOf(aBrowser);
|
|
|
|
// Only add it if we've found the index and the URI is still the same.
|
|
|
|
// The tab could have closed, and there's no guarantee the icons
|
|
|
|
// will have finished fetching 'in order'.
|
2014-10-24 21:36:11 +00:00
|
|
|
if (index != -1) {
|
2016-06-29 22:30:51 +00:00
|
|
|
let tab = this.tabbrowser.tabs[index];
|
2016-07-07 17:38:43 +00:00
|
|
|
let preview = this.previews.get(tab);
|
|
|
|
if (tab.getAttribute("image") == aIconURL ||
|
|
|
|
(!preview.icon && isDefaultFavicon)) {
|
|
|
|
preview.icon = img;
|
2016-06-29 22:30:51 +00:00
|
|
|
}
|
2014-10-24 21:36:11 +00:00
|
|
|
}
|
2016-06-29 22:30:51 +00:00
|
|
|
}
|
|
|
|
);
|
2009-10-06 04:26:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// AeroPeek
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This object acts as global storage and external interface for this feature.
|
|
|
|
* It maintains the values of the prefs.
|
|
|
|
*/
|
2012-10-31 16:13:28 +00:00
|
|
|
this.AeroPeek = {
|
2009-10-06 04:26:15 +00:00
|
|
|
available: false,
|
|
|
|
// Does the pref say we're enabled?
|
2016-07-07 17:38:43 +00:00
|
|
|
__prefenabled: false,
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
_enabled: true,
|
|
|
|
|
2016-07-07 17:38:43 +00:00
|
|
|
initialized: false,
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
// nsITaskbarTabPreview array
|
|
|
|
previews: [],
|
|
|
|
|
|
|
|
// TabWindow array
|
|
|
|
windows: [],
|
|
|
|
|
|
|
|
// nsIWinTaskbar service
|
|
|
|
taskbar: null,
|
|
|
|
|
|
|
|
// Maximum number of previews
|
|
|
|
maxpreviews: 20,
|
|
|
|
|
|
|
|
// Length of time in seconds that previews are cached
|
|
|
|
cacheLifespan: 20,
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
if (!(WINTASKBAR_CONTRACTID in Cc))
|
|
|
|
return;
|
|
|
|
this.taskbar = Cc[WINTASKBAR_CONTRACTID].getService(Ci.nsIWinTaskbar);
|
|
|
|
this.available = this.taskbar.available;
|
|
|
|
if (!this.available)
|
|
|
|
return;
|
|
|
|
|
2016-07-07 17:38:43 +00:00
|
|
|
this.prefs.addObserver(TOGGLE_PREF_NAME, this, true);
|
2009-10-06 04:26:15 +00:00
|
|
|
this.enabled = this._prefenabled = this.prefs.getBoolPref(TOGGLE_PREF_NAME);
|
2016-07-07 17:38:43 +00:00
|
|
|
this.initialized = true;
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
2010-03-17 19:08:56 +00:00
|
|
|
destroy: function destroy() {
|
|
|
|
this._enabled = false;
|
|
|
|
|
|
|
|
if (this.cacheTimer)
|
|
|
|
this.cacheTimer.cancel();
|
|
|
|
},
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
get enabled() {
|
|
|
|
return this._enabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
set enabled(enable) {
|
2009-10-08 17:35:18 +00:00
|
|
|
if (this._enabled == enable)
|
|
|
|
return;
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
this._enabled = enable;
|
|
|
|
|
2009-10-08 17:35:18 +00:00
|
|
|
this.windows.forEach(function (win) {
|
2009-10-06 04:26:15 +00:00
|
|
|
win.enabled = enable;
|
2009-10-08 17:35:18 +00:00
|
|
|
});
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
2016-07-07 17:38:43 +00:00
|
|
|
get _prefenabled() {
|
|
|
|
return this.__prefenabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
set _prefenabled(enable) {
|
|
|
|
if (enable == this.__prefenabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.__prefenabled = enable;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
this.enable();
|
|
|
|
} else {
|
|
|
|
this.disable();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_observersAdded: false,
|
|
|
|
|
|
|
|
enable() {
|
|
|
|
if (!this._observersAdded) {
|
|
|
|
this.prefs.addObserver(DISABLE_THRESHOLD_PREF_NAME, this, true);
|
|
|
|
this.prefs.addObserver(CACHE_EXPIRATION_TIME_PREF_NAME, this, true);
|
|
|
|
PlacesUtils.history.addObserver(this, true);
|
|
|
|
this._observersAdded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cacheLifespan = this.prefs.getIntPref(CACHE_EXPIRATION_TIME_PREF_NAME);
|
|
|
|
|
|
|
|
this.maxpreviews = this.prefs.getIntPref(DISABLE_THRESHOLD_PREF_NAME);
|
|
|
|
|
|
|
|
// If the user toggled us on/off while the browser was already up
|
|
|
|
// (rather than this code running on startup because the pref was
|
|
|
|
// already set to true), we must initialize previews for open windows:
|
|
|
|
if (this.initialized) {
|
|
|
|
let browserWindows = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (browserWindows.hasMoreElements()) {
|
|
|
|
let win = browserWindows.getNext();
|
|
|
|
if (!win.closed) {
|
|
|
|
this.onOpenWindow(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
disable() {
|
|
|
|
while (this.windows.length) {
|
2016-07-13 13:31:13 +00:00
|
|
|
// We can't call onCloseWindow here because it'll bail if we're not
|
|
|
|
// enabled.
|
|
|
|
let tabWinObject = this.windows[0];
|
|
|
|
tabWinObject.destroy(); // This will remove us from the array.
|
|
|
|
delete tabWinObject.win.gTaskbarTabGroup; // Tidy up the window.
|
2016-07-07 17:38:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-10-06 04:26:15 +00:00
|
|
|
addPreview: function (preview) {
|
|
|
|
this.previews.push(preview);
|
|
|
|
this.checkPreviewCount();
|
|
|
|
},
|
|
|
|
|
|
|
|
removePreview: function (preview) {
|
|
|
|
let idx = this.previews.indexOf(preview);
|
|
|
|
this.previews.splice(idx, 1);
|
|
|
|
this.checkPreviewCount();
|
|
|
|
},
|
|
|
|
|
|
|
|
checkPreviewCount: function () {
|
2016-07-07 17:38:43 +00:00
|
|
|
if (!this._prefenabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.enabled = this.previews.length <= this.maxpreviews;
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onOpenWindow: function (win) {
|
|
|
|
// This occurs when the taskbar service is not available (xp, vista)
|
2016-07-07 17:38:43 +00:00
|
|
|
if (!this.available || !this._prefenabled)
|
2009-10-06 04:26:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
win.gTaskbarTabGroup = new TabWindow(win);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCloseWindow: function (win) {
|
|
|
|
// This occurs when the taskbar service is not available (xp, vista)
|
2016-07-07 17:38:43 +00:00
|
|
|
if (!this.available || !this._prefenabled)
|
2009-10-06 04:26:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
win.gTaskbarTabGroup.destroy();
|
2010-03-17 19:08:56 +00:00
|
|
|
delete win.gTaskbarTabGroup;
|
|
|
|
|
|
|
|
if (this.windows.length == 0)
|
|
|
|
this.destroy();
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resetCacheTimer: function () {
|
|
|
|
this.cacheTimer.cancel();
|
2016-11-10 22:48:04 +00:00
|
|
|
this.cacheTimer.init(this, 1000 * this.cacheLifespan, Ci.nsITimer.TYPE_ONE_SHOT);
|
2009-10-06 04:26:15 +00:00
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:06 +00:00
|
|
|
// nsIObserver
|
2009-10-06 04:26:15 +00:00
|
|
|
observe: function (aSubject, aTopic, aData) {
|
2016-07-07 17:38:43 +00:00
|
|
|
if (aTopic == "nsPref:changed" && aData == TOGGLE_PREF_NAME) {
|
|
|
|
this._prefenabled = this.prefs.getBoolPref(TOGGLE_PREF_NAME);
|
|
|
|
}
|
|
|
|
if (!this._prefenabled) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-06 04:26:15 +00:00
|
|
|
switch (aTopic) {
|
|
|
|
case "nsPref:changed":
|
2009-10-07 08:35:16 +00:00
|
|
|
if (aData == CACHE_EXPIRATION_TIME_PREF_NAME)
|
2009-10-06 04:26:15 +00:00
|
|
|
break;
|
2009-10-07 08:35:16 +00:00
|
|
|
|
2016-07-07 17:38:43 +00:00
|
|
|
if (aData == DISABLE_THRESHOLD_PREF_NAME)
|
2009-10-06 04:26:15 +00:00
|
|
|
this.maxpreviews = this.prefs.getIntPref(DISABLE_THRESHOLD_PREF_NAME);
|
|
|
|
// Might need to enable/disable ourselves
|
|
|
|
this.checkPreviewCount();
|
|
|
|
break;
|
|
|
|
case "timer-callback":
|
2009-10-08 17:35:18 +00:00
|
|
|
this.previews.forEach(function (preview) {
|
2009-10-06 04:26:15 +00:00
|
|
|
let controller = preview.controller.wrappedJSObject;
|
|
|
|
controller.resetCanvasPreview();
|
2009-10-08 17:35:18 +00:00
|
|
|
});
|
2009-10-06 04:26:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-06-29 22:30:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* nsINavHistoryObserver implementation */
|
|
|
|
onBeginUpdateBatch() {},
|
|
|
|
onEndUpdateBatch() {},
|
|
|
|
onVisit() {},
|
|
|
|
onTitleChanged() {},
|
|
|
|
onFrecencyChanged() {},
|
|
|
|
onManyFrecenciesChanged() {},
|
|
|
|
onDeleteURI() {},
|
|
|
|
onClearHistory() {},
|
|
|
|
onDeleteVisits() {},
|
|
|
|
onPageChanged(uri, changedConst, newValue) {
|
2016-07-07 17:38:43 +00:00
|
|
|
if (this.enabled && changedConst == Ci.nsINavHistoryObserver.ATTRIBUTE_FAVICON) {
|
2016-06-29 22:30:51 +00:00
|
|
|
for (let win of this.windows) {
|
2016-11-03 11:51:48 +00:00
|
|
|
for (let [tab, ] of win.previews) {
|
2016-06-29 22:30:51 +00:00
|
|
|
if (tab.getAttribute("image") == newValue) {
|
|
|
|
win.onLinkIconAvailable(tab.linkedBrowser, newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-07-07 17:38:43 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsINavHistoryObserver,
|
|
|
|
Ci.nsIObserver
|
|
|
|
]),
|
2009-10-06 04:26:15 +00:00
|
|
|
};
|
|
|
|
|
2015-09-23 08:58:18 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(AeroPeek, "cacheTimer", () =>
|
2009-10-06 04:26:15 +00:00
|
|
|
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer)
|
|
|
|
);
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(AeroPeek, "prefs",
|
|
|
|
"@mozilla.org/preferences-service;1",
|
2012-01-17 01:34:51 +00:00
|
|
|
"nsIPrefBranch");
|
2009-10-06 04:26:15 +00:00
|
|
|
|
|
|
|
AeroPeek.initialize();
|