Bug 331522. By default, do not allow keyword searches when navigating to URLs; modify browser UI code to enable keyword searches only on selected URL input mechanisms (e.g., typed into the URL bar). r+sr=darin,r=mconnor

git-svn-id: svn://10.0.0.236/trunk@193458 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
roc+%cs.cmu.edu 2006-04-03 23:17:51 +00:00
parent 75a4bcdd89
commit e9fd34c810
15 changed files with 107 additions and 58 deletions

View File

@ -657,7 +657,8 @@ function BrowserStartup()
# only load url passed in when we're not page cycling
if (uriToLoad && !gIsLoadingBlank) {
if (window.arguments.length >= 3)
loadURI(uriToLoad, window.arguments[2], window.arguments[3] || null);
loadURI(uriToLoad, window.arguments[2], window.arguments[3] || null,
window.arguments[4] || false);
else
loadOneOrMoreURIs(uriToLoad);
}
@ -1711,7 +1712,7 @@ function openLocationCallback()
function BrowserOpenTab()
{
gBrowser.loadOneTab("about:blank", null, null, null, false);
gBrowser.loadOneTab("about:blank", null, null, null, false, false);
if (gURLBar)
setTimeout(function() { gURLBar.focus(); }, 0);
}
@ -1732,9 +1733,9 @@ function delayedOpenWindow(chrome, flags, href, postData)
/* Required because the tab needs time to set up its content viewers and get the load of
the URI kicked off before becoming the active content area. */
function delayedOpenTab(aUrl, aReferrer, aCharset, aPostData)
function delayedOpenTab(aUrl, aReferrer, aCharset, aPostData, aAllowThirdPartyFixup)
{
gBrowser.loadOneTab(aUrl, aReferrer, aCharset, aPostData, false);
gBrowser.loadOneTab(aUrl, aReferrer, aCharset, aPostData, false, aAllowThirdPartyFixup);
}
function BrowserOpenFileWindow()
@ -1803,12 +1804,16 @@ function BrowserCloseWindow()
closeWindow(true);
}
function loadURI(uri, referrer, postData)
function loadURI(uri, referrer, postData, allowThirdPartyFixup)
{
try {
if (postData === undefined)
postData = null;
getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, referrer, postData, null);
var flags = nsIWebNavigation.LOAD_FLAGS_NONE;
if (allowThirdPartyFixup) {
flags = nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
}
getWebNavigation().loadURI(uri, flags, referrer, postData, null);
} catch (e) {
}
}
@ -1821,13 +1826,14 @@ function BrowserLoadURL(aTriggeringEvent, aPostData)
aTriggeringEvent.altKey) {
handleURLBarRevert();
content.focus();
gBrowser.loadOneTab(url, null, null, aPostData, false);
gBrowser.loadOneTab(url, null, null, aPostData, false,
true /* allow third party fixup */);
gURLBar.value = url;
aTriggeringEvent.preventDefault();
aTriggeringEvent.stopPropagation();
}
else
loadURI(url, null, aPostData);
loadURI(url, null, aPostData, true /* allow third party fixup */);
content.focus();
}
@ -2667,7 +2673,8 @@ var newTabButtonObserver = {
var url = getShortcutOrURI(draggedText, postData);
if (url) {
getBrowser().dragDropSecurityCheck(aEvent, aDragSession, url);
openNewTabWith(url, null, postData.value, aEvent);
// allow third-party services to fixup this URL
openNewTabWith(url, null, postData.value, aEvent, true);
}
},
getSupportedFlavours: function ()
@ -2702,7 +2709,8 @@ var newWindowButtonObserver = {
var url = getShortcutOrURI(draggedText, postData);
if (url) {
getBrowser().dragDropSecurityCheck(aEvent, aDragSession, url);
openNewWindowWith(url, null, postData.value);
// allow third-party services to fixup this URL
openNewWindowWith(url, null, postData.value, true);
}
},
getSupportedFlavours: function ()
@ -2742,7 +2750,7 @@ var goButtonObserver = {
.getService(Components.interfaces.nsIScriptSecurityManager);
const nsIScriptSecMan = Components.interfaces.nsIScriptSecurityManager;
secMan.checkLoadURI(gBrowser.currentURI, uri, nsIScriptSecMan.DISALLOW_SCRIPT_OR_DATA);
loadURI(uri.spec, null, postData.value);
loadURI(uri.spec, null, postData.value, true);
} catch (ex) {}
},
getSupportedFlavours: function ()
@ -2823,7 +2831,7 @@ const BrowserSearch = {
var ss = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
var searchForm = ss.defaultEngine.searchForm;
loadURI(searchForm, null, null);
loadURI(searchForm, null, null, false);
}
},
@ -2854,9 +2862,9 @@ const BrowserSearch = {
if (useNewTab) {
getBrowser().loadOneTab(submission.uri.spec, null, null,
submission.postData);
submission.postData, false);
} else
loadURI(submission.uri.spec, null, submission.postData);
loadURI(submission.uri.spec, null, submission.postData, false);
},
/**
@ -3763,7 +3771,7 @@ nsBrowserAccess.prototype =
break;
case nsCI.nsIBrowserDOMWindow.OPEN_NEWTAB :
var loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
var newTab = gBrowser.loadOneTab("about:blank", null, null, null, loadInBackground);
var newTab = gBrowser.loadOneTab("about:blank", null, null, null, loadInBackground, false);
newWindow = gBrowser.getBrowserForTab(newTab).docShell
.QueryInterface(nsCI.nsIInterfaceRequestor)
.getInterface(nsCI.nsIDOMWindow);
@ -4560,15 +4568,15 @@ nsContextMenu.prototype = {
// Open linked-to URL in a new window.
openLink : function () {
openNewWindowWith(this.linkURL, this.docURL, null);
openNewWindowWith(this.linkURL, this.docURL, null, false);
},
// Open linked-to URL in a new tab.
openLinkInTab : function () {
openNewTabWith(this.linkURL, this.docURL, null, null);
openNewTabWith(this.linkURL, this.docURL, null, null, false);
},
// Open frame in a new tab.
openFrameInTab : function () {
openNewTabWith(this.target.ownerDocument.location.href, null, null, null);
openNewTabWith(this.target.ownerDocument.location.href, null, null, null, false);
},
// Reload clicked-in frame.
reloadFrame : function () {
@ -4576,11 +4584,11 @@ nsContextMenu.prototype = {
},
// Open clicked-in frame in its own window.
openFrame : function () {
openNewWindowWith(this.target.ownerDocument.location.href, null, null);
openNewWindowWith(this.target.ownerDocument.location.href, null, null, false);
},
// Open clicked-in frame in the same window.
showOnlyThisFrame : function () {
window.loadURI(this.target.ownerDocument.location.href, null, null);
window.loadURI(this.target.ownerDocument.location.href, null, null, false);
},
// View Partial Source
viewPartialSource : function ( context ) {
@ -5142,7 +5150,7 @@ function asyncOpenWebPanel(event)
var url = getShortcutOrURI(wrapper.href, postData);
if (!url)
return true;
loadURI(url, null, postData.value);
loadURI(url, null, postData.value, false);
event.preventDefault();
return false;
}
@ -5231,13 +5239,13 @@ function handleLinkClick(event, href, linkNode)
#else
if (event.ctrlKey) {
#endif
openNewTabWith(href, docURL, null, event);
openNewTabWith(href, docURL, null, event, false);
event.stopPropagation();
return true;
}
// if left button clicked
if (event.shiftKey) {
openNewWindowWith(href, docURL, null);
openNewWindowWith(href, docURL, null, false);
event.stopPropagation();
return true;
}
@ -5258,9 +5266,9 @@ function handleLinkClick(event, href, linkNode)
tab = true;
}
if (tab)
openNewTabWith(href, docURL, null, event);
openNewTabWith(href, docURL, null, event, false);
else
openNewWindowWith(href, docURL, null);
openNewWindowWith(href, docURL, null, false);
event.stopPropagation();
return true;
}
@ -5328,7 +5336,7 @@ var contentAreaDNDObserver = {
case "navigator:browser":
var postData = { };
var uri = getShortcutOrURI(url, postData);
loadURI(uri, null, postData.value);
loadURI(uri, null, postData.value, false);
break;
case "navigator:view-source":
viewSource(url);

View File

@ -101,18 +101,21 @@ function open()
url = dialog.input.value;
try {
// Whichever target we use for the load, we allow third-party services to
// fixup the URI
switch (dialog.openWhereList.value) {
case "0":
browser.loadURI(url, null, postData.value);
browser.loadURI(url, null, postData.value, true);
break;
case "1":
window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no", url, postData.value);
window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no",
url, postData.value, null, null, true);
break;
case "3":
if (browser.getBrowser && browser.getBrowser().localName == "tabbrowser")
browser.delayedOpenTab(url, null, null, postData.value);
browser.delayedOpenTab(url, null, null, postData.value, true);
else
browser.loadURI(url, null, postData.value); // Just do a normal load.
browser.loadURI(url, null, postData.value, true); // Just do a normal load.
break;
}
}

View File

@ -120,7 +120,7 @@ function getBoolPref ( prefname, def )
function openUILink( url, e, ignoreButton, ignoreAlt )
{
var where = whereToOpenLink(e, ignoreButton, ignoreAlt);
openUILinkIn(url, where);
openUILinkIn(url, where, false);
}
@ -193,8 +193,12 @@ function whereToOpenLink( e, ignoreButton, ignoreAlt )
* "tabshifted" same as "tab" but in background if default is to select new tabs, and vice versa
* "window" new window
* "save" save to disk (with no filename hint!)
*
* allowThirdPartyFixup controls whether third party services such as Google's
* I Feel Lucky are allowed to interpret this URL. This parameter may be
* undefined, which is treated as false.
*/
function openUILinkIn( url, where )
function openUILinkIn( url, where, allowThirdPartyFixup )
{
if (!where)
return;
@ -230,7 +234,8 @@ function openUILinkIn( url, where )
case "tabshifted":
case "tab":
var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
browser.loadOneTab(url, null, null, null, loadInBackground);
browser.loadOneTab(url, null, null, null, loadInBackground,
allowThirdPartyFixup || false);
break;
}
}

