зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 3cfea5c3c067 (bug 1612403) for failing test_bug449141.html on a CLOSED TREE
This commit is contained in:
Родитель
2db22c93fd
Коммит
7c1d6a5705
|
@ -181,7 +181,8 @@ nsresult CheckAndGetExtensionForMime(const nsCString& aExtension,
|
||||||
getter_AddRefs(mimeInfo));
|
getter_AddRefs(mimeInfo));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
mimeInfo->GetPrimaryExtension(*aPrimaryExtension);
|
rv = mimeInfo->GetPrimaryExtension(*aPrimaryExtension);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (aExtension.IsEmpty()) {
|
if (aExtension.IsEmpty()) {
|
||||||
*aIsValidExtension = false;
|
*aIsValidExtension = false;
|
||||||
|
@ -278,7 +279,7 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable* aTransferable,
|
||||||
&isValidExtension, &primaryExtension);
|
&isValidExtension, &primaryExtension);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (!isValidExtension && !primaryExtension.IsEmpty()) {
|
if (!isValidExtension) {
|
||||||
// The filename extension is missing or incompatible
|
// The filename extension is missing or incompatible
|
||||||
// with the MIME type, replace it with the primary
|
// with the MIME type, replace it with the primary
|
||||||
// extension.
|
// extension.
|
||||||
|
@ -462,13 +463,12 @@ nsresult DragDataProducer::GetImageData(imgIContainer* aImage,
|
||||||
// Fix the file extension in the URL
|
// Fix the file extension in the URL
|
||||||
nsAutoCString primaryExtension;
|
nsAutoCString primaryExtension;
|
||||||
mimeInfo->GetPrimaryExtension(primaryExtension);
|
mimeInfo->GetPrimaryExtension(primaryExtension);
|
||||||
if (!primaryExtension.IsEmpty()) {
|
|
||||||
rv = NS_MutateURI(imgUrl)
|
rv = NS_MutateURI(imgUrl)
|
||||||
.Apply(NS_MutatorMethod(&nsIURLMutator::SetFileExtension,
|
.Apply(NS_MutatorMethod(&nsIURLMutator::SetFileExtension,
|
||||||
primaryExtension, nullptr))
|
primaryExtension, nullptr))
|
||||||
.Finalize(imgUrl);
|
.Finalize(imgUrl);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* defined(XP_MACOSX) */
|
#endif /* defined(XP_MACOSX) */
|
||||||
|
|
|
@ -639,13 +639,12 @@ static nsresult AppendImagePromise(nsITransferable* aTransferable,
|
||||||
// Fix the file extension in the URL
|
// Fix the file extension in the URL
|
||||||
nsAutoCString primaryExtension;
|
nsAutoCString primaryExtension;
|
||||||
mimeInfo->GetPrimaryExtension(primaryExtension);
|
mimeInfo->GetPrimaryExtension(primaryExtension);
|
||||||
if (!primaryExtension.IsEmpty()) {
|
|
||||||
rv = NS_MutateURI(imgUri)
|
rv = NS_MutateURI(imgUri)
|
||||||
.Apply(NS_MutatorMethod(&nsIURLMutator::SetFileExtension,
|
.Apply(NS_MutatorMethod(&nsIURLMutator::SetFileExtension,
|
||||||
primaryExtension, nullptr))
|
primaryExtension, nullptr))
|
||||||
.Finalize(imgUrl);
|
.Finalize(imgUrl);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString fileName;
|
nsAutoCString fileName;
|
||||||
|
|
|
@ -170,18 +170,13 @@ NS_IMETHODIMP ProxyMIMEInfo::SetFileExtensions(const nsACString& aExtensions) {
|
||||||
/* boolean extensionExists (in AUTF8String aExtension); */
|
/* boolean extensionExists (in AUTF8String aExtension); */
|
||||||
NS_IMETHODIMP ProxyMIMEInfo::ExtensionExists(const nsACString& aExtension,
|
NS_IMETHODIMP ProxyMIMEInfo::ExtensionExists(const nsACString& aExtension,
|
||||||
bool* _retval) {
|
bool* _retval) {
|
||||||
*_retval = mProxyHandlerInfo->Extensions().Contains(
|
*_retval = mProxyHandlerInfo->Extensions().Contains(aExtension);
|
||||||
aExtension, nsCaseInsensitiveCStringArrayComparator());
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* void appendExtension (in AUTF8String aExtension); */
|
/* void appendExtension (in AUTF8String aExtension); */
|
||||||
NS_IMETHODIMP ProxyMIMEInfo::AppendExtension(const nsACString& aExtension) {
|
NS_IMETHODIMP ProxyMIMEInfo::AppendExtension(const nsACString& aExtension) {
|
||||||
if (!aExtension.IsEmpty() &&
|
mProxyHandlerInfo->Extensions().AppendElement(aExtension);
|
||||||
!mProxyHandlerInfo->Extensions().Contains(
|
|
||||||
aExtension, nsCaseInsensitiveCStringArrayComparator())) {
|
|
||||||
mProxyHandlerInfo->Extensions().AppendElement(aExtension);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +185,6 @@ NS_IMETHODIMP ProxyMIMEInfo::GetPrimaryExtension(
|
||||||
nsACString& aPrimaryExtension) {
|
nsACString& aPrimaryExtension) {
|
||||||
const auto& extensions = mProxyHandlerInfo->Extensions();
|
const auto& extensions = mProxyHandlerInfo->Extensions();
|
||||||
if (extensions.IsEmpty()) {
|
if (extensions.IsEmpty()) {
|
||||||
aPrimaryExtension.Truncate();
|
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
aPrimaryExtension = extensions[0];
|
aPrimaryExtension = extensions[0];
|
||||||
|
|
|
@ -238,16 +238,15 @@ nsMIMEInfoAndroid::GetFileExtensions(nsIUTF8StringEnumerator** aResult) {
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoAndroid::SetFileExtensions(const nsACString& aExtensions) {
|
nsMIMEInfoAndroid::SetFileExtensions(const nsACString& aExtensions) {
|
||||||
mExtensions.Clear();
|
mExtensions.Clear();
|
||||||
nsACString::const_iterator start, end;
|
nsCString extList(aExtensions);
|
||||||
aExtensions.BeginReading(start);
|
|
||||||
aExtensions.EndReading(end);
|
int32_t breakLocation = -1;
|
||||||
while (start != end) {
|
while ((breakLocation = extList.FindChar(',')) != -1) {
|
||||||
nsACString::const_iterator cursor = start;
|
mExtensions.AppendElement(
|
||||||
mozilla::Unused << FindCharInReadable(',', cursor, end);
|
Substring(extList.get(), extList.get() + breakLocation));
|
||||||
AddUniqueExtension(Substring(start, cursor));
|
extList.Cut(0, breakLocation + 1);
|
||||||
// If a comma was found, skip it for the next search.
|
|
||||||
start = cursor != end ? ++cursor : cursor;
|
|
||||||
}
|
}
|
||||||
|
if (!extList.IsEmpty()) mExtensions.AppendElement(extList);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,43 +268,38 @@ nsMIMEInfoAndroid::ExtensionExists(const nsACString& aExtension,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsMIMEInfoAndroid::AddUniqueExtension(const nsACString& aExtension) {
|
|
||||||
if (!aExtension.IsEmpty() &&
|
|
||||||
!mExtensions.Contains(aExtension,
|
|
||||||
nsCaseInsensitiveCStringArrayComparator())) {
|
|
||||||
mExtensions.AppendElement(aExtension);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoAndroid::AppendExtension(const nsACString& aExtension) {
|
nsMIMEInfoAndroid::AppendExtension(const nsACString& aExtension) {
|
||||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
mExtensions.AppendElement(aExtension);
|
||||||
AddUniqueExtension(aExtension);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoAndroid::GetPrimaryExtension(nsACString& aPrimaryExtension) {
|
nsMIMEInfoAndroid::GetPrimaryExtension(nsACString& aPrimaryExtension) {
|
||||||
if (!mExtensions.Length()) {
|
if (!mExtensions.Length()) return NS_ERROR_NOT_INITIALIZED;
|
||||||
aPrimaryExtension.Truncate();
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
}
|
|
||||||
aPrimaryExtension = mExtensions[0];
|
aPrimaryExtension = mExtensions[0];
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoAndroid::SetPrimaryExtension(const nsACString& aExtension) {
|
nsMIMEInfoAndroid::SetPrimaryExtension(const nsACString& aExtension) {
|
||||||
if (MOZ_UNLIKELY(aExtension.IsEmpty())) {
|
uint32_t extCount = mExtensions.Length();
|
||||||
// Don't assert since Java may return an empty extension for unknown types.
|
uint8_t i;
|
||||||
return NS_ERROR_INVALID_ARG;
|
bool found = false;
|
||||||
|
for (i = 0; i < extCount; i++) {
|
||||||
|
const nsCString& ext = mExtensions[i];
|
||||||
|
if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int32_t i = mExtensions.IndexOf(aExtension, 0,
|
if (found) {
|
||||||
nsCaseInsensitiveCStringArrayComparator());
|
|
||||||
if (i != -1) {
|
|
||||||
mExtensions.RemoveElementAt(i);
|
mExtensions.RemoveElementAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
mExtensions.InsertElementAt(0, aExtension);
|
mExtensions.InsertElementAt(0, aExtension);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,6 @@ class nsMIMEInfoAndroid final : public nsIMIMEInfo {
|
||||||
private:
|
private:
|
||||||
~nsMIMEInfoAndroid() {}
|
~nsMIMEInfoAndroid() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal helper to avoid adding duplicates.
|
|
||||||
*/
|
|
||||||
void AddUniqueExtension(const nsACString& aExtension);
|
|
||||||
|
|
||||||
virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile);
|
virtual MOZ_MUST_USE nsresult LaunchDefaultWithFile(nsIFile* aFile);
|
||||||
virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI* aURI);
|
virtual MOZ_MUST_USE nsresult LoadUriInternal(nsIURI* aURI);
|
||||||
nsCOMPtr<nsIMutableArray> mHandlerApps;
|
nsCOMPtr<nsIMutableArray> mHandlerApps;
|
||||||
|
|
|
@ -95,49 +95,56 @@ nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult) {
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, bool* _retval) {
|
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, bool* _retval) {
|
||||||
MOZ_ASSERT(!aExtension.IsEmpty(), "no extension");
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
||||||
*_retval = mExtensions.Contains(aExtension,
|
bool found = false;
|
||||||
nsCaseInsensitiveCStringArrayComparator());
|
uint32_t extCount = mExtensions.Length();
|
||||||
|
if (extCount < 1) return NS_OK;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < extCount; i++) {
|
||||||
|
const nsCString& ext = mExtensions[i];
|
||||||
|
if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*_retval = found;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval) {
|
nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval) {
|
||||||
if (!mExtensions.Length()) {
|
if (!mExtensions.Length()) return NS_ERROR_NOT_INITIALIZED;
|
||||||
_retval.Truncate();
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
}
|
|
||||||
_retval = mExtensions[0];
|
_retval = mExtensions[0];
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension) {
|
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension) {
|
||||||
if (MOZ_UNLIKELY(aExtension.IsEmpty())) {
|
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
||||||
MOZ_ASSERT(false, "No extension");
|
uint32_t extCount = mExtensions.Length();
|
||||||
return NS_ERROR_INVALID_ARG;
|
uint8_t i;
|
||||||
|
bool found = false;
|
||||||
|
for (i = 0; i < extCount; i++) {
|
||||||
|
const nsCString& ext = mExtensions[i];
|
||||||
|
if (ext.Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int32_t i = mExtensions.IndexOf(aExtension, 0,
|
if (found) {
|
||||||
nsCaseInsensitiveCStringArrayComparator());
|
|
||||||
if (i != -1) {
|
|
||||||
mExtensions.RemoveElementAt(i);
|
mExtensions.RemoveElementAt(i);
|
||||||
}
|
}
|
||||||
mExtensions.InsertElementAt(0, aExtension);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void nsMIMEInfoBase::AddUniqueExtension(const nsACString& aExtension) {
|
mExtensions.InsertElementAt(0, aExtension);
|
||||||
if (!aExtension.IsEmpty() &&
|
|
||||||
!mExtensions.Contains(aExtension,
|
return NS_OK;
|
||||||
nsCaseInsensitiveCStringArrayComparator())) {
|
|
||||||
mExtensions.AppendElement(aExtension);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension) {
|
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension) {
|
||||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
mExtensions.AppendElement(aExtension);
|
||||||
AddUniqueExtension(aExtension);
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,16 +192,15 @@ nsMIMEInfoBase::Equals(nsIMIMEInfo* aMIMEInfo, bool* _retval) {
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions) {
|
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions) {
|
||||||
mExtensions.Clear();
|
mExtensions.Clear();
|
||||||
nsACString::const_iterator start, end;
|
nsCString extList(aExtensions);
|
||||||
aExtensions.BeginReading(start);
|
|
||||||
aExtensions.EndReading(end);
|
int32_t breakLocation = -1;
|
||||||
while (start != end) {
|
while ((breakLocation = extList.FindChar(',')) != -1) {
|
||||||
nsACString::const_iterator cursor = start;
|
mExtensions.AppendElement(
|
||||||
mozilla::Unused << FindCharInReadable(',', cursor, end);
|
Substring(extList.get(), extList.get() + breakLocation));
|
||||||
AddUniqueExtension(Substring(start, cursor));
|
extList.Cut(0, breakLocation + 1);
|
||||||
// If a comma was found, skip it for the next search.
|
|
||||||
start = cursor != end ? ++cursor : cursor;
|
|
||||||
}
|
}
|
||||||
|
if (!extList.IsEmpty()) mExtensions.AppendElement(extList);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,6 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
|
||||||
*/
|
*/
|
||||||
static nsresult GetLocalFileFromURI(nsIURI* aURI, nsIFile** aFile);
|
static nsresult GetLocalFileFromURI(nsIURI* aURI, nsIFile** aFile);
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal helper to avoid adding duplicates.
|
|
||||||
*/
|
|
||||||
void AddUniqueExtension(const nsACString& aExtension);
|
|
||||||
|
|
||||||
// member variables
|
// member variables
|
||||||
nsTArray<nsCString>
|
nsTArray<nsCString>
|
||||||
mExtensions; ///< array of file extensions associated w/ this MIME obj
|
mExtensions; ///< array of file extensions associated w/ this MIME obj
|
||||||
|
|
|
@ -53,7 +53,8 @@ function assertAllHandlerInfosMatchTestData() {
|
||||||
|
|
||||||
// It's important that the MIME types we check here do not exist at the
|
// It's important that the MIME types we check here do not exist at the
|
||||||
// operating system level, otherwise the list of handlers and file extensions
|
// operating system level, otherwise the list of handlers and file extensions
|
||||||
// will be merged. The current implementation avoids duplicate entries.
|
// will be merged. The current implementation adds each saved file extension
|
||||||
|
// even if one already exists in the system, resulting in duplicate entries.
|
||||||
|
|
||||||
HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), {
|
HandlerServiceTestUtils.assertHandlerInfoMatches(handlerInfos.shift(), {
|
||||||
type: "example/type.handleinternally",
|
type: "example/type.handleinternally",
|
||||||
|
@ -414,8 +415,8 @@ add_task(async function test_store_fileExtensions_lowercase() {
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that appendExtension doesn't add duplicates, and that anyway duplicates
|
* Tests that duplicates added with "appendExtension" or present in
|
||||||
* from possibleApplicationHandlers are removed when saving and reloading.
|
* "possibleApplicationHandlers" are removed when saving and reloading.
|
||||||
*/
|
*/
|
||||||
add_task(async function test_store_no_duplicates() {
|
add_task(async function test_store_no_duplicates() {
|
||||||
await deleteHandlerStore();
|
await deleteHandlerStore();
|
||||||
|
@ -430,10 +431,6 @@ add_task(async function test_store_no_duplicates() {
|
||||||
handlerInfo.appendExtension("extension_test2");
|
handlerInfo.appendExtension("extension_test2");
|
||||||
handlerInfo.appendExtension("extension_test1");
|
handlerInfo.appendExtension("extension_test1");
|
||||||
handlerInfo.appendExtension("EXTENSION_test1");
|
handlerInfo.appendExtension("EXTENSION_test1");
|
||||||
Assert.deepEqual(Array.from(handlerInfo.getFileExtensions()), [
|
|
||||||
"extension_test1",
|
|
||||||
"extension_test2",
|
|
||||||
]);
|
|
||||||
gHandlerService.store(handlerInfo);
|
gHandlerService.store(handlerInfo);
|
||||||
|
|
||||||
await unloadHandlerStore();
|
await unloadHandlerStore();
|
||||||
|
@ -452,21 +449,6 @@ add_task(async function test_store_no_duplicates() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests that setFileExtensions doesn't add duplicates.
|
|
||||||
*/
|
|
||||||
add_task(async function test_setFileExtensions_no_duplicates() {
|
|
||||||
await deleteHandlerStore();
|
|
||||||
|
|
||||||
let handlerInfo = getKnownHandlerInfo("example/new");
|
|
||||||
handlerInfo.setFileExtensions("a,b,A,b,c,a");
|
|
||||||
let expected = ["a", "b", "c"];
|
|
||||||
Assert.deepEqual(Array.from(handlerInfo.getFileExtensions()), expected);
|
|
||||||
// Test empty extensions, also at begin and end.
|
|
||||||
handlerInfo.setFileExtensions(",a,,b,A,c,");
|
|
||||||
Assert.deepEqual(Array.from(handlerInfo.getFileExtensions()), expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that "store" deletes properties that have their default values from
|
* Tests that "store" deletes properties that have their default values from
|
||||||
* the data store.
|
* the data store.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче