Backed out changeset bcd726a4a258 (bug 725268)

This commit is contained in:
Tim Taubert 2012-02-09 11:47:08 +01:00
parent e6e882d134
commit 481de717cf
5 changed files with 65 additions and 69 deletions

View File

@ -77,8 +77,11 @@ let gBrowserThumbnails = {
}, },
_capture: function Thumbnails_capture(aBrowser) { _capture: function Thumbnails_capture(aBrowser) {
if (this._shouldCapture(aBrowser)) if (this._shouldCapture(aBrowser)) {
this._pageThumbs.captureAndStore(aBrowser); this._pageThumbs.capture(aBrowser.contentWindow, function (aInputStream) {
this._pageThumbs.store(aBrowser.currentURI.spec, aInputStream);
}.bind(this));
}
}, },
_delayedCapture: function Thumbnails_delayedCapture(aBrowser) { _delayedCapture: function Thumbnails_delayedCapture(aBrowser) {

View File

@ -135,24 +135,16 @@ let gTransformation = {
* callback - the callback to call when finished * callback - the callback to call when finished
*/ */
rearrangeSites: function Transformation_rearrangeSites(aSites, aOptions) { rearrangeSites: function Transformation_rearrangeSites(aSites, aOptions) {
let batch;
let cells = gGrid.cells; let cells = gGrid.cells;
let callback = aOptions && aOptions.callback; let callback = aOptions && aOptions.callback;
let unfreeze = aOptions && aOptions.unfreeze; let unfreeze = aOptions && aOptions.unfreeze;
let batch = new Batch(function () {
if (aOptions && "callback" in aOptions)
aOptions.callback();
gGrid.unlock();
});
if (callback) { if (callback) {
batch = new Batch(callback); batch = new Batch(callback);
callback = function () batch.pop(); callback = function () batch.pop();
} }
gGrid.lock();
aSites.forEach(function (aSite, aIndex) { aSites.forEach(function (aSite, aIndex) {
// Do not re-arrange empty cells or the dragged site. // Do not re-arrange empty cells or the dragged site.
if (!aSite || aSite == gDrag.draggedSite) if (!aSite || aSite == gDrag.draggedSite)

View File

@ -20,34 +20,29 @@ let gUpdater = {
// Find all sites that remain in the grid. // Find all sites that remain in the grid.
let sites = this._findRemainingSites(links); let sites = this._findRemainingSites(links);
Grid.lock(); let self = this;
// Remove sites that are no longer in the grid. // Remove sites that are no longer in the grid.
this._removeLegacySites(sites, function () { this._removeLegacySites(sites, function () {
// Freeze all site positions so that we can move their DOM nodes around // Freeze all site positions so that we can move their DOM nodes around
// without any visual impact. // without any visual impact.
this._freezeSitePositions(sites); self._freezeSitePositions(sites);
// Move the sites' DOM nodes to their new position in the DOM. This will // Move the sites' DOM nodes to their new position in the DOM. This will
// have no visual effect as all the sites have been frozen and will // have no visual effect as all the sites have been frozen and will
// remain in their current position. // remain in their current position.
this._moveSiteNodes(sites); self._moveSiteNodes(sites);
// Now it's time to animate the sites actually moving to their new // Now it's time to animate the sites actually moving to their new
// positions. // positions.
this._rearrangeSites(sites, function () { self._rearrangeSites(sites, function () {
// Try to fill empty cells and finish. // Try to fill empty cells and finish.
this._fillEmptyCells(links, function () { self._fillEmptyCells(links, aCallback);
gGrid.unlock();
if (aCallback)
aCallback();
});
// Update other pages that might be open to keep them synced. // Update other pages that might be open to keep them synced.
gAllPages.update(gPage); gAllPages.update(gPage);
}.bind(this)); });
}.bind(this)); });
}, },
/** /**

View File

@ -104,42 +104,43 @@ let PageThumbs = {
}, },
/** /**
* Captures a thumbnail for the given browser and stores it to the cache. * Stores the image data contained in the given canvas to the underlying
* @param aBrowser The browser to capture a thumbnail for. * storage.
* @param aCallback The function to be called when finished (optional). * @param aKey The key to use for the storage.
* @param aInputStream The input stream containing the image data.
* @param aCallback The function to be called when the canvas data has been
* stored (optional).
*/ */
captureAndStore: function PageThumbs_captureAndStore(aBrowser, aCallback) { store: function PageThumbs_store(aKey, aInputStream, aCallback) {
this.capture(aBrowser.contentWindow, function (aInputStream) { let telemetryStoreTime = new Date();
let telemetryStoreTime = new Date();
function finish(aSuccessful) { function finish(aSuccessful) {
if (aSuccessful) { if (aSuccessful) {
Services.telemetry.getHistogramById("FX_THUMBNAILS_STORE_TIME_MS") Services.telemetry.getHistogramById("FX_THUMBNAILS_STORE_TIME_MS")
.add(new Date() - telemetryStoreTime); .add(new Date() - telemetryStoreTime);
}
if (aCallback)
aCallback(aSuccessful);
} }
// Get a writeable cache entry. if (aCallback)
PageThumbsCache.getWriteEntry(aBrowser.currentURI.spec, function (aEntry) { aCallback(aSuccessful);
if (!aEntry) { }
finish(false);
return;
}
let outputStream = aEntry.openOutputStream(0); // Get a writeable cache entry.
PageThumbsCache.getWriteEntry(aKey, function (aEntry) {
if (!aEntry) {
finish(false);
return;
}
// Write the image data to the cache entry. let outputStream = aEntry.openOutputStream(0);
NetUtil.asyncCopy(aInputStream, outputStream, function (aResult) {
let success = Components.isSuccessCode(aResult);
if (success)
aEntry.markValid();
aEntry.close(); // Write the image data to the cache entry.
finish(success); NetUtil.asyncCopy(aInputStream, outputStream, function (aResult) {
}); let success = Components.isSuccessCode(aResult);
if (success)
aEntry.markValid();
aEntry.close();
finish(success);
}); });
}); });
}, },

View File

@ -94,29 +94,34 @@ function whenLoaded(aElement, aCallback) {
* @param aMessage The info message to print when comparing the pixel color. * @param aMessage The info message to print when comparing the pixel color.
*/ */
function captureAndCheckColor(aRed, aGreen, aBlue, aMessage) { function captureAndCheckColor(aRed, aGreen, aBlue, aMessage) {
let browser = gBrowser.selectedBrowser; let window = gBrowser.selectedTab.linkedBrowser.contentWindow;
// Capture the screenshot. // Capture the screenshot.
PageThumbs.captureAndStore(browser, function () { PageThumbs.capture(window, function (aData) {
let width = 100, height = 100; let key = Date.now();
let thumb = PageThumbs.getThumbnailURL(browser.currentURI.spec, width, height);
getXULDocument(function (aDocument) { // Store the thumbnail in the cache.
let htmlns = "http://www.w3.org/1999/xhtml"; PageThumbs.store(key, aData, function () {
let img = aDocument.createElementNS(htmlns, "img"); let width = 100, height = 100;
img.setAttribute("src", thumb); let thumb = PageThumbs.getThumbnailURL(key, width, height);
whenLoaded(img, function () { getXULDocument(function (aDocument) {
let canvas = aDocument.createElementNS(htmlns, "canvas"); let htmlns = "http://www.w3.org/1999/xhtml";
canvas.setAttribute("width", width); let img = aDocument.createElementNS(htmlns, "img");
canvas.setAttribute("height", height); img.setAttribute("src", thumb);
// Draw the image to a canvas and compare the pixel color values. whenLoaded(img, function () {
let ctx = canvas.getContext("2d"); let canvas = aDocument.createElementNS(htmlns, "canvas");
ctx.drawImage(img, 0, 0, width, height); canvas.setAttribute("width", width);
checkCanvasColor(ctx, aRed, aGreen, aBlue, aMessage); canvas.setAttribute("height", height);
next(); // Draw the image to a canvas and compare the pixel color values.
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
checkCanvasColor(ctx, aRed, aGreen, aBlue, aMessage);
next();
});
}); });
}); });
}); });