View File

@ -686,7 +686,7 @@ var BookmarksCommand = {
if (url == "")
return;
openUILinkIn(url, aTargetBrowser);
openUILinkIn(url, aTargetBrowser, false);
},
openGroupBookmark: function (aURI, aTargetBrowser)

View File

@ -1282,7 +1282,7 @@ var PlacesController = {
if (node) {
var browser = this._getBrowserWindow();
if (browser)
browser.openNewWindowWith(node.uri, null, null);
browser.openNewWindowWith(node.uri, null, null, false);
else
this._openBrowserWith(node.uri);
}
@ -1296,7 +1296,7 @@ var PlacesController = {
if (node) {
var browser = this._getBrowserWindow();
if (browser)
browser.loadURI(node.uri, null, null);
browser.loadURI(node.uri, null, null, false);
else
this._openBrowserWith(node.uri);
}

View File

@ -226,7 +226,7 @@
/* openDialog("chrome://browser/content/search/edit-engines.xul", "",
"modal,centerscreen"); */
var regionBundle = document.getElementById("bundle_browser_region");
loadURI(regionBundle.getString("searchEnginesURL"), null, null);
loadURI(regionBundle.getString("searchEnginesURL"), null, null, false);
} else {
this.currentEngine = aEvent.target.engine;
this.focus();
@ -270,11 +270,11 @@
if (aInNewTab) {
content.focus();
getBrowser().loadOneTab(url, null, null, postData.value, false);
getBrowser().loadOneTab(url, null, null, postData.value, false, false);
if (gURLBar)
gURLBar.value = url;
} else
loadURI(url, null, postData.value);
loadURI(url, null, postData.value, false);
content.focus();
]]></body>
</method>

View File

@ -77,7 +77,7 @@
var url = node.getAttribute("link");
if (url != "")
window.opener.openNewWindowWith(url, null, false);
window.opener.openNewWindowWith(url, null, false, false);
}
]]>

View File

@ -259,6 +259,7 @@ nsDocShell::nsDocShell():
mUseErrorPages(PR_FALSE),
mObserveErrorPages(PR_TRUE),
mAllowAuth(PR_TRUE),
mAllowKeywordFixup(PR_FALSE),
mFiredUnloadEvent(PR_FALSE),
mEODForCurrentDocument(PR_FALSE),
mURIResultedInDocument(PR_FALSE),
@ -801,6 +802,9 @@ nsDocShell::LoadURI(nsIURI * aURI,
if (!sendReferrer)
flags |= INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER;
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP)
flags |= INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
rv = InternalLoad(aURI,
referrer,
@ -828,6 +832,8 @@ nsDocShell::LoadStream(nsIInputStream *aStream, nsIURI * aURI,
{
NS_ENSURE_ARG(aStream);
mAllowKeywordFixup = PR_FALSE;
// if the caller doesn't pass in a URI we need to create a dummy URI. necko
// currently requires a URI in various places during the load. Some consumers
// do as well.
@ -2793,8 +2799,11 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
rv = NS_NewURI(getter_AddRefs(uri), uriString);
} else {
// Call the fixup object
rv = sURIFixup->CreateFixupURI(NS_ConvertUTF16toUTF8(aURI),
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
PRUint32 fixupFlags = 0;
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
}
rv = sURIFixup->CreateFixupURI(NS_ConvertUTF16toUTF8(aURI), fixupFlags,
getter_AddRefs(uri));
}
@ -2815,8 +2824,9 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
loadInfo->SetReferrer(aReferringURI);
loadInfo->SetHeadersStream(aHeaderStream);
rv = LoadURI(uri, loadInfo, 0, PR_TRUE);
rv = LoadURI(uri, loadInfo,
aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, PR_TRUE);
return rv;
}
@ -6361,6 +6371,8 @@ nsDocShell::InternalLoad(nsIURI * aURI,
return rv;
}
mAllowKeywordFixup =
(aFlags & INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) != 0;
mURIResultedInDocument = PR_FALSE; // reset the clock...
//

View File

@ -477,6 +477,7 @@ protected:
PRPackedBool mUseErrorPages;
PRPackedBool mObserveErrorPages;
PRPackedBool mAllowAuth;
PRPackedBool mAllowKeywordFixup;
PRPackedBool mFiredUnloadEvent;

View File

@ -115,9 +115,10 @@ interface nsIDocShell : nsISupports
in ACString aContentCharset,
in nsIDocShellLoadInfo aLoadInfo);
const long INTERNAL_LOAD_FLAGS_NONE = 0x0;
const long INTERNAL_LOAD_FLAGS_INHERIT_OWNER = 0x1;
const long INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER = 0x2;
const long INTERNAL_LOAD_FLAGS_NONE = 0x0;
const long INTERNAL_LOAD_FLAGS_INHERIT_OWNER = 0x1;
const long INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER = 0x2;
const long INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP = 0x4;
/**
* Loads the given URI. This method is identical to loadURI(...) except

View File

@ -175,6 +175,13 @@ interface nsIWebNavigation : nsISupports
* A hint this load was prompted by an external program: take care!
*/
const unsigned long LOAD_FLAGS_FROM_EXTERNAL = 0x1000;
/**
* This flag specifies that the URI may be submitted to a third-party
* server for correction. This should only be applied to non-sensitive
* URIs entered by users.
*/
const unsigned long LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP = 0x2000;
/**
* Loads a given URI. This will give priority to loading the requested URI

View File

@ -958,7 +958,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
//
// First try keyword fixup
//
if (aStatus == NS_ERROR_UNKNOWN_HOST)
if (aStatus == NS_ERROR_UNKNOWN_HOST && mAllowKeywordFixup)
{
PRBool keywordsEnabled = PR_FALSE;

View File

@ -49,8 +49,11 @@
* If null, there will be no referrer header and no security check.
* @param postData Form POST data, or null.
* @param event The triggering event (for the purpose of determining whether to open in the background), or null
* @param allowThirdPartyFixup if true, then we allow the URL text to be sent to third party
* services (e.g., Google's I Feel Lucky) for interpretation. This parameter may be undefined in
* which case it is treated as false.
*/
function openNewTabWith(href, sourceURL, postData, event)
function openNewTabWith(href, sourceURL, postData, event, allowThirdPartyFixup)
{
if (sourceURL)
urlSecurityCheck(href, sourceURL);
@ -82,10 +85,11 @@ function openNewTabWith(href, sourceURL, postData, event)
var referrerURI = sourceURL ? makeURI(sourceURL) : null;
browser.loadOneTab(href, referrerURI, originCharset, postData, loadInBackground);
browser.loadOneTab(href, referrerURI, originCharset, postData, loadInBackground,
allowThirdPartyFixup || false);
}
function openNewWindowWith(href, sourceURL, postData)
function openNewWindowWith(href, sourceURL, postData, allowThirdPartyFixup)
{
if (sourceURL)
urlSecurityCheck(href, sourceURL);
@ -100,7 +104,8 @@ function openNewWindowWith(href, sourceURL, postData)
var referrerURI = sourceURL ? makeURI(sourceURL) : null;
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", href, charsetArg, referrerURI, postData);
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no",
href, charsetArg, referrerURI, postData, allowThirdPartyFixup);
}
/**

View File

@ -225,7 +225,7 @@ function visitLink(aEvent) {
node = node.parentNode;
var url = node.getAttribute("link");
if (url != "")
top.opener.openNewWindowWith(url, null, false);
top.opener.openNewWindowWith(url, null, false, false);
}
function isValidLeftClick(aEvent, aName)

View File

@ -1038,10 +1038,12 @@
<parameter name="aCharset"/>
<parameter name="aPostData"/>
<parameter name="aLoadInBackground"/>
<parameter name="aAllowThirdPartyFixup"/>
<body>
<![CDATA[
var owner = aLoadInBackground ? null : this.selectedTab;
var tab = this.addTab(aURI, aReferrerURI, aCharset, aPostData, owner);
var tab = this.addTab(aURI, aReferrerURI, aCharset, aPostData, owner,
aAllowThirdPartyFixup);
var bgLoad = (typeof(aLoadInBackground) != "undefined") ? aLoadInBackground :
this.mPrefs.getBoolPref("browser.tabs.loadInBackground");
// Set newly selected tab after quick timeout, otherwise hideous focus problems
@ -1080,7 +1082,7 @@
if (aReplace)
this.loadURI(aURIs[0], null, null);
else
firstTabAdded = gBrowser.addTab(aURIs[0], null, null, null, owner);
firstTabAdded = gBrowser.addTab(aURIs[0], null, null, null, owner, false);
for (var i = 1; i < aURIs.length; ++i)
gBrowser.addTab(aURIs[i]);
@ -1101,6 +1103,7 @@
<parameter name="aCharset"/>
<parameter name="aPostData"/>
<parameter name="aOwner"/>
<parameter name="aAllowThirdPartyFixup"/>
<body>
<![CDATA[
if (!this.mTabbedMode)
@ -1194,8 +1197,12 @@
if (aPostData === undefined)
aPostData = null;
b.loadURIWithFlags(aURI, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE,
aReferrerURI, aCharset, aPostData);
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
var flags = nsIWebNavigation.LOAD_FLAGS_NONE;
if (aAllowThirdPartyFixup) {
flags = nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
}
b.loadURIWithFlags(aURI, flags, aReferrerURI, aCharset, aPostData);
}
return t;
@ -1663,7 +1670,7 @@
if (document.getBindingParent(aEvent.originalTarget).localName != "tab") {
// We're adding a new tab.
this.loadOneTab(getShortcutOrURI(url), null, null, null, bgLoad);
this.loadOneTab(getShortcutOrURI(url), null, null, null, bgLoad, false);
}
else {
// Load in an existing tab.