Bug 1626016 - Remove createFixupURI and move postData inside URIFixupInfo. r=Gijs,geckoview-reviewers,preferences-reviewers,snorp

Differential Revision: https://phabricator.services.mozilla.com/D93189
This commit is contained in:
Marco Bonardo 2020-10-13 10:20:16 +00:00
Родитель 2ae8134434
Коммит 1019bbf009
24 изменённых файлов: 167 добавлений и 194 удалений

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

@ -1264,18 +1264,15 @@ var PlacesToolbarHelper = {
this.addManagedBookmarks(submenupopup, entry.children);
} else if (entry.name && entry.url) {
// It's bookmark.
let uri = Services.uriFixup.createFixupURI(
entry.url,
Ci.nsIURIFixup.FIXUP_FLAG_NONE
);
let { preferredURI } = Services.uriFixup.getFixupURIInfo(entry.url);
let menuitem = document.createXULElement("menuitem");
menuitem.setAttribute("label", entry.name);
menuitem.setAttribute("image", "page-icon:" + uri.spec);
menuitem.setAttribute("image", "page-icon:" + preferredURI.spec);
menuitem.setAttribute(
"class",
"menuitem-iconic bookmark-item menuitem-with-favicon"
);
menuitem.link = uri.spec;
menuitem.link = preferredURI.spec;
menu.appendChild(menuitem);
}
}

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

