Bug 1695404 - follow-up: Avoid redundant string copy in Gecko_IsSupportedImageMimeType. r=tnikkel
There's no reason to require a null-terminated string in imgLoader. Differential Revision: https://phabricator.services.mozilla.com/D112478
This commit is contained in:
@@ -74,11 +74,10 @@ uint32_t nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType) {
|
||||
// XXXbz we only need this because images register for the same
|
||||
// contractid as documents, so we can't tell them apart based on
|
||||
// contractid.
|
||||
if (imgLoader::SupportImageWithMimeType(aType.get())) {
|
||||
if (imgLoader::SupportImageWithMimeType(aType)) {
|
||||
return nsIWebNavigationInfo::IMAGE;
|
||||
} else {
|
||||
return nsIWebNavigationInfo::OTHER;
|
||||
}
|
||||
return nsIWebNavigationInfo::OTHER;
|
||||
}
|
||||
|
||||
return nsIWebNavigationInfo::UNSUPPORTED;
|
||||
|
||||
@@ -9806,7 +9806,7 @@ uint32_t nsContentUtils::HtmlObjectContentTypeForMIMEType(
|
||||
return nsIObjectLoadingContent::TYPE_NULL;
|
||||
}
|
||||
|
||||
if (imgLoader::SupportImageWithMimeType(aMIMEType.get())) {
|
||||
if (imgLoader::SupportImageWithMimeType(aMIMEType)) {
|
||||
return nsIObjectLoadingContent::TYPE_IMAGE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1098,8 +1098,7 @@ bool HTMLImageElement::SupportedPictureSourceType(const nsAString& aType) {
|
||||
}
|
||||
|
||||
return imgLoader::SupportImageWithMimeType(
|
||||
NS_ConvertUTF16toUTF8(type).get(),
|
||||
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
NS_ConvertUTF16toUTF8(type), AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
}
|
||||
|
||||
bool HTMLImageElement::SourceElementMatches(Element* aSourceElement) {
|
||||
|
||||
@@ -762,8 +762,7 @@ bool HTMLLinkElement::CheckPreloadAttrs(const nsAttrValue& aAs,
|
||||
}
|
||||
if (policyType == nsIContentPolicy::TYPE_IMAGE) {
|
||||
return imgLoader::SupportImageWithMimeType(
|
||||
NS_ConvertUTF16toUTF8(type).get(),
|
||||
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
NS_ConvertUTF16toUTF8(type), AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
}
|
||||
if (policyType == nsIContentPolicy::TYPE_SCRIPT) {
|
||||
return nsContentUtils::IsJavascriptMIMEType(type);
|
||||
|
||||
@@ -2684,7 +2684,7 @@ nsresult imgLoader::LoadImageWithChannel(nsIChannel* channel,
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool imgLoader::SupportImageWithMimeType(const char* aMimeType,
|
||||
bool imgLoader::SupportImageWithMimeType(const nsACString& aMimeType,
|
||||
AcceptedMimeTypes aAccept
|
||||
/* = AcceptedMimeTypes::IMAGES */) {
|
||||
nsAutoCString mimeType(aMimeType);
|
||||
|
||||
@@ -273,8 +273,7 @@ class imgLoader final : public imgILoader,
|
||||
* @param aAcceptedMimeTypes Which kinds of MIME types to treat as images.
|
||||
*/
|
||||
static bool SupportImageWithMimeType(
|
||||
const char* aMimeType,
|
||||
AcceptedMimeTypes aAccept = AcceptedMimeTypes::IMAGES);
|
||||
const nsACString&, AcceptedMimeTypes aAccept = AcceptedMimeTypes::IMAGES);
|
||||
|
||||
static void GlobalInit(); // for use by the factory
|
||||
static void Shutdown(); // for use by the factory
|
||||
|
||||
@@ -106,7 +106,7 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
|
||||
|
||||
if (knownType) {
|
||||
viewSourceChannel->SetContentType(type);
|
||||
} else if (IsImageContentType(type.get())) {
|
||||
} else if (IsImageContentType(type)) {
|
||||
// If it's an image, we want to display it the same way we normally would.
|
||||
// Also note the lifetime of "type" allows us to safely use "get()" here.
|
||||
contentType = type;
|
||||
@@ -173,7 +173,7 @@ nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel,
|
||||
}
|
||||
|
||||
// Try image types
|
||||
if (IsImageContentType(contentType.get())) {
|
||||
if (IsImageContentType(contentType)) {
|
||||
return CreateDocument(
|
||||
aCommand, aChannel, aLoadGroup, aContainer,
|
||||
[]() -> already_AddRefed<Document> {
|
||||
@@ -307,6 +307,6 @@ nsresult nsContentDLF::CreateDocument(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool nsContentDLF::IsImageContentType(const char* aContentType) {
|
||||
bool nsContentDLF::IsImageContentType(const nsACString& aContentType) {
|
||||
return imgLoader::SupportImageWithMimeType(aContentType);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class nsContentDLF final : public nsIDocumentLoaderFactory {
|
||||
|
||||
private:
|
||||
static nsresult EnsureUAStyleSheet();
|
||||
static bool IsImageContentType(const char* aContentType);
|
||||
static bool IsImageContentType(const nsACString&);
|
||||
};
|
||||
|
||||
nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
|
||||
|
||||
@@ -1272,11 +1272,11 @@ void Gecko_GetComputedImageURLSpec(const StyleComputedUrl* aURL,
|
||||
aOut->AssignLiteral("about:invalid");
|
||||
}
|
||||
|
||||
bool Gecko_IsSupportedImageMimeType(const uint8_t* mime_type,
|
||||
const uint32_t len) {
|
||||
std::string aMimeType(reinterpret_cast<const char*>(mime_type), len);
|
||||
bool Gecko_IsSupportedImageMimeType(const uint8_t* aMimeType,
|
||||
const uint32_t aLen) {
|
||||
nsDependentCSubstring mime(reinterpret_cast<const char*>(aMimeType), aLen);
|
||||
return imgLoader::SupportImageWithMimeType(
|
||||
aMimeType.c_str(), AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
mime, AcceptedMimeTypes::IMAGES_AND_DOCUMENTS);
|
||||
}
|
||||
|
||||
void Gecko_nsIURI_Debug(nsIURI* aURI, nsCString* aOut) {
|
||||
|
||||
@@ -366,8 +366,7 @@ nsFaviconService::ReplaceFaviconData(nsIURI* aFaviconURI,
|
||||
NS_ENSURE_ARG(aData.Length() > 0);
|
||||
NS_ENSURE_ARG(aMimeType.Length() > 0);
|
||||
NS_ENSURE_ARG(imgLoader::SupportImageWithMimeType(
|
||||
PromiseFlatCString(aMimeType).get(),
|
||||
AcceptedMimeTypes::IMAGES_AND_DOCUMENTS));
|
||||
aMimeType, AcceptedMimeTypes::IMAGES_AND_DOCUMENTS));
|
||||
|
||||
PRTime now = PR_Now();
|
||||
if (aExpiration < now + MIN_FAVICON_EXPIRATION) {
|
||||
|
||||
Reference in New Issue
Block a user