зеркало из https://github.com/mozilla/pjs.git
Bug 722273 - [New Tab Page] clear internal links cache on 'browser:purge-session-history'; r=dietrich
This commit is contained in:
Родитель
bc44d81d20
Коммит
016a7112fe
|
@ -20,6 +20,7 @@ _BROWSER_FILES = \
|
||||||
browser_newtab_reset.js \
|
browser_newtab_reset.js \
|
||||||
browser_newtab_tabsync.js \
|
browser_newtab_tabsync.js \
|
||||||
browser_newtab_unpin.js \
|
browser_newtab_unpin.js \
|
||||||
|
browser_newtab_bug722273.js \
|
||||||
browser_newtab_bug723102.js \
|
browser_newtab_bug723102.js \
|
||||||
browser_newtab_bug723121.js \
|
browser_newtab_bug723121.js \
|
||||||
head.js \
|
head.js \
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
const NOW = Date.now() * 1000;
|
||||||
|
const URL = "http://fake-site.com/";
|
||||||
|
|
||||||
|
let tmp = {};
|
||||||
|
Cu.import("resource:///modules/NewTabUtils.jsm", tmp);
|
||||||
|
Cc["@mozilla.org/moz/jssubscript-loader;1"]
|
||||||
|
.getService(Ci.mozIJSSubScriptLoader)
|
||||||
|
.loadSubScript("chrome://browser/content/sanitize.js", tmp);
|
||||||
|
|
||||||
|
let {NewTabUtils, Sanitizer} = tmp;
|
||||||
|
|
||||||
|
let bhist = Cc["@mozilla.org/browser/global-history;2"]
|
||||||
|
.getService(Ci.nsIBrowserHistory);
|
||||||
|
|
||||||
|
function runTests() {
|
||||||
|
clearHistory();
|
||||||
|
fillHistory();
|
||||||
|
yield addNewTabPageTab();
|
||||||
|
|
||||||
|
is(cells[0].site.url, URL, "first site is our fake site");
|
||||||
|
|
||||||
|
let page = {
|
||||||
|
update: function () {
|
||||||
|
executeSoon(TestRunner.next);
|
||||||
|
},
|
||||||
|
|
||||||
|
observe: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
|
NewTabUtils.allPages.register(page);
|
||||||
|
yield clearHistory();
|
||||||
|
|
||||||
|
NewTabUtils.allPages.unregister(page);
|
||||||
|
ok(!cells[0].site, "the fake site is gone");
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillHistory() {
|
||||||
|
let uri = makeURI(URL);
|
||||||
|
for (let i = 59; i > 0; i--)
|
||||||
|
bhist.addPageWithDetails(uri, "fake site", NOW - i * 60 * 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearHistory() {
|
||||||
|
let s = new Sanitizer();
|
||||||
|
s.prefDomain = "privacy.cpd.";
|
||||||
|
|
||||||
|
let prefs = gPrefService.getBranch(s.prefDomain);
|
||||||
|
prefs.setBoolPref("history", true);
|
||||||
|
prefs.setBoolPref("downloads", false);
|
||||||
|
prefs.setBoolPref("cache", false);
|
||||||
|
prefs.setBoolPref("cookies", false);
|
||||||
|
prefs.setBoolPref("formdata", false);
|
||||||
|
prefs.setBoolPref("offlineApps", false);
|
||||||
|
prefs.setBoolPref("passwords", false);
|
||||||
|
prefs.setBoolPref("sessions", false);
|
||||||
|
prefs.setBoolPref("siteSettings", false);
|
||||||
|
|
||||||
|
s.sanitize();
|
||||||
|
}
|
|
@ -129,10 +129,11 @@ function addNewTabPageTab() {
|
||||||
cw = browser.contentWindow;
|
cw = browser.contentWindow;
|
||||||
|
|
||||||
if (NewTabUtils.allPages.enabled) {
|
if (NewTabUtils.allPages.enabled) {
|
||||||
cells = cw.gGrid.cells;
|
|
||||||
|
|
||||||
// Continue when the link cache has been populated.
|
// Continue when the link cache has been populated.
|
||||||
NewTabUtils.links.populateCache(TestRunner.next);
|
NewTabUtils.links.populateCache(function () {
|
||||||
|
cells = cw.gGrid.cells;
|
||||||
|
executeSoon(TestRunner.next);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
TestRunner.next();
|
TestRunner.next();
|
||||||
}
|
}
|
||||||
|
@ -246,6 +247,8 @@ function unpinCell(aCell) {
|
||||||
*/
|
*/
|
||||||
function simulateDrop(aDropTarget, aDragSource) {
|
function simulateDrop(aDropTarget, aDragSource) {
|
||||||
let event = {
|
let event = {
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0,
|
||||||
dataTransfer: {
|
dataTransfer: {
|
||||||
mozUserCancelled: false,
|
mozUserCancelled: false,
|
||||||
setData: function () null,
|
setData: function () null,
|
||||||
|
|
|
@ -121,8 +121,6 @@ let Storage = {
|
||||||
// want any data from private browsing to show up.
|
// want any data from private browsing to show up.
|
||||||
PinnedLinks.resetCache();
|
PinnedLinks.resetCache();
|
||||||
BlockedLinks.resetCache();
|
BlockedLinks.resetCache();
|
||||||
|
|
||||||
Pages.update();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -187,11 +185,6 @@ let AllPages = {
|
||||||
*/
|
*/
|
||||||
_pages: [],
|
_pages: [],
|
||||||
|
|
||||||
/**
|
|
||||||
* Tells whether we already added a preference observer.
|
|
||||||
*/
|
|
||||||
_observing: false,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cached value that tells whether the New Tab Page feature is enabled.
|
* Cached value that tells whether the New Tab Page feature is enabled.
|
||||||
*/
|
*/
|
||||||
|
@ -203,12 +196,7 @@ let AllPages = {
|
||||||
*/
|
*/
|
||||||
register: function AllPages_register(aPage) {
|
register: function AllPages_register(aPage) {
|
||||||
this._pages.push(aPage);
|
this._pages.push(aPage);
|
||||||
|
this._addObserver();
|
||||||
// Add the preference observer if we haven't already.
|
|
||||||
if (!this._observing) {
|
|
||||||
this._observing = true;
|
|
||||||
Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this, true);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,6 +226,14 @@ let AllPages = {
|
||||||
Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, !!aEnabled);
|
Services.prefs.setBoolPref(PREF_NEWTAB_ENABLED, !!aEnabled);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of registered New Tab Pages (i.e. the number of open
|
||||||
|
* about:newtab instances).
|
||||||
|
*/
|
||||||
|
get length() {
|
||||||
|
return this._pages.length;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates all currently active pages but the given one.
|
* Updates all currently active pages but the given one.
|
||||||
* @param aExceptPage The page to exclude from updating.
|
* @param aExceptPage The page to exclude from updating.
|
||||||
|
@ -264,6 +260,15 @@ let AllPages = {
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a preference observer and turns itself into a no-op after the first
|
||||||
|
* invokation.
|
||||||
|
*/
|
||||||
|
_addObserver: function AllPages_addObserver() {
|
||||||
|
Services.prefs.addObserver(PREF_NEWTAB_ENABLED, this, true);
|
||||||
|
this._addObserver = function () {};
|
||||||
|
},
|
||||||
|
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
||||||
Ci.nsISupportsWeakReference])
|
Ci.nsISupportsWeakReference])
|
||||||
};
|
};
|
||||||
|
@ -512,6 +517,8 @@ let Links = {
|
||||||
this._links = aLinks;
|
this._links = aLinks;
|
||||||
executeCallbacks();
|
executeCallbacks();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this._addObserver();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -544,7 +551,32 @@ let Links = {
|
||||||
*/
|
*/
|
||||||
resetCache: function Links_resetCache() {
|
resetCache: function Links_resetCache() {
|
||||||
this._links = [];
|
this._links = [];
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements the nsIObserver interface to get notified about browser history
|
||||||
|
* sanitization.
|
||||||
|
*/
|
||||||
|
observe: function Links_observe(aSubject, aTopic, aData) {
|
||||||
|
// Make sure to update open about:newtab instances. If there are no opened
|
||||||
|
// pages we can just wait for the next new tab to populate the cache again.
|
||||||
|
if (AllPages.length && AllPages.enabled)
|
||||||
|
this.populateCache(function () { AllPages.update() }, true);
|
||||||
|
else
|
||||||
|
this._links = null;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a sanitization observer and turns itself into a no-op after the first
|
||||||
|
* invokation.
|
||||||
|
*/
|
||||||
|
_addObserver: function Links_addObserver() {
|
||||||
|
Services.obs.addObserver(this, "browser:purge-session-history", true);
|
||||||
|
this._addObserver = function () {};
|
||||||
|
},
|
||||||
|
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
|
||||||
|
Ci.nsISupportsWeakReference])
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Загрузка…
Ссылка в новой задаче