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
|
// Whether the Panorama should animate going in/out of tabs
|
||||||
pref("browser.panorama.animate_zoom", true);
|
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.
|
// Activates preloading of the new tab url.
|
||||||
pref("browser.newtab.preload", true);
|
pref("browser.newtab.preload", true);
|
||||||
|
|
||||||
|
@ -54,6 +54,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
|
|||||||
"resource://gre/modules/LightweightThemeManager.jsm");
|
"resource://gre/modules/LightweightThemeManager.jsm");
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "Pocket",
|
XPCOMUtils.defineLazyModuleGetter(this, "Pocket",
|
||||||
"resource:///modules/Pocket.jsm");
|
"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
|
// Can't use XPCOMUtils for these because the scripts try to define the variables
|
||||||
// on window, and so the defineProperty inside defineLazyGetter fails.
|
// on window, and so the defineProperty inside defineLazyGetter fails.
|
||||||
@ -4091,6 +4093,10 @@ var XULBrowserWindow = {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
shouldAddToSessionHistory: function(aDocShell, aURI) {
|
||||||
|
return aURI.spec != NewTabURL.get();
|
||||||
|
},
|
||||||
|
|
||||||
onProgressChange: function (aWebProgress, aRequest,
|
onProgressChange: function (aWebProgress, aRequest,
|
||||||
aCurSelfProgress, aMaxSelfProgress,
|
aCurSelfProgress, aMaxSelfProgress,
|
||||||
aCurTotalProgress, aMaxTotalProgress) {
|
aCurTotalProgress, aMaxTotalProgress) {
|
||||||
|
@ -1609,7 +1609,7 @@
|
|||||||
// and the URL is "about:newtab". We do not support preloading for
|
// and the URL is "about:newtab". We do not support preloading for
|
||||||
// custom newtab URLs.
|
// custom newtab URLs.
|
||||||
return Services.prefs.getBoolPref("browser.newtab.preload") &&
|
return Services.prefs.getBoolPref("browser.newtab.preload") &&
|
||||||
!Services.prefs.prefHasUserValue("browser.newtab.url");
|
!NewTabURL.overridden;
|
||||||
]]>
|
]]>
|
||||||
</body>
|
</body>
|
||||||
</method>
|
</method>
|
||||||
|
@ -8,7 +8,6 @@ function test() {
|
|||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
let windowsToClose = [];
|
let windowsToClose = [];
|
||||||
let newTab;
|
let newTab;
|
||||||
let newTabPrefName = "browser.newtab.url";
|
|
||||||
let newTabURL;
|
let newTabURL;
|
||||||
let mode;
|
let mode;
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ function test() {
|
|||||||
newTabURL = "about:privatebrowsing";
|
newTabURL = "about:privatebrowsing";
|
||||||
} else {
|
} else {
|
||||||
mode = "normal";
|
mode = "normal";
|
||||||
newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
|
newTabURL = NewTabURL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
is(aWindow.gBrowser.currentURI.spec, newTabURL,
|
is(aWindow.gBrowser.currentURI.spec, newTabURL,
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
function test() {
|
function test() {
|
||||||
//initialization
|
//initialization
|
||||||
waitForExplicitFinish();
|
waitForExplicitFinish();
|
||||||
let newTabPrefName = "browser.newtab.url";
|
|
||||||
let newTabURL;
|
let newTabURL;
|
||||||
let testURL = "http://example.com/";
|
let testURL = "http://example.com/";
|
||||||
let mode;
|
let mode;
|
||||||
@ -17,24 +16,24 @@ function test() {
|
|||||||
newTabURL = "about:privatebrowsing";
|
newTabURL = "about:privatebrowsing";
|
||||||
} else {
|
} else {
|
||||||
mode = "normal";
|
mode = "normal";
|
||||||
newTabURL = Services.prefs.getCharPref(newTabPrefName) || "about:blank";
|
newTabURL = NewTabURL.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the new tab opened while in normal/private mode
|
// Check the new tab opened while in normal/private mode
|
||||||
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL,
|
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, newTabURL,
|
||||||
"URL of NewTab should be " + newTabURL + " in " + mode + " mode");
|
"URL of NewTab should be " + newTabURL + " in " + mode + " mode");
|
||||||
// Set the custom newtab url
|
// Set the custom newtab url
|
||||||
Services.prefs.setCharPref(newTabPrefName, testURL);
|
NewTabURL.override(testURL);
|
||||||
ok(Services.prefs.prefHasUserValue(newTabPrefName), "Custom newtab url is set");
|
is(NewTabURL.get(), testURL, "Custom newtab url is set");
|
||||||
|
|
||||||
// Open a newtab after setting the custom newtab url
|
// Open a newtab after setting the custom newtab url
|
||||||
openNewTab(aWindow, function () {
|
openNewTab(aWindow, function () {
|
||||||
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL,
|
is(aWindow.gBrowser.selectedBrowser.currentURI.spec, testURL,
|
||||||
"URL of NewTab should be the custom url");
|
"URL of NewTab should be the custom url");
|
||||||
|
|
||||||
// clear the custom url preference
|
// Clear the custom url.
|
||||||
Services.prefs.clearUserPref(newTabPrefName);
|
NewTabURL.reset();
|
||||||
ok(!Services.prefs.prefHasUserValue(newTabPrefName), "No custom newtab url is set");
|
is(NewTabURL.get(), "about:newtab", "No custom newtab url is set");
|
||||||
|
|
||||||
aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
|
aWindow.gBrowser.removeTab(aWindow.gBrowser.selectedTab);
|
||||||
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
|
// 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
|
// test normal mode
|
||||||
testOnWindow(false, function(aWindow) {
|
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://gre/modules/PrivateBrowsingUtils.jsm");
|
||||||
Components.utils.import("resource:///modules/RecentWindow.jsm");
|
Components.utils.import("resource:///modules/RecentWindow.jsm");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(this, "BROWSER_NEW_TAB_URL", function () {
|
XPCOMUtils.defineLazyModuleGetter(this, "NewTabURL",
|
||||||
const PREF = "browser.newtab.url";
|
"resource:///modules/NewTabURL.jsm");
|
||||||
|
|
||||||
function getNewTabPageURL() {
|
this.__defineGetter__("BROWSER_NEW_TAB_URL", () => {
|
||||||
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
if (PrivateBrowsingUtils.isWindowPrivate(window) &&
|
||||||
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
!PrivateBrowsingUtils.permanentPrivateBrowsing &&
|
||||||
!Services.prefs.prefHasUserValue(PREF)) {
|
!NewTabURL.overridden) {
|
||||||
return "about:privatebrowsing";
|
return "about:privatebrowsing";
|
||||||
}
|
|
||||||
|
|
||||||
let url = Services.prefs.getComplexValue(PREF, Ci.nsISupportsString).data;
|
|
||||||
return url || "about:blank";
|
|
||||||
}
|
}
|
||||||
|
return NewTabURL.get();
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
var TAB_DROP_TYPE = "application/x-moz-tabbrowser-tab";
|
||||||
|
@ -28,14 +28,14 @@ add_task(function* () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
add_task(function* () {
|
add_task(function* () {
|
||||||
Services.prefs.setCharPref("browser.newtab.url", "about:blank");
|
NewTabURL.override("about:blank");
|
||||||
registerCleanupFunction(() => {
|
registerCleanupFunction(() => {
|
||||||
Services.prefs.clearUserPref("browser.newtab.url");
|
NewTabURL.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
let win = yield openNewPrivateWindow();
|
let win = yield openNewPrivateWindow();
|
||||||
checkUrlbarFocus(win);
|
checkUrlbarFocus(win);
|
||||||
win.close();
|
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',
|
'FormValidationHandler.jsm',
|
||||||
'HiddenFrame.jsm',
|
'HiddenFrame.jsm',
|
||||||
'NetworkPrioritizer.jsm',
|
'NetworkPrioritizer.jsm',
|
||||||
|
'NewTabURL.jsm',
|
||||||
'offlineAppCache.jsm',
|
'offlineAppCache.jsm',
|
||||||
'PanelFrame.jsm',
|
'PanelFrame.jsm',
|
||||||
'PluginContent.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'
|
skip-if = toolkit == 'android' || toolkit == 'gonk'
|
||||||
|
|
||||||
[test_DirectoryLinksProvider.js]
|
[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
|
// should just do a spec compare, rather than two gets of the scheme and
|
||||||
// then the path. -Gagan
|
// then the path. -Gagan
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsAutoCString buf, pref;
|
nsAutoCString buf;
|
||||||
|
|
||||||
rv = aURI->GetScheme(buf);
|
rv = aURI->GetScheme(buf);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
@ -11750,16 +11750,17 @@ nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = Preferences::GetDefaultCString("browser.newtab.url", &pref);
|
// Check if the webbrowser chrome wants us to proceed - by default it ensures
|
||||||
|
// aURI is not the newtab URI.
|
||||||
if (NS_FAILED(rv)) {
|
nsCOMPtr<nsIWebBrowserChrome3> browserChrome3 = do_GetInterface(mTreeOwner);
|
||||||
return true;
|
if (browserChrome3) {
|
||||||
|
bool shouldAdd;
|
||||||
|
rv = browserChrome3->ShouldAddToSessionHistory(this, aURI, &shouldAdd);
|
||||||
|
NS_ENSURE_SUCCESS(rv, true);
|
||||||
|
return shouldAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = aURI->GetSpec(buf);
|
return true;
|
||||||
NS_ENSURE_SUCCESS(rv, true);
|
|
||||||
|
|
||||||
return !buf.Equals(pref);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -12,7 +12,7 @@ interface nsIInputStream;
|
|||||||
/**
|
/**
|
||||||
* nsIWebBrowserChrome3 is an extension to nsIWebBrowserChrome2.
|
* nsIWebBrowserChrome3 is an extension to nsIWebBrowserChrome2.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(9e6c2372-5d9d-4ce8-ab9e-c5df1494dc84)]
|
[scriptable, uuid(da646a9c-5788-4860-88a4-bd5d0ad853da)]
|
||||||
interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -47,4 +47,7 @@ interface nsIWebBrowserChrome3 : nsIWebBrowserChrome2
|
|||||||
bool shouldLoadURI(in nsIDocShell aDocShell,
|
bool shouldLoadURI(in nsIDocShell aDocShell,
|
||||||
in nsIURI aURI,
|
in nsIURI aURI,
|
||||||
in nsIURI aReferrer);
|
in nsIURI aReferrer);
|
||||||
|
|
||||||
|
bool shouldAddToSessionHistory(in nsIDocShell aDocShell,
|
||||||
|
in nsIURI aURI);
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
},
|
},
|
||||||
"global": {
|
"global": {
|
||||||
"talos_repo": "https://hg.mozilla.org/build/talos",
|
"talos_repo": "https://hg.mozilla.org/build/talos",
|
||||||
"talos_revision": "39db01f6dabb"
|
"talos_revision": "33449734f99f"
|
||||||
},
|
},
|
||||||
"extra_options": {
|
"extra_options": {
|
||||||
"android": [ "--apkPath=%(apk_path)s" ]
|
"android": [ "--apkPath=%(apk_path)s" ]
|
||||||
|
@ -462,6 +462,24 @@ NS_IMETHODIMP nsContentTreeOwner::ShouldLoadURI(nsIDocShell *aDocShell,
|
|||||||
return NS_OK;
|
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
|
// nsContentTreeOwner::nsIWebBrowserChrome2
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
@ -19,7 +19,7 @@ interface nsITabParent;
|
|||||||
* internals of the browser area to tell the containing xul window to update
|
* internals of the browser area to tell the containing xul window to update
|
||||||
* its ui.
|
* its ui.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(db89f748-9736-40b2-a172-3928aa1194b2)]
|
[scriptable, uuid(8974a499-d49b-43e1-8b32-c9b3ed81be3f)]
|
||||||
interface nsIXULBrowserWindow : nsISupports
|
interface nsIXULBrowserWindow : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -62,6 +62,9 @@ interface nsIXULBrowserWindow : nsISupports
|
|||||||
bool shouldLoadURI(in nsIDocShell aDocShell,
|
bool shouldLoadURI(in nsIDocShell aDocShell,
|
||||||
in nsIURI aURI,
|
in nsIURI aURI,
|
||||||
in nsIURI aReferrer);
|
in nsIURI aReferrer);
|
||||||
|
|
||||||
|
bool shouldAddToSessionHistory(in nsIDocShell aDocShell,
|
||||||
|
in nsIURI aURI);
|
||||||
/**
|
/**
|
||||||
* Show/hide a tooltip (when the user mouses over a link, say).
|
* Show/hide a tooltip (when the user mouses over a link, say).
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user