mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1118285 - The browser.newtab.url preference is abused and should be removed.
This commit is contained in:
parent
1e3b105e83
commit
fb7c08fefa
@ -1665,8 +1665,6 @@ pref("prompts.tab_modal.enabled", true);
|
||||
// Whether the Panorama should animate going in/out of tabs
|
||||
pref("browser.panorama.animate_zoom", true);
|
||||
|
||||
// Defines the url to be used for new tabs.
|
||||
pref("browser.newtab.url", "about:newtab");
|
||||
// Activates preloading of the new tab url.
|
||||
pref("browser.newtab.preload", true);
|
||||
|
||||
|
@ -54,6 +54,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
|
||||
"resource://gre/modules/LightweightThemeManager.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Pocket",
|
||||
"resource:///modules/Pocket.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NewTabURL",
|
||||
"resource:///modules/NewTabURL.jsm");
|
||||
|
||||
// Can't use XPCOMUtils for these because the scripts try to define the variables
|
||||
// on window, and so the defineProperty inside defineLazyGetter fails.
|
||||
@ -4091,6 +4093,10 @@ var XULBrowserWindow = {
|
||||
return true;
|
||||
},
|
||||
|
||||
shouldAddToSessionHistory: function(aDocShell, aURI) {
|
||||
return aURI.spec != NewTabURL.get();
|
||||
},
|
||||
|
||||
onProgressChange: function (aWebProgress, aRequest,
|
||||
aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress) {
|
||||
|
@ -1609,7 +1609,7 @@
|
||||
// and the URL is "about:newtab". We do not support preloading for
|
||||
// custom newtab URLs.
|
||||
return Services.prefs.getBoolPref("browser.newtab.preload") &&
|
||||
!Services.prefs.prefHasUserValue("browser.newtab.url");
|
||||
!NewTabURL.overridden;
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
@ -8,7 +8,6 @@ function test() {
|
||||
waitForExplicitFinish();
|
||||
let windowsToClose = [];
|
||||
let newTab;
|
||||
let newTabPrefName = "browser.newtab.url";
|
||||
let newTabURL;
|
||||
let mode;
|
||||
|
||||
@ -19,7 +18,7 @@ function test() {
|
||||
newTabURL = "about:privatebrowsing";
|
||||
} else {
|
||||
mode = "normal";
|
||||
newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
|
||||
newTabURL = NewTabURL.get();
|
||||
}
|
||||
|
||||
is(aWindow.gBrowser.currentURI.spec, newTabURL,
|
||||
|
@ -5,7 +5,6 @@
|
||||
function test() {
|
||||
//initialization
|
||||
waitForExplicitFinish();
|
||||
let newTabPrefName = "browser.newtab.url";
|
||||
let newTabURL;
|
||||
let testURL = "http://example.com/";
|
||||
let mode;
|
||||
@ -17,24 +16,24 @@ function test() {
|
||||
newTabURL = "about:privatebrowsing";
|
||||
} else {
|
||||
mode = "normal";
|
||||
newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
|
||||
newTabURL = NewTabURL.get();
|
||||
}
|
||||
|
||||
// Check the new tab opened while in normal/private mode
|
||||
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL,
|
||||
"URL of NewTab should be " + newTabURL + " in " + mode + " mode");
|
||||
// Set the custom newtab url
|
||||
Services.prefs.setCharPref(newTabPrefName, testURL);
|
||||
ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set");
|
||||
NewTabURL.override(testURL);
|
||||
is(NewTabURL.get(), testURL, "Custom newtab url is set");
|
||||
|
||||
// Open a newtab after setting the custom newtab url
|
||||
openNewTab(aWindow, function () {
|
||||
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL,
|
||||
"URL of NewTab should be the custom url");
|
||||
|
||||
// clear the custom url preference
|
||||
Services.prefs.clearUserPref(newTabPrefName);
|
||||
ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
|
||||
// Clear the custom url.
|
||||
NewTabURL.reset();
|
||||
is(NewTabURL.get(), "about:newtab", "No custom newtab url is set");
|
||||
|
||||
aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
|
||||
aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
|
||||
@ -51,7 +50,7 @@ function test() {
|
||||
}
|
||||
|
||||
// check whether any custom new tab url has been configured
|
||||
ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
|
||||
ok(!NewTabURL.overridden, "No custom newtab url is set");
|
||||
|
||||
// test normal mode
|
||||
testOnWindow(false, function(aWindow) {
|
||||
|
@ -9,32 +9,16 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
||||
Components.utils.import("resource:///modules/RecentWindow.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "BROWSER_NEW_TAB_URL", function () {
|
||||
const PREF = "browser.newtab.url";
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NewTabURL",
|
||||
"resource:///modules/NewTabURL.jsm");
|
||||
|
||||
function getNewTabPageURL() {
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
||||
!Services.prefs.prefHasUserValue(PREF)) {
|
||||
return "about:privatebrowsing";
|
||||
}
|
||||
|
||||
let url = Services.prefs.getComplexValue(PREF, Ci.nsISupportsString).data;
|
||||
return url || "about:blank";
|
||||
this.__defineGetter__("BROWSER_NEW_TAB_URL", () => {
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
||||
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
||||
!NewTabURL.overridden) {
|
||||
return "about:privatebrowsing";
|
||||
}
|
||||
|
||||
function update() {
|
||||
BROWSER_NEW_TAB_URL = getNewTabPageURL();
|
||||
}
|
||||
|
||||
Services.prefs.addObserver(PREF, update, false);
|
||||
|
||||
addEventListener("unload", function onUnload() {
|
||||
removeEventListener("unload", onUnload);
|
||||
Services.prefs.removeObserver(PREF, update);
|
||||
});
|
||||
|
||||
return getNewTabPageURL();
|
||||
return NewTabURL.get();
|
||||
});
|
||||
|
||||
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
||||
|
@ -28,14 +28,14 @@ add_task(function* () {
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
Services.prefs.setCharPref("browser.newtab.url", "about:blank");
|
||||
NewTabURL.override("about:blank");
|
||||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("browser.newtab.url");
|
||||
NewTabURL.reset();
|
||||
});
|
||||
|
||||
let win = yield openNewPrivateWindow();
|
||||
checkUrlbarFocus(win);
|
||||
win.close();
|
||||
|
||||
Services.prefs.clearUserPref("browser.newtab.url");
|
||||
NewTabURL.reset();
|
||||
});
|
||||
|
34
browser/modules/NewTabURL.jsm
Normal file
34
browser/modules/NewTabURL.jsm
Normal file
@ -0,0 +1,34 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
let Cc = Components.classes;
|
||||
let Ci = Components.interfaces;
|
||||
let Cu = Components.utils;
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "NewTabURL" ];
|
||||
|
||||
this.NewTabURL = {
|
||||
_url: "about:newtab",
|
||||
_overridden: false,
|
||||
|
||||
get: function() {
|
||||
return this._url;
|
||||
},
|
||||
|
||||
get overridden() {
|
||||
return this._overridden;
|
||||
},
|
||||
|
||||
override: function(newURL) {
|
||||
this._url = newURL;
|
||||
this._overridden = true;
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this._url = "about:newtab";
|
||||
this._overridden = false;
|
||||
}
|
||||
};
|
@ -30,6 +30,7 @@ EXTRA_JS_MODULES += [
|
||||
'FormValidationHandler.jsm',
|
||||
'HiddenFrame.jsm',
|
||||
'NetworkPrioritizer.jsm',
|
||||
'NewTabURL.jsm',
|
||||
'offlineAppCache.jsm',
|
||||
'PanelFrame.jsm',
|
||||
'PluginContent.jsm',
|
||||
|
17
browser/modules/test/xpcshell/test_NewTabURL.js
Normal file
17
browser/modules/test/xpcshell/test_NewTabURL.js
Normal file
@ -0,0 +1,17 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
Components.utils.import("resource:///modules/NewTabURL.jsm");
|
||||
|
||||
function run_test() {
|
||||
Assert.equal(NewTabURL.get(), "about:newtab", "Default newtab URL should be about:newtab");
|
||||
let url = "http://example.com/";
|
||||
NewTabURL.override(url);
|
||||
Assert.ok(NewTabURL.overridden, "Newtab URL should be overridden");
|
||||
Assert.equal(NewTabURL.get(), url, "Newtab URL should be the custom URL");
|
||||
NewTabURL.reset();
|
||||
Assert.ok(!NewTabURL.overridden, "Newtab URL should not be overridden");
|
||||
Assert.equal(NewTabURL.get(), "about:newtab", "Newtab URL should be the about:newtab");
|
||||
}
|
@ -5,3 +5,4 @@ firefox-appdir = browser
|
||||
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||
|
||||
[test_DirectoryLinksProvider.js]
|
||||
[test_NewTabURL.js]
|
||||
|
@ -11732,7 +11732,7 @@ nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI)
|
||||
// should just do a spec compare, rather than two gets of the scheme and
|
||||
// then the path. -Gagan
|
||||
nsresult rv;
|
||||
nsAutoCString buf, pref;
|
||||
nsAutoCString buf;
|
||||
|
||||
rv = aURI->GetScheme(buf);
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -11750,16 +11750,17 @@ nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI)
|
||||
}
|
||||
}
|
||||
|
||||
rv = Preferences::GetDefaultCString("browser.newtab.url", &pref);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return true;
|
||||
// Check if the webbrowser chrome wants us to proceed - by default it ensures
|
||||
// aURI is not the newtab URI.
|
||||
nsCOMPtr<nsIWebBrowserChrome3> browserChrome3 = do_GetInterface(mTreeOwner);
|
||||
if (browserChrome3) {
|
||||
bool shouldAdd;
|
||||
rv = browserChrome3->ShouldAddToSessionHistory(this, aURI, &shouldAdd);
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
return shouldAdd;
|
||||
}
|
||||
|
||||
rv = aURI->GetSpec(buf);
|
||||
NS_ENSURE_SUCCESS(rv, true);
|
||||
|
||||
return !buf.Equals(pref);
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -12,7 +12,7 @@ interface nsIInputStream;
|
||||
/**
|
||||
* nsIWebBrowserChrome3 is an extension to nsIWebBrowserChrome2.
|
||||
*/
|
||||
[scriptable, uuid(9e6c2372-5d9d-4ce8-ab9e-c5df1494dc84)]
|
||||
[scriptable, uuid(da646a9c-5788-4860-88a4-bd5d0ad853da)]
|
||||
interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
||||
{
|
||||
/**
|
||||
@ -47,4 +47,7 @@ interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
||||
bool shouldLoadURI(in nsIDocShell aDocShell,
|
||||
in nsIURI aURI,
|
||||
in nsIURI aReferrer);
|
||||
|
||||
bool shouldAddToSessionHistory(in nsIDocShell aDocShell,
|
||||
in nsIURI aURI);
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
},
|
||||
"global": {
|
||||
"talos_repo": "https://hg.mozilla.org/build/talos",
|
||||
"talos_revision": "39db01f6dabb"
|
||||
"talos_revision": "33449734f99f"
|
||||
},
|
||||
"extra_options": {
|
||||
"android": [ "--apkPath=%(apk_path)s" ]
|
||||
|
@ -462,6 +462,24 @@ NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsContentTreeOwner::ShouldAddToSessionHistory(nsIDocShell *aDocShell,
|
||||
nsIURI *aURI,
|
||||
bool *_retval)
|
||||
{
|
||||
NS_ENSURE_STATE(mXULWindow);
|
||||
|
||||
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
|
||||
mXULWindow->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
|
||||
|
||||
if (xulBrowserWindow) {
|
||||
return xulBrowserWindow->ShouldAddToSessionHistory(aDocShell, aURI, _retval);
|
||||
}
|
||||
|
||||
*_retval = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsContentTreeOwner::nsIWebBrowserChrome2
|
||||
//*****************************************************************************
|
||||
|
@ -19,7 +19,7 @@ interface nsITabParent;
|
||||
* internals of the browser area to tell the containing xul window to update
|
||||
* its ui.
|
||||
*/
|
||||
[scriptable, uuid(db89f748-9736-40b2-a172-3928aa1194b2)]
|
||||
[scriptable, uuid(8974a499-d49b-43e1-8b32-c9b3ed81be3f)]
|
||||
interface nsIXULBrowserWindow : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -62,6 +62,9 @@ interface nsIXULBrowserWindow : nsISupports
|
||||
bool shouldLoadURI(in nsIDocShell aDocShell,
|
||||
in nsIURI aURI,
|
||||
in nsIURI aReferrer);
|
||||
|
||||
bool shouldAddToSessionHistory(in nsIDocShell aDocShell,
|
||||
in nsIURI aURI);
|
||||
/**
|
||||
* Show/hide a tooltip (when the user mouses over a link, say).
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user