зеркало из https://github.com/mozilla/pjs.git
Bug 90633. Use the URL extension for the temp file we pass to helpers
if it matches the extension list in the mime info. r=law, sr=mscott.
This commit is contained in:
Родитель
e91b7917da
Коммит
1c61776f7a
|
@ -359,7 +359,7 @@ function GetExtensionBasedOnMimeType(aMIMEType)
|
|||
var mimeInfo = mimeService.GetFromMIMEType(aMIMEType);
|
||||
if (!mimeInfo) return "";
|
||||
|
||||
var fileExtension = mimeInfo.FirstExtension();
|
||||
var fileExtension = mimeInfo.primaryExtension;
|
||||
|
||||
// the MIME service likes to give back ".htm" for text/html files,
|
||||
// so do a special-case fix here.
|
||||
|
|
|
@ -1002,7 +1002,7 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
|
|||
// Append the mime file extension
|
||||
nsXPIDLCString fileExt;
|
||||
if (!hasExtension &&
|
||||
NS_SUCCEEDED(mimeInfo->FirstExtension(getter_Copies(fileExt))))
|
||||
NS_SUCCEEDED(mimeInfo->GetPrimaryExtension(getter_Copies(fileExt))))
|
||||
{
|
||||
newFileName.Append(".");
|
||||
newFileName.Append(fileExt.get());
|
||||
|
|
|
@ -1849,7 +1849,7 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers )
|
|||
{
|
||||
nsXPIDLCString fileExtension;
|
||||
|
||||
if ( (NS_SUCCEEDED(mimeInfo->FirstExtension(getter_Copies(fileExtension)))) && fileExtension)
|
||||
if ( (NS_SUCCEEDED(mimeInfo->GetPrimaryExtension(getter_Copies(fileExtension)))) && fileExtension)
|
||||
{
|
||||
newAttachName.Append(".");
|
||||
newAttachName.Append(fileExtension);
|
||||
|
|
|
@ -273,7 +273,7 @@ ValidateRealName(nsMsgAttachmentData *aAttach, MimeHeaders *aHdrs)
|
|||
{
|
||||
char *aFileExtension = nsnull;
|
||||
|
||||
if ( (NS_SUCCEEDED(mimeInfo->FirstExtension(&aFileExtension))) && aFileExtension)
|
||||
if ( (NS_SUCCEEDED(mimeInfo->GetPrimaryExtension(&aFileExtension))) && aFileExtension)
|
||||
{
|
||||
newAttachName.Append(NS_LITERAL_STRING("."));
|
||||
newAttachName.AppendWithConversion(aFileExtension);
|
||||
|
|
|
@ -334,7 +334,7 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports
|
|||
if (mimeObject)
|
||||
{
|
||||
nsXPIDLCString fileExt;
|
||||
mimeObject->FirstExtension(getter_Copies(fileExt));
|
||||
mimeObject->GetPrimaryExtension(getter_Copies(fileExt));
|
||||
// we need to insert a '.' b4 the extension...
|
||||
nsCAutoString formattedFileExt;
|
||||
formattedFileExt = ".";
|
||||
|
|
|
@ -72,13 +72,6 @@ interface nsIMIMEInfo : nsISupports {
|
|||
|
||||
boolean ExtensionExists(in string aExtension);
|
||||
|
||||
/* Returns the first extension association in
|
||||
* the internal set of extensions.
|
||||
*
|
||||
* @return The first extension.
|
||||
*/
|
||||
string FirstExtension();
|
||||
|
||||
/*
|
||||
* Append a given extension to the set of extensions
|
||||
*/
|
||||
|
@ -91,6 +84,13 @@ interface nsIMIMEInfo : nsISupports {
|
|||
|
||||
nsIMIMEInfo clone();
|
||||
|
||||
/* Returns the first extension association in
|
||||
* the internal set of extensions.
|
||||
*
|
||||
* @return The first extension.
|
||||
*/
|
||||
attribute string primaryExtension;
|
||||
|
||||
/* The MIME type of this MIMEInfo.
|
||||
*
|
||||
* @return String representing the MIME type.
|
||||
|
|
|
@ -98,9 +98,10 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|||
|
||||
if (!aExtension) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsDependentCString extension(aExtension);
|
||||
for (PRUint8 i=0; i < extCount; i++) {
|
||||
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
||||
if (ext->Equals(aExtension)) {
|
||||
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
||||
nsMIMEInfoImpl::GetPrimaryExtension(char **_retval) {
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
|
@ -120,6 +121,29 @@ nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::SetPrimaryExtension(const char *aExtension) {
|
||||
NS_ASSERTION(aExtension, "no extension");
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
nsCString extension(aExtension);
|
||||
PRUint8 i;
|
||||
PRBool found = PR_FALSE;
|
||||
for (i=0; i < extCount; i++) {
|
||||
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
||||
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
mExtensions.RemoveCStringAt(i);
|
||||
}
|
||||
|
||||
mExtensions.InsertCStringAt(extension, 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::AppendExtension(const char *aExtension)
|
||||
{
|
||||
mExtensions.AppendCString( nsCAutoString(aExtension) );
|
||||
|
|
|
@ -275,9 +275,25 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
|
|||
*aStreamListener = nsnull;
|
||||
if (mimeInfo)
|
||||
{
|
||||
// ensure that the file extension field is always filled in
|
||||
mimeInfo->FirstExtension(getter_Copies(fileExtension));
|
||||
// The primary extension for the mime info may be different from
|
||||
// the URL extension. If the URL extension matches the mime info,
|
||||
// set it as the primary extension. In either case, fileExtension
|
||||
// should be the primary extension once we are doen.
|
||||
if (fileExtension.IsEmpty()) {
|
||||
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
||||
if (url) {
|
||||
url->GetFileExtension(getter_Copies(fileExtension));
|
||||
}
|
||||
}
|
||||
|
||||
PRBool matches = PR_FALSE;
|
||||
mimeInfo->ExtensionExists(fileExtension.get(), &matches);
|
||||
if (matches) {
|
||||
mimeInfo->SetPrimaryExtension(fileExtension.get());
|
||||
} else {
|
||||
mimeInfo->GetPrimaryExtension(getter_Copies(fileExtension));
|
||||
}
|
||||
|
||||
// this code is incomplete and just here to get things started..
|
||||
nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext);
|
||||
handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener);
|
||||
|
|
|
@ -98,9 +98,10 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|||
|
||||
if (!aExtension) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsDependentCString extension(aExtension);
|
||||
for (PRUint8 i=0; i < extCount; i++) {
|
||||
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
||||
if (ext->Equals(aExtension)) {
|
||||
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ nsMIMEInfoImpl::ExtensionExists(const char *aExtension, PRBool *_retval) {
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
||||
nsMIMEInfoImpl::GetPrimaryExtension(char **_retval) {
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
|
@ -120,6 +121,29 @@ nsMIMEInfoImpl::FirstExtension(char **_retval) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMIMEInfoImpl::SetPrimaryExtension(const char *aExtension) {
|
||||
NS_ASSERTION(aExtension, "no extension");
|
||||
PRUint32 extCount = mExtensions.Count();
|
||||
nsCString extension(aExtension);
|
||||
PRUint8 i;
|
||||
PRBool found = PR_FALSE;
|
||||
for (i=0; i < extCount; i++) {
|
||||
nsCString* ext = (nsCString*)mExtensions.CStringAt(i);
|
||||
if (ext->Equals(extension, nsCaseInsensitiveCStringComparator())) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
mExtensions.RemoveCStringAt(i);
|
||||
}
|
||||
|
||||
mExtensions.InsertCStringAt(extension, 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMIMEInfoImpl::AppendExtension(const char *aExtension)
|
||||
{
|
||||
mExtensions.AppendCString( nsCAutoString(aExtension) );
|
||||
|
|
|
@ -52,7 +52,7 @@ nsresult nsOSHelperAppService::FindOSMimeInfoForType(const char * aMimeContentTy
|
|||
if (mimeInfo)
|
||||
{
|
||||
nsXPIDLCString mimefileExt;
|
||||
mimeInfo->FirstExtension(getter_Copies(mimefileExt));
|
||||
mimeInfo->GetPrimaryExtension(getter_Copies(mimefileExt));
|
||||
fileExtension = ".";
|
||||
fileExtension.Append(mimefileExt);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ function Startup()
|
|||
|
||||
// Fill the fields we can from this.
|
||||
gDescriptionField.value = info.Description;
|
||||
gExtensionField.value = info.FirstExtension();
|
||||
gExtensionField.value = info.primaryExtension;
|
||||
gMIMEField.value = info.MIMEType;
|
||||
var app = info.preferredApplicationHandler;
|
||||
if ( app ) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче