зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1558915 - Use infallible nsIURI::SchemeIs in dom/base. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D39780 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
af8f619ad2
Коммит
6bfc234bde
|
@ -1391,9 +1391,7 @@ bool Document::CallerIsTrustedAboutCertError(JSContext* aCx,
|
|||
|
||||
// getSpec is an expensive operation, hence we first check the scheme
|
||||
// to see if the caller is actually an about: page.
|
||||
bool isAboutScheme = false;
|
||||
uri->SchemeIs("about", &isAboutScheme);
|
||||
if (!isAboutScheme) {
|
||||
if (!uri->SchemeIs("about")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1658,11 +1656,7 @@ bool Document::IsAboutPage() const {
|
|||
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
principal->GetURI(getter_AddRefs(uri));
|
||||
bool isAboutScheme = true;
|
||||
if (uri) {
|
||||
uri->SchemeIs("about", &isAboutScheme);
|
||||
}
|
||||
return isAboutScheme;
|
||||
return !uri || uri->SchemeIs("about");
|
||||
}
|
||||
|
||||
void Document::ConstructUbiNode(void* storage) {
|
||||
|
@ -3506,8 +3500,7 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
|
|||
if (aNewPrincipal && mAllowDNSPrefetch && sDisablePrefetchHTTPSPref) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
aNewPrincipal->GetURI(getter_AddRefs(uri));
|
||||
bool isHTTPS;
|
||||
if (!uri || NS_FAILED(uri->SchemeIs("https", &isHTTPS)) || isHTTPS) {
|
||||
if (!uri || uri->SchemeIs("https")) {
|
||||
mAllowDNSPrefetch = false;
|
||||
}
|
||||
}
|
||||
|
@ -7165,10 +7158,7 @@ void Document::DispatchContentLoadedEvents() {
|
|||
static void AssertAboutPageHasCSP(Document* aDocument) {
|
||||
// Check if we are loading an about: URI at all
|
||||
nsCOMPtr<nsIURI> documentURI = aDocument->GetDocumentURI();
|
||||
bool isAboutURI =
|
||||
(NS_SUCCEEDED(documentURI->SchemeIs("about", &isAboutURI)) && isAboutURI);
|
||||
|
||||
if (!isAboutURI ||
|
||||
if (!documentURI->SchemeIs("about") ||
|
||||
Preferences::GetBool("csp.skip_about_page_has_csp_assert")) {
|
||||
return;
|
||||
}
|
||||
|
@ -10508,10 +10498,7 @@ bool Document::CanSavePresentation(nsIRequest* aNewRequest,
|
|||
}
|
||||
|
||||
static bool HasHttpScheme(nsIURI* aURI) {
|
||||
bool isHttpish = false;
|
||||
return aURI &&
|
||||
((NS_SUCCEEDED(aURI->SchemeIs("http", &isHttpish)) && isHttpish) ||
|
||||
(NS_SUCCEEDED(aURI->SchemeIs("https", &isHttpish)) && isHttpish));
|
||||
return aURI && (aURI->SchemeIs("http") || aURI->SchemeIs("https"));
|
||||
}
|
||||
|
||||
void Document::Destroy() {
|
||||
|
@ -11569,17 +11556,12 @@ bool Document::IsDocumentRightToLeft() {
|
|||
if (!reg) return false;
|
||||
|
||||
nsAutoCString package;
|
||||
bool isChrome;
|
||||
if (NS_SUCCEEDED(mDocumentURI->SchemeIs("chrome", &isChrome)) && isChrome) {
|
||||
if (mDocumentURI->SchemeIs("chrome")) {
|
||||
mDocumentURI->GetHostPort(package);
|
||||
} else {
|
||||
// use the 'global' package for about and resource uris.
|
||||
// otherwise, just default to left-to-right.
|
||||
bool isAbout, isResource;
|
||||
if (NS_SUCCEEDED(mDocumentURI->SchemeIs("about", &isAbout)) && isAbout) {
|
||||
package.AssignLiteral("global");
|
||||
} else if (NS_SUCCEEDED(mDocumentURI->SchemeIs("resource", &isResource)) &&
|
||||
isResource) {
|
||||
if (mDocumentURI->SchemeIs("about") || mDocumentURI->SchemeIs("resource")) {
|
||||
package.AssignLiteral("global");
|
||||
} else {
|
||||
return false;
|
||||
|
@ -14379,27 +14361,13 @@ const Document* Document::GetTopLevelContentDocument() const {
|
|||
return parent;
|
||||
}
|
||||
|
||||
static bool MightBeChromeScheme(nsIURI* aURI) {
|
||||
MOZ_ASSERT(aURI);
|
||||
bool isChrome = true;
|
||||
aURI->SchemeIs("chrome", &isChrome);
|
||||
return isChrome;
|
||||
}
|
||||
|
||||
static bool MightBeAboutOrChromeScheme(nsIURI* aURI) {
|
||||
MOZ_ASSERT(aURI);
|
||||
bool isAbout = true;
|
||||
aURI->SchemeIs("about", &isAbout);
|
||||
return isAbout || MightBeChromeScheme(aURI);
|
||||
}
|
||||
|
||||
void Document::PropagateUseCounters(Document* aParentDocument) {
|
||||
MOZ_ASSERT(this != aParentDocument);
|
||||
|
||||
// Don't count chrome resources, even in the web content.
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NodePrincipal()->GetURI(getter_AddRefs(uri));
|
||||
if (!uri || MightBeChromeScheme(uri)) {
|
||||
if (!uri || uri->SchemeIs("chrome")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -14507,7 +14475,7 @@ void Document::ReportUseCounters(UseCounterReportKind aKind) {
|
|||
(IsContentDocument() || IsResourceDoc())) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NodePrincipal()->GetURI(getter_AddRefs(uri));
|
||||
if (!uri || MightBeAboutOrChromeScheme(uri)) {
|
||||
if (!uri || uri->SchemeIs("about") || uri->SchemeIs("chrome")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -791,11 +791,7 @@ EventSourceImpl::AsyncOnChannelRedirect(
|
|||
rv = NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(newURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bool isValidScheme =
|
||||
(NS_SUCCEEDED(newURI->SchemeIs("http", &isValidScheme)) &&
|
||||
isValidScheme) ||
|
||||
(NS_SUCCEEDED(newURI->SchemeIs("https", &isValidScheme)) &&
|
||||
isValidScheme);
|
||||
bool isValidScheme = newURI->SchemeIs("http") || newURI->SchemeIs("https");
|
||||
|
||||
rv = mEventSource->CheckCurrentGlobalCorrectness();
|
||||
if (NS_FAILED(rv) || !isValidScheme) {
|
||||
|
@ -949,9 +945,7 @@ nsresult EventSourceImpl::InitChannelAndRequestEventSource() {
|
|||
return NS_ERROR_ABORT;
|
||||
}
|
||||
|
||||
bool isValidScheme =
|
||||
(NS_SUCCEEDED(mSrc->SchemeIs("http", &isValidScheme)) && isValidScheme) ||
|
||||
(NS_SUCCEEDED(mSrc->SchemeIs("https", &isValidScheme)) && isValidScheme);
|
||||
bool isValidScheme = mSrc->SchemeIs("http") || mSrc->SchemeIs("https");
|
||||
|
||||
nsresult rv = mEventSource->CheckCurrentGlobalCorrectness();
|
||||
if (NS_FAILED(rv) || !isValidScheme) {
|
||||
|
|
|
@ -132,13 +132,8 @@ already_AddRefed<nsDocShellLoadState> Location::CheckURL(
|
|||
// cleaner, but given that we need to start using Source Browsing
|
||||
// Context for referrer (see Bug 960639) this may be wasted effort at
|
||||
// this stage.
|
||||
if (principalURI) {
|
||||
bool isNullPrincipalScheme;
|
||||
rv = principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME,
|
||||
&isNullPrincipalScheme);
|
||||
if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) {
|
||||
sourceURI = principalURI;
|
||||
}
|
||||
if (principalURI && !principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME)) {
|
||||
sourceURI = principalURI;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -669,19 +664,7 @@ void Location::SetProtocol(const nsAString& aProtocol,
|
|||
return;
|
||||
}
|
||||
|
||||
bool isHttp;
|
||||
aRv = uri->SchemeIs("http", &isHttp);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isHttps;
|
||||
aRv = uri->SchemeIs("https", &isHttps);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isHttp && !isHttps) {
|
||||
if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) {
|
||||
// No-op, per spec.
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -547,7 +547,7 @@ void Navigator::GetBuildID(nsAString& aBuildID, CallerType aCallerType,
|
|||
if (doc) {
|
||||
nsIURI* uri = doc->GetDocumentURI();
|
||||
if (uri) {
|
||||
MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("https", &isHTTPS));
|
||||
isHTTPS = uri->SchemeIs("https");
|
||||
if (isHTTPS) {
|
||||
MOZ_ALWAYS_SUCCEEDS(uri->GetHost(host));
|
||||
}
|
||||
|
@ -1120,10 +1120,7 @@ bool Navigator::SendBeaconInternal(const nsAString& aUrl,
|
|||
}
|
||||
|
||||
// Spec disallows any schemes save for HTTP/HTTPs
|
||||
bool isValidScheme;
|
||||
if (!(NS_SUCCEEDED(uri->SchemeIs("http", &isValidScheme)) && isValidScheme) &&
|
||||
!(NS_SUCCEEDED(uri->SchemeIs("https", &isValidScheme)) &&
|
||||
isValidScheme)) {
|
||||
if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) {
|
||||
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(NS_LITERAL_STRING("Beacon"),
|
||||
aUrl);
|
||||
return false;
|
||||
|
|
|
@ -381,12 +381,8 @@ ThirdPartyUtil::GetBaseDomain(nsIURI* aHostURI, nsACString& aBaseDomain) {
|
|||
// only way we can get a base domain consisting of the empty string, which
|
||||
// means we can safely perform foreign tests on such URIs where "not foreign"
|
||||
// means "the involved URIs are all file://".
|
||||
if (aBaseDomain.IsEmpty()) {
|
||||
bool isFileURI = false;
|
||||
aHostURI->SchemeIs("file", &isFileURI);
|
||||
if (!isFileURI) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
if (aBaseDomain.IsEmpty() && !aHostURI->SchemeIs("file")) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -902,7 +902,7 @@ void nsContentSink::PrefetchDNS(const nsAString& aHref) {
|
|||
uri->GetHost(host);
|
||||
CopyUTF8toUTF16(host, hostname);
|
||||
}
|
||||
uri->SchemeIs("https", &isHttps);
|
||||
isHttps = uri->SchemeIs("https");
|
||||
}
|
||||
|
||||
if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
|
||||
|
|
|
@ -5020,9 +5020,7 @@ void nsContentUtils::NotifyInstalledMenuKeyboardListener(bool aInstalling) {
|
|||
bool nsContentUtils::SchemeIs(nsIURI* aURI, const char* aScheme) {
|
||||
nsCOMPtr<nsIURI> baseURI = NS_GetInnermostURI(aURI);
|
||||
NS_ENSURE_TRUE(baseURI, false);
|
||||
|
||||
bool isScheme = false;
|
||||
return NS_SUCCEEDED(baseURI->SchemeIs(aScheme, &isScheme)) && isScheme;
|
||||
return baseURI->SchemeIs(aScheme);
|
||||
}
|
||||
|
||||
bool nsContentUtils::IsSystemPrincipal(nsIPrincipal* aPrincipal) {
|
||||
|
@ -5713,18 +5711,14 @@ nsresult nsContentUtils::GetASCIIOrigin(nsIPrincipal* aPrincipal,
|
|||
nsresult nsContentUtils::GetASCIIOrigin(nsIURI* aURI, nsACString& aOrigin) {
|
||||
MOZ_ASSERT(aURI, "missing uri");
|
||||
|
||||
bool isBlobURL = false;
|
||||
nsresult rv = aURI->SchemeIs(BLOBURI_SCHEME, &isBlobURL);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// For Blob URI, the path is the URL of the owning page.
|
||||
if (isBlobURL) {
|
||||
if (aURI->SchemeIs(BLOBURI_SCHEME)) {
|
||||
nsAutoCString path;
|
||||
rv = aURI->GetPathQueryRef(path);
|
||||
nsresult rv = aURI->GetPathQueryRef(path);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), path);
|
||||
rv = NS_NewURI(getter_AddRefs(uri), path);
|
||||
if (NS_FAILED(rv)) {
|
||||
aOrigin.AssignLiteral("null");
|
||||
return NS_OK;
|
||||
|
@ -5739,7 +5733,7 @@ nsresult nsContentUtils::GetASCIIOrigin(nsIURI* aURI, nsACString& aOrigin) {
|
|||
NS_ENSURE_TRUE(uri, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsAutoCString host;
|
||||
rv = uri->GetAsciiHost(host);
|
||||
nsresult rv = uri->GetAsciiHost(host);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !host.IsEmpty()) {
|
||||
nsAutoCString userPass;
|
||||
|
@ -8711,9 +8705,7 @@ bool nsContentUtils::IsSpecificAboutPage(JSObject* aGlobal, const char* aUri) {
|
|||
}
|
||||
|
||||
// First check the scheme to avoid getting long specs in the common case.
|
||||
bool isAbout = false;
|
||||
uri->SchemeIs("about", &isAbout);
|
||||
if (!isAbout) {
|
||||
if (!uri->SchemeIs("about")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1653,18 +1653,13 @@ nsresult nsGlobalWindowInner::EnsureClientSource() {
|
|||
|
||||
// Note, this is mostly copied from NS_IsAboutBlank(). Its duplicated
|
||||
// here so we can efficiently check about:srcdoc as well.
|
||||
bool isAbout = false;
|
||||
if (NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) {
|
||||
if (uri->SchemeIs("about")) {
|
||||
nsCString spec = uri->GetSpecOrDefault();
|
||||
ignoreLoadInfo = spec.EqualsLiteral("about:blank") ||
|
||||
spec.EqualsLiteral("about:srcdoc");
|
||||
} else {
|
||||
// Its not an about: URL, so now check for our other URL types.
|
||||
bool isData = false;
|
||||
bool isBlob = false;
|
||||
ignoreLoadInfo =
|
||||
(NS_SUCCEEDED(uri->SchemeIs("data", &isData)) && isData) ||
|
||||
(NS_SUCCEEDED(uri->SchemeIs("blob", &isBlob)) && isBlob);
|
||||
ignoreLoadInfo = uri->SchemeIs("data") || uri->SchemeIs("blob");
|
||||
}
|
||||
|
||||
if (!ignoreLoadInfo) {
|
||||
|
|
|
@ -1996,9 +1996,7 @@ nsresult nsObjectLoadingContent::LoadObject(bool aNotify, bool aForceLoad,
|
|||
while (nestedURI) {
|
||||
// view-source should always be an nsINestedURI, loop and check the
|
||||
// scheme on this and all inner URIs that are also nested URIs.
|
||||
bool isViewSource = false;
|
||||
rv = tempURI->SchemeIs("view-source", &isViewSource);
|
||||
if (NS_FAILED(rv) || isViewSource) {
|
||||
if (tempURI->SchemeIs("view-source")) {
|
||||
LOG(("OBJLC [%p]: Blocking as effective URI has view-source scheme",
|
||||
this));
|
||||
mType = eType_Null;
|
||||
|
@ -2290,10 +2288,8 @@ nsresult nsObjectLoadingContent::OpenChannel() {
|
|||
nsSecurityFlags securityFlags =
|
||||
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
|
||||
|
||||
bool isData;
|
||||
bool isURIUniqueOrigin = nsIOService::IsDataURIUniqueOpaqueOrigin() &&
|
||||
NS_SUCCEEDED(mURI->SchemeIs("data", &isData)) &&
|
||||
isData;
|
||||
bool isURIUniqueOrigin =
|
||||
nsIOService::IsDataURIUniqueOpaqueOrigin() && mURI->SchemeIs("data");
|
||||
|
||||
if (inherit && !isURIUniqueOrigin) {
|
||||
securityFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
|
||||
|
|
|
@ -295,12 +295,10 @@ nsresult nsSyncLoadService::LoadDocument(
|
|||
channel->SetContentType(NS_LITERAL_CSTRING("text/xml"));
|
||||
}
|
||||
|
||||
bool isChrome = false, isResource = false;
|
||||
// if the load needs to enforce CORS, then force the load to be async
|
||||
bool isSync =
|
||||
!(aSecurityFlags & nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS) &&
|
||||
((NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome) ||
|
||||
(NS_SUCCEEDED(aURI->SchemeIs("resource", &isResource)) && isResource));
|
||||
(aURI->SchemeIs("chrome") || aURI->SchemeIs("resource"));
|
||||
RefPtr<nsSyncLoader> loader = new nsSyncLoader();
|
||||
return loader->LoadDocument(channel, isSync, aForceToXML, aReferrerPolicy,
|
||||
aResult);
|
||||
|
|
Загрузка…
Ссылка в новой задаче