Bug 1383599 - browser.newtabpage.enabled = false is not working. r=ursula

MozReview-Commit-ID: HUBr10vb9qJ

--HG--
extra : rebase_source : 222994b1f0f808985a5963dcb6cf1e1ea1bba097
This commit is contained in:
Ed Lee 2018-03-06 23:49:05 -08:00
Родитель e4b9916e1e
Коммит 2b013a5250
6 изменённых файлов: 39 добавлений и 5 удалений

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

@ -1257,8 +1257,7 @@ pref("prompts.tab_modal.enabled", true);
// Activates preloading of the new tab url.
pref("browser.newtab.preload", true);
// Is supposed to toggle something to do with about:newtab . Doesn't seem to do
// anything in activity stream. bug 1443646 covers dealing with this.
// Indicates if about:newtab shows content (enabled) or just blank
pref("browser.newtabpage.enabled", true);
// Activity Stream prefs that control to which page to redirect

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

@ -21,6 +21,8 @@ namespace browser {
NS_IMPL_ISUPPORTS(AboutRedirector, nsIAboutModule)
bool AboutRedirector::sNewTabPageEnabled = false;
struct RedirEntry {
const char* id;
const char* url;
@ -133,12 +135,21 @@ AboutRedirector::NewChannel(nsIURI* aURI,
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
NS_ENSURE_SUCCESS(rv, rv);
static bool sNTPEnabledCacheInited = false;
if (!sNTPEnabledCacheInited) {
Preferences::AddBoolVarCache(&AboutRedirector::sNewTabPageEnabled,
"browser.newtabpage.enabled");
sNTPEnabledCacheInited = true;
}
for (auto & redir : kRedirMap) {
if (!strcmp(path.get(), redir.id)) {
nsAutoCString url;
if (path.EqualsLiteral("newtab") || path.EqualsLiteral("home")) {
// let the aboutNewTabService decide where to redirect
// Let the aboutNewTabService decide where to redirect for about:home and
// enabled about:newtab. Disabled about:newtab page uses fallback.
if (path.EqualsLiteral("home") ||
(sNewTabPageEnabled && path.EqualsLiteral("newtab"))) {
nsCOMPtr<nsIAboutNewTabService> aboutNewTabService =
do_GetService("@mozilla.org/browser/aboutnewtab-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -24,6 +24,9 @@ public:
protected:
virtual ~AboutRedirector() {}
private:
static bool sNewTabPageEnabled;
};
} // namespace browser

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

@ -15,7 +15,6 @@ ChromeUtils.defineModuleGetter(this, "AboutNewTab",
// Dummy references to the files that this service no longer allows loading.
// Bug 1409054 to remove "chrome://browser/content/abouthome/aboutHome.xhtml"
// Bug 1433133 to remove "chrome://browser/content/newtab/newTab.xhtml"
const TOPIC_APP_QUIT = "quit-application-granted";
const TOPIC_LOCALES_CHANGE = "intl:requested-locales-changed";

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

@ -1,6 +1,7 @@
[DEFAULT]
[browser_activity_stream_strings.js]
[browser_enabled_newtabpage.js]
[browser_packaged_as_locales.js]
skip-if=true # bug 1423703 comment 20
[browser_newtab_overrides.js]

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

@ -0,0 +1,21 @@
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
function checkSpec(uri, check, message) {
const {spec} = NetUtil.newChannel({
loadUsingSystemPrincipal: true,
uri
}).URI;
info(`got ${spec} for ${uri}`);
check(spec, "about:blank", message);
}
add_task(async function test_newtab_enabled() {
checkSpec("about:newtab", isnot, "did not get blank for default about:newtab");
checkSpec("about:home", isnot, "did not get blank for default about:home");
await SpecialPowers.pushPrefEnv({set: [["browser.newtabpage.enabled", false]]});
checkSpec("about:newtab", is, "got blank when newtab is not enabled");
checkSpec("about:home", isnot, "still did not get blank for about:home");
});