mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Backed out changeset 8eb23bb2215a (bug 1612403) for Build bustage in android/nsMIMEInfoAndroid.cpp. CLOSED TREE
This commit is contained in:
parent
0bc317ccf1
commit
860a94407d
@ -170,17 +170,13 @@ NS_IMETHODIMP ProxyMIMEInfo::SetFileExtensions(const nsACString& aExtensions) {
|
||||
/* boolean extensionExists (in AUTF8String aExtension); */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::ExtensionExists(const nsACString& aExtension,
|
||||
bool* _retval) {
|
||||
*_retval = mProxyHandlerInfo->Extensions().Contains(
|
||||
aExtension, nsCaseInsensitiveCStringArrayComparator());
|
||||
*_retval = mProxyHandlerInfo->Extensions().Contains(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void appendExtension (in AUTF8String aExtension); */
|
||||
NS_IMETHODIMP ProxyMIMEInfo::AppendExtension(const nsACString& aExtension) {
|
||||
if (!mProxyHandlerInfo->Extensions().Contains(
|
||||
aExtension, nsCaseInsensitiveCStringArrayComparator())) {
|
||||
mProxyHandlerInfo->Extensions().AppendElement(aExtension);
|
||||
}
|
||||
mProxyHandlerInfo->Extensions().AppendElement(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -238,16 +238,15 @@ nsMIMEInfoAndroid::GetFileExtensions(nsIUTF8StringEnumerator** aResult) {
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoAndroid::SetFileExtensions(const nsACString& aExtensions) {
|
||||
mExtensions.Clear();
|
||||
nsACString::const_iterator start, end;
|
||||
aExtensions.BeginReading(start);
|
||||
aExtensions.EndReading(end);
|
||||
while (start != end) {
|
||||
nsACString::const_iterator cursor = start;
|
||||
mozilla::Unused << FindCharInReadable(',', cursor, end);
|
||||
AddUniqueExtension(Substring(start, cursor));
|
||||
// If a comma was found, skip it for the next search.
|
||||
start = cursor != end ? ++cursor : cursor;
|
||||
nsCString extList(aExtensions);
|
||||
|
||||
int32_t breakLocation = -1;
|
||||
while ((breakLocation = extList.FindChar(',')) != -1) {
|
||||
mExtensions.AppendElement(
|
||||
Substring(extList.get(), extList.get() + breakLocation));
|
||||
extList.Cut(0, breakLocation + 1);
|
||||
}
|
||||
if (!extList.IsEmpty()) mExtensions.AppendElement(extList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -269,18 +268,9 @@ nsMIMEInfoAndroid::ExtensionExists(const nsACString& aExtension,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsMIMEInfoAndroid::AddUniqueExtension(const nsACString& aExtension) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "no extension");
|
||||
if (!mExtensions.Contains(aExtension,
|
||||
nsCaseInsensitiveCStringArrayComparator())) {
|
||||
mExtensions.AppendElement(aExtension);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoAndroid::AppendExtension(const nsACString& aExtension) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
||||
AddUniqueExtension(aExtension);
|
||||
mExtensions.AppendElement(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -294,13 +284,22 @@ nsMIMEInfoAndroid::GetPrimaryExtension(nsACString& aPrimaryExtension) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoAndroid::SetPrimaryExtension(const nsACString& aExtension) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
||||
int32_t i = mExtensions.IndexOf(aExtension, 0,
|
||||
nsCaseInsensitiveCStringArrayComparator());
|
||||
if (i != -1) {
|
||||
uint32_t extCount = mExtensions.Length();
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
mExtensions.RemoveElementAt(i);
|
||||
}
|
||||
|
||||
mExtensions.InsertElementAt(0, aExtension);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -50,11 +50,6 @@ class nsMIMEInfoAndroid final : public nsIMIMEInfo {
|
||||
private:
|
||||
~SystemChooser() {}
|
||||
|
||||
/**
|
||||
* Internal helper to avoid adding duplicates.
|
||||
*/
|
||||
void AddUniqueExtension(const nsACString& aExtension);
|
||||
|
||||
nsMIMEInfoAndroid* mOuter;
|
||||
};
|
||||
};
|
||||
|
@ -95,9 +95,20 @@ nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, bool* _retval) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "no extension");
|
||||
*_retval = mExtensions.Contains(aExtension,
|
||||
nsCaseInsensitiveCStringArrayComparator());
|
||||
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
||||
bool found = false;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -111,28 +122,29 @@ nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval) {
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
||||
int32_t i = mExtensions.IndexOf(aExtension, 0,
|
||||
nsCaseInsensitiveCStringArrayComparator());
|
||||
if (i != -1) {
|
||||
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
|
||||
uint32_t extCount = mExtensions.Length();
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
mExtensions.RemoveElementAt(i);
|
||||
}
|
||||
mExtensions.InsertElementAt(0, aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsMIMEInfoBase::AddUniqueExtension(const nsACString& aExtension) {
|
||||
if (!aExtension.IsEmpty() &&
|
||||
!mExtensions.Contains(aExtension,
|
||||
nsCaseInsensitiveCStringArrayComparator())) {
|
||||
mExtensions.AppendElement(aExtension);
|
||||
}
|
||||
mExtensions.InsertElementAt(0, aExtension);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension) {
|
||||
MOZ_ASSERT(!aExtension.IsEmpty(), "No extension");
|
||||
AddUniqueExtension(aExtension);
|
||||
mExtensions.AppendElement(aExtension);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -180,16 +192,15 @@ nsMIMEInfoBase::Equals(nsIMIMEInfo* aMIMEInfo, bool* _retval) {
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions) {
|
||||
mExtensions.Clear();
|
||||
nsACString::const_iterator start, end;
|
||||
aExtensions.BeginReading(start);
|
||||
aExtensions.EndReading(end);
|
||||
while (start != end) {
|
||||
nsACString::const_iterator cursor = start;
|
||||
mozilla::Unused << FindCharInReadable(',', cursor, end);
|
||||
AddUniqueExtension(Substring(start, cursor));
|
||||
// If a comma was found, skip it for the next search.
|
||||
start = cursor != end ? ++cursor : cursor;
|
||||
nsCString extList(aExtensions);
|
||||
|
||||
int32_t breakLocation = -1;
|
||||
while ((breakLocation = extList.FindChar(',')) != -1) {
|
||||
mExtensions.AppendElement(
|
||||
Substring(extList.get(), extList.get() + breakLocation));
|
||||
extList.Cut(0, breakLocation + 1);
|
||||
}
|
||||
if (!extList.IsEmpty()) mExtensions.AppendElement(extList);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -137,11 +137,6 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
|
||||
*/
|
||||
static nsresult GetLocalFileFromURI(nsIURI* aURI, nsIFile** aFile);
|
||||
|
||||
/**
|
||||
* Internal helper to avoid adding duplicates.
|
||||
*/
|
||||
void AddUniqueExtension(const nsACString& aExtension);
|
||||
|
||||
// member variables
|
||||
nsTArray<nsCString>
|
||||
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
|
||||
// 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(), {
|
||||
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
|
||||
* from possibleApplicationHandlers are removed when saving and reloading.
|
||||
* Tests that duplicates added with "appendExtension" or present in
|
||||
* "possibleApplicationHandlers" are removed when saving and reloading.
|
||||
*/
|
||||
add_task(async function test_store_no_duplicates() {
|
||||
await deleteHandlerStore();
|
||||
@ -430,10 +431,6 @@ add_task(async function test_store_no_duplicates() {
|
||||
handlerInfo.appendExtension("extension_test2");
|
||||
handlerInfo.appendExtension("extension_test1");
|
||||
handlerInfo.appendExtension("EXTENSION_test1");
|
||||
Assert.deepEqual(Array.from(handlerInfo.getFileExtensions()), [
|
||||
"extension_test1",
|
||||
"extension_test2",
|
||||
]);
|
||||
gHandlerService.store(handlerInfo);
|
||||
|
||||
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
|
||||
* the data store.
|
||||
|
Loading…
Reference in New Issue
Block a user