From 0ad961344a9a8edae7b3d85e9c6c2a588da20cdc Mon Sep 17 00:00:00 2001 From: Frank Yan Date: Fri, 23 Mar 2012 07:12:34 -0700 Subject: [PATCH 1/2] Bug 731546 - Add link to marketplace on about:home. r=mak --- browser/base/content/abouthome/aboutHome.css | 17 +++++++++++------ browser/base/content/abouthome/aboutHome.xhtml | 7 ++++--- browser/base/content/abouthome/apps.png | Bin 0 -> 438 bytes browser/base/content/browser.js | 17 ++++++++++++----- browser/base/jar.mn | 5 +++-- 5 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 browser/base/content/abouthome/apps.png diff --git a/browser/base/content/abouthome/aboutHome.css b/browser/base/content/abouthome/aboutHome.css index 1574276a537..b4c4c19caac 100644 --- a/browser/base/content/abouthome/aboutHome.css +++ b/browser/base/content/abouthome/aboutHome.css @@ -255,6 +255,7 @@ body[narrow] #launcher[session] > .launchButton { -moz-transition-duration: 0ms; } +.launchButton[hidden], #launcher:not([session]) > #restorePreviousSessionSeparator, #launcher:not([session]) > #restorePreviousSession { display: none; @@ -298,6 +299,10 @@ body[narrow] #restorePreviousSession { line-height: 0; /* remove extra vertical space due to non-zero font-size */ } +#downloads::before { + content: url("chrome://browser/content/abouthome/downloads.png"); +} + #bookmarks::before { content: url("chrome://browser/content/abouthome/bookmarks.png"); } @@ -306,22 +311,22 @@ body[narrow] #restorePreviousSession { content: url("chrome://browser/content/abouthome/history.png"); } -#settings::before { - content: url("chrome://browser/content/abouthome/settings.png"); +#apps::before { + content: url("chrome://browser/content/abouthome/apps.png"); } #addons::before { content: url("chrome://browser/content/abouthome/addons.png"); } -#downloads::before { - content: url("chrome://browser/content/abouthome/downloads.png"); -} - #sync::before { content: url("chrome://browser/content/abouthome/sync.png"); } +#settings::before { + content: url("chrome://browser/content/abouthome/settings.png"); +} + #restorePreviousSession::before { content: url("chrome://browser/content/abouthome/restore-large.png"); height: 48px; diff --git a/browser/base/content/abouthome/aboutHome.xhtml b/browser/base/content/abouthome/aboutHome.xhtml index 2bb268ffa60..12e1c885cf5 100644 --- a/browser/base/content/abouthome/aboutHome.xhtml +++ b/browser/base/content/abouthome/aboutHome.xhtml @@ -91,16 +91,17 @@
+ - + - +
- + diff --git a/browser/base/content/abouthome/apps.png b/browser/base/content/abouthome/apps.png new file mode 100644 index 0000000000000000000000000000000000000000..c6907b2006fa30d7aec833e3cff99706014babac GIT binary patch literal 438 zcmV;n0ZIOeP)L1Va z2LMk13xJ&xx!D6mpstwdUuhE{vfQ{x0x&g#2-J~I^sfLOAiDjHBmgr*cqi=h8{;B9 zcqjXXY&SrN@lDa)gAZa+q7VW67(sO08x`-5D+ojq4Is2gi07K|O}x(^%bYwtuzOmX6+7BQY91pK3BG2eCIwwej*g zwg%&yM@b)UMk4a83z>XZf`~lh#;8Hzj8Z1}()p3+RsiFFc%Lc&Brgz_3RhDx-TB-C z;#NOl<#TH-m}{$`h0i6=wTfBQPgwa}^4wY{O#MU)pEvgt9(-QgPjtEGgA~ZvX%Q07*qoM6N<$g36e}C;$Ke literal 0 HcmV?d00001 diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 61096e45f50..8cb0fdf11f0 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2707,6 +2707,10 @@ function PageProxyClickHandler(aEvent) */ function BrowserOnAboutPageLoad(document) { if (/^about:home$/i.test(document.documentURI)) { + // XXX bug 738646 - when Marketplace is launched, remove this statement and + // the hidden attribute set on the apps button in aboutHome.xhtml + if (getBoolPref("browser.aboutHome.apps", false)) + document.getElementById("apps").removeAttribute("hidden"); let ss = Components.classes["@mozilla.org/browser/sessionstore;1"]. getService(Components.interfaces.nsISessionStore); if (!ss.canRestoreLastSession) @@ -2849,24 +2853,27 @@ function BrowserOnClick(event) { ss.restoreLastSession(); ownerDoc.getElementById("launcher").removeAttribute("session"); } + else if (ot == ownerDoc.getElementById("downloads")) { + BrowserDownloadsUI(); + } else if (ot == ownerDoc.getElementById("bookmarks")) { PlacesCommandHook.showPlacesOrganizer("AllBookmarks"); } else if (ot == ownerDoc.getElementById("history")) { PlacesCommandHook.showPlacesOrganizer("History"); } - else if (ot == ownerDoc.getElementById("settings")) { - openPreferences(); + else if (ot == ownerDoc.getElementById("apps")) { + openUILinkIn("https://marketplace.mozilla.org/", "tab"); } else if (ot == ownerDoc.getElementById("addons")) { BrowserOpenAddonsMgr(); } - else if (ot == ownerDoc.getElementById("downloads")) { - BrowserDownloadsUI(); - } else if (ot == ownerDoc.getElementById("sync")) { openPreferences("paneSync"); } + else if (ot == ownerDoc.getElementById("settings")) { + openPreferences(); + } } } diff --git a/browser/base/jar.mn b/browser/base/jar.mn index 072b7038967..f5699010043 100644 --- a/browser/base/jar.mn +++ b/browser/base/jar.mn @@ -21,12 +21,13 @@ browser.jar: * content/browser/abouthome/aboutHome.css (content/abouthome/aboutHome.css) content/browser/abouthome/snippet1.png (content/abouthome/snippet1.png) content/browser/abouthome/snippet2.png (content/abouthome/snippet2.png) + content/browser/abouthome/downloads.png (content/abouthome/downloads.png) content/browser/abouthome/bookmarks.png (content/abouthome/bookmarks.png) content/browser/abouthome/history.png (content/abouthome/history.png) - content/browser/abouthome/settings.png (content/abouthome/settings.png) + content/browser/abouthome/apps.png (content/abouthome/apps.png) content/browser/abouthome/addons.png (content/abouthome/addons.png) - content/browser/abouthome/downloads.png (content/abouthome/downloads.png) content/browser/abouthome/sync.png (content/abouthome/sync.png) + content/browser/abouthome/settings.png (content/abouthome/settings.png) content/browser/abouthome/restore.png (content/abouthome/restore.png) content/browser/abouthome/restore-large.png (content/abouthome/restore-large.png) content/browser/abouthome/mozilla.png (content/abouthome/mozilla.png) From 222810aa9f1a8d0e01bc4b219d1c5c6b38ef9f1d Mon Sep 17 00:00:00 2001 From: Tim Taubert Date: Fri, 23 Mar 2012 19:12:43 +0100 Subject: [PATCH 2/2] Bug 705911 - [Page Thumbnails] Save screenshots of redirecting sites; r=dao --- browser/components/thumbnails/PageThumbs.jsm | 65 +++++++++++++++++++ .../components/thumbnails/test/Makefile.in | 3 + .../thumbnails/test/background_red.html | 3 + .../test/background_red_redirect.sjs | 10 +++ .../test/browser_thumbnails_redirect.js | 51 +++++++++++++++ browser/components/thumbnails/test/head.js | 44 ++++++++----- 6 files changed, 160 insertions(+), 16 deletions(-) create mode 100644 browser/components/thumbnails/test/background_red.html create mode 100644 browser/components/thumbnails/test/background_red_redirect.sjs create mode 100644 browser/components/thumbnails/test/browser_thumbnails_redirect.js diff --git a/browser/components/thumbnails/PageThumbs.jsm b/browser/components/thumbnails/PageThumbs.jsm index 3512b89d623..78a59c9d2d4 100644 --- a/browser/components/thumbnails/PageThumbs.jsm +++ b/browser/components/thumbnails/PageThumbs.jsm @@ -110,6 +110,9 @@ let PageThumbs = { */ captureAndStore: function PageThumbs_captureAndStore(aBrowser, aCallback) { let url = aBrowser.currentURI.spec; + let channel = aBrowser.docShell.currentDocumentChannel; + let originalURL = channel.originalURI.spec; + this.capture(aBrowser.contentWindow, function (aInputStream) { let telemetryStoreTime = new Date(); @@ -117,6 +120,20 @@ let PageThumbs = { if (aSuccessful) { Services.telemetry.getHistogramById("FX_THUMBNAILS_STORE_TIME_MS") .add(new Date() - telemetryStoreTime); + + // We've been redirected. Create a copy of the current thumbnail for + // the redirect source. We need to do this because: + // + // 1) Users can drag any kind of links onto the newtab page. If those + // links redirect to a different URL then we want to be able to + // provide thumbnails for both of them. + // + // 2) The newtab page should actually display redirect targets, only. + // Because of bug 559175 this information can get lost when using + // Sync and therefore also redirect sources appear on the newtab + // page. We also want thumbnails for those. + if (url != originalURL) + PageThumbsCache._copy(url, originalURL); } if (aCallback) @@ -206,6 +223,54 @@ let PageThumbsCache = { this._openCacheEntry(aKey, Ci.nsICache.ACCESS_WRITE, aCallback); }, + /** + * Copies an existing cache entry's data to a new cache entry. + * @param aSourceKey The key that contains the data to copy. + * @param aTargetKey The key that will be the copy of aSourceKey's data. + */ + _copy: function Cache_copy(aSourceKey, aTargetKey) { + let sourceEntry, targetEntry, waitingCount = 2; + + function finish() { + if (sourceEntry) + sourceEntry.close(); + + if (targetEntry) + targetEntry.close(); + } + + function copyDataWhenReady() { + if (--waitingCount > 0) + return; + + if (!sourceEntry || !targetEntry) { + finish(); + return; + } + + let inputStream = sourceEntry.openInputStream(0); + let outputStream = targetEntry.openOutputStream(0); + + // Copy the image data to a new entry. + NetUtil.asyncCopy(inputStream, outputStream, function (aResult) { + if (Components.isSuccessCode(aResult)) + targetEntry.markValid(); + + finish(); + }); + } + + this.getReadEntry(aSourceKey, function (aSourceEntry) { + sourceEntry = aSourceEntry; + copyDataWhenReady(); + }); + + this.getWriteEntry(aTargetKey, function (aTargetEntry) { + targetEntry = aTargetEntry; + copyDataWhenReady(); + }); + }, + /** * Opens the cache entry identified by the given key. * @param aKey The key identifying the desired cache entry. diff --git a/browser/components/thumbnails/test/Makefile.in b/browser/components/thumbnails/test/Makefile.in index 0ebea85cebb..ac00a023a67 100644 --- a/browser/components/thumbnails/test/Makefile.in +++ b/browser/components/thumbnails/test/Makefile.in @@ -13,8 +13,11 @@ include $(topsrcdir)/config/rules.mk _BROWSER_FILES = \ browser_thumbnails_capture.js \ + browser_thumbnails_redirect.js \ browser_thumbnails_bug726727.js \ head.js \ + background_red.html \ + background_red_redirect.sjs \ $(NULL) libs:: $(_BROWSER_FILES) diff --git a/browser/components/thumbnails/test/background_red.html b/browser/components/thumbnails/test/background_red.html new file mode 100644 index 00000000000..95159dd2973 --- /dev/null +++ b/browser/components/thumbnails/test/background_red.html @@ -0,0 +1,3 @@ + + + diff --git a/browser/components/thumbnails/test/background_red_redirect.sjs b/browser/components/thumbnails/test/background_red_redirect.sjs new file mode 100644 index 00000000000..f4b70ec7c0d --- /dev/null +++ b/browser/components/thumbnails/test/background_red_redirect.sjs @@ -0,0 +1,10 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +function handleRequest(aRequest, aResponse) { + // Set HTTP Status. + aResponse.setStatusLine(aRequest.httpVersion, 301, "Moved Permanently"); + + // Set redirect URI. + aResponse.setHeader("Location", "http://mochi.test:8888/browser/browser/components/thumbnails/test/background_red.html"); +} diff --git a/browser/components/thumbnails/test/browser_thumbnails_redirect.js b/browser/components/thumbnails/test/browser_thumbnails_redirect.js new file mode 100644 index 00000000000..54803e1e348 --- /dev/null +++ b/browser/components/thumbnails/test/browser_thumbnails_redirect.js @@ -0,0 +1,51 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +const URL = "http://mochi.test:8888/browser/browser/components/thumbnails/" + + "test/background_red_redirect.sjs"; + +let cacheService = Cc["@mozilla.org/network/cache-service;1"] + .getService(Ci.nsICacheService); + +/** + * These tests ensure that we save and provide thumbnails for redirecting sites. + */ +function runTests() { + // Kick off history by loading a tab first or the test fails in single mode. + yield addTab(URL); + gBrowser.removeTab(gBrowser.selectedTab); + + // Create a tab, redirecting to a page with a red background. + yield addTab(URL); + yield captureAndCheckColor(255, 0, 0, "we have a red thumbnail"); + + // Wait until the referrer's thumbnail's cache entry has been written. + yield whenCacheEntryExists(URL); + yield checkThumbnailColor(URL, 255, 0, 0, "referrer has a red thumbnail"); +} + +function whenCacheEntryExists(aKey) { + let callback = next; + + checkCacheEntryExists(aKey, function (aExists) { + if (!aExists) + callback = function () whenCacheEntryExists(aKey); + + executeSoon(callback); + }); +} + +function checkCacheEntryExists(aKey, aCallback) { + PageThumbsCache.getReadEntry(aKey, function (aEntry) { + let inputStream = aEntry && aEntry.openInputStream(0); + let exists = inputStream && inputStream.available(); + + if (inputStream) + inputStream.close(); + + if (aEntry) + aEntry.close(); + + aCallback(exists); + }); +} diff --git a/browser/components/thumbnails/test/head.js b/browser/components/thumbnails/test/head.js index 99a778aedba..6bfd76e7d30 100644 --- a/browser/components/thumbnails/test/head.js +++ b/browser/components/thumbnails/test/head.js @@ -98,26 +98,38 @@ function captureAndCheckColor(aRed, aGreen, aBlue, aMessage) { // Capture the screenshot. PageThumbs.captureAndStore(browser, function () { - let width = 100, height = 100; - let thumb = PageThumbs.getThumbnailURL(browser.currentURI.spec, width, height); + checkThumbnailColor(browser.currentURI.spec, aRed, aGreen, aBlue, aMessage); + }); +} - getXULDocument(function (aDocument) { - let htmlns = "http://www.w3.org/1999/xhtml"; - let img = aDocument.createElementNS(htmlns, "img"); - img.setAttribute("src", thumb); +/** + * Retrieve a thumbnail from the cache and compare its pixel color values. + * @param aURL The URL of the thumbnail's page. + * @param aRed The red component's intensity. + * @param aGreen The green component's intensity. + * @param aBlue The blue component's intensity. + * @param aMessage The info message to print when comparing the pixel color. + */ +function checkThumbnailColor(aURL, aRed, aGreen, aBlue, aMessage) { + let width = 100, height = 100; + let thumb = PageThumbs.getThumbnailURL(aURL, 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(); }); }); }