Bug 935377 - Firefox should fix common scheme typos, r=dolske

This commit is contained in:
Christian Legnitto 2014-01-12 12:02:27 -08:00
parent 2faa3798f1
commit a7ce12665b
13 changed files with 50 additions and 16 deletions

View File

@ -1839,8 +1839,10 @@ function loadURI(uri, referrer, postData, allowThirdPartyFixup) {
postData = null;
var flags = nsIWebNavigation.LOAD_FLAGS_NONE;
if (allowThirdPartyFixup)
if (allowThirdPartyFixup) {
flags |= nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
flags |= nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
}
try {
gBrowser.loadURIWithFlags(uri, flags, referrer, null, postData);

View File

@ -82,7 +82,8 @@ function open()
switch (dialog.openWhereList.value) {
case "0":
var webNav = Components.interfaces.nsIWebNavigation;
var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
var flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
if (!mayInheritPrincipal)
flags |= webNav.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
browser.gBrowser.loadURIWithFlags(url, flags, null, null, postData);

View File

@ -1601,8 +1601,10 @@
b.userTypedValue = aURI;
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (aAllowThirdPartyFixup)
if (aAllowThirdPartyFixup) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
}
if (aFromExternal)
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FROM_EXTERNAL;
if (aDisableMCB)
@ -4480,7 +4482,10 @@
} else {
// Load in an existing tab.
try {
this.tabbrowser.getBrowserForTab(tab).loadURIWithFlags(url, Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
let webNav = Ci.nsIWebNavigation;
let flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
this.tabbrowser.getBrowserForTab(tab).loadURIWithFlags(url, flags);
if (!bgLoad)
this.selectedItem = tab;
} catch(ex) {

View File

@ -293,7 +293,9 @@
}
function loadCurrent() {
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
let webnav = Ci.nsIWebNavigation;
let flags = webnav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
webnav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
// Pass LOAD_FLAGS_DISALLOW_INHERIT_OWNER to prevent any loads from
// inheriting the currently loaded document's principal, unless this
// URL is marked as safe to inherit (e.g. came from a bookmark

View File

@ -300,8 +300,10 @@ function openLinkIn(url, where, params) {
switch (where) {
case "current":
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (aAllowThirdPartyFixup)
if (aAllowThirdPartyFixup) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
}
if (aDisallowInheritPrincipal)
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
w.gBrowser.loadURIWithFlags(url, flags, aReferrerURI, null, aPostData);

View File

@ -54,9 +54,12 @@ function shouldLoadURI(aURI) {
function resolveURIInternal(aCmdLine, aArgument) {
var uri = aCmdLine.resolveURI(aArgument);
var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
.getService(nsIURIFixup);
if (!(uri instanceof nsIFileURL)) {
return uri;
return urifixup.createFixupURI(aArgument,
urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);
}
try {
@ -71,9 +74,6 @@ function resolveURIInternal(aCmdLine, aArgument) {
// doesn't exist. Try URI fixup heuristics: see bug 290782.
try {
var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
.getService(nsIURIFixup);
uri = urifixup.createFixupURI(aArgument, 0);
}
catch (e) {

View File

@ -368,12 +368,16 @@ var BrowserUI = {
Task.spawn(function() {
let postData = {};
let webNav = Ci.nsIWebNavigation;
let flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
aURI = yield Browser.getShortcutOrURI(aURI, postData);
Browser.loadURI(aURI, { flags: Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, postData: postData });
Browser.loadURI(aURI, { flags: flags, postData: postData });
// Delay doing the fixup so the raw URI is passed to loadURIWithFlags
// and the proper third-party fixup can be done
let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
let fixupFlags = Ci.nsIURIFixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |
Ci.nsIURIFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS;
let uri = gURIFixup.createFixupURI(aURI, fixupFlags);
gHistSvc.markPageAsTyped(uri);

View File

@ -172,7 +172,10 @@ var Browser = {
let self = this;
function loadStartupURI() {
if (activationURI) {
self.addTab(activationURI, true, null, { flags: Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP });
let webNav = Ci.nsIWebNavigation;
let flags = webNav.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
webNav.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
self.addTab(activationURI, true, null, { flags: flags });
} else {
let uri = commandURL || Browser.getHomePage();
self.addTab(uri, true);

View File

@ -1271,6 +1271,7 @@ nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(nsIPrincipal* aPrincipal,
uint32_t flags[] = {
nsIURIFixup::FIXUP_FLAG_NONE,
nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS,
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP,
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP |

View File

@ -1583,6 +1583,9 @@ nsDocShell::LoadURI(nsIURI * aURI,
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP)
flags |= INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
if (aLoadFlags & LOAD_FLAGS_FIXUP_SCHEME_TYPOS)
flags |= INTERNAL_LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
if (aLoadFlags & LOAD_FLAGS_FIRST_LOAD)
flags |= INTERNAL_LOAD_FLAGS_FIRST_LOAD;
@ -4272,6 +4275,9 @@ nsDocShell::LoadURI(const char16_t * aURI,
if (aLoadFlags & LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP;
}
if (aLoadFlags & LOAD_FLAGS_FIXUP_SCHEME_TYPOS) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_FIX_SCHEME_TYPOS;
}
nsCOMPtr<nsIInputStream> fixupStream;
rv = sURIFixup->CreateFixupURI(uriString, fixupFlags,
getter_AddRefs(fixupStream),

View File

@ -44,7 +44,7 @@ interface nsIReflowObserver;
typedef unsigned long nsLoadFlags;
[scriptable, builtinclass, uuid(55ca6545-7ce4-49ad-8117-8286ca9c61bb)]
[scriptable, builtinclass, uuid(e3ea830d-2614-4aeb-9ec3-b8f744b03b80)]
interface nsIDocShell : nsIDocShellTreeItem
{
/**
@ -111,6 +111,8 @@ interface nsIDocShell : nsIDocShellTreeItem
// Whether the load should be treated as srcdoc load, rather than a URI one.
const long INTERNAL_LOAD_FLAGS_IS_SRCDOC = 0x40;
const long INTERNAL_LOAD_FLAGS_FIXUP_SCHEME_TYPOS = 0x80;
/**
* Loads the given URI. This method is identical to loadURI(...) except
* that its parameter list is broken out instead of being packaged inside

View File

@ -16,7 +16,7 @@ interface nsIURI;
* location, stop or restart an in process load, or determine where the object
* has previously gone.
*/
[scriptable, uuid(28404f7e-0f17-4dc3-a21a-2074d8659b02)]
[scriptable, uuid(dbd6241d-c76e-42c0-9410-930589d803a2)]
interface nsIWebNavigation : nsISupports
{
/**
@ -191,6 +191,11 @@ interface nsIWebNavigation : nsISupports
*/
const unsigned long LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP = 0x100000;
/**
* This flag specifies that common scheme typos should be corrected.
*/
const unsigned long LOAD_FLAGS_FIXUP_SCHEME_TYPOS = 0x200000;
/* Note that flag 0x80000 is available. */
/**

View File

@ -1427,7 +1427,8 @@ var BrowserApp = {
// Pass LOAD_FLAGS_DISALLOW_INHERIT_OWNER to prevent any loads from
// inheriting the currently loaded document's principal.
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
if (data.userEntered) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_OWNER;
}