@ -65,10 +65,10 @@ function resolveURIInternal(aCmdLine, aArgument) {
var uriFixup = Services.uriFixup;
if (!(uri instanceof Ci.nsIFileURL)) {
return uriFixup.createFixupURI(
return Services.uriFixup.getFixupURIInfo(
aArgument,
uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS
);
).preferredURI;
}
try {
@ -83,7 +83,7 @@ function resolveURIInternal(aCmdLine, aArgument) {
// doesn't exist. Try URI fixup heuristics: see bug 290782.
try {
uri = uriFixup.createFixupURI(aArgument, 0);
uri = Services.uriFixup.getFixupURIInfo(aArgument).preferredURI;
} catch (e) {
Cu.reportError(e);
}

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

@ -234,19 +234,6 @@ let InternalFaviconLoader = {
var PlacesUIUtils = {
LAST_USED_FOLDERS_META_KEY: "bookmarks/lastusedfolders",
/**
* Makes a URI from a spec, and do fixup
* @param aSpec
* The string spec of the URI
* @return A URI object for the spec.
*/
createFixedURI: function PUIU_createFixedURI(aSpec) {
return Services.uriFixup.createFixupURI(
aSpec,
Ci.nsIURIFixup.FIXUP_FLAG_NONE
);
},
getFormattedString: function PUIU_getFormattedString(key, params) {
return bundle.formatStringFromName(key, params);
},
@ -525,7 +512,9 @@ var PlacesUIUtils = {
* TRANSITION_LINK.
*/
markPageAsTyped: function PUIU_markPageAsTyped(aURL) {
PlacesUtils.history.markPageAsTyped(this.createFixedURI(aURL));
PlacesUtils.history.markPageAsTyped(
Services.uriFixup.getFixupURIInfo(aURL).preferredURI
);
},
/**
@ -536,7 +525,9 @@ var PlacesUIUtils = {
* If this is not called visits will be marked as TRANSITION_LINK.
*/
markPageAsFollowedBookmark: function PUIU_markPageAsFollowedBookmark(aURL) {
PlacesUtils.history.markPageAsFollowedBookmark(this.createFixedURI(aURL));
PlacesUtils.history.markPageAsFollowedBookmark(
Services.uriFixup.getFixupURIInfo(aURL).preferredURI
);
},
/**
@ -546,7 +537,9 @@ var PlacesUIUtils = {
* so automatic visits can be correctly ignored.
*/
markPageAsFollowedLink: function PUIU_markPageAsFollowedLink(aURL) {
PlacesUtils.history.markPageAsFollowedLink(this.createFixedURI(aURL));
PlacesUtils.history.markPageAsFollowedLink(
Services.uriFixup.getFixupURIInfo(aURL).preferredURI
);
},
/**

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

@ -456,7 +456,7 @@ var BookmarkPropertiesPanel = {
try {
var value = this._element(aTextboxID).value;
if (value) {
PlacesUIUtils.createFixedURI(value);
Services.uriFixup.getFixupURIInfo(value);
return true;
}
} catch (e) {}

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

@ -735,7 +735,8 @@ var gEditItemOverlay = {
let newURI;
try {
newURI = PlacesUIUtils.createFixedURI(this._locationField.value);
newURI = Services.uriFixup.getFixupURIInfo(this._locationField.value)
.preferredURI;
} catch (ex) {
// TODO: Bug 1089141 - Provide some feedback about the invalid url.
return;

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

@ -339,10 +339,9 @@ var gConnectionsDialog = {
var autoURL = document.getElementById("networkProxyAutoconfigURL");
var autoURLPref = Preferences.get("network.proxy.autoconfig_url");
try {
autoURLPref.value = autoURL.value = Services.uriFixup.createFixupURI(
autoURL.value,
0
).spec;
autoURLPref.value = autoURL.value = Services.uriFixup.getFixupURIInfo(
autoURL.value
).preferredURI.spec;
} catch (ex) {}
},

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

@ -604,13 +604,15 @@ class UrlbarInput {
if (this.isPrivate) {
flags |= Ci.nsIURIFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
}
let postData = {};
let uri = Services.uriFixup.createFixupURI(url, flags, postData);
let {
preferredURI: uri,
postData,
} = Services.uriFixup.getFixupURIInfo(url, flags);
if (
where != "current" ||
browser.lastLocationChange == lastLocationChange
) {
openParams.postData = postData.value;
openParams.postData = postData;
this._loadURL(uri.spec, where, openParams, null, browser);
}
}

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

@ -212,10 +212,12 @@ function setupUrlBar() {
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
flags |= Services.uriFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
}
let { preferredURI } = Services.uriFixup.getFixupURIInfo(
valueToFixUp,
flags
);
let uriToLoad = Services.uriFixup.createFixupURI(valueToFixUp, flags);
browser.loadUrlWithSystemPrincipal(uriToLoad.spec);
browser.loadUrlWithSystemPrincipal(preferredURI.spec);
browser.focus();
}
});

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

@ -1100,8 +1100,11 @@ nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(
if (aPrincipal->OriginAttributesRef().mPrivateBrowsingId > 0) {
fixupFlags |= nsIURIFixup::FIXUP_FLAG_PRIVATE_CONTEXT;
}
rv = fixup->CreateFixupURI(aTargetURIStr, fixupFlags, nullptr,
getter_AddRefs(target));
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
rv = fixup->GetFixupURIInfo(aTargetURIStr, fixupFlags,
getter_AddRefs(fixupInfo));
NS_ENSURE_SUCCESS(rv, rv);
rv = fixupInfo->GetPreferredURI(getter_AddRefs(target));
NS_ENSURE_SUCCESS(rv, rv);
rv = CheckLoadURIWithPrincipal(aPrincipal, target, aFlags, 0);

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

@ -256,11 +256,7 @@ URIFixup.prototype = {
return FIXUP_FLAG_FIX_SCHEME_TYPOS;
},
createFixupURI(uriString, fixupFlags = FIXUP_FLAG_NONE, postData) {
return this.getFixupURIInfo(uriString, fixupFlags, postData).preferredURI;
},
getFixupURIInfo(uriString, fixupFlags = FIXUP_FLAG_NONE, postData) {
getFixupURIInfo(uriString, fixupFlags = FIXUP_FLAG_NONE) {
let isPrivateContext = fixupFlags & FIXUP_FLAG_PRIVATE_CONTEXT;
// Eliminate embedded newlines, which single-line text fields now allow,
@ -278,11 +274,9 @@ URIFixup.prototype = {
let scheme = extractScheme(uriString);
if (scheme == "view-source") {
info.preferredURI = info.fixedURI = fixupViewSource(
uriString,
fixupFlags,
postData
);
let { preferredURI, postData } = fixupViewSource(uriString, fixupFlags);
info.preferredURI = info.fixedURI = preferredURI;
info.postData = postData;
return info;
}
@ -363,7 +357,7 @@ URIFixup.prototype = {
scheme &&
!canHandleProtocol
) {
tryKeywordFixupForURIInfo(uriString, info, isPrivateContext, postData);
tryKeywordFixupForURIInfo(uriString, info, isPrivateContext);
}
if (info.fixedURI) {
@ -419,7 +413,7 @@ URIFixup.prototype = {
fixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP &&
!inputHadDuffProtocol &&
!checkSuffix(info).suffix &&
keywordURIFixup(uriString, info, isPrivateContext, postData)
keywordURIFixup(uriString, info, isPrivateContext)
) {
return info;
}
@ -434,12 +428,7 @@ URIFixup.prototype = {
// If we still haven't been able to construct a valid URI, try to force a
// keyword match.
if (keywordEnabled && fixupFlags & FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP) {
tryKeywordFixupForURIInfo(
info.originalInput,
info,
isPrivateContext,
postData
);
tryKeywordFixupForURIInfo(info.originalInput, info, isPrivateContext);
}
if (!info.preferredURI) {
@ -473,7 +462,7 @@ URIFixup.prototype = {
return fixupFlags;
},
keywordToURI(keyword, isPrivateContext, postData) {
keywordToURI(keyword, isPrivateContext) {
if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT) {
// There's no search service in the content process, thus all the calls
// from it that care about keywords conversion should go through the
@ -518,20 +507,7 @@ URIFixup.prototype = {
}
let submissionPostDataStream = submission.postData;
if (submissionPostDataStream) {
if (postData) {
// TODO (Bug 1626016): instead of having postData as an optional out
// argument, it could be part of URIFixupInfo.
postData.value = submissionPostDataStream;
} else {
// The submission specifies POST data (i.e. the search
// engine's "method" is POST), but our caller didn't allow
// passing post data back. No point passing back a URL that
// won't load properly.
throw new Components.Exception(
"Didn't request POST data",
Cr.NS_ERROR_NOT_AVAILABLE
);
}
info.postData = submissionPostDataStream;
}
info.keywordProviderName = engine.name;
@ -608,6 +584,13 @@ URIFixupInfo.prototype = {
return this._originalInput || "";
},
set postData(postData) {
this._postData = postData;
},
get postData() {
return this._postData || null;
},
classID: Components.ID("{33d75835-722f-42c0-89cc-44f328e56a86}"),
QueryInterface: ChromeUtils.generateQI(["nsIURIFixupInfo"]),
};
@ -734,17 +717,11 @@ function checkAndFixPublicSuffix(info) {
return { suffix: "", hasUnknownSuffix: true };
}
function tryKeywordFixupForURIInfo(
uriString,
fixupInfo,
isPrivateContext,
postData
) {
function tryKeywordFixupForURIInfo(uriString, fixupInfo, isPrivateContext) {
try {
let keywordInfo = Services.uriFixup.keywordToURI(
uriString,
isPrivateContext,
postData
isPrivateContext
);
fixupInfo.keywordProviderName = keywordInfo.keywordProviderName;
fixupInfo.keywordAsSent = keywordInfo.keywordAsSent;
@ -891,7 +868,7 @@ function fixupURIProtocol(uriString) {
* @param {nsIInputStream} postData optional POST data for the search
* @returns {boolean} Whether the keyword fixup was succesful.
*/
function keywordURIFixup(uriString, fixupInfo, isPrivateContext, postData) {
function keywordURIFixup(uriString, fixupInfo, isPrivateContext) {
// Here is a few examples of strings that should be searched:
// "what is mozilla"
// "what is mozilla?"
@ -913,8 +890,7 @@ function keywordURIFixup(uriString, fixupInfo, isPrivateContext, postData) {
return tryKeywordFixupForURIInfo(
fixupInfo.originalInput,
fixupInfo,
isPrivateContext,
postData
isPrivateContext
);
}
@ -951,8 +927,7 @@ function keywordURIFixup(uriString, fixupInfo, isPrivateContext, postData) {
return tryKeywordFixupForURIInfo(
fixupInfo.originalInput,
fixupInfo,
isPrivateContext,
postData
isPrivateContext
);
}
@ -976,10 +951,10 @@ function extractScheme(uriString) {
* @param {string} uriString The original string to fixup
* @param {integer} fixupFlags The original fixup flags
* @param {nsIInputStream} postData Optional POST data for the search
* @returns {nsIURI} a fixed URI
* @returns {object} {preferredURI, postData} The fixed URI and relative postData
* @throws if it's not possible to fixup the url
*/
function fixupViewSource(uriString, fixupFlags, postData) {
function fixupViewSource(uriString, fixupFlags) {
// We disable keyword lookup and alternate URIs so that small typos don't
// cause us to look at very different domains.
let newFixupFlags =
@ -998,16 +973,15 @@ function fixupViewSource(uriString, fixupFlags, postData) {
);
}
let info = Services.uriFixup.getFixupURIInfo(
innerURIString,
newFixupFlags,
postData
);
let info = Services.uriFixup.getFixupURIInfo(innerURIString, newFixupFlags);
if (!info.preferredURI) {
throw new Components.Exception(
"Couldn't build a valid uri",
Cr.NS_ERROR_MALFORMED_URI
);
}
return Services.io.newURI("view-source:" + info.preferredURI.spec);
return {
preferredURI: Services.io.newURI("view-source:" + info.preferredURI.spec),
postData: info.postData,
};
}

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

@ -5949,14 +5949,12 @@ nsDocShell::OnContentBlockingEvent(nsIWebProgress* aWebProgress,
}
already_AddRefed<nsIURIFixupInfo> nsDocShell::KeywordToURI(
const nsACString& aKeyword, bool aIsPrivateContext,
nsIInputStream** aPostData) {
const nsACString& aKeyword, bool aIsPrivateContext) {
nsCOMPtr<nsIURIFixupInfo> info;
if (!XRE_IsContentProcess()) {
nsCOMPtr<nsIURIFixup> uriFixup = components::URIFixup::Service();
if (uriFixup) {
uriFixup->KeywordToURI(aKeyword, aIsPrivateContext, aPostData,
getter_AddRefs(info));
uriFixup->KeywordToURI(aKeyword, aIsPrivateContext, getter_AddRefs(info));
}
}
return info.forget();
@ -6166,8 +6164,7 @@ already_AddRefed<nsIURI> nsDocShell::AttemptURIFixup(
nsCOMPtr<nsIURIFixupInfo> info;
// only send non-qualified hosts to the keyword server
if (aOriginalURIString && !aOriginalURIString->IsEmpty()) {
info = KeywordToURI(*aOriginalURIString, aUsePrivateBrowsing,
getter_AddRefs(newPostData));
info = KeywordToURI(*aOriginalURIString, aUsePrivateBrowsing);
} else {
//
// If this string was passed through nsStandardURL by
@ -6185,11 +6182,10 @@ already_AddRefed<nsIURI> nsDocShell::AttemptURIFixup(
do_GetService(NS_IDNSERVICE_CONTRACTID);
if (idnSrv && NS_SUCCEEDED(idnSrv->IsACE(host, &isACE)) && isACE &&
NS_SUCCEEDED(idnSrv->ConvertACEtoUTF8(host, utf8Host))) {
info = KeywordToURI(utf8Host, aUsePrivateBrowsing,
getter_AddRefs(newPostData));
info = KeywordToURI(utf8Host, aUsePrivateBrowsing);
} else {
info = KeywordToURI(host, aUsePrivateBrowsing,
getter_AddRefs(newPostData));
info = KeywordToURI(host, aUsePrivateBrowsing);
}
}
if (info) {
@ -6197,6 +6193,7 @@ already_AddRefed<nsIURI> nsDocShell::AttemptURIFixup(
if (newURI) {
info->GetKeywordAsSent(keywordAsSent);
info->GetKeywordProviderName(keywordProviderName);
info->GetPostData(getter_AddRefs(newPostData));
}
}
}
@ -6244,9 +6241,13 @@ already_AddRefed<nsIURI> nsDocShell::AttemptURIFixup(
keywordAsSent.Truncate();
nsCOMPtr<nsIURIFixup> uriFixup = components::URIFixup::Service();
if (uriFixup) {
uriFixup->CreateFixupURI(
oldSpec, nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
getter_AddRefs(newPostData), getter_AddRefs(newURI));
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
uriFixup->GetFixupURIInfo(oldSpec,
nsIURIFixup::FIXUP_FLAGS_MAKE_ALTERNATE_URI,
getter_AddRefs(fixupInfo));
if (fixupInfo) {
fixupInfo->GetPreferredURI(getter_AddRefs(newURI));
}
}
}
} else if (aStatus == NS_ERROR_CONNECTION_REFUSED &&

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

@ -820,8 +820,7 @@ class nsDocShell final : public nsDocLoader,
nsIWidget* aWidget, uint32_t aLoadType);
static already_AddRefed<nsIURIFixupInfo> KeywordToURI(
const nsACString& aKeyword, bool aIsPrivateContext,
nsIInputStream** aPostData);
const nsACString& aKeyword, bool aIsPrivateContext);
// Sets the current document's current state object to the given SHEntry's
// state object. The current state object is eventually given to the page

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

@ -254,7 +254,6 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
if (!XRE_IsContentProcess()) {
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
sURIFixup->GetFixupURIInfo(uriString, fixupFlags,
getter_AddRefs(fixupStream),
getter_AddRefs(fixupInfo));
if (fixupInfo) {
// We could fix the uri, clear NS_ERROR_MALFORMED_URI.
@ -263,6 +262,7 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
fixupInfo->SetConsumer(aBrowsingContext);
fixupInfo->GetKeywordProviderName(searchProvider);
fixupInfo->GetKeywordAsSent(keyword);
fixupInfo->GetPostData(getter_AddRefs(fixupStream));
didFixup = true;
if (fixupInfo &&

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

@ -65,6 +65,11 @@ interface nsIURIFixupInfo : nsISupports
* The original input
*/
attribute AUTF8String originalInput;
/**
* The POST data to submit with the returned URI (see nsISearchSubmission).
*/
attribute nsIInputStream postData;
};
@ -103,31 +108,18 @@ interface nsIURIFixup : nsISupports
const unsigned long FIXUP_FLAG_FIX_SCHEME_TYPOS = 8;
/**
* Converts the specified string into a URI, first attempting
* to correct any errors in the syntax or other vagaries. Returns
* a wellformed URI or nullptr if it can't.
*
* @param aURIText Candidate URI.
* @param aFixupFlags Flags that govern ways the URI may be fixed up.
* @param aPostData The POST data to submit with the returned
* URI (see nsISearchSubmission).
*/
nsIURI createFixupURI(in AUTF8String aURIText, in unsigned long aFixupFlags,
[optional] out nsIInputStream aPostData);
/**
* Same as createFixupURI, but returns information about what it corrected
* Tries to converts the specified string into a URI, first attempting
* to correct any errors in the syntax or other vagaries.
* It returns information about what it corrected
* (e.g. whether we could rescue the URI or "just" generated a keyword
* search URI instead).
*
* @param aURIText Candidate URI.
* @param aFixupFlags Flags that govern ways the URI may be fixed up.
* @param aPostData The POST data to submit with the returned
* URI (see nsISearchSubmission).
* Defaults to FIXUP_FLAG_NONE.
*/
nsIURIFixupInfo getFixupURIInfo(in AUTF8String aURIText,
in unsigned long aFixupFlags,
[optional] out nsIInputStream aPostData);
[optional] in unsigned long aFixupFlags);
/**
* Convert load flags from nsIWebNavigation to URI fixup flags for use in
@ -147,15 +139,9 @@ interface nsIURIFixup : nsISupports
*
* @param aKeyword The keyword string to convert into a URI
* @param aIsPrivateContext Whether this is invoked from a private context.
* @param aPostData The POST data to submit to the returned URI
* (see nsISearchSubmission).
*
* @throws NS_ERROR_FAILURE if the resulting URI requires submission of POST
* data and aPostData is null.
*/
nsIURIFixupInfo keywordToURI(in AUTF8String aKeyword,
[optional] in boolean aIsPrivateContext,
[optional] out nsIInputStream aPostData);
[optional] in boolean aIsPrivateContext);
/**
* Returns true if the specified domain is known and false otherwise.

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

@ -8,6 +8,7 @@ var { XPCOMUtils } = ChromeUtils.import(
XPCOMUtils.defineLazyModuleGetters(this, {
AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm",
SearchUtils: "resource://gre/modules/SearchUtils.jsm",
SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
@ -21,6 +22,9 @@ const kSearchEngineURL = "https://www.example.org/?search={searchTerms}";
const kPrivateSearchEngineID = "test_urifixup_search_engine_private";
const kPrivateSearchEngineURL =
"https://www.example.org/?private={searchTerms}";
const kPostSearchEngineID = "test_urifixup_search_engine_post";
const kPostSearchEngineURL = "https://www.example.org/";
const kPostSearchEngineData = "q={searchTerms}";
const SEARCH_CONFIG = [
{
@ -64,8 +68,8 @@ async function addTestEngines() {
description: "urifixup search engine",
chrome_settings_overrides: {
search_provider: {
name: "test_urifixup_search_engine",
search_url: "https://www.example.org/?search={searchTerms}",
name: kSearchEngineID,
search_url: kSearchEngineURL,
},
},
});
@ -73,8 +77,18 @@ async function addTestEngines() {
description: "urifixup private search engine",
chrome_settings_overrides: {
search_provider: {
name: "test_urifixup_search_engine_private",
search_url: "https://www.example.org/?private={searchTerms}",
name: kPrivateSearchEngineID,
search_url: kPrivateSearchEngineURL,
},
},
});
await Services.search.addPolicyEngine({
description: "urifixup POST search engine",
chrome_settings_overrides: {
search_provider: {
name: kPostSearchEngineID,
search_url: kPostSearchEngineURL,
search_url_post_params: kPostSearchEngineData,
},
},
});

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

@ -68,11 +68,11 @@ add_task(function test_unset_pref_fixes_typos() {
Services.prefs.clearUserPref(pref);
for (let i = 0; i < len; ++i) {
let item = data[i];
let result = Services.uriFixup.createFixupURI(
let { preferredURI } = Services.uriFixup.getFixupURIInfo(
item.wrong,
Services.uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS
).spec;
Assert.equal(result, item.fixed);
);
Assert.equal(preferredURI.spec, item.fixed);
}
});
@ -82,11 +82,11 @@ add_task(function test_false_pref_keeps_typos() {
Services.prefs.setBoolPref(pref, false);
for (let i = 0; i < len; ++i) {
let item = data[i];
let result = Services.uriFixup.createFixupURI(
let { preferredURI } = Services.uriFixup.getFixupURIInfo(
item.wrong,
Services.uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS
).spec;
Assert.equal(result, item.wrong);
);
Assert.equal(preferredURI.spec, item.wrong);
}
});
@ -96,10 +96,10 @@ add_task(function test_true_pref_fixes_typos() {
Services.prefs.setBoolPref(pref, true);
for (let i = 0; i < len; ++i) {
let item = data[i];
let result = Services.uriFixup.createFixupURI(
let { preferredURI } = Services.uriFixup.getFixupURIInfo(
item.wrong,
Services.uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS
).spec;
Assert.equal(result, item.fixed);
);
Assert.equal(preferredURI.spec, item.fixed);
}
});

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

@ -719,18 +719,31 @@ add_task(async function run_test() {
}
}
Assert.equal(affectedTests.length, 0);
do_single_test_run();
await do_single_test_run();
gSingleWordDNSLookup = true;
do_single_test_run();
await do_single_test_run();
gSingleWordDNSLookup = false;
await Services.search.setDefault(
Services.search.getEngineByName(kPostSearchEngineID)
);
await do_single_test_run();
});
function do_single_test_run() {
async function do_single_test_run() {
Services.prefs.setBoolPref(kForceDNSLookup, gSingleWordDNSLookup);
let relevantTests = gSingleWordDNSLookup
? testcases.filter(t => t.keywordLookup)
: testcases;
let engine = await Services.search.getDefault();
let engineUrl =
engine.name == kPostSearchEngineID
? kPostSearchEngineURL
: kSearchEngineURL;
let privateEngine = await Services.search.getDefaultPrivate();
let privateEngineUrl = kPrivateSearchEngineURL;
for (let {
input: testInput,
fixedURI: expectedFixedURI,
@ -762,34 +775,15 @@ function do_single_test_run() {
);
let URIInfo;
let fixupURIOnly = null;
try {
fixupURIOnly = Services.uriFixup.createFixupURI(testInput, flags);
} catch (ex) {
info("Caught exception: " + ex);
Assert.equal(expectedFixedURI, null);
}
try {
URIInfo = Services.uriFixup.getFixupURIInfo(testInput, flags);
} catch (ex) {
// Both APIs should return an error in the same cases.
info("Caught exception: " + ex);
Assert.equal(expectedFixedURI, null);
Assert.equal(fixupURIOnly, null);
continue;
}
// Both APIs should then also be using the same spec.
Assert.equal(!!fixupURIOnly, !!URIInfo.preferredURI);
if (fixupURIOnly) {
Assert.equal(
fixupURIOnly.spec,
URIInfo.preferredURI.spec,
"Fixed and preferred URI should match"
);
}
// Check the fixedURI:
let makeAlternativeURI =
flags & Services.uriFixup.FIXUP_FLAGS_MAKE_ALTERNATE_URI;
@ -841,18 +835,14 @@ function do_single_test_run() {
}
let isPrivate =
flags & Services.uriFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
let searchEngineUrl = isPrivate
? kPrivateSearchEngineURL
: kSearchEngineURL;
let searchEngineUrl = isPrivate ? privateEngineUrl : engineUrl;
let searchURL = searchEngineUrl.replace(
"{searchTerms}",
urlparamInput
);
let spec = URIInfo.preferredURI.spec.replace(/%27/g, "'");
Assert.equal(spec, searchURL, "should get correct search URI");
let providerName = isPrivate
? kPrivateSearchEngineID
: kSearchEngineID;
let providerName = isPrivate ? privateEngine.name : engine.name;
Assert.equal(
URIInfo.keywordProviderName,
providerName,
@ -864,6 +854,19 @@ function do_single_test_run() {
isPrivate
);
Assert.equal(kwInfo.providerName, URIInfo.providerName);
if (providerName == kPostSearchEngineID) {
Assert.ok(kwInfo.postData);
let submission = engine.getSubmission(urlparamInput);
let enginePostData = NetUtil.readInputStreamToString(
submission.postData,
submission.postData.available()
);
let postData = NetUtil.readInputStreamToString(
kwInfo.postData,
kwInfo.postData.available()
);
Assert.equal(postData, enginePostData);
}
} else {
Assert.equal(
URIInfo.preferredURI,

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

@ -136,7 +136,7 @@ add_task(function test_fix_unknown_schemes() {
if (item.inPrivateBrowsing) {
flags |= Services.uriFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
}
let result = Services.uriFixup.createFixupURI(item.wrong, flags).spec;
Assert.equal(result, item.fixed);
let { preferredURI } = Services.uriFixup.getFixupURIInfo(item.wrong, flags);
Assert.equal(preferredURI.spec, item.fixed);
}
});

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

@ -142,7 +142,9 @@ function getURI() {
// likely that the host will be supplied without a protocol prefix, resulting
// in malformed uri exceptions being thrown.
let locationTextBox = document.getElementById("locationTextBox");
let uri = Services.uriFixup.createFixupURI(locationTextBox.value, 0);
let { preferredURI: uri } = Services.uriFixup.getFixupURIInfo(
locationTextBox.value
);
if (!uri) {
return null;

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

@ -193,10 +193,7 @@ var ReaderMode = {
if (originalUrl) {
let uriObj;
try {
uriObj = Services.uriFixup.createFixupURI(
originalUrl,
Services.uriFixup.FIXUP_FLAG_NONE
);
uriObj = Services.uriFixup.getFixupURIInfo(originalUrl).preferredURI;
} catch (ex) {
return null;
}

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

@ -91,7 +91,8 @@ class RemoteWebNavigation {
if (isBrowserPrivate) {
fixupFlags |= Services.uriFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
}
uri = Services.uriFixup.createFixupURI(aURI, fixupFlags);
uri = Services.uriFixup.getFixupURIInfo(aURI, fixupFlags).preferredURI;
// We know the url is going to be loaded, let's start requesting network
// connection before the content process asks.

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

@ -600,10 +600,7 @@ var BrowserUtils = {
if (delimitedAtStart && delimitedAtEnd) {
try {
url = Services.uriFixup.createFixupURI(
linkText,
Services.uriFixup.FIXUP_FLAG_NONE
);
url = Services.uriFixup.getFixupURIInfo(linkText).preferredURI;
} catch (ex) {}
}
}

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

@ -379,10 +379,7 @@ var E10SUtils = {
let uri;
try {
uri = Services.uriFixup.createFixupURI(
aURL,
Ci.nsIURIFixup.FIXUP_FLAG_NONE
);
uri = Services.uriFixup.getFixupURIInfo(aURL).preferredURI;
} catch (e) {
// If we have an invalid URI, it's still possible that it might get
// fixed-up into a valid URI later on. However, we don't want to return
@ -886,7 +883,9 @@ var E10SUtils = {
if (PrivateBrowsingUtils.isBrowserPrivate(browser)) {
fixupFlags |= Ci.nsIURIFixup.FIXUP_FLAG_PRIVATE_CONTEXT;
}
uriObject = Services.uriFixup.createFixupURI(uri, fixupFlags);
uriObject = Services.uriFixup.getFixupURIInfo(uri, fixupFlags)
.preferredURI;
// Note that I had thought that we could set uri = uriObject.spec here, to
// save on fixup later on, but that changes behavior and breaks tests.
requiredRemoteType = this.getRemoteTypeForURIObject(

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

@ -737,8 +737,11 @@ already_AddRefed<nsIURI> nsAppShell::ResolveURI(const nsCString& aUriStr) {
}
nsCOMPtr<nsIURIFixup> fixup = components::URIFixup::Service();
if (fixup && NS_SUCCEEDED(fixup->CreateFixupURI(aUriStr, 0, nullptr,
getter_AddRefs(uri)))) {
nsCOMPtr<nsIURIFixupInfo> fixupInfo;
if (fixup &&
NS_SUCCEEDED(fixup->GetFixupURIInfo(aUriStr, nsIURIFixup::FIXUP_FLAG_NONE,
getter_AddRefs(fixupInfo))) &&
NS_SUCCEEDED(fixupInfo->GetPreferredURI(getter_AddRefs(uri)))) {
return uri.forget();
}
return nullptr;