Bug 235502 nsIMIMEService, nsIMIMEInfo should use nsACString/nsAString instead of string/wstring

r=bzbarsky sr=darin
This commit is contained in:
cbiesinger%web.de 2004-04-15 20:56:37 +00:00
Родитель a600bb61fc
Коммит d4e1da55f3
50 изменённых файлов: 400 добавлений и 460 удалений

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

@ -301,7 +301,7 @@ nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI)
if (!mimeService)
return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = mimeService->GetFromTypeAndExtension(mContentType.get(), nsnull, getter_AddRefs(mimeInfo));
rv = mimeService->GetFromTypeAndExtension(mContentType, EmptyCString(), getter_AddRefs(mimeInfo));
if (!mimeInfo)
return rv;

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

@ -2221,13 +2221,9 @@ nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission,
do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
char * contentTypeChars = nsnull;
rv = MIMEService->GetTypeFromFile(file, &contentTypeChars);
nsCAutoString contentType;
if (contentTypeChars) {
contentType.Adopt(contentTypeChars);
} else {
rv = MIMEService->GetTypeFromFile(file, contentType);
if (NS_FAILED(rv)) {
contentType = NS_LITERAL_CSTRING("application/octet-stream");
}

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

@ -80,7 +80,6 @@
#include "nsIFIXptr.h"
#include "nsIXPointer.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
#include "nsIEventListenerManager.h"

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

@ -105,7 +105,6 @@
#include "nsIFrame.h"
#include "nsIXBLService.h"
#include "nsCExternalHandlerService.h"
#include "nsIMIMEService.h"
#include "nsMimeTypes.h"
#include "nsIFastLoadService.h"
#include "nsIObjectInputStream.h"

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

@ -135,7 +135,7 @@ MimeTypeArrayImpl::NamedItem(const nsAString& aName,
nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1");
if (mimeSrv) {
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mimeSrv->GetFromTypeAndExtension(NS_ConvertUCS2toUTF8(aName).get(), nsnull,
mimeSrv->GetFromTypeAndExtension(NS_ConvertUCS2toUTF8(aName), EmptyCString(),
getter_AddRefs(mimeInfo));
if (mimeInfo) {
// Now we check whether we can really claim to support this type
@ -150,8 +150,8 @@ MimeTypeArrayImpl::NamedItem(const nsAString& aName,
if (!helper) {
// mime info from the OS may not have a PreferredApplicationHandler
// so just check for an empty default description
nsXPIDLString defaultDescription;
mimeInfo->GetDefaultDescription(getter_Copies(defaultDescription));
nsAutoString defaultDescription;
mimeInfo->GetDefaultDescription(defaultDescription);
if (defaultDescription.IsEmpty()) {
// no support; just leave
return NS_OK;

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

@ -118,18 +118,8 @@ void AppLauncherDlg::OnInitDialog()
if (mimeInfo)
{
mimeInfo->GetPreferredAction(&prefAction);
nsXPIDLString appDesc;
nsresult rv = mimeInfo->GetApplicationDescription(getter_Copies(appDesc));
if (NS_SUCCEEDED(rv))
{
appName = appDesc.get();
}
nsXPIDLCString mimeType;
rv = mimeInfo->GetMIMEType(getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
{
contentType = mimeType;
}
mimeInfo->GetApplicationDescription(appName);
mimeInfo->GetMIMEType(contentType);
}
if (prefAction == nsIMIMEInfo::saveToDisk)
{

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

@ -110,12 +110,10 @@ LRESULT CPPageDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
nsCOMPtr<nsIMIMEInfo> mimeInfo;
nsCAutoString contentType;
contentType.AssignWithConversion(mType);
mimeService->GetFromTypeAndExtension(contentType.get(), nsnull, getter_AddRefs(mimeInfo));
mimeService->GetFromTypeAndExtension(contentType, EmptyCString(), getter_AddRefs(mimeInfo));
if (mimeInfo)
{
nsXPIDLString description;
mimeInfo->GetDescription(getter_Copies(description));
desc = description;
mimeInfo->GetDescription(desc);
}
}

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

@ -262,7 +262,7 @@ nsresult nsHeaderSniffer::PerformSave(nsIURI* inOriginalURI)
if (!mimeService)
return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = mimeService->GetFromTypeAndExtension(mContentType.get(), nsnull, getter_AddRefs(mimeInfo));
rv = mimeService->GetFromTypeAndExtension(mContentType, EmptyCString(), getter_AddRefs(mimeInfo));
if (!mimeInfo)
return rv;

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

@ -281,7 +281,7 @@ nsresult CHeaderSniffer::PerformSave(nsIURI* inOriginalURI, const ESaveFormat in
if (!mimeService)
return rv;
nsCOMPtr<nsIMIMEInfo> mimeInfo;
rv = mimeService->GetFromTypeAndExtension(mContentType.get(), nsnull, getter_AddRefs(mimeInfo));
rv = mimeService->GetFromTypeAndExtension(mContentType, EmptyCString(), getter_AddRefs(mimeInfo));
if (!mimeInfo)
return rv;

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

@ -1287,8 +1287,8 @@ nsWebBrowserPersist::GetExtensionForContentType(const PRUnichar *aContentType, P
nsCOMPtr<nsIMIMEInfo> mimeInfo;
nsCAutoString contentType;
contentType.AssignWithConversion(aContentType);
nsXPIDLCString ext;
rv = mMIMEService->GetPrimaryExtension(contentType.get(), nsnull, getter_Copies(ext));
nsCAutoString ext;
rv = mMIMEService->GetPrimaryExtension(contentType, EmptyCString(), ext);
if (NS_SUCCEEDED(rv))
{
*aExt = ToNewUnicode(ext);
@ -2053,10 +2053,7 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
{
nsCOMPtr<nsIURI> uri;
aChannel->GetOriginalURI(getter_AddRefs(uri));
nsXPIDLCString mimeType;
rv = mMIMEService->GetTypeFromURI(uri, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
contentType = mimeType;
mMIMEService->GetTypeFromURI(uri, contentType);
}
// Append the extension onto the file
@ -2064,7 +2061,7 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
{
nsCOMPtr<nsIMIMEInfo> mimeInfo;
mMIMEService->GetFromTypeAndExtension(
contentType.get(), nsnull, getter_AddRefs(mimeInfo));
contentType, EmptyCString(), getter_AddRefs(mimeInfo));
nsCOMPtr<nsILocalFile> localFile;
GetLocalFileFromURI(aURI, getter_AddRefs(localFile));
@ -2082,11 +2079,11 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
PRInt32 ext = newFileName.RFind(".");
if (ext != -1)
{
mimeInfo->ExtensionExists(newFileName.get() + ext + 1, &hasExtension);
mimeInfo->ExtensionExists(Substring(newFileName, ext + 1), &hasExtension);
}
// Append the mime file extension
nsXPIDLCString fileExt;
nsCAutoString fileExt;
if (!hasExtension)
{
// Test if previous extension is acceptable
@ -2102,7 +2099,7 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne
// can't use old extension so use primary extension
if (!useOldExt)
{
mimeInfo->GetPrimaryExtension(getter_Copies(fileExt));
mimeInfo->GetPrimaryExtension(fileExt);
}
if (!fileExt.IsEmpty())

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

@ -313,8 +313,8 @@ BOOL CChooseActionDlg::OnInitDialog()
// Retrieve and set the Mime type of the content we're downloading
// in the content type field of the dialog box
//
nsXPIDLCString mimeType;
nsresult rv = mimeInfo->GetMIMEType(getter_Copies(mimeType));
nsCAutoString mimeType;
nsresult rv = mimeInfo->GetMIMEType(mimeType);
if(NS_SUCCEEDED(rv))
{
CStatic *pMimeType = (CStatic *)GetDlgItem(IDC_CONTENT_TYPE);
@ -358,8 +358,8 @@ void CChooseActionDlg::InitWithPreferredAction(nsIMIMEInfo* aMimeInfo)
// See if we can get the appname
//
nsXPIDLString appDesc;
nsresult rv = aMimeInfo->GetApplicationDescription(getter_Copies(appDesc));
nsAutoString appDesc;
nsresult rv = aMimeInfo->GetApplicationDescription(appDesc);
if(NS_SUCCEEDED(rv))
{
USES_CONVERSION;

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

@ -517,13 +517,9 @@ PRBool nsObjectFrame::IsSupportedImage(nsIContent* aContent)
if (NS_FAILED(rv))
return PR_FALSE;
nsXPIDLCString cType;
rv = mimeService->GetTypeFromExtension(NS_ConvertUCS2toUTF8(ext).get(), getter_Copies(cType));
rv = mimeService->GetTypeFromExtension(NS_ConvertUCS2toUTF8(ext), type);
if (NS_FAILED(rv))
return PR_FALSE;
type.Assign(cType);
}
nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
@ -562,18 +558,15 @@ PRBool nsObjectFrame::IsSupportedDocument(nsIContent* aContent)
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return PR_FALSE;
nsXPIDLCString contentType;
rv = mimeService->GetTypeFromURI(uri, getter_Copies(contentType));
if (NS_FAILED(rv) || contentType.IsEmpty())
rv = mimeService->GetTypeFromURI(uri, typeStr);
if (NS_FAILED(rv))
return PR_FALSE;
typeStr = contentType;
} else {
CopyUTF16toUTF8(type, typeStr);
}
nsXPIDLCString value;
rv = catman->GetCategoryEntry("Gecko-Content-Viewers",typeStr.get(), getter_Copies(value));
rv = catman->GetCategoryEntry("Gecko-Content-Viewers", typeStr.get(), getter_Copies(value));
// If we have a content viewer entry in the catagory manager for this mime type
// and it's not the full-page plugin one, return PR_TRUE to act like an IFRAME.

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

@ -517,13 +517,9 @@ PRBool nsObjectFrame::IsSupportedImage(nsIContent* aContent)
if (NS_FAILED(rv))
return PR_FALSE;
nsXPIDLCString cType;
rv = mimeService->GetTypeFromExtension(NS_ConvertUCS2toUTF8(ext).get(), getter_Copies(cType));
rv = mimeService->GetTypeFromExtension(NS_ConvertUCS2toUTF8(ext), type);
if (NS_FAILED(rv))
return PR_FALSE;
type.Assign(cType);
}
nsCOMPtr<imgILoader> loader(do_GetService("@mozilla.org/image/loader;1"));
@ -562,18 +558,15 @@ PRBool nsObjectFrame::IsSupportedDocument(nsIContent* aContent)
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return PR_FALSE;
nsXPIDLCString contentType;
rv = mimeService->GetTypeFromURI(uri, getter_Copies(contentType));
if (NS_FAILED(rv) || contentType.IsEmpty())
rv = mimeService->GetTypeFromURI(uri, typeStr);
if (NS_FAILED(rv))
return PR_FALSE;
typeStr = contentType;
} else {
CopyUTF16toUTF8(type, typeStr);
}
nsXPIDLCString value;
rv = catman->GetCategoryEntry("Gecko-Content-Viewers",typeStr.get(), getter_Copies(value));
rv = catman->GetCategoryEntry("Gecko-Content-Viewers", typeStr.get(), getter_Copies(value));
// If we have a content viewer entry in the catagory manager for this mime type
// and it's not the full-page plugin one, return PR_TRUE to act like an IFRAME.

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

@ -1823,7 +1823,7 @@ nsresult nsSaveMsgListener::InitializeDownload(nsIRequest * aRequest, PRInt32 aB
nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID));
nsCOMPtr<nsIMIMEInfo> mimeinfo;
mimeService->GetFromTypeAndExtension(m_contentType.get(), nsnull, getter_AddRefs(mimeinfo));
mimeService->GetFromTypeAndExtension(m_contentType, EmptyCString(), getter_AddRefs(mimeinfo));
nsFileSpec realSpec;
m_fileSpec->GetFileSpec(&realSpec);

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

@ -3372,11 +3372,11 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, PRBool aQuoted, nsStrin
// Now, most importantly, we need to figure out what the content type is for
// this signature...if we can't, we assume text
nsXPIDLCString sigContentType;
nsCAutoString sigContentType;
nsresult rv2; // don't want to clobber the other rv
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv2));
if (NS_SUCCEEDED(rv2)) {
rv2 = mimeFinder->GetTypeFromFile(sigFile, getter_Copies(sigContentType));
rv2 = mimeFinder->GetTypeFromFile(sigFile, sigContentType);
if (NS_SUCCEEDED(rv2)) {
if (StringBeginsWith(sigContentType, NS_LITERAL_CSTRING("image/"), nsCaseInsensitiveCStringComparator()))
imageSig = PR_TRUE;

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

@ -2305,8 +2305,11 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments()
if (NS_SUCCEEDED(rv))
{
rv = fileUrl->GetFileExtension(fileExt);
if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty())
mimeFinder->GetTypeFromExtension(fileExt.get(), &(m_attachments[newLoc].m_type));
if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) {
nsCAutoString type;
mimeFinder->GetTypeFromExtension(fileExt, type);
m_attachments[newLoc].m_type = ToNewCString(type);
}
}
//Then try using the url if we still haven't figured out the content type
@ -2316,8 +2319,11 @@ nsMsgComposeAndSend::AddCompFieldLocalAttachments()
if (NS_SUCCEEDED(rv))
{
rv = fileUrl->GetFileExtension(fileExt);
if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty())
mimeFinder->GetTypeFromExtension(fileExt.get(), &(m_attachments[newLoc].m_type));
if (NS_SUCCEEDED(rv) && !fileExt.IsEmpty()) {
nsCAutoString type;
mimeFinder->GetTypeFromExtension(fileExt, type);
m_attachments[newLoc].m_type = ToNewCString(type);
}
}
}
}

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

@ -40,7 +40,6 @@
#include "nsMsgMdnGenerator.h"
#include "nsImapCore.h"
#include "nsIMsgImapMailFolder.h"
#include "nsIMIMEService.h"
#include "nsMsgMimeCID.h"
#include "nsIMsgAccountManager.h"
#include "nsMsgBaseCID.h"

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

@ -1891,8 +1891,8 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers )
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && mimeFinder)
{
nsXPIDLCString fileExtension;
rv = mimeFinder->GetPrimaryExtension(contentType.get(), nsnull, getter_Copies(fileExtension));
nsCAutoString fileExtension;
rv = mimeFinder->GetPrimaryExtension(contentType, EmptyCString(), fileExtension);
if (NS_SUCCEEDED(rv) && !fileExtension.IsEmpty())
{

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

@ -281,8 +281,8 @@ ValidateRealName(nsMsgAttachmentData *aAttach, MimeHeaders *aHdrs)
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
{
nsXPIDLCString fileExtension;
rv = mimeFinder->GetPrimaryExtension(contentType.get(), nsnull, getter_Copies(fileExtension));
nsCAutoString fileExtension;
rv = mimeFinder->GetPrimaryExtension(contentType, EmptyCString(), fileExtension);
if (NS_SUCCEEDED(rv) && !fileExtension.IsEmpty())
{
@ -724,8 +724,11 @@ mime_file_type (const char *filename, void *stream_closure)
{
ext++;
nsCOMPtr<nsIMIMEService> mimeFinder (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv) && mimeFinder)
mimeFinder->GetTypeFromExtension(ext, &retType);
if (mimeFinder) {
nsCAutoString type;
mimeFinder->GetTypeFromExtension(nsDependentCString(ext), type);
retType = ToNewCString(type);
}
}
return retType;

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

@ -489,12 +489,8 @@ nsJARChannel::GetContentType(nsACString &result)
}
if (ext) {
nsIMIMEService *mimeServ = gJarHandler->MimeService();
if (mimeServ) {
nsXPIDLCString mimeType;
nsresult rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
mContentType = mimeType;
}
if (mimeServ)
mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType);
}
if (mContentType.IsEmpty())
mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);

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

@ -332,8 +332,8 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports
nsCOMPtr<nsIMIMEInfo> mimeInfo;
if (mimeService && (!contentType.IsEmpty() || !fileExtension.IsEmpty()))
{
mimeService->GetFromTypeAndExtension(contentType.get(),
fileExtension.get(),
mimeService->GetFromTypeAndExtension(contentType,
fileExtension,
getter_AddRefs(mimeInfo));
}

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

@ -445,8 +445,8 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBloc
nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString fileExt;
mimeService->GetPrimaryExtension(contentType.get(), nsnull, getter_Copies(fileExt));
nsCAutoString fileExt;
mimeService->GetPrimaryExtension(contentType.get(), EmptyCString(), fileExt);
// If the mime service does not know about this mime type, we show
// the generic icon.
// In any case, we need to insert a '.' before the extension.

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

@ -253,8 +253,8 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBloc
nsCOMPtr<nsIMIMEService> mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString fileExt;
mimeService->GetPrimaryExtension(contentType.get(), nsnull, getter_Copies(fileExt));
nsCAutoString fileExt;
mimeService->GetPrimaryExtension(contentType, EmptyCString(), fileExt);
// If the mime service does not know about this mime type, we show
// the generic icon.
// In any case, we need to insert a '.' before the extension.

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

@ -3885,12 +3885,13 @@ nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsI
nsresult result = NS_ERROR_FAILURE;
nsIPluginInstance* instance = NULL;
nsCOMPtr<nsIPlugin> plugin = NULL;
const char* mimetype;
if(!aURL)
return NS_ERROR_FAILURE;
mimetype = aMimeType;
nsCAutoString mimetype;
if (aMimeType)
mimetype = aMimeType;
GetPluginFactory("*", getter_AddRefs(plugin));
@ -3917,21 +3918,21 @@ nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsI
// if we don't have a mimetype, check by file extension
nsXPIDLCString mt;
if(mimetype == nsnull)
if(mimetype.IsEmpty())
{
nsresult res = NS_OK;
nsCOMPtr<nsIMIMEService> ms (do_GetService(NS_MIMESERVICE_CONTRACTID, &res));
if(NS_SUCCEEDED(res))
{
nsXPIDLCString mt;
res = ms->GetTypeFromURI(aURL, getter_Copies(mt));
nsCAutoString mt;
res = ms->GetTypeFromURI(aURL, mt);
if(NS_SUCCEEDED(res))
mimetype = mt;
}
}
// set up the peer for the instance
peer->Initialize(aOwner, mimetype);
peer->Initialize(aOwner, mimetype.get());
nsCOMPtr<nsIPluginInstancePeer> pIpeer;
peer->QueryInterface(kIPluginInstancePeerIID, getter_AddRefs(pIpeer));

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

@ -54,7 +54,7 @@ interface nsIUTF8StringEnumerator;
typedef long nsMIMEInfoHandleAction;
[scriptable, uuid(4174ca8f-5a33-44fd-8735-ffb95baca30a)]
[scriptable, uuid(1448b42f-cf0d-466e-9a15-64e876ebe857)]
interface nsIMIMEInfo : nsISupports {
/**
* Gives you an array of file types associated with this type.
@ -67,7 +67,7 @@ interface nsIMIMEInfo : nsISupports {
/**
* Set File Extensions. Input is a comma delimited list of extensions.
*/
void SetFileExtensions(in string aExtensions);
void SetFileExtensions(in ACString aExtensions);
/**
* Returns whether or not the given extension is
@ -75,12 +75,12 @@ interface nsIMIMEInfo : nsISupports {
*
* @return TRUE if the association exists.
*/
boolean ExtensionExists(in string aExtension);
boolean ExtensionExists(in ACString aExtension);
/**
* Append a given extension to the set of extensions
*/
void AppendExtension(in string aExtension);
void AppendExtension(in ACString aExtension);
/**
* Returns the first extension association in
@ -88,21 +88,21 @@ interface nsIMIMEInfo : nsISupports {
*
* @return The first extension.
*/
attribute string primaryExtension;
attribute ACString primaryExtension;
/**
* The MIME type of this MIMEInfo.
*
* @return String representing the MIME type.
*/
attribute string MIMEType;
attribute ACString MIMEType;
/**
* A human readable description of the MIME info.
*
* @return The description
*/
attribute wstring Description;
attribute AString Description;
/**
* Mac Type and creator types
@ -129,7 +129,7 @@ interface nsIMIMEInfo : nsISupports {
/**
* A pretty name description of the preferred application.
*/
attribute wstring applicationDescription;
attribute AString applicationDescription;
/**
* Indicates whether a default application handler exists,
@ -142,7 +142,7 @@ interface nsIMIMEInfo : nsISupports {
* A pretty name description of the associated default application. Only
* usable if hasDefaultHandler is true.
*/
readonly attribute wstring defaultDescription;
readonly attribute AString defaultDescription;
/**
* Launches the application with the specified file, in a way that

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

@ -61,28 +61,28 @@
*
* @see nsIMIMEInfo
*/
[scriptable, uuid(6C424C90-2FE7-11d3-A164-0050041CAF44)]
[scriptable, uuid(5b3675a1-02db-4f8f-a560-b34736635f47)]
interface nsIMIMEService : nsISupports {
/**
* Retrieves an nsIMIMEInfo using both the extension
* and the type of a file. The type is given preference
* during the lookup. One of aMIMEType and aFileExt
* can be null. At least one of aMIMEType and aFileExt
* must be non-null and nonempty.
* can be an empty string. At least one of aMIMEType and aFileExt
* must be nonempty.
*/
nsIMIMEInfo getFromTypeAndExtension(in string aMIMEType, in string aFileExt);
nsIMIMEInfo getFromTypeAndExtension(in ACString aMIMEType, in ACString aFileExt);
/**
* Retrieves a string representation of the MIME type
* Retrieves a ACString representation of the MIME type
* associated with this file extension.
*
* @param A file extension (excluding the dot ('.')).
* @return The MIME type, if any.
*/
string getTypeFromExtension(in string aFileExt);
ACString getTypeFromExtension(in ACString aFileExt);
/**
* Retrieves a string representation of the MIME type
* Retrieves a ACString representation of the MIME type
* associated with this URI. The association is purely
* file extension to MIME type based. No attempt to determine
* the type via server headers or byte scanning is made.
@ -90,17 +90,17 @@ interface nsIMIMEService : nsISupports {
* @param The URI the user wants MIME info on.
* @return The MIME type, if any.
*/
string getTypeFromURI(in nsIURI aURI);
ACString getTypeFromURI(in nsIURI aURI);
//
string getTypeFromFile(in nsIFile aFile);
ACString getTypeFromFile(in nsIFile aFile);
/**
* Given a Type/Extension combination, returns the default extension
* for this type. This may be identical to the passed-in extension.
*
* @param aMIMEType The Type to get information on. Must not be null.
* @param aFileExt File Extension. Can be null.
* @param aMIMEType The Type to get information on. Must not be empty.
* @param aFileExt File Extension. Can be empty.
*/
string getPrimaryExtension(in string aMIMEType, in string aFileExt);
ACString getPrimaryExtension(in ACString aMIMEType, in ACString aFileExt);
};

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

@ -295,15 +295,12 @@ nsFileChannel::GetContentType(nsACString &aContentType)
nsresult rv = mURL->GetFile(getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString mimeType;
nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1", &rv);
if (NS_SUCCEEDED(rv))
mime->GetTypeFromFile(file, getter_Copies(mimeType));
mime->GetTypeFromFile(file, mContentType);
if (mimeType.IsEmpty())
if (mContentType.IsEmpty())
mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
else
mContentType = mimeType;
}
}

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

@ -39,7 +39,6 @@
#include "nsFTPChannel.h"
#include "nsIStreamListener.h"
#include "nsIServiceManager.h"
#include "nsIMIMEService.h"
#include "nsNetUtil.h"
#include "nsMimeTypes.h"
#include "nsIProxyObjectManager.h"

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

@ -36,7 +36,6 @@
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIURL.h"
#include "nsIMIMEService.h"
#include "nsIScriptSecurityManager.h"
#include "nsIIDNService.h"
#include "nsIStreamListenerTee.h"

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

@ -489,12 +489,8 @@ nsJARChannel::GetContentType(nsACString &result)
}
if (ext) {
nsIMIMEService *mimeServ = gJarHandler->MimeService();
if (mimeServ) {
nsXPIDLCString mimeType;
nsresult rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
if (NS_SUCCEEDED(rv))
mContentType = mimeType;
}
if (mimeServ)
mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType);
}
if (mContentType.IsEmpty())
mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);

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

@ -508,7 +508,7 @@ nsresult nsBinHexDecoder::SetContentType(nsIRequest* aRequest,
nsCOMPtr<nsIMIMEService> mimeService(do_GetService("@mozilla.org/mime;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLCString contentType;
nsCAutoString contentType;
// extract the extension from fileName and look it up.
const char * fileExt = strrchr(fileName, '.');
@ -516,7 +516,7 @@ nsresult nsBinHexDecoder::SetContentType(nsIRequest* aRequest,
return NS_OK;
}
mimeService->GetTypeFromExtension(fileExt, getter_Copies(contentType));
mimeService->GetTypeFromExtension(nsDependentCString(fileExt), contentType);
// Only set the type if it's not empty and, to prevent recursive loops, not the binhex type
if (!contentType.IsEmpty() && !contentType.Equals(APPLICATION_BINHEX)) {

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

@ -480,8 +480,8 @@ PRBool nsUnknownDecoder::SniffURI(nsIRequest* aRequest)
nsCOMPtr<nsIURI> uri;
nsresult result = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(result) && uri) {
nsXPIDLCString type;
result = mimeService->GetTypeFromURI(uri, getter_Copies(type));
nsCAutoString type;
result = mimeService->GetTypeFromURI(uri, type);
if (NS_SUCCEEDED(result)) {
mContentType = type;
return PR_TRUE;

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

@ -569,7 +569,7 @@ nsresult nsDocumentOpenInfo::DispatchContent(nsIRequest *request, nsISupports *
do_GetService(NS_EXTERNALHELPERAPPSERVICE_CONTRACTID, &rv);
if (helperAppService) {
LOG((" Passing load off to helper app service"));
rv = helperAppService->DoContent(mContentType.get(),
rv = helperAppService->DoContent(mContentType,
request,
m_originalContext,
getter_AddRefs(m_targetStreamListener));

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

@ -112,12 +112,11 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
nsresult rv = NS_ERROR_FAILURE;
nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS();
nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS(aMIMEType);
if (mimeInfo) {
NS_ADDREF(mimeInfo);
BMimeType mimeType(aMIMEType);
BMessage data;
mimeInfo->SetMIMEType(aMIMEType);
int32 index = 0;
BString strData;
LOG((" Adding extensions:\n"));
@ -127,7 +126,7 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
// it to the mime info object.
if (strData.ByteAt(0) == '.')
strData.RemoveFirst(".");
mimeInfo->AppendExtension(strData.String());
mimeInfo->AppendExtension(nsDependentCString(strData.String()));
LOG((" %s\n",strData.String()));
index++;
}
@ -135,12 +134,12 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
char desc[B_MIME_TYPE_LENGTH + 1];
if (mimeType.GetShortDescription(desc) == B_OK) {
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc).get());
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc));
} else {
if (mimeType.GetLongDescription(desc) == B_OK) {
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc).get());
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc));
} else {
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(aMIMEType).get());
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(aMIMEType));
}
}
@ -166,7 +165,7 @@ nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsIMIME
if (NS_SUCCEEDED(rv)) {
mimeInfo->SetDefaultApplication(handlerFile);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf()).get());
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf()));
LOG((" Preferred App: %s\n",path.Leaf()));
doSave = false;
}
@ -264,28 +263,28 @@ nsresult nsOSHelperAppService::GetMimeInfoFromMIMEType(const char *aMIMEType,
}
already_AddRefed<nsIMIMEInfo>
nsOSHelperAppService::GetMIMEInfoFromOS(const char *aMIMEType, const char *aFileExt, PRBool* aFound)
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool* aFound)
{
*aFound = PR_TRUE;
nsIMIMEInfo* mi = nsnull;
GetMimeInfoFromMIMEType(aMIMEType, &mi);
const nsCString& flatType = PromiseFlatCString(aMIMEType);
const nsCString& flatExt = PromiseFlatCString(aFileExt);
GetMimeInfoFromMIMEType(flatType.get(), &mi);
if (mi)
return mi;
GetMimeInfoFromExtension(aFileExt, &mi);
if (mi && aMIMEType && *aMIMEType)
GetMimeInfoFromExtension(flatExt.get(), &mi);
if (mi && !aMIMEType.IsEmpty())
mi->SetMIMEType(aMIMEType);
if (mi)
return mi;
*aFound = PR_FALSE;
mi = new nsMIMEInfoBeOS();
mi = new nsMIMEInfoBeOS(flatType.get());
if (!mi)
return nsnull;
NS_ADDREF(mi);
if (aMIMEType && *aMIMEType)
mi->SetMIMEType(aMIMEType);
if (aFileExt && *aFileExt)
if (!aFileExt.IsEmpty())
mi->AppendExtension(aFileExt);
return mi;

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

@ -51,7 +51,7 @@ public:
nsOSHelperAppService();
virtual ~nsOSHelperAppService();
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMIMEType, const char * aFileExt, PRBool *aFound);
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool *aFound);
// override nsIExternalProtocolService methods
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);

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

