Bug 1384977 - Remove unused PreviewProvider.jsm and refs, r=ursula?

MozReview-Commit-ID: Ee4uIdPJ0Cy

--HG--
extra : rebase_source : e1badbbbee1c2af1ac92e641599e8d540fd21891
This commit is contained in:
Dan Mosedale ext:(%3E) 2017-07-27 09:26:39 -07:00
Родитель 61246931b7
Коммит 20769f61be
7 изменённых файлов: 1 добавлений и 152 удалений

Просмотреть файл

@ -84,9 +84,6 @@ var whitelist = [
{file: "resource://app/modules/NewTabSearchProvider.jsm"},
{file: "resource://app/modules/NewTabWebChannel.jsm"},
// Activity Stream currently needs this file in all channels except Nightly
{file: "resource://app/modules/PreviewProvider.jsm", skipNightly: true},
// layout/mathml/nsMathMLChar.cpp
{file: "resource://gre/res/fonts/mathfontSTIXGeneral.properties"},
{file: "resource://gre/res/fonts/mathfontUnicode.properties"},

Просмотреть файл

@ -1,45 +0,0 @@
"use strict";
this.EXPORTED_SYMBOLS = ["PreviewProvider"];
const {utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/PageThumbs.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
XPCOMUtils.defineLazyModuleGetter(this, "BackgroundPageThumbs",
"resource://gre/modules/BackgroundPageThumbs.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "MIMEService",
"@mozilla.org/mime;1", "nsIMIMEService");
let PreviewProvider = {
/**
* Returns a thumbnail as a data URI for a url, creating it if necessary
*
* @param {String} url
* a url to obtain a thumbnail for
* @return {Promise} A Promise that resolves with a base64 encoded thumbnail
*/
getThumbnail: async function PreviewProvider_getThumbnail(url) {
try {
await BackgroundPageThumbs.captureIfMissing(url);
let imgPath = PageThumbsStorage.getFilePathForURL(url);
// OS.File object used to easily read off-thread
let file = await OS.File.open(imgPath, {read: true, existing: true});
// nsIFile object needed for MIMEService
let nsFile = FileUtils.File(imgPath);
let contentType = MIMEService.getTypeFromFile(nsFile);
let bytes = await file.read();
let encodedData = btoa(String.fromCharCode.apply(null, bytes));
file.close();
return `data:${contentType};base64,${encodedData}`;
} catch (err) {
Cu.reportError(`PreviewProvider_getThumbnail error: ${err}`);
throw err;
}
}
};

Просмотреть файл

@ -18,8 +18,7 @@ EXTRA_JS_MODULES += [
'NewTabRemoteResources.jsm',
'NewTabSearchProvider.jsm',
'NewTabURL.jsm',
'NewTabWebChannel.jsm',
'PreviewProvider.jsm'
'NewTabWebChannel.jsm'
]
XPIDL_SOURCES += [

Просмотреть файл

@ -1,9 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body style="background-color: blue">
</body>
</html>

Просмотреть файл

@ -1,9 +1,6 @@
[DEFAULT]
support-files =
blue_page.html
dummy_page.html
[browser_PreviewProvider.js]
skip-if = os == 'linux' || os == 'win' # bug 1343150
[browser_remotenewtab_pageloads.js]
[browser_newtab_overrides.js]

Просмотреть файл

@ -1,87 +0,0 @@
"use strict";
let Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PreviewProvider",
"resource:///modules/PreviewProvider.jsm");
var oldEnabledPref = Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled");
Services.prefs.setBoolPref("browser.pagethumbnails.capturing_disabled", false);
registerCleanupFunction(function() {
while (gBrowser.tabs.length > 1) {
gBrowser.removeTab(gBrowser.tabs[1]);
}
Services.prefs.setBoolPref("browser.pagethumbnails.capturing_disabled", oldEnabledPref);
});
const TEST_URL = "https://example.com/browser/browser/components/newtab/tests/browser/blue_page.html";
function pixelsForDataURI(dataURI, options) {
return new Promise(resolve => {
if (!options) {
options = {};
}
let {width, height} = options;
if (!width) {
width = 100;
}
if (!height) {
height = 100;
}
let htmlns = "http://www.w3.org/1999/xhtml";
let img = document.createElementNS(htmlns, "img");
img.setAttribute("src", dataURI);
img.addEventListener("load", function() {
let canvas = document.createElementNS(htmlns, "canvas");
canvas.setAttribute("width", width);
canvas.setAttribute("height", height);
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
let result = ctx.getImageData(0, 0, width, height).data;
resolve(result);
}, {once: true});
});
}
function* chunk_four(listData) {
let index = 0;
while (index < listData.length) {
yield listData.slice(index, index + 5);
index += 4;
}
}
add_task(async function open_page() {
let dataURI = await PreviewProvider.getThumbnail(TEST_URL);
let pixels = await pixelsForDataURI(dataURI, {width: 10, height: 10});
let rgbCount = {r: 0, g: 0, b: 0, a: 0};
for (let [r, g, b, a] of chunk_four(pixels)) {
if (r === 255) {
rgbCount.r += 1;
}
if (g === 255) {
rgbCount.g += 1;
}
if (b === 255) {
rgbCount.b += 1;
}
if (a === 255) {
rgbCount.a += 1;
}
}
Assert.equal(`${rgbCount.r},${rgbCount.g},${rgbCount.b},${rgbCount.a}`,
"0,0,100,100", "there should be 100 blue-only pixels at full opacity");
});
add_task(async function invalid_url() {
try {
await PreviewProvider.getThumbnail("invalid:URL");
} catch (err) {
Assert.ok(true, "URL Failed");
}
});

Просмотреть файл

@ -12,9 +12,6 @@ const {insertPinned} = Cu.import("resource://activity-stream/common/Reducers.jsm
XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
"resource://gre/modules/NewTabUtils.jsm");
// Keep a reference to PreviewProvider.jsm until it's good to remove. See #2849
XPCOMUtils.defineLazyModuleGetter(this, "PreviewProvider",
"resource://app/modules/PreviewProvider.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Screenshots",
"resource://activity-stream/lib/Screenshots.jsm");