diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 9979b9dfbcf1..54c86aaf030e 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -231,8 +231,8 @@ uint32_t nsScriptSecurityManager::SecurityHashURI(nsIURI* aURI) { bool nsScriptSecurityManager::IsHttpOrHttpsAndCrossOrigin(nsIURI* aUriA, nsIURI* aUriB) { - if (!aUriA || (!net::SchemeIsHTTP(aUriA) && !net::SchemeIsHTTPS(aUriA)) || - !aUriB || (!net::SchemeIsHTTP(aUriB) && !net::SchemeIsHTTPS(aUriB))) { + if (!aUriA || !net::SchemeIsHttpOrHttps(aUriA) || !aUriB || + !net::SchemeIsHttpOrHttps(aUriB)) { return false; } if (!SecurityCompareURIs(aUriA, aUriB)) { diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 2b94131e1f2f..b83a470f44ee 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -2040,7 +2040,7 @@ nsresult BrowsingContext::LoadURI(nsDocShellLoadState* aLoadState, const auto& sourceBC = aLoadState->SourceBrowsingContext(); - if (net::SchemeIsJavascript(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("javascript")) { if (!XRE_IsParentProcess()) { // Web content should only be able to load javascript: URIs into documents // whose principals the caller principal subsumes, which by definition @@ -2135,7 +2135,7 @@ nsresult BrowsingContext::InternalLoad(nsDocShellLoadState* aLoadState) { const auto& sourceBC = aLoadState->SourceBrowsingContext(); - if (net::SchemeIsJavascript(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("javascript")) { if (!XRE_IsParentProcess()) { // Web content should only be able to load javascript: URIs into documents // whose principals the caller principal subsumes, which by definition diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index b817dcea0410..eb99262d3e8c 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -2398,18 +2398,18 @@ bool CanonicalBrowsingContext::SupportsLoadingInParent( // DocumentChannel currently only supports connecting channels into the // content process, so we can only support schemes that will always be loaded // there for now. Restrict to just http(s) for simplicity. - if (!net::SchemeIsHTTP(aLoadState->URI()) && - !net::SchemeIsHTTPS(aLoadState->URI())) { + if (!net::SchemeIsHttpOrHttps(aLoadState->URI())) { return false; } if (WindowGlobalParent* global = GetCurrentWindowGlobal()) { nsCOMPtr currentURI = global->GetDocumentURI(); if (currentURI) { + nsCOMPtr uri = aLoadState->URI(); bool newURIHasRef = false; - aLoadState->URI()->GetHasRef(&newURIHasRef); + uri->GetHasRef(&newURIHasRef); bool equalsExceptRef = false; - aLoadState->URI()->EqualsExceptRef(currentURI, &equalsExceptRef); + uri->EqualsExceptRef(currentURI, &equalsExceptRef); if (equalsExceptRef && newURIHasRef) { // This navigation is same-doc WRT the current one, we should pass it @@ -2454,7 +2454,7 @@ bool CanonicalBrowsingContext::LoadInParent(nsDocShellLoadState* aLoadState, return false; } - MOZ_ASSERT(!net::SchemeIsJavascript(aLoadState->URI())); + MOZ_ASSERT(!aLoadState->URI()->SchemeIs("javascript")); MOZ_ALWAYS_SUCCEEDS( SetParentInitiatedNavigationEpoch(++gParentInitiatedNavigationEpoch)); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d6b51882f50b..bdeaa6e86c4f 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -667,7 +667,7 @@ nsDocShell::SetCancelContentJSEpoch(int32_t aEpoch) { nsresult nsDocShell::CheckDisallowedJavascriptLoad( nsDocShellLoadState* aLoadState) { - if (!net::SchemeIsJavascript(aLoadState->URI())) { + if (!aLoadState->URI()->SchemeIs("javascript")) { return NS_OK; } @@ -1616,8 +1616,8 @@ nsDocShell::ForceEncodingDetection() { mForcedAutodetection = true; - nsIURI* url = doc->GetOriginalURI(); - bool isFileURL = url && SchemeIsFile(url); + nsIURI* uri = doc->GetOriginalURI(); + bool isFileURL = uri && uri->SchemeIs("file"); int32_t charsetSource = doc->GetDocumentCharacterSetSource(); auto encoding = doc->GetDocumentCharacterSet(); @@ -3710,7 +3710,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, if (aURI) { // displaying "file://" is aesthetically unpleasing and could even be // confusing to the user - if (SchemeIsFile(aURI)) { + if (aURI->SchemeIs("file")) { aURI->GetPathQueryRef(spec); } else { aURI->GetSpec(spec); @@ -3740,7 +3740,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI, NS_ENSURE_FALSE(messageStr.IsEmpty(), NS_ERROR_FAILURE); if ((NS_ERROR_NET_INTERRUPT == aError || NS_ERROR_NET_RESET == aError) && - SchemeIsHTTPS(aURI)) { + aURI->SchemeIs("https")) { // Maybe TLS intolerant. Treat this as an SSL error. error = "nssFailure2"; } @@ -5780,7 +5780,7 @@ already_AddRefed nsDocShell::MaybeFixBadCertDomainErrorURI( } // Return if scheme is not HTTPS. - if (!SchemeIsHTTPS(aUrl)) { + if (!aUrl->SchemeIs("https")) { return nullptr; } @@ -5949,10 +5949,8 @@ already_AddRefed nsDocShell::AttemptURIFixup( // Someone needs to clean up keywords in general so we can // determine on a per url basis if we want keywords // enabled...this is just a bandaid... - nsAutoCString scheme; - Unused << url->GetScheme(scheme); if (Preferences::GetBool("keyword.enabled", false) && - StringBeginsWith(scheme, "http"_ns)) { + net::SchemeIsHttpOrHttps(url)) { bool attemptFixup = false; nsAutoCString host; Unused << url->GetHost(host); @@ -6050,7 +6048,7 @@ already_AddRefed nsDocShell::AttemptURIFixup( } else if (aStatus == NS_ERROR_CONNECTION_REFUSED && Preferences::GetBool("browser.fixup.fallback-to-https", false)) { // Try HTTPS, since http didn't work - if (SchemeIsHTTP(url)) { + if (url->SchemeIs("http")) { int32_t port = 0; url->GetPort(&port); @@ -9309,7 +9307,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, MOZ_DIAGNOSTIC_ASSERT(aLoadState->LoadType() == LOAD_NORMAL); // Disallow external chrome: loads targetted at content windows - if (SchemeIsChrome(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("chrome")) { NS_WARNING("blocked external chrome: url -- use '--chrome' option"); return NS_ERROR_FAILURE; } @@ -9353,7 +9351,7 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, // XXXbz mTiming should know what channel it's for, so we don't // need this hackery. - const bool isJavaScript = SchemeIsJavascript(aLoadState->URI()); + const bool isJavaScript = aLoadState->URI()->SchemeIs("javascript"); const bool isExternalProtocol = nsContentUtils::IsExternalProtocol(aLoadState->URI()); const bool isDownload = !aLoadState->FileName().IsVoid(); @@ -9733,7 +9731,7 @@ nsIPrincipal* nsDocShell::GetInheritedPrincipal( MOZ_ALWAYS_SUCCEEDS(vsc->SetBaseURI(aBaseURI)); } } - } else if (SchemeIsViewSource(aURI)) { + } else if (aURI->SchemeIs("view-source")) { // Instantiate view source handler protocol, if it doesn't exist already. nsCOMPtr io(do_GetIOService()); MOZ_ASSERT(io); @@ -10239,7 +10237,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState, 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. - if (SchemeIsViewSource(tempURI)) { + if (tempURI->SchemeIs("view-source")) { return NS_ERROR_UNKNOWN_PROTOCOL; } nestedURI->GetInnerURI(getter_AddRefs(tempURI)); @@ -10256,20 +10254,21 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState, // configured as unique opaque origin. bool inheritPrincipal = false; + nsCOMPtr uri = aLoadState->URI(); if (aLoadState->PrincipalToInherit()) { bool isSrcdoc = aLoadState->HasInternalLoadFlags(INTERNAL_LOAD_FLAGS_IS_SRCDOC); bool inheritAttrs = nsContentUtils::ChannelShouldInheritPrincipal( - aLoadState->PrincipalToInherit(), aLoadState->URI(), + aLoadState->PrincipalToInherit(), uri, true, // aInheritForAboutBlank isSrcdoc); - inheritPrincipal = inheritAttrs && !SchemeIsData(aLoadState->URI()); + inheritPrincipal = inheritAttrs && !uri->SchemeIs("data"); } // See https://bugzilla.mozilla.org/show_bug.cgi?id=1736570 const bool isAboutBlankLoadOntoInitialAboutBlank = - IsAboutBlankLoadOntoInitialAboutBlank(aLoadState->URI(), inheritPrincipal, + IsAboutBlankLoadOntoInitialAboutBlank(uri, inheritPrincipal, aLoadState->PrincipalToInherit()); // FIXME We still have a ton of codepaths that don't pass through @@ -10282,7 +10281,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState, // Materialize LoadingSessionHistoryInfo here, because DocumentChannel // loads have it, and later history behavior depends on it existing. UniquePtr entry = MakeUnique( - aLoadState->URI(), aLoadState->TriggeringPrincipal(), + uri, aLoadState->TriggeringPrincipal(), aLoadState->PrincipalToInherit(), aLoadState->PartitionedPrincipalToInherit(), aLoadState->Csp(), mContentTypeHint); @@ -10394,8 +10393,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState, aLoadState->GetLoadIdentifier()); RefPtr loadInfo = (contentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) - ? new LoadInfo(loadingWindow, aLoadState->URI(), - aLoadState->TriggeringPrincipal(), + ? new LoadInfo(loadingWindow, uri, aLoadState->TriggeringPrincipal(), topLevelLoadingContext, securityFlags, sandboxFlags) : new LoadInfo(loadingPrincipal, aLoadState->TriggeringPrincipal(), loadingNode, securityFlags, contentPolicyType, @@ -10502,7 +10500,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState, mBrowsingContext, uriModified, Some(isEmbeddingBlockedError)); nsCOMPtr channel; - if (DocumentChannel::CanUseDocumentChannel(aLoadState->URI()) && + if (DocumentChannel::CanUseDocumentChannel(uri) && !isAboutBlankLoadOntoInitialAboutBlank) { channel = DocumentChannel::CreateForDocument( aLoadState, loadInfo, loadFlags, this, cacheKey, uriModified, @@ -12065,7 +12063,7 @@ nsresult nsDocShell::LoadHistoryEntry(nsDocShellLoadState* aLoadState, aLoadState->SetLoadType(aLoadType); nsresult rv; - if (SchemeIsJavascript(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("javascript")) { // We're loading a URL that will execute script from inside asyncOpen. // Replace the current document with about:blank now to prevent // anything from the current document from leaking into any JavaScript @@ -12908,7 +12906,7 @@ nsresult nsDocShell::OnLinkClick( bool nsDocShell::ShouldOpenInBlankTarget(const nsAString& aOriginalTarget, nsIURI* aLinkURI, nsIContent* aContent, bool aIsUserTriggered) { - if (net::SchemeIsJavascript(aLinkURI)) { + if (aLinkURI->SchemeIs("javascript")) { return false; } diff --git a/docshell/base/nsPingListener.cpp b/docshell/base/nsPingListener.cpp index bcf43cfdad14..7355ff83010b 100644 --- a/docshell/base/nsPingListener.cpp +++ b/docshell/base/nsPingListener.cpp @@ -278,7 +278,7 @@ static void ForEachPing(nsIContent* aContent, ForEachPingCallback aCallback, continue; } // Explicitly not allow loading data: URIs - if (!net::SchemeIsData(uri)) { + if (!uri->SchemeIs("data")) { aCallback(aClosure, aContent, uri, ios); } } diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index 71d6ee74f71e..67d2ed8bb216 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -826,7 +826,7 @@ EventSourceImpl::AsyncOnChannelRedirect( rv = NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(newURI)); NS_ENSURE_SUCCESS(rv, rv); - bool isValidScheme = newURI->SchemeIs("http") || newURI->SchemeIs("https"); + bool isValidScheme = net::SchemeIsHttpOrHttps(newURI); rv = mIsMainThread ? GetEventSource()->CheckCurrentGlobalCorrectness() : NS_OK; @@ -988,7 +988,7 @@ nsresult EventSourceImpl::InitChannelAndRequestEventSource( return NS_ERROR_ABORT; } - bool isValidScheme = mSrc->SchemeIs("http") || mSrc->SchemeIs("https"); + bool isValidScheme = net::SchemeIsHttpOrHttps(mSrc); MOZ_ASSERT_IF(mIsMainThread, aEventTargetAccessAllowed); diff --git a/dom/base/Location.cpp b/dom/base/Location.cpp index fbf9b188e4f7..33902b2b23d3 100644 --- a/dom/base/Location.cpp +++ b/dom/base/Location.cpp @@ -456,7 +456,7 @@ void Location::SetProtocol(const nsACString& aProtocol, return; } - if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(uri)) { // No-op, per spec. return; } diff --git a/dom/base/LocationBase.cpp b/dom/base/LocationBase.cpp index 443065dca835..489e368f76af 100644 --- a/dom/base/LocationBase.cpp +++ b/dom/base/LocationBase.cpp @@ -162,7 +162,7 @@ void LocationBase::SetURI(nsIURI* aURI, nsIPrincipal& aSubjectPrincipal, rv = bc->LoadURI(loadState); if (NS_WARN_IF(NS_FAILED(rv))) { if (rv == NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI && - net::SchemeIsJavascript(loadState->URI())) { + loadState->URI()->SchemeIs("javascript")) { // Per spec[1], attempting to load a javascript: URI into a cross-origin // BrowsingContext is a no-op, and should not raise an exception. // Technically, Location setters run with exceptions enabled should only diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 5b0a6e787539..74be83180547 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1236,7 +1236,7 @@ bool Navigator::SendBeaconInternal(const nsAString& aUrl, } // Spec disallows any schemes save for HTTP/HTTPs - if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(uri)) { aRv.ThrowTypeError("Beacon", uri->GetSpecOrDefault()); return false; diff --git a/dom/base/ThirdPartyUtil.cpp b/dom/base/ThirdPartyUtil.cpp index 5b24bda438a1..1a46ad53cb5e 100644 --- a/dom/base/ThirdPartyUtil.cpp +++ b/dom/base/ThirdPartyUtil.cpp @@ -455,7 +455,7 @@ ThirdPartyUtil::GetBaseDomain(nsIURI* aHostURI, nsACString& aBaseDomain) { // The aHostURI can be a view-source URI, in which case we need to get the // base domain from the inner most URI. - if (net::SchemeIsViewSource(aHostURI)) { + if (aHostURI->SchemeIs("view-source")) { rv = NS_GetInnermostURIHost(aHostURI, aBaseDomain); } else { rv = aHostURI->GetAsciiHost(aBaseDomain); diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index e95034d76548..50d18cd5752d 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7113,8 +7113,8 @@ nsresult nsContentUtils::GetWebExposedOriginSerialization(nsIURI* aURI, if ( // Schemes in spec. https://url.spec.whatwg.org/#origin - !uri->SchemeIs("http") && !uri->SchemeIs("https") && - !uri->SchemeIs("file") && !uri->SchemeIs("resource") && + !net::SchemeIsHttpOrHttps(uri) && !uri->SchemeIs("file") && + !uri->SchemeIs("resource") && // Our own schemes. !uri->SchemeIs("moz-extension")) { aOrigin.AssignLiteral("null"); diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 4b7e309de0d3..5b72a13863a5 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -1402,7 +1402,7 @@ nsresult nsObjectLoadingContent::OpenChannel() { true, // aInheritForAboutBlank false); // aForceInherit - bool inheritPrincipal = inheritAttrs && !SchemeIsData(mURI); + bool inheritPrincipal = inheritAttrs && !mURI->SchemeIs("data"); nsSecurityFlags securityFlags = nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL; diff --git a/dom/events/IMEStateManager.cpp b/dom/events/IMEStateManager.cpp index 86e3725b4cc5..77a6ccb01eca 100644 --- a/dom/events/IMEStateManager.cpp +++ b/dom/events/IMEStateManager.cpp @@ -1962,7 +1962,7 @@ void IMEStateManager::SetIMEState(const IMEState& aState, // other apps like IME know which one is touched by the user because // malicious text services may like files which are explicitly used // by the user better. - if (uri->SchemeIs("http") || uri->SchemeIs("https")) { + if (net::SchemeIsHttpOrHttps(uri)) { // Note that we don't need to expose UserPass, Query and Reference to // IME since they may contain sensitive data, but non-malicious text // services must not require these data. diff --git a/dom/ipc/BrowserChild.cpp b/dom/ipc/BrowserChild.cpp index 93f20a36acef..24b950350a1f 100644 --- a/dom/ipc/BrowserChild.cpp +++ b/dom/ipc/BrowserChild.cpp @@ -3550,8 +3550,7 @@ nsresult BrowserChild::CanCancelContentJS( NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr currentURI = entry->GetURI(); - if (!currentURI->SchemeIs("http") && !currentURI->SchemeIs("https") && - !currentURI->SchemeIs("file")) { + if (!net::SchemeIsHttpOrHttps(currentURI) && !currentURI->SchemeIs("file")) { // Only cancel content JS for http(s) and file URIs. Other URIs are probably // internal and we should just let them run to completion. return NS_OK; diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index 3ebb9f420d0d..25137bea3b6e 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -3746,8 +3746,7 @@ bool BrowserParent::CanCancelContentJS( false); nsCOMPtr currentURI = entry->GetURI(); - if (!currentURI->SchemeIs("http") && !currentURI->SchemeIs("https") && - !currentURI->SchemeIs("file")) { + if (!net::SchemeIsHttpOrHttps(currentURI) && !currentURI->SchemeIs("file")) { // Only cancel content JS for http(s) and file URIs. Other URIs are probably // internal and we should just let them run to completion. return false; diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 9c386c4665d5..63055ad953d2 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -332,7 +332,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvLoadURI( return IPC_OK(); } - if (net::SchemeIsJavascript(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("javascript")) { return IPC_FAIL(this, "Illegal cross-process javascript: load attempt"); } @@ -365,7 +365,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvInternalLoad( return IPC_OK(); } - if (net::SchemeIsJavascript(aLoadState->URI())) { + if (aLoadState->URI()->SchemeIs("javascript")) { return IPC_FAIL(this, "Illegal cross-process javascript: load attempt"); } @@ -1372,23 +1372,23 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvSetDocumentDomain( mozilla::ipc::IPCResult WindowGlobalParent::RecvReloadWithHttpsOnlyException() { nsresult rv; - nsCOMPtr currentUri = BrowsingContext()->Top()->GetCurrentURI(); + nsCOMPtr currentURI = BrowsingContext()->Top()->GetCurrentURI(); - if (!currentUri) { + if (!currentURI) { return IPC_FAIL(this, "HTTPS-only mode: Failed to get current URI"); } - bool isViewSource = currentUri->SchemeIs("view-source"); + bool isViewSource = currentURI->SchemeIs("view-source"); - nsCOMPtr nestedURI = do_QueryInterface(currentUri); + nsCOMPtr nestedURI = do_QueryInterface(currentURI); nsCOMPtr innerURI; if (isViewSource) { nestedURI->GetInnerURI(getter_AddRefs(innerURI)); } else { - innerURI = currentUri; + innerURI = currentURI; } - if (!innerURI->SchemeIs("https") && !innerURI->SchemeIs("http")) { + if (!net::SchemeIsHttpOrHttps(innerURI)) { return IPC_FAIL(this, "HTTPS-only mode: Illegal state"); } @@ -1641,8 +1641,7 @@ void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) { BrowsingContext()->IsTopContent()) { GetContentBlockingLog()->ReportLog(); - if (mDocumentURI && (net::SchemeIsHTTP(mDocumentURI) || - net::SchemeIsHTTPS(mDocumentURI))) { + if (mDocumentURI && net::SchemeIsHttpOrHttps(mDocumentURI)) { GetContentBlockingLog()->ReportCanvasFingerprintingLog( DocumentPrincipal()); GetContentBlockingLog()->ReportFontFingerprintingLog( diff --git a/dom/prototype/PrototypeDocumentContentSink.cpp b/dom/prototype/PrototypeDocumentContentSink.cpp index 6795937eaa2c..690ac03d80de 100644 --- a/dom/prototype/PrototypeDocumentContentSink.cpp +++ b/dom/prototype/PrototypeDocumentContentSink.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/PrototypeDocumentContentSink.h" #include "nsIParser.h" #include "mozilla/dom/Document.h" -#include "mozilla/dom/URL.h" #include "nsIContent.h" #include "nsIURI.h" #include "nsNetUtil.h" @@ -666,7 +665,7 @@ nsresult PrototypeDocumentContentSink::DoneWalking() { StartLayout(); - if (IsChromeURI(mDocumentURI) && + if (mDocumentURI->SchemeIs("chrome") && nsXULPrototypeCache::GetInstance()->IsEnabled()) { bool isCachedOnDisk; nsXULPrototypeCache::GetInstance()->HasPrototype(mDocumentURI, @@ -733,7 +732,7 @@ nsresult PrototypeDocumentContentSink::LoadScript( // Load a transcluded script nsresult rv; - bool isChromeDoc = IsChromeURI(mDocumentURI); + bool isChromeDoc = mDocumentURI->SchemeIs("chrome"); if (isChromeDoc && aScriptProto->HasStencil()) { rv = ExecuteScript(aScriptProto); @@ -938,7 +937,8 @@ PrototypeDocumentContentSink::OnScriptCompileComplete(JS::Stencil* aStencil, // the true crime story.) bool useXULCache = nsXULPrototypeCache::GetInstance()->IsEnabled(); - if (useXULCache && IsChromeURI(mDocumentURI) && scriptProto->HasStencil()) { + if (useXULCache && mDocumentURI->SchemeIs("chrome") && + scriptProto->HasStencil()) { nsXULPrototypeCache::GetInstance()->PutStencil(scriptProto->mSrcURI, scriptProto->GetStencil()); } diff --git a/dom/security/nsCSPContext.cpp b/dom/security/nsCSPContext.cpp index ff5db2020dc7..bf974a1c9369 100644 --- a/dom/security/nsCSPContext.cpp +++ b/dom/security/nsCSPContext.cpp @@ -1005,10 +1005,9 @@ void StripURIForReporting(nsIURI* aSelfURI, nsIURI* aURI, // If the origin of aURI is a globally unique identifier (for example, // aURI has a scheme of data, blob, or filesystem), then // return the ASCII serialization of uri’s scheme. - bool isHttpOrWs = (aURI->SchemeIs("http") || aURI->SchemeIs("https") || - aURI->SchemeIs("ws") || aURI->SchemeIs("wss")); + bool isWsOrWss = aURI->SchemeIs("ws") || aURI->SchemeIs("wss"); - if (!isHttpOrWs) { + if (!net::SchemeIsHttpOrHttps(aURI) && !isWsOrWss) { // not strictly spec compliant, but what we really care about is // http/https. If it's not http/https, then treat aURI // as if it's a globally unique identifier and just return the scheme. @@ -1337,10 +1336,7 @@ nsresult nsCSPContext::SendReportsToURIs( } // log a warning to console if scheme is not http or https - bool isHttpScheme = - reportURI->SchemeIs("http") || reportURI->SchemeIs("https"); - - if (!isHttpScheme) { + if (!net::SchemeIsHttpOrHttps(reportURI)) { AutoTArray params = {reportURIs[r]}; logToConsole("reportURInotHttpsOrHttp2", params, NS_ConvertUTF16toUTF8(aViolationEventInit.mSourceFile), diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index fd84d6508f2b..ba21fe151caa 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -98,8 +98,7 @@ bool nsContentSecurityManager::AllowTopLevelNavigationToDataURI( nsCOMPtr uri; nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, true); - bool isDataURI = uri->SchemeIs("data"); - if (!isDataURI) { + if (!uri->SchemeIs("data")) { return true; } @@ -175,11 +174,7 @@ bool nsContentSecurityManager::AllowInsecureRedirectToDataURI( } nsCOMPtr newURI; nsresult rv = NS_GetFinalChannelURI(aNewChannel, getter_AddRefs(newURI)); - if (NS_FAILED(rv) || !newURI) { - return true; - } - bool isDataURI = newURI->SchemeIs("data"); - if (!isDataURI) { + if (NS_FAILED(rv) || !newURI || !newURI->SchemeIs("data")) { return true; } @@ -1007,15 +1002,15 @@ nsresult nsContentSecurityManager::CheckAllowLoadInSystemPrivilegedContext( if (contentPolicyType == ExtContentPolicy::TYPE_SUBDOCUMENT) { if (StaticPrefs::security_disallow_privileged_https_subdocuments_loads() && - (innerURI->SchemeIs("http") || innerURI->SchemeIs("https"))) { + net::SchemeIsHttpOrHttps(innerURI)) { MOZ_ASSERT( false, "Disallowing SystemPrincipal load of subdocuments on HTTP(S)."); aChannel->Cancel(NS_ERROR_CONTENT_BLOCKED); return NS_ERROR_CONTENT_BLOCKED; } - if ((StaticPrefs::security_disallow_privileged_data_subdocuments_loads()) && - (innerURI->SchemeIs("data"))) { + if (StaticPrefs::security_disallow_privileged_data_subdocuments_loads() && + innerURI->SchemeIs("data")) { MOZ_ASSERT( false, "Disallowing SystemPrincipal load of subdocuments on data URL."); @@ -1024,8 +1019,8 @@ nsresult nsContentSecurityManager::CheckAllowLoadInSystemPrivilegedContext( } } if (contentPolicyType == ExtContentPolicy::TYPE_SCRIPT) { - if ((StaticPrefs::security_disallow_privileged_https_script_loads()) && - (innerURI->SchemeIs("http") || innerURI->SchemeIs("https"))) { + if (StaticPrefs::security_disallow_privileged_https_script_loads() && + net::SchemeIsHttpOrHttps(innerURI)) { MOZ_ASSERT(false, "Disallowing SystemPrincipal load of scripts on HTTP(S)."); aChannel->Cancel(NS_ERROR_CONTENT_BLOCKED); @@ -1034,7 +1029,7 @@ nsresult nsContentSecurityManager::CheckAllowLoadInSystemPrivilegedContext( } if (contentPolicyType == ExtContentPolicy::TYPE_STYLESHEET) { if (StaticPrefs::security_disallow_privileged_https_stylesheet_loads() && - (innerURI->SchemeIs("http") || innerURI->SchemeIs("https"))) { + net::SchemeIsHttpOrHttps(innerURI)) { MOZ_ASSERT(false, "Disallowing SystemPrincipal load of stylesheets on HTTP(S)."); aChannel->Cancel(NS_ERROR_CONTENT_BLOCKED); @@ -1091,8 +1086,7 @@ nsresult nsContentSecurityManager::CheckAllowLoadInPrivilegedAboutContext( &isLocal); // We allow URLs that are URI_IS_LOCAL (but that includes `data` // and `blob` which are also undesirable. - if ((isLocal) && (!innerURI->SchemeIs("data")) && - (!innerURI->SchemeIs("blob"))) { + if (isLocal && !innerURI->SchemeIs("data") && !innerURI->SchemeIs("blob")) { return NS_OK; } MOZ_ASSERT( @@ -1759,10 +1753,8 @@ nsresult nsContentSecurityManager::CheckForIncoherentResultPrincipal( if (nsScriptSecurityManager::IsHttpOrHttpsAndCrossOrigin( resultSiteOriginURI, channelSiteOriginURI) || - (!net::SchemeIsHTTP(resultSiteOriginURI) && - !net::SchemeIsHTTPS(resultSiteOriginURI) && - (net::SchemeIsHTTP(channelSiteOriginURI) || - net::SchemeIsHTTPS(channelSiteOriginURI)))) { + (!net::SchemeIsHttpOrHttps(resultSiteOriginURI) && + net::SchemeIsHttpOrHttps(channelSiteOriginURI))) { return NS_ERROR_CONTENT_BLOCKED; } diff --git a/dom/security/nsHTTPSOnlyUtils.cpp b/dom/security/nsHTTPSOnlyUtils.cpp index c4c9a0b20304..334b28d4ae51 100644 --- a/dom/security/nsHTTPSOnlyUtils.cpp +++ b/dom/security/nsHTTPSOnlyUtils.cpp @@ -927,12 +927,12 @@ bool nsHTTPSOnlyUtils::IsHttpDowngrade(nsIURI* aFromURI, nsIURI* aToURI) { } // 2. If the target URI is not http, then it's not a http downgrade - if (!mozilla::net::SchemeIsHTTP(aToURI)) { + if (!aToURI->SchemeIs("http")) { return false; } // 3. If the origin URI isn't https, then it's not a http downgrade either. - if (!mozilla::net::SchemeIsHTTPS(aFromURI)) { + if (!aFromURI->SchemeIs("https")) { return false; } diff --git a/dom/serviceworkers/ServiceWorkerUtils.cpp b/dom/serviceworkers/ServiceWorkerUtils.cpp index 8fd76dedccaf..3a290eae9eb2 100644 --- a/dom/serviceworkers/ServiceWorkerUtils.cpp +++ b/dom/serviceworkers/ServiceWorkerUtils.cpp @@ -236,7 +236,7 @@ void ServiceWorkerScopeAndScriptAreValid(const ClientInfo& aClientInfo, } auto hasHTTPScheme = [](nsIURI* aURI) -> bool { - return aURI->SchemeIs("http") || aURI->SchemeIs("https"); + return net::SchemeIsHttpOrHttps(aURI); }; auto hasMozExtScheme = [](nsIURI* aURI) -> bool { return aURI->SchemeIs("moz-extension"); diff --git a/dom/url/URL.cpp b/dom/url/URL.cpp index eceaf9247258..6538fc62579b 100644 --- a/dom/url/URL.cpp +++ b/dom/url/URL.cpp @@ -153,8 +153,6 @@ URLSearchParams* URL::SearchParams() { return mSearchParams; } -bool IsChromeURI(nsIURI* aURI) { return aURI->SchemeIs("chrome"); } - void URL::CreateSearchParamsIfNeeded() { if (!mSearchParams) { mSearchParams = new URLSearchParams(mParent, this); diff --git a/dom/url/URL.h b/dom/url/URL.h index 7cf0deb23c0e..fb5b6b1366f4 100644 --- a/dom/url/URL.h +++ b/dom/url/URL.h @@ -135,8 +135,6 @@ class URL final : public URLSearchParamsObserver, public nsWrapperCache { nsCOMPtr mURI; }; -bool IsChromeURI(nsIURI* aURI); - } // namespace dom } // namespace mozilla diff --git a/image/ImageBlocker.cpp b/image/ImageBlocker.cpp index c8ff1baaafb0..67735e4cbaf9 100644 --- a/image/ImageBlocker.cpp +++ b/image/ImageBlocker.cpp @@ -58,6 +58,5 @@ bool ImageBlocker::ShouldBlock(nsIURI* aContentLocation) { // we only want to check http, https // for chrome:// and resources and others, no need to check. - return aContentLocation->SchemeIs("http") || - aContentLocation->SchemeIs("https"); + return net::SchemeIsHttpOrHttps(aContentLocation); } diff --git a/intl/hyphenation/glue/nsHyphenator.cpp b/intl/hyphenation/glue/nsHyphenator.cpp index 96faea1a816e..8a4c0b28e5c4 100644 --- a/intl/hyphenation/glue/nsHyphenator.cpp +++ b/intl/hyphenation/glue/nsHyphenator.cpp @@ -260,7 +260,7 @@ nsHyphenator::nsHyphenator(nsIURI* aURI, bool aHyphenateCapitalized) // We get file:// URIs when running an unpackaged build; they could also // occur if we support adding hyphenation dictionaries by putting files in // a directory of the profile, for example. - if (net::SchemeIsFile(aURI)) { + if (aURI->SchemeIs("file")) { // Ask the Rust lib to mmap the file. In this case our mDictSize field // remains zero; mDict is not a pointer to the raw data but an opaque // reference to a Rust object, and can only be freed by passing it to diff --git a/netwerk/base/Predictor.cpp b/netwerk/base/Predictor.cpp index 9752efe9201f..3ee7cc5ffc29 100644 --- a/netwerk/base/Predictor.cpp +++ b/netwerk/base/Predictor.cpp @@ -109,7 +109,7 @@ static bool IsNullOrHttp(nsIURI* uri) { return true; } - return uri->SchemeIs("http") || uri->SchemeIs("https"); + return SchemeIsHttpOrHttps(uri); } // Listener for the speculative DNS requests we'll fire off, which just ignores diff --git a/netwerk/base/nsIOService.cpp b/netwerk/base/nsIOService.cpp index 4adc5f388879..e957628acc2f 100644 --- a/netwerk/base/nsIOService.cpp +++ b/netwerk/base/nsIOService.cpp @@ -2114,7 +2114,7 @@ nsresult nsIOService::SpeculativeConnectInternal( nsIInterfaceRequestor* aCallbacks, bool aAnonymous) { NS_ENSURE_ARG(aURI); - if (!aURI->SchemeIs("http") && !aURI->SchemeIs("https")) { + if (!SchemeIsHttpOrHttps(aURI)) { // We don't speculatively connect to non-HTTP[S] URIs. return NS_OK; } diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 4d0767a8eab0..5ce40403fd0e 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -3366,59 +3366,9 @@ bool ChannelIsPost(nsIChannel* aChannel) { return false; } -bool SchemeIsHTTP(nsIURI* aURI) { +bool SchemeIsHttpOrHttps(nsIURI* aURI) { MOZ_ASSERT(aURI); - return aURI->SchemeIs("http"); -} - -bool SchemeIsHTTPS(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("https"); -} - -bool SchemeIsJavascript(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("javascript"); -} - -bool SchemeIsChrome(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("chrome"); -} - -bool SchemeIsAbout(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("about"); -} - -bool SchemeIsBlob(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("blob"); -} - -bool SchemeIsFile(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("file"); -} - -bool SchemeIsData(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("data"); -} - -bool SchemeIsViewSource(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("view-source"); -} - -bool SchemeIsResource(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("resource"); -} - -bool SchemeIsFTP(nsIURI* aURI) { - MOZ_ASSERT(aURI); - return aURI->SchemeIs("ftp"); + return aURI->SchemeIs("http") || aURI->SchemeIs("https"); } bool SchemeIsSpecial(const nsACString& aScheme) { diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h index b62fe5ea8f7a..6fbd162f2d0b 100644 --- a/netwerk/base/nsNetUtil.h +++ b/netwerk/base/nsNetUtil.h @@ -1091,21 +1091,9 @@ nsresult GetParameterHTTP(const nsACString& aHeaderVal, const char* aParamName, bool ChannelIsPost(nsIChannel* aChannel); /** - * Convenience functions for verifying nsIURI schemes. These functions simply - * wrap aURI->SchemeIs(), but specify the protocol as part of the function name. + * Convenience function for verifying nsIURI scheme is either HTTP or HTTPS. */ - -bool SchemeIsHTTP(nsIURI* aURI); -bool SchemeIsHTTPS(nsIURI* aURI); -bool SchemeIsJavascript(nsIURI* aURI); -bool SchemeIsChrome(nsIURI* aURI); -bool SchemeIsAbout(nsIURI* aURI); -bool SchemeIsBlob(nsIURI* aURI); -bool SchemeIsFile(nsIURI* aURI); -bool SchemeIsData(nsIURI* aURI); -bool SchemeIsViewSource(nsIURI* aURI); -bool SchemeIsResource(nsIURI* aURI); -bool SchemeIsFTP(nsIURI* aURI); +bool SchemeIsHttpOrHttps(nsIURI* aURI); // Helper functions for SetProtocol methods to follow // step 2.1 in https://url.spec.whatwg.org/#scheme-state diff --git a/netwerk/ipc/DocumentChannel.cpp b/netwerk/ipc/DocumentChannel.cpp index 0e8a9e02da88..9e33ce45cb11 100644 --- a/netwerk/ipc/DocumentChannel.cpp +++ b/netwerk/ipc/DocumentChannel.cpp @@ -156,7 +156,7 @@ nsDocShell* DocumentChannel::GetDocShell() { } static bool URIUsesDocChannel(nsIURI* aURI) { - if (SchemeIsJavascript(aURI)) { + if (aURI->SchemeIs("javascript")) { return false; } diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 828e9c09dfc8..ec94730fe706 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -119,15 +119,15 @@ static auto SecurityFlagsForLoadInfo(nsDocShellLoadState* aLoadState) } if (aLoadState->PrincipalToInherit()) { + nsIURI* uri = aLoadState->URI(); bool isSrcdoc = aLoadState->HasInternalLoadFlags( nsDocShell::INTERNAL_LOAD_FLAGS_IS_SRCDOC); bool inheritAttrs = nsContentUtils::ChannelShouldInheritPrincipal( - aLoadState->PrincipalToInherit(), aLoadState->URI(), + aLoadState->PrincipalToInherit(), uri, true, // aInheritForAboutBlank isSrcdoc); - bool isData = SchemeIsData(aLoadState->URI()); - if (inheritAttrs && !isData) { + if (inheritAttrs && !uri->SchemeIs("data")) { securityFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL; } } @@ -691,7 +691,7 @@ auto DocumentLoadListener::Open(nsDocShellLoadState* aLoadState, mLoadIdentifier = aLoadState->GetLoadIdentifier(); // See description of mFileName in nsDocShellLoadState.h mIsDownload = !aLoadState->FileName().IsVoid(); - mIsLoadingJSURI = net::SchemeIsJavascript(aLoadState->URI()); + mIsLoadingJSURI = aLoadState->URI()->SchemeIs("javascript"); mHTTPSFirstDowngradeData = aLoadState->GetHttpsFirstDowngradeData().forget(); // Check for infinite recursive object or iframe loads diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 0b2ac14fdef3..9b95b14bddeb 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -4473,7 +4473,7 @@ already_AddRefed HttpBaseChannel::CloneLoadInfoForRedirect( // the "external" flag, as loads that now go to other apps should be // allowed to go ahead and not trip infinite-loop protection // (see bug 1717314 for context). - if (!aNewURI->SchemeIs("http") && !aNewURI->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(aNewURI)) { newLoadInfo->SetLoadTriggeredFromExternal(false); } newLoadInfo->ResetSandboxedNullPrincipalID(); diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 9caf71adc11d..7b935b2cc794 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3149,18 +3149,15 @@ void nsHttpChannel::UpdateCacheDisposition(bool aSuccessfulReval, nsresult nsHttpChannel::ContinueProcessResponse4(nsresult rv) { bool doNotRender = DoNotRender3xxBody(rv); - if (rv == NS_ERROR_DOM_BAD_URI && mRedirectURI) { - bool isHTTP = - mRedirectURI->SchemeIs("http") || mRedirectURI->SchemeIs("https"); - if (!isHTTP) { - // This was a blocked attempt to redirect and subvert the system by - // redirecting to another protocol (perhaps javascript:) - // In that case we want to throw an error instead of displaying the - // non-redirected response body. - LOG(("ContinueProcessResponse4 detected rejected Non-HTTP Redirection")); - doNotRender = true; - rv = NS_ERROR_CORRUPTED_CONTENT; - } + if (rv == NS_ERROR_DOM_BAD_URI && mRedirectURI && + !net::SchemeIsHttpOrHttps(mRedirectURI)) { + // This was a blocked attempt to redirect and subvert the system by + // redirecting to another protocol (perhaps javascript:) + // In that case we want to throw an error instead of displaying the + // non-redirected response body. + LOG(("ContinueProcessResponse4 detected rejected Non-HTTP Redirection")); + doNotRender = true; + rv = NS_ERROR_CORRUPTED_CONTENT; } if (doNotRender) { diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 043496f7b415..ac6446efeb6c 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -2042,7 +2042,7 @@ nsHttpHandler::NewChannel(nsIURI* uri, nsILoadInfo* aLoadInfo, NS_ENSURE_ARG_POINTER(result); // Verify that we have been given a valid scheme - if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(uri)) { NS_WARNING("Invalid URI scheme"); return NS_ERROR_UNEXPECTED; } @@ -2866,8 +2866,7 @@ void nsHttpHandler::MaybeAddAltSvcForTesting( return; } - bool isHttps = false; - if (NS_FAILED(aUri->SchemeIs("https", &isHttps)) || !isHttps) { + if (!aUri->SchemeIs("https")) { // Only set for HTTPS. return; } diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp index d38cc4358636..4a825ead1943 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp @@ -175,10 +175,8 @@ nsresult nsViewSourceChannel::UpdateLoadInfoResultPrincipalURI() { return NS_ERROR_UNEXPECTED; } - bool alreadyViewSource; - if (NS_SUCCEEDED(channelResultPrincipalURI->SchemeIs("view-source", - &alreadyViewSource)) && - alreadyViewSource) { + if (channelResultPrincipalURI->SchemeIs("view-source")) { + // already view-source return NS_OK; } diff --git a/parser/html/nsHtml5DocumentBuilder.cpp b/parser/html/nsHtml5DocumentBuilder.cpp index b2220253dc41..c6a83d302af5 100644 --- a/parser/html/nsHtml5DocumentBuilder.cpp +++ b/parser/html/nsHtml5DocumentBuilder.cpp @@ -78,15 +78,9 @@ void nsHtml5DocumentBuilder::SetDocumentMode(nsHtml5DocumentMode m) { if (errMsgId && !mDocument->IsLoadedAsData()) { nsCOMPtr docURI = mDocument->GetDocumentURI(); - bool isData = false; - docURI->SchemeIs("data", &isData); - bool isHttp = false; - docURI->SchemeIs("http", &isHttp); - bool isHttps = false; - docURI->SchemeIs("https", &isHttps); - nsCOMPtr principal = mDocument->GetPrincipal(); - if (principal->GetIsNullPrincipal() && !isData && !isHttp && !isHttps) { + if (principal->GetIsNullPrincipal() && !docURI->SchemeIs("data") && + !mozilla::net::SchemeIsHttpOrHttps(docURI)) { // Don't normally warn for null principals. It may well be internal // documents for which the warning is not applicable. return; diff --git a/parser/prototype/PrototypeDocumentParser.cpp b/parser/prototype/PrototypeDocumentParser.cpp index c07a35b892d0..7b84d42647a6 100644 --- a/parser/prototype/PrototypeDocumentParser.cpp +++ b/parser/prototype/PrototypeDocumentParser.cpp @@ -13,7 +13,6 @@ #include "nsCharsetSource.h" #include "nsParser.h" #include "mozilla/dom/Document.h" -#include "mozilla/dom/URL.h" #include "mozilla/dom/PrototypeDocumentContentSink.h" using namespace mozilla::dom; @@ -64,7 +63,7 @@ PrototypeDocumentParser::Parse(nsIURI* aURL) { // Look in the chrome cache: we've got this puppy loaded // already. nsXULPrototypeDocument* proto = - IsChromeURI(mDocumentURI) + mDocumentURI->SchemeIs("chrome") ? nsXULPrototypeCache::GetInstance()->GetPrototype(mDocumentURI) : nullptr; @@ -183,7 +182,7 @@ nsresult PrototypeDocumentParser::PrepareToLoadPrototype( // Store the new prototype right away so if there are multiple requests // for the same document they all get the same prototype. - if (IsChromeURI(mDocumentURI) && + if (mDocumentURI->SchemeIs("chrome") && nsXULPrototypeCache::GetInstance()->IsEnabled()) { nsXULPrototypeCache::GetInstance()->PutPrototype(mCurrentPrototype); } diff --git a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp index 58221f4c85bc..e5ccfbf56f79 100644 --- a/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp +++ b/toolkit/components/antitracking/bouncetrackingprotection/BounceTrackingState.cpp @@ -452,7 +452,7 @@ nsresult BounceTrackingState::OnDocumentStartRequest(nsIChannel* aChannel) { rv = aChannel->GetURI(getter_AddRefs(channelURI)); NS_ENSURE_SUCCESS(rv, rv); - if (channelURI->SchemeIs("http") || channelURI->SchemeIs("https")) { + if (mozilla::net::SchemeIsHttpOrHttps(channelURI)) { nsCOMPtr tldService = do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); diff --git a/toolkit/components/sessionstore/SessionStoreUtils.cpp b/toolkit/components/sessionstore/SessionStoreUtils.cpp index 2983be44146f..5a30292b2b02 100644 --- a/toolkit/components/sessionstore/SessionStoreUtils.cpp +++ b/toolkit/components/sessionstore/SessionStoreUtils.cpp @@ -1675,8 +1675,7 @@ void SessionStoreUtils::RestoreDocShellState( if (aDocShell) { nsCOMPtr currentUri; nsDocShell::Cast(aDocShell)->GetCurrentURI(getter_AddRefs(currentUri)); - if (aState.URI() && - (!currentUri || mozilla::net::SchemeIsAbout(currentUri))) { + if (aState.URI() && (!currentUri || currentUri->SchemeIs("about"))) { aDocShell->SetCurrentURIForSessionStore(aState.URI()); } RestoreDocShellCapabilities(aDocShell, aState.docShellCaps()); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 35811056c34e..ead54f67d44b 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -1765,7 +1765,7 @@ nsXULAppInfo::GetServerURL(nsIURL** aServerURL) { NS_IMETHODIMP nsXULAppInfo::SetServerURL(nsIURL* aServerURL) { // Only allow https or http URLs - if (!aServerURL->SchemeIs("http") && !aServerURL->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(aServerURL)) { return NS_ERROR_INVALID_ARG; } diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index e23df8e6f982..c0953c6e8c91 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -3277,7 +3277,7 @@ bool nsExternalHelperAppService::GetFileNameFromChannel(nsIChannel* aChannel, nsAutoCString query; // We only care about the query for HTTP and HTTPS URLs - if (url->SchemeIs("http") || url->SchemeIs("https")) { + if (net::SchemeIsHttpOrHttps(url)) { url->GetQuery(query); } diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index 635e4e34a948..0ebe6c7738e8 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -284,7 +284,7 @@ nsPrefetchNode::AsyncOnChannelRedirect( nsresult rv = aNewChannel->GetURI(getter_AddRefs(newURI)); if (NS_FAILED(rv)) return rv; - if (!newURI->SchemeIs("http") && !newURI->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(newURI)) { LOG(("rejected: URL is not of type http/https\n")); return NS_ERROR_ABORT; } @@ -550,7 +550,7 @@ nsresult nsPrefetchService::CheckURIScheme(nsIURI* aURI, // for now, we'll only prefetch http and https links since we know that's // the most common case. // - if (!aURI->SchemeIs("http") && !aURI->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(aURI)) { LOG(("rejected: URL is not of type http/https\n")); return NS_ERROR_ABORT; } @@ -563,7 +563,7 @@ nsresult nsPrefetchService::CheckURIScheme(nsIURI* aURI, return NS_ERROR_ABORT; } - if (!referrer->SchemeIs("http") && !referrer->SchemeIs("https")) { + if (!net::SchemeIsHttpOrHttps(referrer)) { LOG(("rejected: referrer URL is neither http nor https\n")); return NS_ERROR_ABORT; } diff --git a/widget/android/nsWindow.cpp b/widget/android/nsWindow.cpp index 887fc34b8b24..00f8471b4594 100644 --- a/widget/android/nsWindow.cpp +++ b/widget/android/nsWindow.cpp @@ -2346,7 +2346,7 @@ RefPtr> nsWindow::OnLoadRequest( nsAutoCString spec, triggeringSpec; if (aUri) { aUri->GetDisplaySpec(spec); - if (aIsTopLevel && mozilla::net::SchemeIsData(aUri) && + if (aIsTopLevel && aUri->SchemeIs("data") && spec.Length() > MAX_TOPLEVEL_DATA_URI_LEN) { return MozPromise::CreateAndResolve(false, __func__); }