mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1042204 - Control the enhancement of history tiles with a pref [r=adw]
Only show enhanced history when the pref allows it. Update newtab pages when enhanced pref changes. --HG-- extra : rebase_source : 3a7466d119df6d0bffef4a71e9142b1e21f077ed
This commit is contained in:
parent
7cf81a9756
commit
ac46985dbb
@ -1479,6 +1479,9 @@ pref("browser.newtab.preload", true);
|
||||
// Toggles the content of 'about:newtab'. Shows the grid when enabled.
|
||||
pref("browser.newtabpage.enabled", true);
|
||||
|
||||
// Toggles the enhancement of history content of 'about:newtab'
|
||||
pref("browser.newtabpage.enhanced", false);
|
||||
|
||||
// number of rows of newtab grid
|
||||
pref("browser.newtabpage.rows", 3);
|
||||
|
||||
|
@ -51,6 +51,11 @@ let gPage = {
|
||||
let enabled = gAllPages.enabled;
|
||||
this._updateAttributes(enabled);
|
||||
|
||||
// Update thumbnails to the new enhanced setting
|
||||
if (aData == "browser.newtabpage.enhanced") {
|
||||
this.update();
|
||||
}
|
||||
|
||||
// Initialize the whole page if we haven't done that, yet.
|
||||
if (enabled) {
|
||||
this._init();
|
||||
|
@ -153,7 +153,9 @@ Site.prototype = {
|
||||
* Refreshes the thumbnail for the site.
|
||||
*/
|
||||
refreshThumbnail: function Site_refreshThumbnail() {
|
||||
let link = DirectoryLinksProvider.getEnhancedLink(this.link) || this.link;
|
||||
// Only enhance tiles if that feature is turned on
|
||||
let link = gAllPages.enhanced && DirectoryLinksProvider.getEnhancedLink(this.link) ||
|
||||
this.link;
|
||||
|
||||
let thumbnail = this._querySelector(".newtab-thumbnail");
|
||||
if (link.bgColor) {
|
||||
|
@ -23,6 +23,7 @@ skip-if = os == "mac" # Intermittent failures, bug 898317
|
||||
[browser_newtab_drag_drop.js]
|
||||
[browser_newtab_drag_drop_ext.js]
|
||||
[browser_newtab_drop_preview.js]
|
||||
[browser_newtab_enhanced.js]
|
||||
[browser_newtab_focus.js]
|
||||
[browser_newtab_perwindow_private_browsing.js]
|
||||
[browser_newtab_reportLinkAction.js]
|
||||
|
55
browser/base/content/test/newtab/browser_newtab_enhanced.js
Normal file
55
browser/base/content/test/newtab/browser_newtab_enhanced.js
Normal file
@ -0,0 +1,55 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const PRELOAD_PREF = "browser.newtab.preload";
|
||||
|
||||
gDirectorySource = "data:application/json," + JSON.stringify({
|
||||
"en-US": [{
|
||||
url: "http://example.com/",
|
||||
enhancedImageURI: "data:image/png;base64,helloWORLD",
|
||||
type: "organic"
|
||||
}]
|
||||
});
|
||||
|
||||
function runTests() {
|
||||
let origEnhanced = NewTabUtils.allPages.enhanced;
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref(PRELOAD_PREF);
|
||||
NewTabUtils.allPages.enhanced = origEnhanced;
|
||||
});
|
||||
|
||||
Services.prefs.setBoolPref(PRELOAD_PREF, false);
|
||||
|
||||
function getData(cellNum) {
|
||||
let siteNode = getCell(cellNum).site.node;
|
||||
return {
|
||||
type: siteNode.getAttribute("type"),
|
||||
enhanced: siteNode.querySelector(".enhanced-content").style.backgroundImage,
|
||||
};
|
||||
}
|
||||
|
||||
// Make the page have a directory link followed by a history link
|
||||
yield setLinks("1");
|
||||
|
||||
// Test with enhanced = false
|
||||
NewTabUtils.allPages.enhanced = false;
|
||||
yield addNewTabPageTab();
|
||||
let {type, enhanced} = getData(0);
|
||||
is(type, "organic", "directory link is organic");
|
||||
isnot(enhanced, "", "directory link has enhanced image");
|
||||
|
||||
let {type, enhanced} = getData(1);
|
||||
is(type, "history", "history link is history");
|
||||
is(enhanced, "", "history link has no enhanced image");
|
||||
|
||||
// Test with enhanced = true
|
||||
NewTabUtils.allPages.enhanced = true;
|
||||
yield addNewTabPageTab();
|
||||
let {type, enhanced} = getData(0);
|
||||
is(type, "organic", "directory link is still organic");
|
||||
isnot(enhanced, "", "directory link still has enhanced image");
|
||||
|
||||
let {type, enhanced} = getData(1);
|
||||
is(type, "enhanced", "history link now is enhanced");
|
||||
isnot(enhanced, "", "history link now has enhanced image");
|
||||
}
|
@ -608,6 +608,7 @@ function createDragEvent(aEventType, aData) {
|
||||
*/
|
||||
function whenPagesUpdated(aCallback, aOnlyIfHidden=false) {
|
||||
let page = {
|
||||
observe: _ => _,
|
||||
update: function (onlyIfHidden=false) {
|
||||
if (onlyIfHidden == aOnlyIfHidden) {
|
||||
NewTabUtils.allPages.unregister(this);
|
||||
|
@ -42,8 +42,9 @@ XPCOMUtils.defineLazyGetter(this, "gUnicodeConverter", function () {
|
||||
return converter;
|
||||
});
|
||||
|
||||
// The preference that tells whether this feature is enabled.
|
||||
// Boolean preferences that control newtab content
|
||||
const PREF_NEWTAB_ENABLED = "browser.newtabpage.enabled";
|
||||
const PREF_NEWTAB_ENHANCED = "browser.newtabpage.enhanced";
|
||||
|
||||
// The preference that tells the number of rows of the newtab grid.
|
||||
const PREF_NEWTAB_ROWS = "browser.newtabpage.rows";
|
||||
@ -209,6 +210,11 @@ let AllPages = {
|
||||
*/
|
||||
_enabled: null,
|
||||
|
||||
/**
|
||||
* Cached value that tells whether the New Tab Page feature is enhanced.
|
||||
*/
|
||||
_enhanced: null,
|
||||
|
||||
/**
|
||||
* Adds a page to the internal list of pages.
|
||||
* @param aPage The page to register.
|
||||
@ -246,6 +252,24 @@ let AllPages = {
|
||||
Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, !!aEnabled);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns whether the history tiles are enhanced.
|
||||
*/
|
||||
get enhanced() {
|
||||
if (this._enhanced === null)
|
||||
this._enhanced = Services.prefs.getBoolPref(PREF_NEWTAB_ENHANCED);
|
||||
|
||||
return this._enhanced;
|
||||
},
|
||||
|
||||
/**
|
||||
* Enables or disables the enhancement of history tiles feature.
|
||||
*/
|
||||
set enhanced(aEnhanced) {
|
||||
if (this.enhanced != aEnhanced)
|
||||
Services.prefs.setBoolPref(PREF_NEWTAB_ENHANCED, !!aEnhanced);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the number of registered New Tab Pages (i.e. the number of open
|
||||
* about:newtab instances).
|
||||
@ -288,7 +312,14 @@ let AllPages = {
|
||||
observe: function AllPages_observe(aSubject, aTopic, aData) {
|
||||
if (aTopic == "nsPref:changed") {
|
||||
// Clear the cached value.
|
||||
this._enabled = null;
|
||||
switch (aData) {
|
||||
case PREF_NEWTAB_ENABLED:
|
||||
this._enabled = null;
|
||||
break;
|
||||
case PREF_NEWTAB_ENHANCED:
|
||||
this._enhanced = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// and all notifications get forwarded to each page.
|
||||
this._pages.forEach(function (aPage) {
|
||||
@ -302,6 +333,7 @@ let AllPages = {
|
||||
*/
|
||||
_addObserver: function AllPages_addObserver() {
|
||||
Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this, true);
|
||||
Services.prefs.addObserver(PREF_NEWTAB_ENHANCED, this, true);
|
||||
Services.obs.addObserver(this, "page-thumbnail:create", true);
|
||||
this._addObserver = function () {};
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user