From 481de717cf753092ec7b01fa45b41719e24b64c5 Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Thu, 9 Feb 2012 11:47:08 +0100 Subject: [PATCH] Backed out changeset bcd726a4a258 (bug 725268) --- browser/base/content/browser-thumbnails.js | 7 ++- .../base/content/newtab/transformations.js | 10 +--- browser/base/content/newtab/updater.js | 19 +++--- browser/components/thumbnails/PageThumbs.jsm | 59 ++++++++++--------- browser/components/thumbnails/test/head.js | 39 ++++++------ 5 files changed, 65 insertions(+), 69 deletions(-) diff --git a/browser/base/content/browser-thumbnails.js b/browser/base/content/browser-thumbnails.js index cb43cfac025..a9af8b1bc3a 100644 --- a/browser/base/content/browser-thumbnails.js +++ b/browser/base/content/browser-thumbnails.js @@ -77,8 +77,11 @@ let gBrowserThumbnails = { }, _capture: function Thumbnails_capture(aBrowser) { - if (this._shouldCapture(aBrowser)) - this._pageThumbs.captureAndStore(aBrowser); + if (this._shouldCapture(aBrowser)) { + this._pageThumbs.capture(aBrowser.contentWindow, function (aInputStream) { + this._pageThumbs.store(aBrowser.currentURI.spec, aInputStream); + }.bind(this)); + } }, _delayedCapture: function Thumbnails_delayedCapture(aBrowser) { diff --git a/browser/base/content/newtab/transformations.js b/browser/base/content/newtab/transformations.js index e5961f68210..bd05076b782 100644 --- a/browser/base/content/newtab/transformations.js +++ b/browser/base/content/newtab/transformations.js @@ -135,24 +135,16 @@ let gTransformation = { * callback - the callback to call when finished */ rearrangeSites: function Transformation_rearrangeSites(aSites, aOptions) { + let batch; let cells = gGrid.cells; let callback = aOptions && aOptions.callback; let unfreeze = aOptions && aOptions.unfreeze; - let batch = new Batch(function () { - if (aOptions && "callback" in aOptions) - aOptions.callback(); - - gGrid.unlock(); - }); - if (callback) { batch = new Batch(callback); callback = function () batch.pop(); } - gGrid.lock(); - aSites.forEach(function (aSite, aIndex) { // Do not re-arrange empty cells or the dragged site. if (!aSite || aSite == gDrag.draggedSite) diff --git a/browser/base/content/newtab/updater.js b/browser/base/content/newtab/updater.js index 2b60261beb6..1b931046634 100644 --- a/browser/base/content/newtab/updater.js +++ b/browser/base/content/newtab/updater.js @@ -20,34 +20,29 @@ let gUpdater = { // Find all sites that remain in the grid. let sites = this._findRemainingSites(links); - Grid.lock(); + let self = this; // Remove sites that are no longer in the grid. this._removeLegacySites(sites, function () { // Freeze all site positions so that we can move their DOM nodes around // without any visual impact. - this._freezeSitePositions(sites); + self._freezeSitePositions(sites); // 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 // remain in their current position. - this._moveSiteNodes(sites); + self._moveSiteNodes(sites); // Now it's time to animate the sites actually moving to their new // positions. - this._rearrangeSites(sites, function () { + self._rearrangeSites(sites, function () { // Try to fill empty cells and finish. - this._fillEmptyCells(links, function () { - gGrid.unlock(); - - if (aCallback) - aCallback(); - }); + self._fillEmptyCells(links, aCallback); // Update other pages that might be open to keep them synced. gAllPages.update(gPage); - }.bind(this)); - }.bind(this)); + }); + }); }, /** diff --git a/browser/components/thumbnails/PageThumbs.jsm b/browser/components/thumbnails/PageThumbs.jsm index 3958d28b0ae..ff3a6a2fce1 100644 --- a/browser/components/thumbnails/PageThumbs.jsm +++ b/browser/components/thumbnails/PageThumbs.jsm @@ -104,42 +104,43 @@ let PageThumbs = { }, /** - * Captures a thumbnail for the given browser and stores it to the cache. - * @param aBrowser The browser to capture a thumbnail for. - * @param aCallback The function to be called when finished (optional). + * Stores the image data contained in the given canvas to the underlying + * storage. + * @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) { - this.capture(aBrowser.contentWindow, function (aInputStream) { - let telemetryStoreTime = new Date(); + store: function PageThumbs_store(aKey, aInputStream, aCallback) { + let telemetryStoreTime = new Date(); - function finish(aSuccessful) { - if (aSuccessful) { - Services.telemetry.getHistogramById("FX_THUMBNAILS_STORE_TIME_MS") - .add(new Date() - telemetryStoreTime); - } - - if (aCallback) - aCallback(aSuccessful); + function finish(aSuccessful) { + if (aSuccessful) { + Services.telemetry.getHistogramById("FX_THUMBNAILS_STORE_TIME_MS") + .add(new Date() - telemetryStoreTime); } - // Get a writeable cache entry. - PageThumbsCache.getWriteEntry(aBrowser.currentURI.spec, function (aEntry) { - if (!aEntry) { - finish(false); - return; - } + if (aCallback) + aCallback(aSuccessful); + } - 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. - NetUtil.asyncCopy(aInputStream, outputStream, function (aResult) { - let success = Components.isSuccessCode(aResult); - if (success) - aEntry.markValid(); + let outputStream = aEntry.openOutputStream(0); - aEntry.close(); - finish(success); - }); + // Write the image data to the cache entry. + NetUtil.asyncCopy(aInputStream, outputStream, function (aResult) { + let success = Components.isSuccessCode(aResult); + if (success) + aEntry.markValid(); + + aEntry.close(); + finish(success); }); }); }, diff --git a/browser/components/thumbnails/test/head.js b/browser/components/thumbnails/test/head.js index 99a778aedba..c5d63c38a77 100644 --- a/browser/components/thumbnails/test/head.js +++ b/browser/components/thumbnails/test/head.js @@ -94,29 +94,34 @@ function whenLoaded(aElement, aCallback) { * @param aMessage The info message to print when comparing the pixel color. */ function captureAndCheckColor(aRed, aGreen, aBlue, aMessage) { - let browser = gBrowser.selectedBrowser; + let window = gBrowser.selectedTab.linkedBrowser.contentWindow; // Capture the screenshot. - PageThumbs.captureAndStore(browser, function () { - let width = 100, height = 100; - let thumb = PageThumbs.getThumbnailURL(browser.currentURI.spec, width, height); + PageThumbs.capture(window, function (aData) { + let key = Date.now(); - getXULDocument(function (aDocument) { - let htmlns = "http://www.w3.org/1999/xhtml"; - let img = aDocument.createElementNS(htmlns, "img"); - img.setAttribute("src", thumb); + // Store the thumbnail in the cache. + PageThumbs.store(key, aData, function () { + let width = 100, height = 100; + let thumb = PageThumbs.getThumbnailURL(key, width, height); - whenLoaded(img, function () { - let canvas = aDocument.createElementNS(htmlns, "canvas"); - canvas.setAttribute("width", width); - canvas.setAttribute("height", height); + getXULDocument(function (aDocument) { + let htmlns = "http://www.w3.org/1999/xhtml"; + let img = aDocument.createElementNS(htmlns, "img"); + img.setAttribute("src", thumb); - // 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); + whenLoaded(img, function () { + let canvas = aDocument.createElementNS(htmlns, "canvas"); + canvas.setAttribute("width", width); + 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(); + }); }); }); });