@ -371,22 +371,22 @@ nsresult nsInternetConfigService::FillMIMEInfoForICEntry(ICMapEntry& entry, nsIM
// get a file of type 'TEXT' with no mime type mapping so that we'll display the
// file rather than trying to download it.
if (entry.fileType == 'TEXT')
info->SetMIMEType(TEXT_PLAIN);
info->SetMIMEType(NS_LITERAL_CSTRING(TEXT_PLAIN));
else
info->SetMIMEType(APPLICATION_OCTET_STREAM);
info->SetMIMEType(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM));
}
// convert entry.extension which is a Str255
// don't forget to remove the '.' in front of the file extension....
nsCAutoString temp((char *)&entry.extension[2], entry.extension[0] > 0 ? (int)entry.extension[0]-1 : 0);
info->AppendExtension(temp.get());
info->AppendExtension(temp);
info->SetMacType(entry.fileType);
info->SetMacCreator(entry.fileCreator);
temp.Assign((char *) &entry.entryName[1], entry.entryName[0]);
info->SetDescription(NS_ConvertASCIItoUCS2(temp.get()).get());
info->SetDescription(NS_ConvertASCIItoUCS2(temp));
temp.Assign((char *) &entry.postAppName[1], entry.postAppName[0]);
info->SetDefaultDescription(NS_ConvertASCIItoUCS2(temp.get()).get());
info->SetDefaultDescription(NS_ConvertASCIItoUCS2(temp));
if (entry.flags & kICMapPostMask)
{

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

@ -176,7 +176,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAp
// method overrides --> use internet config information for mime type lookup.
///////////////////////////
NS_IMETHODIMP nsOSHelperAppService::GetFromTypeAndExtension(const char * aType, const char * aFileExt, nsIMIMEInfo ** aMIMEInfo)
NS_IMETHODIMP nsOSHelperAppService::GetFromTypeAndExtension(const nsACString& aType, const nsACString& aFileExt, nsIMIMEInfo ** aMIMEInfo)
{
// first, ask our base class....
nsresult rv = nsExternalHelperAppService::GetFromTypeAndExtension(aType, aFileExt, aMIMEInfo);
@ -188,30 +188,33 @@ NS_IMETHODIMP nsOSHelperAppService::GetFromTypeAndExtension(const char * aType,
}
already_AddRefed<nsIMIMEInfo>
nsOSHelperAppService::GetMIMEInfoFromOS(const char * aMIMEType,
const char * aFileExt,
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
const nsACString& aFileExt,
PRBool * aFound)
{
nsIMIMEInfo* mimeInfo = nsnull;
*aFound = PR_TRUE;
const nsCString& flatType = PromiseFlatCString(aMIMEType);
const nsCString& flatExt = PromiseFlatCString(aFileExt);
// ask the internet config service to look it up for us...
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
PR_LOG(mLog, PR_LOG_DEBUG, ("Mac: HelperAppService lookup for type '%s' ext '%s' (IC: 0x%p)\n",
aMIMEType, aFileExt, icService.get()));
flatType.get(), flatExt.get(), icService.get()));
if (icService)
{
nsCOMPtr<nsIMIMEInfo> miByType, miByExt;
if (aMIMEType && *aMIMEType)
icService->FillInMIMEInfo(aMIMEType, aFileExt, getter_AddRefs(miByType));
if (!aMIMEType.IsEmpty())
icService->FillInMIMEInfo(flatType.get(), flatExt.get(), getter_AddRefs(miByType));
PRBool hasDefault = PR_FALSE;
if (miByType)
miByType->GetHasDefaultHandler(&hasDefault);
if (aFileExt && *aFileExt && (!hasDefault || !miByType)) {
icService->GetMIMEInfoFromExtension(aFileExt, getter_AddRefs(miByExt));
if (miByExt && aMIMEType)
if (!aFileExt.IsEmpty() && (!hasDefault || !miByType)) {
icService->GetMIMEInfoFromExtension(flatExt.get(), getter_AddRefs(miByExt));
if (miByExt && !aMIMEType.IsEmpty())
miByExt->SetMIMEType(aMIMEType);
}
PR_LOG(mLog, PR_LOG_DEBUG, ("OS gave us: By Type: 0x%p By Ext: 0x%p type has default: %s\n",
@ -251,9 +254,9 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char * aMIMEType,
return nsnull;
NS_ADDREF(mimeInfo);
if (aMIMEType && *aMIMEType)
if (!aMIMEType.IsEmpty())
mimeInfo->SetMIMEType(aMIMEType);
if (aFileExt && *aFileExt)
if (!aFileExt.IsEmpty())
mimeInfo->AppendExtension(aFileExt);
}

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

@ -42,8 +42,8 @@ public:
NS_IMETHOD LoadUrl(nsIURI * aURL);
// method overrides --> used to hook the mime service into internet config....
NS_IMETHOD GetFromTypeAndExtension(const char * aType, const char * aFileExt, nsIMIMEInfo ** aMIMEInfo);
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char * aMIMEType, const char * aFileExt, PRBool * aFound);
NS_IMETHOD GetFromTypeAndExtension(const nsACString& aType, const nsACString& aFileExt, nsIMIMEInfo ** aMIMEInfo);
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool * aFound);
// GetFileTokenForPath must be implemented by each platform.
// platformAppPath --> a platform specific path to an application that we got out of the

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

@ -303,6 +303,7 @@ struct nsDefaultMimeTypeEntry {
/**
* Default extension->mimetype mappings. These are not overridable.
* If you add types here, make sure they are lowercase, or you'll regret it.
*/
static nsDefaultMimeTypeEntry defaultMimeEntries [] =
{
@ -347,6 +348,7 @@ struct nsExtraMimeTypeEntry {
* file extensions. These entries also ensure that we provide a good descriptive name
* when we encounter files with these content types and/or extensions. These can be
* overridden by user helper app prefs.
* If you add types here, make sure they are lowercase, or you'll regret it.
*/
static nsExtraMimeTypeEntry extraMimeEntries [] =
{
@ -486,7 +488,7 @@ nsresult nsExternalHelperAppService::InitDataSource()
return rv;
}
NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType,
NS_IMETHODIMP nsExternalHelperAppService::DoContent(const nsACString& aMimeContentType,
nsIRequest *aRequest,
nsISupports *aWindowContext,
nsIStreamListener ** aStreamListener)
@ -549,16 +551,16 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
}
LOG(("HelperAppService::DoContent: mime '%s', extension '%s'\n",
aMimeContentType, fileExtension.get()));
PromiseFlatCString(aMimeContentType).get(), fileExtension.get()));
// Try to find a mime object by looking at the mime type/extension
nsCOMPtr<nsIMIMEInfo> mimeInfo;
if (!nsCRT::strcasecmp(aMimeContentType, APPLICATION_GUESS_FROM_EXT)) {
nsXPIDLCString mimeType;
if (aMimeContentType.Equals(APPLICATION_GUESS_FROM_EXT, nsCaseInsensitiveCStringComparator())) {
nsCAutoString mimeType;
if (!fileExtension.IsEmpty()) {
GetFromTypeAndExtension(nsnull, fileExtension.get(), getter_AddRefs(mimeInfo));
GetFromTypeAndExtension(EmptyCString(), fileExtension, getter_AddRefs(mimeInfo));
if (mimeInfo) {
mimeInfo->GetMIMEType(getter_Copies(mimeType));
mimeInfo->GetMIMEType(mimeType);
LOG(("OS-Provided mime type '%s' for extension '%s'\n",
mimeType.get(), fileExtension.get()));
@ -567,12 +569,12 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
if (fileExtension.IsEmpty() || mimeType.IsEmpty()) {
// Extension lookup gave us no useful match
GetFromTypeAndExtension(APPLICATION_OCTET_STREAM, fileExtension.get(),
GetFromTypeAndExtension(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM), fileExtension,
getter_AddRefs(mimeInfo));
}
}
else {
GetFromTypeAndExtension(aMimeContentType, fileExtension.get(),
GetFromTypeAndExtension(aMimeContentType, fileExtension,
getter_AddRefs(mimeInfo));
}
LOG(("Type/Ext lookup found 0x%p\n", mimeInfo.get()));
@ -584,12 +586,12 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
*aStreamListener = nsnull;
// We want the mimeInfo's primary extension to pass it to
// CreateNewExternalHandler
nsXPIDLCString buf;
mimeInfo->GetPrimaryExtension(getter_Copies(buf));
nsCAutoString buf;
mimeInfo->GetPrimaryExtension(buf);
// this code is incomplete and just here to get things started..
nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo,
buf.get(),
buf,
fileName,
isAttachment,
aWindowContext);
@ -600,15 +602,15 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType
return NS_OK;
}
NS_IMETHODIMP nsExternalHelperAppService::ApplyDecodingForExtension(const char *aExtension, const char* aEncodingType, PRBool *aApplyDecoding)
NS_IMETHODIMP nsExternalHelperAppService::ApplyDecodingForExtension(const nsACString& aExtension,
const nsACString& aEncodingType,
PRBool *aApplyDecoding)
{
NS_PRECONDITION(aExtension, "Null extension");
NS_PRECONDITION(aEncodingType, "Null encoding type");
*aApplyDecoding = PR_TRUE;
PRUint32 i;
for(i = 0; i < NS_ARRAY_LENGTH(nonDecodableExtensions); ++i) {
if (!PL_strcasecmp(aExtension, nonDecodableExtensions[i].mFileExtension) &&
!PL_strcasecmp(aEncodingType, nonDecodableExtensions[i].mMimeType)) {
if (aExtension.Equals(nonDecodableExtensions[i].mFileExtension, nsCaseInsensitiveCStringComparator()) &&
aEncodingType.Equals(nonDecodableExtensions[i].mMimeType, nsCaseInsensitiveCStringComparator())) {
*aApplyDecoding = PR_FALSE;
break;
}
@ -617,7 +619,7 @@ NS_IMETHODIMP nsExternalHelperAppService::ApplyDecodingForExtension(const char *
}
nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler(nsIMIMEInfo * aMIMEInfo,
const char * aTempFileExtension,
const nsCSubstring& aTempFileExtension,
const nsAString& aFileName,
PRBool aIsAttachment,
nsISupports * aWindowContext)
@ -633,7 +635,7 @@ nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler(nsIM
return handler;
}
nsresult nsExternalHelperAppService::FillTopLevelProperties(const char * aContentType, nsIRDFResource * aContentTypeNodeResource,
nsresult nsExternalHelperAppService::FillTopLevelProperties(const nsCSubstring& aContentType, nsIRDFResource * aContentTypeNodeResource,
nsIRDFService * aRDFService, nsIMIMEInfo * aMIMEInfo)
{
nsresult rv = NS_OK;
@ -650,7 +652,7 @@ nsresult nsExternalHelperAppService::FillTopLevelProperties(const char * aConten
// set the pretty name description, if nonempty
FillLiteralValueFromTarget(aContentTypeNodeResource,kNC_Description, &stringValue);
if (stringValue && *stringValue)
aMIMEInfo->SetDescription(stringValue);
aMIMEInfo->SetDescription(nsDependentString(stringValue));
// now iterate over all the file type extensions...
nsCOMPtr<nsISimpleEnumerator> fileExtensions;
@ -674,7 +676,7 @@ nsresult nsExternalHelperAppService::FillTopLevelProperties(const char * aConten
literal->GetValueConst(&stringValue);
fileExtension.AssignWithConversion(stringValue);
if (!fileExtension.IsEmpty())
aMIMEInfo->AppendExtension(fileExtension.get());
aMIMEInfo->AppendExtension(fileExtension);
}
fileExtensions->HasMoreElements(&hasMoreElements);
@ -764,13 +766,13 @@ nsresult nsExternalHelperAppService::FillContentHandlerProperties(const char * a
aRDFService->GetResource(externalAppNodeName, getter_AddRefs(externalAppNodeResource));
// Clear out any possibly set preferred application, to match the datasource
aMIMEInfo->SetApplicationDescription(nsnull);
aMIMEInfo->SetApplicationDescription(EmptyString());
aMIMEInfo->SetPreferredApplicationHandler(nsnull);
if (externalAppNodeResource)
{
FillLiteralValueFromTarget(externalAppNodeResource, kNC_PrettyName, &stringValue);
if (stringValue)
aMIMEInfo->SetApplicationDescription(stringValue);
aMIMEInfo->SetApplicationDescription(nsDependentString(stringValue));
FillLiteralValueFromTarget(externalAppNodeResource, kNC_Path, &stringValue);
if (stringValue && stringValue[0])
@ -821,7 +823,7 @@ PRBool nsExternalHelperAppService::MIMETypeIsInDataSource(const char * aContentT
return PR_FALSE;
}
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const char * aContentType, nsIMIMEInfo * aMIMEInfo)
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const nsACString& aContentType, nsIMIMEInfo * aMIMEInfo)
{
NS_ENSURE_ARG_POINTER(aMIMEInfo);
nsresult rv = InitDataSource();
@ -860,7 +862,7 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const char * a
if (NS_SUCCEEDED(rv) && exists)
{
// fill the mimeinfo in based on the values from the data source
rv = FillTopLevelProperties(contentType.get(), contentTypeNodeResource, rdf, aMIMEInfo);
rv = FillTopLevelProperties(contentType, contentTypeNodeResource, rdf, aMIMEInfo);
NS_ENSURE_SUCCESS(rv, rv);
rv = FillContentHandlerProperties(contentType.get(), contentTypeNodeResource, rdf, aMIMEInfo);
@ -873,7 +875,7 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromDS(const char * a
return rv;
}
nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const char * aFileExtension, nsIMIMEInfo * aMIMEInfo)
nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const nsACString& aFileExtension, nsIMIMEInfo * aMIMEInfo)
{
NS_ENSURE_ARG_POINTER(aMIMEInfo);
@ -909,7 +911,7 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const char *
if (NS_SUCCEEDED(rv))
{
// fill the mimeinfo based on the values from the data source
rv = FillTopLevelProperties(contentTypeStr.get(), contentTypeNodeResource, rdf, aMIMEInfo);
rv = FillTopLevelProperties(contentTypeStr, contentTypeNodeResource, rdf, aMIMEInfo);
NS_ENSURE_SUCCESS(rv, rv);
rv = FillContentHandlerProperties(contentTypeStr.get(), contentTypeNodeResource, rdf, aMIMEInfo);
}
@ -919,7 +921,6 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const char *
return rv;
}
nsresult nsExternalHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAppPath,
nsIFile ** aFile)
{
@ -1261,8 +1262,8 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel)
}
// now append our extension.
nsXPIDLCString ext;
mMimeInfo->GetPrimaryExtension(getter_Copies(ext));
nsCAutoString ext;
mMimeInfo->GetPrimaryExtension(ext);
if (!ext.IsEmpty()) {
if (ext.First() != '.')
saltedTempLeafName.Append(PRUnichar('.'));
@ -1346,8 +1347,8 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
}
// Extract mime type for later use below.
nsXPIDLCString MIMEType;
mMimeInfo->GetMIMEType( getter_Copies( MIMEType ) );
nsCAutoString MIMEType;
mMimeInfo->GetMIMEType(MIMEType);
// retarget all load notifications to our docloader instead of the original window's docloader...
RetargetLoadNotifications(request);
@ -1377,8 +1378,8 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo
if (NS_SUCCEEDED(rv) && !encType.IsEmpty())
{
NS_ASSERTION(sSrv, "Where did the service go?");
sSrv->ApplyDecodingForExtension(extension.get(),
encType.get(),
sSrv->ApplyDecodingForExtension(extension,
encType,
&applyConversion);
}
}
@ -1766,7 +1767,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction()
}
nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo,
const char * aTempFileExtension,
const nsCSubstring& aTempFileExtension,
nsISupports * aWindowContext,
const nsAString& aSuggestedFilename,
PRBool aIsAttachment)
@ -1776,7 +1777,7 @@ nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo,
mHandlingAttachment = aIsAttachment;
// make sure the extention includes the '.'
if (aTempFileExtension && *aTempFileExtension != '.')
if (!aTempFileExtension.IsEmpty() && aTempFileExtension.First() != '.')
mTempFileExtension = PRUnichar('.');
mTempFileExtension.AppendWithConversion(aTempFileExtension);
@ -1807,9 +1808,9 @@ NS_IMETHODIMP nsExternalAppHandler::GetSource(nsIURI ** aSourceURI)
return NS_OK;
}
NS_IMETHODIMP nsExternalAppHandler::GetSuggestedFileName(PRUnichar ** aSuggestedFileName)
NS_IMETHODIMP nsExternalAppHandler::GetSuggestedFileName(nsAString& aSuggestedFileName)
{
*aSuggestedFileName = ToNewUnicode(mSuggestedFileName);
aSuggestedFileName = mSuggestedFileName;
return NS_OK;
}
@ -2216,12 +2217,13 @@ PRBool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, cons
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// nsIMIMEService methods
NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aMIMEType, const char *aFileExt, nsIMIMEInfo **_retval)
NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const nsACString& aMIMEType, const nsACString& aFileExt, nsIMIMEInfo **_retval)
{
NS_PRECONDITION((aMIMEType && *aMIMEType) ||
(aFileExt && *aFileExt),
NS_PRECONDITION(!aMIMEType.IsEmpty() ||
!aFileExt.IsEmpty(),
"Give me something to work with");
LOG(("Getting mimeinfo from type '%s' ext '%s'\n", aMIMEType, aFileExt));
LOG(("Getting mimeinfo from type '%s' ext '%s'\n",
PromiseFlatCString(aMIMEType).get(), PromiseFlatCString(aFileExt).get()));
*_retval = nsnull;
@ -2235,7 +2237,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
// (2) Now, let's see if we can find something in our datasource
nsresult rv = NS_ERROR_FAILURE;
if (aMIMEType && *aMIMEType) {
if (!aMIMEType.IsEmpty()) {
// This will not overwrite the OS information that interests us
// (i.e. default application, default app. description)
rv = GetMIMEInfoForMimeTypeFromDS(aMIMEType, *_retval);
@ -2246,11 +2248,11 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
if (!found || NS_FAILED(rv)) {
// No type match, try extension match
if (aFileExt && *aFileExt) {
if (!aFileExt.IsEmpty()) {
rv = GetMIMEInfoForExtensionFromDS(aFileExt, *_retval);
LOG(("Data source: Via ext: retval 0x%08x\n", rv));
found = found || NS_SUCCEEDED(rv);
if (NS_SUCCEEDED(rv) && aMIMEType && *aMIMEType)
if (NS_SUCCEEDED(rv) && !aMIMEType.IsEmpty())
(*_retval)->SetMIMEType(aMIMEType);
}
}
@ -2258,7 +2260,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
// (3) No match yet. Ask extras.
if (!found) {
rv = NS_ERROR_FAILURE;
if (aMIMEType && *aMIMEType) {
if (!aMIMEType.IsEmpty()) {
#ifdef XP_WIN
/* XXX Gross hack to wallpaper over the most common Win32
* extension issues caused by the fix for bug 116938. See bug
@ -2267,15 +2269,15 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
* right; any info we get from extras on this type is pretty much
* useless....
*/
if (PL_strcasecmp(aMIMEType, APPLICATION_OCTET_STREAM) != 0)
if (!aMIMEType.Equals(APPLICATION_OCTET_STREAM, nsCaseInsensitiveCStringComparator()))
#endif
rv = GetMIMEInfoForMimeTypeFromExtras(aMIMEType, *_retval);
LOG(("Searched extras (by type), rv 0x%08X\n", rv));
}
// If that didn't work out, try file extension from extras
if (NS_FAILED(rv) && aFileExt && *aFileExt) {
if (NS_FAILED(rv) && !aFileExt.IsEmpty()) {
rv = GetMIMEInfoForExtensionFromExtras(aFileExt, *_retval);
if (NS_SUCCEEDED(rv) && aMIMEType && *aMIMEType)
if (NS_SUCCEEDED(rv) && !aMIMEType.IsEmpty())
(*_retval)->SetMIMEType(aMIMEType);
LOG(("Searched extras (by ext), rv 0x%08X\n", rv));
}
@ -2283,22 +2285,22 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
// Finally, check if we got a file extension and if yes, if it is an
// extension on the mimeinfo, in which case we want it to be the primary one
if (aFileExt && *aFileExt) {
if (!aFileExt.IsEmpty()) {
PRBool matches = PR_FALSE;
(*_retval)->ExtensionExists(aFileExt, &matches);
LOG(("Extension '%s' matches mime info: %i\n", aFileExt, matches));
LOG(("Extension '%s' matches mime info: %i\n", PromiseFlatCString(aFileExt).get(), matches));
if (matches)
(*_retval)->SetPrimaryExtension(aFileExt);
}
// Verify we have a type.
nsXPIDLCString type;
(*_retval)->GetMIMEType(getter_Copies(type));
nsCAutoString type;
(*_retval)->GetMIMEType(type);
#ifdef PR_LOGGING
if (LOG_ENABLED()) {
nsXPIDLCString ext;
(*_retval)->GetPrimaryExtension(getter_Copies(ext));
nsCAutoString ext;
(*_retval)->GetPrimaryExtension(ext);
LOG(("MIME Info Summary: Type '%s', Primary Ext '%s'\n", type.get(), ext.get()));
}
#endif
@ -2312,28 +2314,29 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const char *aM
}
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const char *aFileExt, char **aContentType)
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt, nsACString& aContentType)
{
nsresult rv = NS_OK;
// First of all, check our default entries
for (size_t i = 0; i < NS_ARRAY_LENGTH(defaultMimeEntries); i++)
{
if (nsCRT::strcasecmp(defaultMimeEntries[i].mFileExtension, aFileExt) == 0) {
*aContentType = nsCRT::strdup(defaultMimeEntries[i].mMimeType);
if (aFileExt.Equals(defaultMimeEntries[i].mFileExtension, nsCaseInsensitiveCStringComparator())) {
aContentType = defaultMimeEntries[i].mMimeType;
return rv;
}
}
const nsCString& flatExt = PromiseFlatCString(aFileExt);
nsCOMPtr<nsIMIMEInfo> info;
rv = GetFromTypeAndExtension(nsnull, aFileExt, getter_AddRefs(info));
rv = GetFromTypeAndExtension(EmptyCString(), aFileExt, getter_AddRefs(info));
if (NS_FAILED(rv)) {
// Try the plugins
const char* mimeType;
nsCOMPtr<nsIPluginHost> pluginHost (do_GetService(kPluginManagerCID, &rv));
if (NS_SUCCEEDED(rv)) {
if (pluginHost->IsPluginEnabledForExtension(aFileExt, mimeType) == NS_OK)
if (pluginHost->IsPluginEnabledForExtension(flatExt.get(), mimeType) == NS_OK)
{
*aContentType = nsCRT::strdup(mimeType);
aContentType = mimeType;
rv = NS_OK;
return rv;
}
@ -2349,18 +2352,21 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromExtension(const char *aFile
else {
// Let's see if an extension added something
nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
if (catMan)
rv = catMan->GetCategoryEntry("ext-to-type-mapping", aFileExt, aContentType);
else
if (catMan) {
nsXPIDLCString type;
rv = catMan->GetCategoryEntry("ext-to-type-mapping", flatExt.get(), getter_Copies(type));
aContentType = type;
}
else {
rv = NS_ERROR_NOT_AVAILABLE;
}
}
return rv;
}
NS_IMETHODIMP nsExternalHelperAppService::GetPrimaryExtension(const char* aMIMEType, const char* aFileExt, char** _retval)
NS_IMETHODIMP nsExternalHelperAppService::GetPrimaryExtension(const nsACString& aMIMEType, const nsACString& aFileExt, nsACString& _retval)
{
NS_ENSURE_ARG_POINTER(aMIMEType);
NS_ENSURE_ARG(!aMIMEType.IsEmpty());
nsCOMPtr<nsIMIMEInfo> mi;
nsresult rv = GetFromTypeAndExtension(aMIMEType, aFileExt, getter_AddRefs(mi));
@ -2370,11 +2376,10 @@ NS_IMETHODIMP nsExternalHelperAppService::GetPrimaryExtension(const char* aMIMET
return mi->GetPrimaryExtension(_retval);
}
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromURI(nsIURI *aURI, char **aContentType)
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromURI(nsIURI *aURI, nsACString& aContentType)
{
NS_PRECONDITION(aContentType, "Null out param!");
nsresult rv = NS_ERROR_NOT_AVAILABLE;
*aContentType = nsnull;
aContentType.Truncate();
// First look for a file to use. If we have one, we just use that.
nsCOMPtr<nsIFileURL> fileUrl = do_QueryInterface(aURI);
@ -2399,7 +2404,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromURI(nsIURI *aURI, char **aC
if (ext.IsEmpty()) {
return NS_ERROR_NOT_AVAILABLE;
}
return GetTypeFromExtension(ext.get(), aContentType);
return GetTypeFromExtension(ext, aContentType);
}
// no url, let's give the raw spec a shot
@ -2416,16 +2421,14 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromURI(nsIURI *aURI, char **aC
// extension.... Dat dere would be just data.
specLength - extLoc < 20)
{
return GetTypeFromExtension(PromiseFlatCString(
Substring(specStr, extLoc + 1, specStr.Length() - extLoc - 1)
).get(), aContentType);
return GetTypeFromExtension(Substring(specStr, extLoc + 1), aContentType);
}
// We found no information; say so.
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile( nsIFile* aFile, char **aContentType )
NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile(nsIFile* aFile, nsACString& aContentType)
{
nsresult rv;
nsCOMPtr<nsIMIMEInfo> info;
@ -2449,7 +2452,7 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile( nsIFile* aFile, char
}
}
nsCAutoString fileExt( ext );
nsDependentCString fileExt( ext );
// Handle the mac case
#if defined(XP_MAC) || defined (XP_MACOSX)
nsCOMPtr<nsILocalFileMac> macFile;
@ -2471,15 +2474,14 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile( nsIFile* aFile, char
// Windows, unix and mac when no type match occured.
if (fileExt.IsEmpty())
return NS_ERROR_FAILURE;
return GetTypeFromExtension( fileExt.get(), aContentType );
return GetTypeFromExtension( fileExt, aContentType );
}
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromExtras(const char * aContentType, nsIMIMEInfo * aMIMEInfo )
nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromExtras(const nsACString& aContentType, nsIMIMEInfo * aMIMEInfo )
{
NS_ENSURE_ARG( aMIMEInfo );
NS_ENSURE_ARG_POINTER( aContentType );
NS_ENSURE_ARG( *aContentType );
NS_ENSURE_ARG( !aContentType.IsEmpty() );
// Look for default entry with matching mime type.
nsCAutoString MIMEType(aContentType);
@ -2490,28 +2492,25 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForMimeTypeFromExtras(const char
if ( MIMEType.Equals(extraMimeEntries[index].mMimeType) )
{
// This is the one. Set attributes appropriately.
aMIMEInfo->SetFileExtensions(extraMimeEntries[index].mFileExtensions);
aMIMEInfo->SetDescription(NS_ConvertASCIItoUCS2(extraMimeEntries[index].mDescription).get());
aMIMEInfo->SetFileExtensions(nsDependentCString(extraMimeEntries[index].mFileExtensions));
aMIMEInfo->SetDescription(NS_ConvertASCIItoUCS2(extraMimeEntries[index].mDescription));
aMIMEInfo->SetMacType(extraMimeEntries[index].mMactype);
aMIMEInfo->SetMacCreator(extraMimeEntries[index].mMacCreator);
return NS_OK;
}
}
return NS_ERROR_NOT_AVAILABLE;
}
nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromExtras(const char* aExtension, nsIMIMEInfo * aMIMEInfo )
nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromExtras(const nsACString& aExtension, nsIMIMEInfo * aMIMEInfo )
{
NS_ENSURE_ARG( aMIMEInfo );
NS_ASSERTION(aExtension, "Null aExtension parameter!");
NS_ASSERTION(*aExtension, "Empty aExtension parameter!");
NS_ASSERTION(!aExtension.IsEmpty(), "Empty aExtension parameter!");
// Look for default entry with matching extension.
nsDependentCString extension(aExtension);
nsDependentCString::const_iterator start, end, iter;
PRInt32 numEntries = NS_ARRAY_LENGTH(extraMimeEntries);
for (PRInt32 index = 0; index < numEntries; index++)
@ -2523,13 +2522,13 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromExtras(const cha
while (start != end)
{
FindCharInReadable(',', iter, end);
if (Substring(start, iter).Equals(extension,
if (Substring(start, iter).Equals(aExtension,
nsCaseInsensitiveCStringComparator()))
{
// Set attributes appropriately.
aMIMEInfo->SetMIMEType(extraMimeEntries[index].mMimeType);
aMIMEInfo->SetFileExtensions(extraMimeEntries[index].mFileExtensions);
aMIMEInfo->SetDescription(NS_ConvertASCIItoUCS2(extraMimeEntries[index].mDescription).get());
aMIMEInfo->SetMIMEType(nsDependentCString(extraMimeEntries[index].mMimeType));
aMIMEInfo->SetFileExtensions(nsDependentCString(extraMimeEntries[index].mFileExtensions));
aMIMEInfo->SetDescription(NS_ConvertASCIItoUCS2(extraMimeEntries[index].mDescription));
aMIMEInfo->SetMacType(extraMimeEntries[index].mMactype);
aMIMEInfo->SetMacCreator(extraMimeEntries[index].mMacCreator);

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

@ -108,7 +108,7 @@ public:
* @param aWindowContext Window context, as passed to DoContent
*/
nsExternalAppHandler * CreateNewExternalHandler(nsIMIMEInfo * aMIMEInfo,
const char * aFileExtension,
const nsCSubstring& aFileExtension,
const nsAString& aFileName,
PRBool aIsAttachment,
nsISupports * aWindowContext);
@ -119,7 +119,7 @@ public:
* over ride information is contained in a in memory data source.
* @param aMIMEInfo The mime info to fill with the information
*/
nsresult GetMIMEInfoForMimeTypeFromDS(const char * aContentType,
nsresult GetMIMEInfoForMimeTypeFromDS(const nsACString& aContentType,
nsIMIMEInfo * aMIMEInfo);
/**
@ -128,7 +128,7 @@ public:
* information is contained in a in memory data source.
* @param aMIMEInfo The mime info to fill with the information
*/
nsresult GetMIMEInfoForExtensionFromDS(const char * aFileExtension,
nsresult GetMIMEInfoForExtensionFromDS(const nsACString& aFileExtension,
nsIMIMEInfo * aMIMEInfo);
/**
@ -145,8 +145,8 @@ public:
* returning one is an out-of-memory error.
* If null, the value of aFound is unspecified.
*/
virtual already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char * aMIMEType,
const char * aFileExt,
virtual already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType,
const nsACString& aFileExt,
PRBool * aFound) = 0;
/**
@ -179,9 +179,9 @@ protected:
*/
nsCOMPtr<nsIRDFDataSource> mOverRideDataSource;
nsCOMPtr<nsIRDFResource> kNC_Description;
nsCOMPtr<nsIRDFResource> kNC_Value;
nsCOMPtr<nsIRDFResource> kNC_FileExtensions;
nsCOMPtr<nsIRDFResource> kNC_Description;
nsCOMPtr<nsIRDFResource> kNC_Value;
nsCOMPtr<nsIRDFResource> kNC_FileExtensions;
nsCOMPtr<nsIRDFResource> kNC_Path;
nsCOMPtr<nsIRDFResource> kNC_UseSystemDefault;
nsCOMPtr<nsIRDFResource> kNC_SaveToDisk;
@ -198,7 +198,7 @@ protected:
* Helper routines for digesting the data source and filling in a mime info
* object for a given content type inside that data source.
*/
nsresult FillTopLevelProperties(const char * aContentType,
nsresult FillTopLevelProperties(const nsCSubstring& aContentType,
nsIRDFResource * aContentTypeNodeResource,
nsIRDFService * aRDFService,
nsIMIMEInfo * aMIMEInfo);
@ -227,14 +227,14 @@ protected:
* @param aContentType The type to search for.
* @param aMIMEInfo [inout] The mime info, if found
*/
nsresult GetMIMEInfoForMimeTypeFromExtras(const char * aContentType,
nsresult GetMIMEInfoForMimeTypeFromExtras(const nsACString& aContentType,
nsIMIMEInfo * aMIMEInfo);
/**
* Searches the "extra" array of MIMEInfo objects for an object
* with a specific extension.
* @see GetMIMEInfoForMimeTypeFromExtras
*/
nsresult GetMIMEInfoForExtensionFromExtras(const char * aExtension,
nsresult GetMIMEInfoForExtensionFromExtras(const nsACString& aExtension,
nsIMIMEInfo * aMIMEInfo);
/**
@ -296,7 +296,7 @@ public:
nsExternalAppHandler();
~nsExternalAppHandler();
nsresult Init(nsIMIMEInfo * aMIMEInfo, const char * aFileExtension,
nsresult Init(nsIMIMEInfo * aMIMEInfo, const nsCSubstring& aFileExtension,
nsISupports * aWindowContext,
const nsAString& aFilename,
PRBool aIsAttachment);

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

@ -33,7 +33,7 @@ interface nsIWebProgressListener;
* The external helper app service is used for finding and launching
* platform specific external applications for a given mime content type.
*/
[scriptable, uuid(663CC0AA-42EA-11d4-98D0-001083010E9B)]
[scriptable, uuid(8a902933-d1a2-48a1-93a5-da64d6a2786f)]
interface nsIExternalHelperAppService : nsISupports
{
/**
@ -48,7 +48,7 @@ interface nsIExternalHelperAppService : nsISupports
* The service might need this in order to bring up dialogs.
* @return A nsIStreamListener which the caller should pump the data into.
*/
nsIStreamListener doContent (in string aMimeContentType, in nsIRequest aRequest,
nsIStreamListener doContent (in ACString aMimeContentType, in nsIRequest aRequest,
in nsISupports aWindowContext);
/**
@ -56,8 +56,8 @@ interface nsIExternalHelperAppService : nsISupports
* is to be decoded from aEncodingType prior to saving or passing
* off to helper apps, false otherwise.
*/
boolean applyDecodingForExtension(in string aExtension,
in string aEncodingType);
boolean applyDecodingForExtension(in ACString aExtension,
in ACString aEncodingType);
};
@ -80,7 +80,7 @@ interface nsPIExternalAppLauncher : nsISupports
* A helper app launcher is a small object created to handle the launching
* of an external application.
*/
[scriptable, uuid(9503D0FE-4C9D-11d4-98D0-001083010E9B)]
[scriptable, uuid(15437993-9732-4aaf-977b-69a16b6334ff)]
interface nsIHelperAppLauncher : nsISupports
{
/**
@ -97,7 +97,7 @@ interface nsIHelperAppLauncher : nsISupports
/**
* The suggested name for this file
*/
readonly attribute wstring suggestedFileName;
readonly attribute AString suggestedFileName;
/**
* Called when we want to just save the content to a particular file.

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

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=4 sw=4 sts=4 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -63,19 +64,16 @@ nsMIMEInfoBase::GetFileExtensions(nsIUTF8StringEnumerator** aResult)
}
NS_IMETHODIMP
nsMIMEInfoBase::ExtensionExists(const char *aExtension, PRBool *_retval)
nsMIMEInfoBase::ExtensionExists(const nsACString& aExtension, PRBool *_retval)
{
NS_ASSERTION(aExtension, "no extension");
NS_ASSERTION(!aExtension.IsEmpty(), "no extension");
PRBool found = PR_FALSE;
PRUint32 extCount = mExtensions.Count();
if (extCount < 1) return NS_OK;
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(extension, nsCaseInsensitiveCStringComparator())) {
if (ext->Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
found = PR_TRUE;
break;
}
@ -86,27 +84,25 @@ nsMIMEInfoBase::ExtensionExists(const char *aExtension, PRBool *_retval)
}
NS_IMETHODIMP
nsMIMEInfoBase::GetPrimaryExtension(char **_retval)
nsMIMEInfoBase::GetPrimaryExtension(nsACString& _retval)
{
PRUint32 extCount = mExtensions.Count();
if (extCount < 1) return NS_ERROR_NOT_INITIALIZED;
*_retval = ToNewCString(*(mExtensions.CStringAt(0)));
if (!*_retval) return NS_ERROR_OUT_OF_MEMORY;
_retval = *(mExtensions.CStringAt(0));
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetPrimaryExtension(const char *aExtension)
nsMIMEInfoBase::SetPrimaryExtension(const nsACString& aExtension)
{
NS_ASSERTION(aExtension, "no extension");
NS_ASSERTION(!aExtension.IsEmpty(), "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())) {
if (ext->Equals(aExtension, nsCaseInsensitiveCStringComparator())) {
found = PR_TRUE;
break;
}
@ -115,55 +111,47 @@ nsMIMEInfoBase::SetPrimaryExtension(const char *aExtension)
mExtensions.RemoveCStringAt(i);
}
mExtensions.InsertCStringAt(extension, 0);
mExtensions.InsertCStringAt(aExtension, 0);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::AppendExtension(const char *aExtension)
nsMIMEInfoBase::AppendExtension(const nsACString& aExtension)
{
mExtensions.AppendCString( nsCAutoString(aExtension) );
return NS_OK;
mExtensions.AppendCString(aExtension);
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetMIMEType(char * *aMIMEType)
nsMIMEInfoBase::GetMIMEType(nsACString& aMIMEType)
{
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
if (mMIMEType.IsEmpty())
return NS_ERROR_NOT_INITIALIZED;
*aMIMEType = ToNewCString(mMIMEType);
if (!*aMIMEType) return NS_ERROR_OUT_OF_MEMORY;
aMIMEType = mMIMEType;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetMIMEType(const char* aMIMEType)
nsMIMEInfoBase::SetMIMEType(const nsACString& aMIMEType)
{
if (!aMIMEType) return NS_ERROR_NULL_POINTER;
mMIMEType=aMIMEType;
mMIMEType = aMIMEType;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetDescription(PRUnichar * *aDescription)
nsMIMEInfoBase::GetDescription(nsAString& aDescription)
{
if (!aDescription) return NS_ERROR_NULL_POINTER;
*aDescription = ToNewUnicode(mDescription);
if (!*aDescription) return NS_ERROR_OUT_OF_MEMORY;
aDescription = mDescription;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetDescription(const PRUnichar * aDescription)
nsMIMEInfoBase::SetDescription(const nsAString& aDescription)
{
mDescription = aDescription;
return NS_OK;
mDescription = aDescription;
return NS_OK;
}
NS_IMETHODIMP
@ -171,8 +159,8 @@ nsMIMEInfoBase::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
{
if (!aMIMEInfo) return NS_ERROR_NULL_POINTER;
nsXPIDLCString type;
nsresult rv = aMIMEInfo->GetMIMEType(getter_Copies(type));
nsCAutoString type;
nsresult rv = aMIMEInfo->GetMIMEType(type);
if (NS_FAILED(rv)) return rv;
*_retval = mMIMEType.Equals(type);
@ -183,77 +171,74 @@ nsMIMEInfoBase::Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval)
NS_IMETHODIMP
nsMIMEInfoBase::GetMacType(PRUint32 *aMacType)
{
*aMacType = mMacType;
return NS_OK;
*aMacType = mMacType;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetMacType(PRUint32 aMacType)
{
mMacType = aMacType;
return NS_OK;
mMacType = aMacType;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetMacCreator(PRUint32 *aMacCreator)
{
*aMacCreator = mMacCreator;
return NS_OK;
*aMacCreator = mMacCreator;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetMacCreator(PRUint32 aMacCreator)
{
mMacCreator = aMacCreator;
return NS_OK;
mMacCreator = aMacCreator;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetFileExtensions(const char* aExtensions)
nsMIMEInfoBase::SetFileExtensions(const nsACString& aExtensions)
{
mExtensions.Clear();
nsCString extList( aExtensions );
PRInt32 breakLocation = -1;
while ( (breakLocation= extList.FindChar(',') )!= -1)
{
nsCString ext( extList.get(), breakLocation );
mExtensions.AppendCString( ext );
extList.Cut(0, breakLocation+1 );
}
if ( !extList.IsEmpty() )
mExtensions.AppendCString( extList );
return NS_OK;
mExtensions.Clear();
nsCString extList( aExtensions );
PRInt32 breakLocation = -1;
while ( (breakLocation= extList.FindChar(',') )!= -1)
{
mExtensions.AppendCString(Substring(extList.get(), extList.get() + breakLocation));
extList.Cut(0, breakLocation+1 );
}
if ( !extList.IsEmpty() )
mExtensions.AppendCString( extList );
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetApplicationDescription(PRUnichar ** aApplicationDescription)
nsMIMEInfoBase::GetApplicationDescription(nsAString& aApplicationDescription)
{
if (mPreferredAppDescription.IsEmpty() && mPreferredApplication) {
// Don't want to cache this, just in case someone resets the app
// without changing the description....
nsAutoString leafName;
mPreferredApplication->GetLeafName(leafName);
*aApplicationDescription = ToNewUnicode(leafName);
mPreferredApplication->GetLeafName(aApplicationDescription);
} else {
*aApplicationDescription = ToNewUnicode(mPreferredAppDescription);
aApplicationDescription = mPreferredAppDescription;
}
return *aApplicationDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::SetApplicationDescription(const PRUnichar * aApplicationDescription)
nsMIMEInfoBase::SetApplicationDescription(const nsAString& aApplicationDescription)
{
mPreferredAppDescription = aApplicationDescription;
return NS_OK;
}
NS_IMETHODIMP
nsMIMEInfoBase::GetDefaultDescription(PRUnichar ** aDefaultDescription)
nsMIMEInfoBase::GetDefaultDescription(nsAString& aDefaultDescription)
{
*aDefaultDescription = ToNewUnicode(mDefaultAppDescription);
return *aDefaultDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
aDefaultDescription = mDefaultAppDescription;
return NS_OK;
}
NS_IMETHODIMP
@ -352,19 +337,17 @@ nsMIMEInfoBase::LaunchWithIProcess(nsIFile* aApp, nsIFile* aFile)
// nsMIMEInfoImpl implementation
NS_IMETHODIMP
nsMIMEInfoImpl::GetDefaultDescription(PRUnichar ** aDefaultDescription)
nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription)
{
if (mDefaultAppDescription.IsEmpty() && mDefaultApplication) {
// Don't want to cache this, just in case someone resets the app
// without changing the description....
nsAutoString leafName;
mDefaultApplication->GetLeafName(leafName);
*aDefaultDescription = ToNewUnicode(leafName);
mDefaultApplication->GetLeafName(aDefaultDescription);
} else {
*aDefaultDescription = ToNewUnicode(mDefaultAppDescription);
aDefaultDescription = mDefaultAppDescription;
}
return *aDefaultDescription ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP

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

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
@ -56,15 +57,15 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
// I'd use NS_DECL_NSIMIMEINFO, but I don't want GetHasDefaultHandler
NS_IMETHOD GetFileExtensions(nsIUTF8StringEnumerator **_retval);
NS_IMETHOD SetFileExtensions(const char *aExtensions);
NS_IMETHOD ExtensionExists(const char *aExtension, PRBool *_retval);
NS_IMETHOD AppendExtension(const char *aExtension);
NS_IMETHOD GetPrimaryExtension(char * *aPrimaryExtension);
NS_IMETHOD SetPrimaryExtension(const char * aPrimaryExtension);
NS_IMETHOD GetMIMEType(char * *aMIMEType);
NS_IMETHOD SetMIMEType(const char * aMIMEType);
NS_IMETHOD GetDescription(PRUnichar * *aDescription);
NS_IMETHOD SetDescription(const PRUnichar * aDescription);
NS_IMETHOD SetFileExtensions(const nsACString & aExtensions);
NS_IMETHOD ExtensionExists(const nsACString & aExtension, PRBool *_retval);
NS_IMETHOD AppendExtension(const nsACString & aExtension);
NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension);
NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension);
NS_IMETHOD GetMIMEType(nsACString & aMIMEType);
NS_IMETHOD SetMIMEType(const nsACString & aMIMEType);
NS_IMETHOD GetDescription(nsAString & aDescription);
NS_IMETHOD SetDescription(const nsAString & aDescription);
NS_IMETHOD GetMacType(PRUint32 *aMacType);
NS_IMETHOD SetMacType(PRUint32 aMacType);
NS_IMETHOD GetMacCreator(PRUint32 *aMacCreator);
@ -72,20 +73,20 @@ class nsMIMEInfoBase : public nsIMIMEInfo {
NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, PRBool *_retval);
NS_IMETHOD GetPreferredApplicationHandler(nsIFile * *aPreferredApplicationHandler);
NS_IMETHOD SetPreferredApplicationHandler(nsIFile * aPreferredApplicationHandler);
NS_IMETHOD GetApplicationDescription(PRUnichar * *aApplicationDescription);
NS_IMETHOD SetApplicationDescription(const PRUnichar * aApplicationDescription);
NS_IMETHOD GetDefaultDescription(PRUnichar * *aDefaultDescription);
NS_IMETHOD GetApplicationDescription(nsAString & aApplicationDescription);
NS_IMETHOD SetApplicationDescription(const nsAString & aApplicationDescription);
NS_IMETHOD GetDefaultDescription(nsAString & aDefaultDescription);
NS_IMETHOD LaunchWithFile(nsIFile *aFile);
NS_IMETHOD GetPreferredAction(nsMIMEInfoHandleAction *aPreferredAction);
NS_IMETHOD SetPreferredAction(nsMIMEInfoHandleAction aPreferredAction);
NS_IMETHOD GetAlwaysAskBeforeHandling(PRBool *aAlwaysAskBeforeHandling);
NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling);
NS_IMETHOD SetAlwaysAskBeforeHandling(PRBool aAlwaysAskBeforeHandling);
// nsMIMEInfoBase methods
nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN;
virtual ~nsMIMEInfoBase(); // must be virtual, as the the base class's Release should call the subclass's destructor
void SetDefaultDescription(const PRUnichar* aDesc) { mDefaultAppDescription = aDesc; }
void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
/**
* Copies basic data of this MIME Info Implementation to the given other
@ -146,7 +147,7 @@ class nsMIMEInfoImpl : public nsMIMEInfoBase {
// nsIMIMEInfo methods
NS_IMETHOD GetHasDefaultHandler(PRBool *_retval);
NS_IMETHOD GetDefaultDescription(PRUnichar ** aDefaultDescription);
NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
// additional methods
void SetDefaultApplication(nsIFile* aApp) { mDefaultApplication = aApp; }

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

@ -1338,12 +1338,12 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
}
already_AddRefed<nsMIMEInfoOS2>
nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
// if the extension is null, return immediately
if (!aFileExt || !*aFileExt)
nsOSHelperAppService::GetFromExtension(const nsCString& aFileExt) {
// if the extension is empty, return immediately
if (aFileExt.IsEmpty())
return nsnull;
LOG(("Here we do an extension lookup for '%s'\n", aFileExt));
LOG(("Here we do an extension lookup for '%s'\n", aFileExt.get()));
nsresult rv;
@ -1402,9 +1402,9 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
mailcap_description.Trim(" \t\"");
mozillaFlags.Trim(" \t");
if (!mime_types_description.IsEmpty()) {
mimeInfo->SetDescription(mime_types_description.get());
mimeInfo->SetDescription(mime_types_description);
} else {
mimeInfo->SetDescription(mailcap_description.get());
mimeInfo->SetDescription(mailcap_description);
}
if (NS_SUCCEEDED(rv) && !handler.IsEmpty()) {
nsCOMPtr<nsIFile> handlerFile;
@ -1413,7 +1413,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
if (NS_SUCCEEDED(rv)) {
mimeInfo->SetDefaultApplication(handlerFile);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
mimeInfo->SetDefaultDescription(handler.get());
mimeInfo->SetDefaultDescription(handler);
}
} else {
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
@ -1423,12 +1423,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
}
already_AddRefed<nsMIMEInfoOS2>
nsOSHelperAppService::GetFromType(const char *aMIMEType) {
// if the extension is null, return immediately
if (!aMIMEType || !*aMIMEType)
nsOSHelperAppService::GetFromType(const nsCString& aMIMEType) {
// if the extension is empty, return immediately
if (aMIMEType.IsEmpty())
return nsnull;
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType));
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
nsresult rv;
nsAutoString extensions,
mime_types_description, mailcap_description,
@ -1437,8 +1437,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
nsHashtable typeOptions;
// extract the major and minor types
nsAutoString mimeType;
mimeType.AssignWithConversion(aMIMEType);
NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
nsAString::const_iterator start_iter, end_iter,
majorTypeStart, majorTypeEnd,
minorTypeStart, minorTypeEnd;
@ -1495,16 +1494,16 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
extensions,
mime_types_description);
nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(aMIMEType);
nsMIMEInfoOS2* mimeInfo = new nsMIMEInfoOS2(aMIMEType.get());
if (!mimeInfo)
return nsnull;
NS_ADDREF(mimeInfo);
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions).get());
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions));
if (! mime_types_description.IsEmpty()) {
mimeInfo->SetDescription(mime_types_description.get());
mimeInfo->SetDescription(mime_types_description);
} else {
mimeInfo->SetDescription(mailcap_description.get());
mimeInfo->SetDescription(mailcap_description);
}
nsCOMPtr<nsIFile> handlerFile;
@ -1513,7 +1512,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
if (NS_SUCCEEDED(rv)) {
mimeInfo->SetDefaultApplication(handlerFile);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
mimeInfo->SetDefaultDescription(handler.get());
mimeInfo->SetDefaultDescription(handler);
} else {
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
}
@ -1523,23 +1522,23 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
already_AddRefed<nsIMIMEInfo>
nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
const char *aFileExt,
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType,
const nsACString& aFileExt,
PRBool *aFound) {
*aFound = PR_TRUE;
nsMIMEInfoOS2* retval = GetFromType(aType).get();
nsMIMEInfoOS2* retval = GetFromType(PromiseFlatCString(aType)).get();
PRBool hasDefault = PR_FALSE;
if (retval)
retval->GetHasDefaultHandler(&hasDefault);
if (!retval || !hasDefault) {
nsRefPtr<nsMIMEInfoOS2> miByExt = GetFromExtension(aFileExt);
nsRefPtr<nsMIMEInfoOS2> miByExt = GetFromExtension(PromiseFlatCString(aFileExt));
// If we had no extension match, but a type match, use that
if (!miByExt && retval)
return retval;
// If we had an extension match but no type match, set the mimetype and use
// it
if (!retval && miByExt) {
if (aType)
if (!aType.IsEmpty())
miByExt->SetMIMEType(aType);
miByExt.swap(retval);
@ -1548,12 +1547,10 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
// If we got nothing, make a new mimeinfo
if (!retval) {
*aFound = PR_FALSE;
retval = new nsMIMEInfoOS2();
retval = new nsMIMEInfoOS2(PromiseFlatCString(aType).get());
if (retval) {
NS_ADDREF(retval);
if (aType && *aType)
retval->SetMIMEType(aType);
if (aFileExt && *aFileExt)
if (!aFileExt.IsEmpty())
retval->AppendExtension(aFileExt);
}

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

@ -42,8 +42,8 @@ public:
virtual ~nsOSHelperAppService();
// method overrides for mime.types and mime.info look up steps
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMimeType,
const char *aFileExt,
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType,
const nsACString& aFileExt,
PRBool *aFound);
// override nsIExternalProtocolService methods
@ -51,8 +51,8 @@ public:
NS_IMETHOD LoadUrl(nsIURI * aURL);
protected:
already_AddRefed<nsMIMEInfoOS2> GetFromType(const char *aMimeType);
already_AddRefed<nsMIMEInfoOS2> GetFromExtension(const char *aFileExt);
already_AddRefed<nsMIMEInfoOS2> GetFromType(const nsCString& aMimeType);
already_AddRefed<nsMIMEInfoOS2> GetFromExtension(const nsCString& aFileExt);
private:
// Helper methods which have to access static members

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

@ -263,20 +263,18 @@ nsGNOMERegistry::GetFromType(const char *aMIMEType)
if (!handlerApp)
return nsnull;
nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl();
nsRefPtr<nsMIMEInfoImpl> mimeInfo = new nsMIMEInfoImpl(aMIMEType);
NS_ENSURE_TRUE(mimeInfo, nsnull);
mimeInfo->SetMIMEType(aMIMEType);
// Get the list of extensions and append then to the mimeInfo.
GList *extensions = _gnome_vfs_mime_get_extensions_list(aMIMEType);
for (GList *extension = extensions; extension; extension = extension->next)
mimeInfo->AppendExtension((const char *) extension->data);
mimeInfo->AppendExtension(nsDependentCString((const char *) extension->data));
_gnome_vfs_mime_extensions_list_free(extensions);
const char *description = _gnome_vfs_mime_get_description(aMIMEType);
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(description).get());
mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(description));
// Convert UTF-8 registry value to filesystem encoding, which
// g_find_program_in_path() uses.
@ -303,7 +301,7 @@ nsGNOMERegistry::GetFromType(const char *aMIMEType)
getter_AddRefs(appFile));
if (appFile) {
mimeInfo->SetDefaultApplication(appFile);
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(handlerApp->name).get());
mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(handlerApp->name));
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
}

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

@ -1347,12 +1347,12 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
}
already_AddRefed<nsMIMEInfoBase>
nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
// if the extension is null, return immediately
if (!aFileExt || !*aFileExt)
nsOSHelperAppService::GetFromExtension(const nsCString& aFileExt) {
// if the extension is empty, return immediately
if (aFileExt.IsEmpty())
return nsnull;
LOG(("Here we do an extension lookup for '%s'\n", aFileExt));
LOG(("Here we do an extension lookup for '%s'\n", aFileExt.get()));
nsAutoString majorType, minorType,
mime_types_description, mailcap_description,
@ -1368,7 +1368,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
#ifdef MOZ_WIDGET_GTK2
LOG(("Looking in GNOME registry\n"));
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromExtension(aFileExt).get();
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromExtension(aFileExt.get()).get();
if (gnomeInfo) {
LOG(("Got MIMEInfo from GNOME registry\n"));
return gnomeInfo;
@ -1416,9 +1416,9 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
mailcap_description.Trim(" \t\"");
mozillaFlags.Trim(" \t");
if (!mime_types_description.IsEmpty()) {
mimeInfo->SetDescription(mime_types_description.get());
mimeInfo->SetDescription(mime_types_description);
} else {
mimeInfo->SetDescription(mailcap_description.get());
mimeInfo->SetDescription(mailcap_description);
}
if (NS_SUCCEEDED(rv) && handler.IsEmpty()) {
@ -1432,7 +1432,7 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
if (NS_SUCCEEDED(rv)) {
mimeInfo->SetDefaultApplication(handlerFile);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
mimeInfo->SetDefaultDescription(handler.get());
mimeInfo->SetDefaultDescription(handler);
}
}
@ -1444,12 +1444,12 @@ nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
}
already_AddRefed<nsMIMEInfoBase>
nsOSHelperAppService::GetFromType(const char *aMIMEType) {
// if the type is null, return immediately
if (!aMIMEType || !*aMIMEType)
nsOSHelperAppService::GetFromType(const nsCString& aMIMEType) {
// if the type is empty, return immediately
if (aMIMEType.IsEmpty())
return nsnull;
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType));
LOG(("Here we do a mimetype lookup for '%s'\n", aMIMEType.get()));
// extract the major and minor types
NS_ConvertASCIItoUTF16 mimeType(aMIMEType);
@ -1494,7 +1494,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
#ifdef MOZ_WIDGET_GTK2
LOG(("Looking in GNOME registry\n"));
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType).get();
nsMIMEInfoBase *gnomeInfo = nsGNOMERegistry::GetFromType(aMIMEType.get()).get();
if (gnomeInfo) {
LOG(("Got MIMEInfo from GNOME registry\n"));
return gnomeInfo;
@ -1546,16 +1546,16 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
return nsnull;
}
nsMIMEInfoImpl* mimeInfo = new nsMIMEInfoImpl(aMIMEType);
nsMIMEInfoImpl* mimeInfo = new nsMIMEInfoImpl(aMIMEType.get());
if (!mimeInfo)
return nsnull;
NS_ADDREF(mimeInfo);
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions).get());
mimeInfo->SetFileExtensions(NS_ConvertUCS2toUTF8(extensions));
if (! mime_types_description.IsEmpty()) {
mimeInfo->SetDescription(mime_types_description.get());
mimeInfo->SetDescription(mime_types_description);
} else {
mimeInfo->SetDescription(mailcap_description.get());
mimeInfo->SetDescription(mailcap_description);
}
rv = NS_ERROR_NOT_AVAILABLE;
@ -1567,7 +1567,7 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
if (NS_SUCCEEDED(rv)) {
mimeInfo->SetDefaultApplication(handlerFile);
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
mimeInfo->SetDefaultDescription(handler.get());
mimeInfo->SetDefaultDescription(handler);
} else {
mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
}
@ -1577,23 +1577,23 @@ nsOSHelperAppService::GetFromType(const char *aMIMEType) {
already_AddRefed<nsIMIMEInfo>
nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
const char *aFileExt,
nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType,
const nsACString& aFileExt,
PRBool *aFound) {
*aFound = PR_TRUE;
nsMIMEInfoBase* retval = GetFromType(aType).get();
nsMIMEInfoBase* retval = GetFromType(PromiseFlatCString(aType)).get();
PRBool hasDefault = PR_FALSE;
if (retval)
retval->GetHasDefaultHandler(&hasDefault);
if (!retval || !hasDefault) {
nsRefPtr<nsMIMEInfoBase> miByExt = GetFromExtension(aFileExt);
nsRefPtr<nsMIMEInfoBase> miByExt = GetFromExtension(PromiseFlatCString(aFileExt));
// If we had no extension match, but a type match, use that
if (!miByExt && retval)
return retval;
// If we had an extension match but no type match, set the mimetype and use
// it
if (!retval && miByExt) {
if (aType)
if (!aType.IsEmpty())
miByExt->SetMIMEType(aType);
miByExt.swap(retval);
@ -1602,12 +1602,10 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
// If we got nothing, make a new mimeinfo
if (!retval) {
*aFound = PR_FALSE;
retval = new nsMIMEInfoImpl();
retval = new nsMIMEInfoImpl(PromiseFlatCString(aType).get());
if (retval) {
NS_ADDREF(retval);
if (aType && *aType)
retval->SetMIMEType(aType);
if (aFileExt && *aFileExt)
if (!aFileExt.IsEmpty())
retval->AppendExtension(aFileExt);
}
@ -1616,6 +1614,7 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const char *aType,
// Copy the attributes of retval onto miByExt, to return it
retval->CopyBasicDataTo(miByExt);
miByExt.swap(retval);
}
return retval;

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

@ -41,8 +41,8 @@ public:
virtual ~nsOSHelperAppService();
// method overrides for mime.types and mime.info look up steps
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMimeType,
const char *aFileExt,
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType,
const nsACString& aFileExt,
PRBool *aFound);
// override nsIExternalProtocolService methods
@ -56,8 +56,8 @@ public:
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
protected:
already_AddRefed<nsMIMEInfoBase> GetFromType(const char *aMimeType);
already_AddRefed<nsMIMEInfoBase> GetFromExtension(const char *aFileExt);
already_AddRefed<nsMIMEInfoBase> GetFromType(const nsCString& aMimeType);
already_AddRefed<nsMIMEInfoBase> GetFromExtension(const nsCString& aFileExt);
virtual void FixFilePermissions(nsILocalFile* aFile);
private:

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

@ -280,7 +280,7 @@ nsresult nsOSHelperAppService::GetMIMEInfoFromRegistry( const nsAFlatString& fil
nsAutoString description;
PRBool found = GetValueString(fileTypeKey, NULL, description);
if (found)
pInfo->SetDescription(description.get());
pInfo->SetDescription(description);
::RegCloseKey(fileTypeKey);
return NS_OK;
@ -349,14 +349,12 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const char
nsAutoString description;
PRBool found = GetValueString(hKey, NULL, description);
nsMIMEInfoWin* mimeInfo = new nsMIMEInfoWin();
nsMIMEInfoWin* mimeInfo = new nsMIMEInfoWin(typeToUse.get());
if (mimeInfo)
{
NS_ADDREF(mimeInfo);
if (!typeToUse.IsEmpty())
mimeInfo->SetMIMEType(typeToUse.get());
// don't append the '.'
mimeInfo->AppendExtension(fileExtToUse.get() + 1);
mimeInfo->AppendExtension(Substring(fileExtToUse, 1));
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
@ -367,7 +365,7 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const char
// the format of the description usually looks like appname.version.something.
// for now, let's try to make it pretty and just show you the appname.
mimeInfo->SetDefaultDescription(visibleDesc.get());
mimeInfo->SetDefaultDescription(visibleDesc);
// Get other nsIMIMEInfo fields from registry, if possible.
if ( found )
@ -389,11 +387,15 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const char
return nsnull;
}
already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char *aMIMEType, const char *aFileExt, PRBool *aFound)
already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool *aFound)
{
*aFound = PR_TRUE;
const nsCString& flatType = PromiseFlatCString(aMIMEType);
const nsCString& flatExt = PromiseFlatCString(aFileExt);
nsCAutoString fileExtension;
/* XXX The strcasecmp is a gross hack to wallpaper over the most common Win32
/* XXX The Equals is a gross hack to wallpaper over the most common Win32
* extension issues caused by the fix for bug 116938. See bug
* 120327, comment 271 for why this is needed. Not even sure we
* want to remove this once we have fixed all this stuff to work
@ -401,20 +403,20 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
* useless....
* We'll do extension-based lookup for this type later in this function.
*/
if (aMIMEType && *aMIMEType && PL_strcasecmp(aMIMEType, APPLICATION_OCTET_STREAM) != 0) {
if (!aMIMEType.Equals(APPLICATION_OCTET_STREAM, nsCaseInsensitiveCStringComparator())) {
// (1) try to use the windows mime database to see if there is a mapping to a file extension
// (2) try to see if we have some left over 4.x registry info we can peek at...
GetExtensionFromWindowsMimeDatabase(aMIMEType, fileExtension);
GetExtensionFromWindowsMimeDatabase(flatType.get(), fileExtension);
LOG(("Windows mime database: extension '%s'\n", fileExtension.get()));
if (fileExtension.IsEmpty()) {
GetExtensionFrom4xRegistryInfo(aMIMEType, fileExtension);
GetExtensionFrom4xRegistryInfo(flatType.get(), fileExtension);
LOG(("4.x Registry: extension '%s'\n", fileExtension.get()));
}
}
// If we found an extension for the type, do the lookup
nsMIMEInfoWin* mi = nsnull;
if (!fileExtension.IsEmpty())
mi = GetByExtension(fileExtension.get(), aMIMEType).get();
mi = GetByExtension(fileExtension.get(), flatType.get()).get();
LOG(("Extension lookup on '%s' found: 0x%p\n", fileExtension.get(), mi));
PRBool hasDefault = PR_FALSE;
@ -425,9 +427,9 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
// to the mimeinfo that we have. (E.g.: We are asked for video/mpeg and
// .mpg, but the primary extension for video/mpeg is .mpeg. But because
// .mpg is an extension for video/mpeg content, we want to append it)
if (aFileExt && *aFileExt && typeFromExtEquals(aFileExt, aMIMEType)) {
if (!aFileExt.IsEmpty() && typeFromExtEquals(flatExt.get(), flatType.get())) {
LOG(("Appending extension '%s' to mimeinfo, because its mimetype is '%s'\n",
aFileExt, aMIMEType));
flatExt.get(), flatType.get()));
PRBool extExist = PR_FALSE;
mi->ExtensionExists(aFileExt, &extExist);
if (!extExist)
@ -435,8 +437,8 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
}
}
if (!mi || !hasDefault) {
nsRefPtr<nsMIMEInfoWin> miByExt = GetByExtension(aFileExt, aMIMEType);
LOG(("Ext. lookup for '%s' found 0x%p\n", aFileExt, miByExt.get()));
nsRefPtr<nsMIMEInfoWin> miByExt = GetByExtension(flatExt.get(), flatType.get());
LOG(("Ext. lookup for '%s' found 0x%p\n", flatExt.get(), miByExt.get()));
if (!miByExt && mi)
return mi;
if (miByExt && !mi) {
@ -445,12 +447,10 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
}
if (!miByExt && !mi) {
*aFound = PR_FALSE;
mi = new nsMIMEInfoWin();
mi = new nsMIMEInfoWin(flatType.get());
if (mi) {
NS_ADDREF(mi);
if (aMIMEType && *aMIMEType)
mi->SetMIMEType(aMIMEType);
if (aFileExt && *aFileExt)
if (!aFileExt.IsEmpty())
mi->AppendExtension(aFileExt);
}
@ -459,10 +459,10 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const char
// if we get here, mi has no default app. copy from extension lookup.
nsCOMPtr<nsIFile> defaultApp;
nsXPIDLString desc;
miByExt->GetDefaultDescription(getter_Copies(desc));
nsAutoString desc;
miByExt->GetDefaultDescription(desc);
mi->SetDefaultDescription(desc.get());
mi->SetDefaultDescription(desc);
}
return mi;
}

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

@ -45,7 +45,7 @@ public:
NS_IMETHOD LoadUrl(nsIURI * aURL);
// method overrides for windows registry look up steps....
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char *aMIMEType, const char *aFileExt, PRBool *aFound);
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool *aFound);
protected:
// Lookup a mime info by extension, using an optional type hint