Backed out changeset b197ca57677a (bug 1558915) for build bustages. CLOSED TREE

This commit is contained in:
Razvan Maries 2019-08-07 01:04:43 +03:00
Родитель 14e46e06a2
Коммит eedbf1137f
20 изменённых файлов: 133 добавлений и 56 удалений

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

@ -372,9 +372,9 @@ bool nsCoreUtils::IsTabDocument(Document* aDocumentNode) {
bool nsCoreUtils::IsErrorPage(Document* aDocument) {
nsIURI* uri = aDocument->GetDocumentURI();
if (!uri->SchemeIs("about")) {
return false;
}
bool isAboutScheme = false;
uri->SchemeIs("about", &isAboutScheme);
if (!isAboutScheme) return false;
nsAutoCString path;
uri->GetPathQueryRef(path);

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

@ -143,8 +143,10 @@ nsresult ContentPrincipal::GenerateOriginNoSuffixFromURI(
// These constraints can generally be achieved by restricting .origin to
// nsIStandardURL-based URIs, but there are a few other URI schemes that we
// need to handle.
if (origin->SchemeIs("about") ||
(origin->SchemeIs("moz-safe-about") &&
bool isBehaved;
if ((NS_SUCCEEDED(origin->SchemeIs("about", &isBehaved)) && isBehaved) ||
(NS_SUCCEEDED(origin->SchemeIs("moz-safe-about", &isBehaved)) &&
isBehaved &&
// We generally consider two about:foo origins to be same-origin, but
// about:blank is special since it can be generated from different
// sources. We check for moz-safe-about:blank since origin is an
@ -196,7 +198,10 @@ nsresult ContentPrincipal::GenerateOriginNoSuffixFromURI(
// See whether we have a useful hostPort. If we do, use that.
nsAutoCString hostPort;
if (!origin->SchemeIs("chrome")) {
bool isChrome = false;
rv = origin->SchemeIs("chrome", &isChrome);
NS_ENSURE_SUCCESS(rv, rv);
if (!isChrome) {
rv = origin->GetAsciiHostPort(hostPort);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -403,7 +408,8 @@ static nsresult GetSpecialBaseDomain(const nsCOMPtr<nsIURI>& aURI,
return aURI->GetSpec(aBaseDomain);
}
if (aURI->SchemeIs("indexeddb")) {
bool isBehaved;
if (NS_SUCCEEDED(aURI->SchemeIs("indexeddb", &isBehaved)) && isBehaved) {
*aHandled = true;
return aURI->GetSpec(aBaseDomain);
}
@ -514,7 +520,8 @@ WebExtensionPolicy* ContentPrincipal::AddonPolicy() {
if (!mAddon.isSome()) {
NS_ENSURE_TRUE(mURI, nullptr);
if (mURI->SchemeIs("moz-extension")) {
bool isMozExt;
if (NS_SUCCEEDED(mURI->SchemeIs("moz-extension", &isMozExt)) && isMozExt) {
mAddon.emplace(EPS().GetByURL(mURI.get()));
} else {
mAddon.emplace(nullptr);
@ -547,7 +554,8 @@ ContentPrincipal::Read(nsIObjectInputStream* aStream) {
principalURI = do_QueryInterface(supports);
// Enforce re-parsing about: URIs so that if they change, we continue to use
// their new principals correctly.
if (principalURI->SchemeIs("about")) {
bool isAbout = false;
if (NS_SUCCEEDED(principalURI->SchemeIs("about", &isAbout)) && isAbout) {
nsAutoCString spec;
principalURI->GetSpec(spec);
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(principalURI), spec),
@ -669,7 +677,10 @@ already_AddRefed<BasePrincipal> ContentPrincipal::FromProperties(
{
// Enforce re-parsing about: URIs so that if they change, we
// continue to use their new principals correctly.
if (principalURI->SchemeIs("about")) {
bool isAbout =
NS_SUCCEEDED(principalURI->SchemeIs("about", &isAbout)) &&
isAbout;
if (isAbout) {
nsAutoCString spec;
principalURI->GetSpec(spec);
if (NS_FAILED(NS_NewURI(getter_AddRefs(principalURI), spec))) {

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

@ -688,6 +688,8 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
"security.view-source.reachable-from-inner-protocol");
}
bool targetIsViewSource = false;
if (sourceScheme.LowerCaseEqualsLiteral(NS_NULLPRINCIPAL_SCHEME)) {
// A null principal can target its own URI.
if (sourceURI == aTargetURI) {
@ -695,7 +697,9 @@ nsScriptSecurityManager::CheckLoadURIWithPrincipal(nsIPrincipal* aPrincipal,
}
} else if (sViewSourceReachableFromInner &&
sourceScheme.EqualsIgnoreCase(targetScheme.get()) &&
aTargetURI->SchemeIs("view-source")) {
NS_SUCCEEDED(
aTargetURI->SchemeIs("view-source", &targetIsViewSource)) &&
targetIsViewSource) {
// exception for foo: linking to view-source:foo for reftests...
return NS_OK;
} else if (sourceScheme.EqualsIgnoreCase("file") &&
@ -944,7 +948,9 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
}
// Allow chrome://
if (aSourceBaseURI->SchemeIs("chrome")) {
bool isChrome = false;
if (NS_SUCCEEDED(aSourceBaseURI->SchemeIs("chrome", &isChrome)) &&
isChrome) {
return NS_OK;
}

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

@ -134,7 +134,11 @@ nsresult nsChromeRegistry::GetProviderAndPath(nsIURI* aChromeURL,
nsACString& aPath) {
nsresult rv;
NS_ASSERTION(aChromeURL->SchemeIs("chrome"), "Non-chrome URI?");
#ifdef DEBUG
bool isChrome;
aChromeURL->SchemeIs("chrome", &isChrome);
NS_ASSERTION(isChrome, "Non-chrome URI?");
#endif
nsAutoCString path;
rv = aChromeURL->GetPathQueryRef(path);
@ -280,8 +284,11 @@ nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool* aResult) {
nsresult rv;
*aResult = false;
NS_ASSERTION(aChromeURI->SchemeIs("chrome"),
"Non-chrome URI passed to AllowScriptsForPackage!");
#ifdef DEBUG
bool isChrome;
aChromeURI->SchemeIs("chrome", &isChrome);
NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowScriptsForPackage!");
#endif
nsCOMPtr<nsIURL> url(do_QueryInterface(aChromeURI));
NS_ENSURE_TRUE(url, NS_NOINTERFACE);
@ -301,8 +308,11 @@ nsChromeRegistry::AllowContentToAccess(nsIURI* aURI, bool* aResult) {
*aResult = false;
NS_ASSERTION(aURI->SchemeIs("chrome"),
"Non-chrome URI passed to AllowContentToAccess!");
#ifdef DEBUG
bool isChrome;
aURI->SchemeIs("chrome", &isChrome);
NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowContentToAccess!");
#endif
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
if (!url) {
@ -329,8 +339,11 @@ nsChromeRegistry::CanLoadURLRemotely(nsIURI* aURI, bool* aResult) {
*aResult = false;
NS_ASSERTION(aURI->SchemeIs("chrome"),
"Non-chrome URI passed to CanLoadURLRemotely!");
#ifdef DEBUG
bool isChrome;
aURI->SchemeIs("chrome", &isChrome);
NS_ASSERTION(isChrome, "Non-chrome URI passed to CanLoadURLRemotely!");
#endif
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
if (!url) {
@ -357,8 +370,11 @@ nsChromeRegistry::MustLoadURLRemotely(nsIURI* aURI, bool* aResult) {
*aResult = false;
NS_ASSERTION(aURI->SchemeIs("chrome"),
"Non-chrome URI passed to MustLoadURLRemotely!");
#ifdef DEBUG
bool isChrome;
aURI->SchemeIs("chrome", &isChrome);
NS_ASSERTION(isChrome, "Non-chrome URI passed to MustLoadURLRemotely!");
#endif
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
if (!url) {

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

@ -594,8 +594,13 @@ void nsChromeRegistryChrome::ManifestOverride(ManifestProcessingContext& cx,
}
if (cx.mType == NS_SKIN_LOCATION) {
bool chromeSkinOnly =
chromeuri->SchemeIs("chrome") && resolveduri->SchemeIs("chrome");
bool chromeSkinOnly = false;
nsresult rv = chromeuri->SchemeIs("chrome", &chromeSkinOnly);
chromeSkinOnly = chromeSkinOnly && NS_SUCCEEDED(rv);
if (chromeSkinOnly) {
rv = resolveduri->SchemeIs("chrome", &chromeSkinOnly);
chromeSkinOnly = chromeSkinOnly && NS_SUCCEEDED(rv);
}
if (chromeSkinOnly) {
nsAutoCString chromePath, resolvedPath;
chromeuri->GetPathQueryRef(chromePath);

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

@ -447,8 +447,12 @@ already_AddRefed<IDBOpenDBRequest> IDBFactory::Open(
if (principal) {
nsCOMPtr<nsIURI> uri;
nsresult rv = principal->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri && uri->SchemeIs("about")) {
ignore = true;
if (NS_SUCCEEDED(rv) && uri) {
bool isAbout;
rv = uri->SchemeIs("about", &isAbout);
if (NS_SUCCEEDED(rv) && isAbout) {
ignore = true;
}
}
}
}

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

@ -319,10 +319,14 @@ nsresult nsContentBlocker::TestPermission(nsIURI* aCurrentURI,
// Need a requesting uri for third party checks to work.
if (!aFirstURI) return NS_OK;
// chrome: and resource: are always trusted.
if (aFirstURI->SchemeIs("chrome") || aFirstURI->SchemeIs("resource")) {
return NS_OK;
bool trustedSource = false;
rv = aFirstURI->SchemeIs("chrome", &trustedSource);
NS_ENSURE_SUCCESS(rv, rv);
if (!trustedSource) {
rv = aFirstURI->SchemeIs("resource", &trustedSource);
NS_ENSURE_SUCCESS(rv, rv);
}
if (trustedSource) return NS_OK;
// compare tails of names checking to see if they have a common domain
// we do this by comparing the tails of both names where each tail

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

@ -478,7 +478,9 @@ nsresult UpgradeHostToOriginAndInsert(
// It was previously possible to insert useless entries to your permissions
// database for URIs which have a null principal. This acts as a cleanup,
// getting rid of these useless database entries
if (uri->SchemeIs("moz-nullprincipal")) {
bool nullpScheme = false;
if (NS_SUCCEEDED(uri->SchemeIs("moz-nullprincipal", &nullpScheme)) &&
nullpScheme) {
NS_WARNING("A moz-nullprincipal: permission is being discarded.");
return NS_OK;
}

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

@ -1349,7 +1349,9 @@ void gfxUserFontSet::UserFontCache::Entry::ReportMemory(
spec.ReplaceChar('/', '\\');
// Some fonts are loaded using horrendously-long data: URIs;
// truncate those before reporting them.
if (mURI->get()->SchemeIs("data") && spec.Length() > 255) {
bool isData;
if (NS_SUCCEEDED(mURI->get()->SchemeIs("data", &isData)) && isData &&
spec.Length() > 255) {
spec.Truncate(252);
spec.AppendLiteral("...");
}

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

@ -322,9 +322,10 @@ nsresult ScriptPreloader::Observe(nsISupports* subject, const char* topic,
if (nsCOMPtr<dom::Document> doc = do_QueryInterface(subject)) {
nsCOMPtr<nsIURI> uri = doc->GetDocumentURI();
bool schemeIs;
if ((NS_IsAboutBlank(uri) &&
doc->GetReadyStateEnum() == doc->READYSTATE_UNINITIALIZED) ||
uri->SchemeIs("chrome")) {
(NS_SUCCEEDED(uri->SchemeIs("chrome", &schemeIs)) && schemeIs)) {
return NS_OK;
}
}

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

@ -401,9 +401,11 @@ static bool PrincipalImmuneToScriptPolicy(nsIPrincipal* aPrincipal) {
aPrincipal->GetURI(getter_AddRefs(principalURI));
MOZ_ASSERT(principalURI);
if (principalURI->SchemeIs("about")) {
bool isAbout;
nsresult rv = principalURI->SchemeIs("about", &isAbout);
if (NS_SUCCEEDED(rv) && isAbout) {
nsCOMPtr<nsIAboutModule> module;
nsresult rv = NS_GetAboutModule(principalURI, getter_AddRefs(module));
rv = NS_GetAboutModule(principalURI, getter_AddRefs(module));
if (NS_SUCCEEDED(rv)) {
uint32_t flags;
rv = module->GetURIFlags(principalURI, &flags);

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

@ -687,7 +687,12 @@ void nsPresContext::AttachPresShell(mozilla::PresShell* aPresShell) {
nsIURI* docURI = doc->GetDocumentURI();
if (IsDynamic() && docURI) {
if (!docURI->SchemeIs("chrome") && !docURI->SchemeIs("resource"))
bool isChrome = false;
bool isRes = false;
docURI->SchemeIs("chrome", &isChrome);
docURI->SchemeIs("resource", &isRes);
if (!isChrome && !isRes)
mImageAnimationMode = mImageAnimationModePref;
else
mImageAnimationMode = imgIContainer::kNormalAnimMode;

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

@ -587,7 +587,9 @@ nsresult FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry,
gfxFontSrcPrincipal* principal = aUserFontEntry->GetPrincipal();
uint32_t securityFlags = 0;
if (aFontFaceSrc->mURI->get()->SchemeIs("file")) {
bool isFile = false;
if (NS_SUCCEEDED(aFontFaceSrc->mURI->get()->SchemeIs("file", &isFile)) &&
isFile) {
securityFlags = nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
} else {
securityFlags = nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;

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

@ -224,11 +224,11 @@ nsresult nsJARChannel::Init(nsIURI* uri) {
// Prevent loading jar:javascript URIs (see bug 290982).
nsCOMPtr<nsIURI> innerURI;
rv = mJarURI->GetJARFile(getter_AddRefs(innerURI));
if (NS_FAILED(rv)) {
return rv;
}
if (innerURI->SchemeIs("javascript")) {
if (NS_FAILED(rv)) return rv;
bool isJS;
rv = innerURI->SchemeIs("javascript", &isJS);
if (NS_FAILED(rv)) return rv;
if (isJS) {
NS_WARNING("blocking jar:javascript:");
return NS_ERROR_INVALID_ARG;
}

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

@ -364,13 +364,17 @@ void nsHtml5StreamParser::SetViewSourceTitle(nsIURI* aURL) {
if (aURL) {
nsCOMPtr<nsIURI> temp;
if (aURL->SchemeIs("view-source")) {
bool isViewSource;
aURL->SchemeIs("view-source", &isViewSource);
if (isViewSource) {
nsCOMPtr<nsINestedURI> nested = do_QueryInterface(aURL);
nested->GetInnerURI(getter_AddRefs(temp));
} else {
temp = aURL;
}
if (temp->SchemeIs("data")) {
bool isData;
temp->SchemeIs("data", &isData);
if (isData) {
// Avoid showing potentially huge data: URLs. The three last bytes are
// UTF-8 for an ellipsis.
mViewSourceTitle.AssignLiteral("data:\xE2\x80\xA6");
@ -1041,7 +1045,9 @@ nsresult nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest) {
nsCOMPtr<nsIURI> originalURI;
rv = channel->GetOriginalURI(getter_AddRefs(originalURI));
if (NS_SUCCEEDED(rv)) {
if (originalURI->SchemeIs("resource")) {
bool originalIsResource;
originalURI->SchemeIs("resource", &originalIsResource);
if (originalIsResource) {
mCharsetSource = kCharsetFromBuiltIn;
mEncoding = UTF_8_ENCODING;
} else {
@ -1049,7 +1055,9 @@ nsresult nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest) {
rv = channel->GetURI(getter_AddRefs(currentURI));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURI> innermost = NS_GetInnermostURI(currentURI);
mDecodingLocalFileAsUTF8 = innermost->SchemeIs("file");
bool innermostIsFile;
innermost->SchemeIs("file", &innermostIsFile);
mDecodingLocalFileAsUTF8 = innermostIsFile;
}
}
}

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

@ -880,7 +880,9 @@ nsIURI* nsHtml5TreeOpExecutor::GetViewSourceBaseURI() {
}
nsCOMPtr<nsIURI> orig = mDocument->GetOriginalURI();
if (orig->SchemeIs("view-source")) {
bool isViewSource;
orig->SchemeIs("view-source", &isViewSource);
if (isViewSource) {
nsCOMPtr<nsINestedURI> nested = do_QueryInterface(orig);
NS_ASSERTION(nested, "URI with scheme view-source didn't QI to nested!");
nested->GetInnerURI(getter_AddRefs(mViewSourceBaseURI));
@ -897,10 +899,11 @@ bool nsHtml5TreeOpExecutor::IsExternalViewSource() {
if (!StaticPrefs::view_source_editor_external()) {
return false;
}
bool isViewSource = false;
if (mDocumentURI) {
return mDocumentURI->SchemeIs("view-source");
mDocumentURI->SchemeIs("view-source", &isViewSource);
}
return false;
return isViewSource;
}
// Speculative loading

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

@ -136,11 +136,12 @@ static inline bool canonicalizeBase(nsAutoCString& spec, nsACString& out) {
* underlying resource, or returns any other URI unchanged.
*/
nsresult ResolveURI(nsIURI* in, nsIURI** out) {
bool equals;
nsresult rv;
// Resolve resource:// URIs. At the end of this if/else block, we
// have both spec and uri variables identifying the same URI.
if (in->SchemeIs("resource")) {
if (NS_SUCCEEDED(in->SchemeIs("resource", &equals)) && equals) {
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -156,7 +157,7 @@ nsresult ResolveURI(nsIURI* in, nsIURI** out) {
NS_ENSURE_SUCCESS(rv, rv);
return ioService->NewURI(spec, nullptr, nullptr, out);
} else if (in->SchemeIs("chrome")) {
} else if (NS_SUCCEEDED(in->SchemeIs("chrome", &equals)) && equals) {
nsCOMPtr<nsIChromeRegistry> chromeReg =
mozilla::services::GetChromeRegistryService();
if (!chromeReg) return NS_ERROR_UNEXPECTED;
@ -206,7 +207,7 @@ nsresult PathifyURI(nsIURI* in, nsACString& out) {
NS_ENSURE_SUCCESS(rv, rv);
if (!canonicalizeBase(spec, out)) {
if (uri->SchemeIs("file")) {
if (NS_SUCCEEDED(uri->SchemeIs("file", &equals)) && equals) {
nsCOMPtr<nsIFileURL> baseFileURL;
baseFileURL = do_QueryInterface(uri, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -216,7 +217,7 @@ nsresult PathifyURI(nsIURI* in, nsACString& out) {
NS_ENSURE_SUCCESS(rv, rv);
out.Append(path);
} else if (uri->SchemeIs("jar")) {
} else if (NS_SUCCEEDED(uri->SchemeIs("jar", &equals)) && equals) {
nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -85,11 +85,14 @@ class ThumbnailHelper final
// Deny storage if we're viewing a HTTPS page with a 'Cache-Control'
// header having a value that is not 'public', unless enabled by user.
nsCOMPtr<nsIURI> uri;
if (NS_FAILED(channel->GetURI(getter_AddRefs(uri))) || !uri) {
bool isHttps = false;
if (NS_FAILED(channel->GetURI(getter_AddRefs(uri))) || !uri ||
NS_FAILED(uri->SchemeIs("https", &isHttps))) {
return false;
}
if (!uri->SchemeIs("https") ||
if (!isHttps ||
Preferences::GetBool("browser.cache.disk_cache_ssl", false)) {
// Allow storing non-HTTPS thumbnails, and HTTPS ones if enabled by
// user.

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

@ -313,8 +313,9 @@ NS_IMETHODIMP nsSound::Play(nsIURL* aURL) {
if (!libcanberra) return NS_ERROR_NOT_AVAILABLE;
nsresult rv;
if (aURL->SchemeIs("file")) {
bool isFile;
nsresult rv = aURL->SchemeIs("file", &isFile);
if (NS_SUCCEEDED(rv) && isFile) {
ca_context* ctx = ca_context_get_default();
if (!ctx) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -20,7 +20,8 @@ nsSoundProxy::Play(nsIURL* aURL) {
nsCOMPtr<nsIURI> soundURI(aURL);
bool isChrome = false;
// Only allow playing a chrome:// URL from the content process.
if (!soundURI || !soundURI->SchemeIs("chrome")) {
if (!soundURI || NS_FAILED(soundURI->SchemeIs("chrome", &isChrome)) ||
!isChrome) {
return NS_ERROR_FAILURE;
}