// set an arbitrary command: // could adjust the code to ask confirmation if it already exists and // overwriteprompt is true, but this is currently ignored as *Associate* has // no overwrite prompt bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool WXUNUSED(overwriteprompt)) { wxArrayString strExtensions; wxString strDesc, strIcon; wxArrayString strTypes; GetMimeTypes(strTypes); if ( strTypes.IsEmpty() ) return false; wxMimeTypeCommands *entry = new wxMimeTypeCommands(); entry->Add(verb + wxT("=") + cmd + wxT(" %s ")); bool ok = false; size_t nCount = strTypes.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t i = 0; i < nCount; i++ ) { if ( m_manager->DoAssociation ( strTypes[i], strIcon, entry, strExtensions, strDesc ) ) { // DoAssociation() took ownership of entry, don't delete it below ok = true; } } if ( !ok ) delete entry; return ok; }
NS_IMETHODIMP nsPluginElement::Item(PRUint32 aIndex, nsIDOMMimeType** aReturn) { if (mMimeTypeArray == nsnull) { nsresult rv = GetMimeTypes(); if (rv != NS_OK) return rv; } if (aIndex < mMimeTypeCount) { nsIDOMMimeType* mimeType = mMimeTypeArray[aIndex]; NS_IF_ADDREF(mimeType); *aReturn = mimeType; return NS_OK; } return NS_ERROR_FAILURE; }
NS_IMETHODIMP nsMimeTypeArray::GetLength(PRUint32* aLength) { if (!mInited) { nsresult rv = GetMimeTypes(); if (rv != NS_OK) return rv; } NS_ASSERTION(mPluginMimeTypeCount <= (PRUint32)mMimeTypeArray.Count(), "The number of total mimetypes should be equal to or higher " "than the number of plugin mimetypes."); *aLength = mPluginMimeTypeCount; return NS_OK; }
// ignore index on the grounds that we only have one icon in a Unix file bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon, int WXUNUSED(index)) { if (strIcon.empty()) return false; wxArrayString strExtensions; wxString strDesc; wxArrayString strTypes; GetMimeTypes(strTypes); if ( strTypes.IsEmpty() ) return false; wxMimeTypeCommands *entry = new wxMimeTypeCommands(); bool ok = false; size_t nCount = strTypes.GetCount(); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( size_t i = 0; i < nCount; i++ ) { if ( m_manager->DoAssociation ( strTypes[i], strIcon, entry, strExtensions, strDesc ) ) { // we don't need to free entry now, DoAssociation() took ownership // of it ok = true; } } if ( !ok ) delete entry; return ok; }
nsIDOMMimeType* nsPluginElement::GetItemAt(PRUint32 aIndex, nsresult *aResult) { if (mMimeTypeArray == nsnull) { *aResult = GetMimeTypes(); if (*aResult != NS_OK) return nsnull; } if (aIndex >= mMimeTypeCount) { *aResult = NS_ERROR_FAILURE; return nsnull; } *aResult = NS_OK; return mMimeTypeArray[aIndex]; }
nsIDOMMimeType* nsPluginElement::GetNamedItem(const nsAString& aName, nsresult *aResult) { if (mMimeTypeArray == nsnull) { *aResult = GetMimeTypes(); if (*aResult != NS_OK) return nsnull; } *aResult = NS_OK; for (PRUint32 i = 0; i < mMimeTypeCount; i++) { nsAutoString type; nsIDOMMimeType* mimeType = mMimeTypeArray[i]; if (mimeType->GetType(type) == NS_OK && type.Equals(aName)) { return mimeType; } } return nsnull; }
// set an arbitrary command: // could adjust the code to ask confirmation if it already exists and // overwriteprompt is true, but this is currently ignored as *Associate* has // no overwrite prompt bool wxFileTypeImpl::SetCommand(const wxString& cmd, const wxString& verb, bool WXUNUSED(overwriteprompt)) { wxArrayString strExtensions; wxString strDesc, strIcon; wxArrayString strTypes; GetMimeTypes(strTypes); if ( strTypes.IsEmpty() ) return false; wxMimeTypeCommands *entry = new wxMimeTypeCommands(); entry->Add(verb + wxT("=") + cmd + wxT(" %s ")); bool ok = false; size_t nCount = strTypes.GetCount(); for ( size_t i = 0; i < nCount; i++ ) { if ( m_manager->DoAssociation ( strTypes[i], strIcon, entry, strExtensions, strDesc ) ) { // DoAssociation() took ownership of entry, don't delete it below ok = true; } } if ( !ok ) delete entry; return ok; }
// ignore index on the grounds that we only have one icon in a Unix file bool wxFileTypeImpl::SetDefaultIcon(const wxString& strIcon, int WXUNUSED(index)) { if (strIcon.empty()) return false; wxArrayString strExtensions; wxString strDesc; wxArrayString strTypes; GetMimeTypes(strTypes); if ( strTypes.IsEmpty() ) return false; wxMimeTypeCommands *entry = new wxMimeTypeCommands(); bool ok = false; size_t nCount = strTypes.GetCount(); for ( size_t i = 0; i < nCount; i++ ) { if ( m_manager->DoAssociation ( strTypes[i], strIcon, entry, strExtensions, strDesc ) ) { // we don't need to free entry now, DoAssociation() took ownership // of it ok = true; } } if ( !ok ) delete entry; return ok; }
nsIDOMMimeType* nsMimeTypeArray::GetItemAt(PRUint32 aIndex, nsresult *aResult) { if (!mInited) { *aResult = GetMimeTypes(); if (*aResult != NS_OK) return nsnull; } NS_ASSERTION(mPluginMimeTypeCount <= (PRUint32)mMimeTypeArray.Count(), "The number of total mimetypes should be equal to or higher " "than the number of plugin mimetypes."); if (aIndex >= mPluginMimeTypeCount) { *aResult = NS_ERROR_FAILURE; return nsnull; } *aResult = NS_OK; return mMimeTypeArray[aIndex]; }
NS_IMETHODIMP nsPluginElement::NamedItem(const nsAString& aName, nsIDOMMimeType** aReturn) { if (mMimeTypeArray == nsnull) { nsresult rv = GetMimeTypes(); if (rv != NS_OK) return rv; } *aReturn = nsnull; for (PRUint32 i = 0; i < mMimeTypeCount; i++) { nsAutoString type; nsIDOMMimeType* mimeType = mMimeTypeArray[i]; if (mimeType->GetType(type) == NS_OK) { if (type.Equals(aName)) { *aReturn = mimeType; NS_ADDREF(mimeType); break; } } } return NS_OK; }
nsresult nsMimeTypeArray::Refresh() { Clear(); return GetMimeTypes(); }
nsIDOMMimeType* nsMimeTypeArray::GetNamedItem(const nsAString& aName, nsresult* aResult) { if (!mInited) { *aResult = GetMimeTypes(); if (*aResult != NS_OK) return nsnull; } NS_ASSERTION(mPluginMimeTypeCount <= (PRUint32)mMimeTypeArray.Count(), "The number of total mimetypes should be equal to or higher " "than the number of plugin mimetypes."); *aResult = NS_OK; nsAutoString type; for (PRInt32 i = 0; i < mMimeTypeArray.Count(); i++) { nsIDOMMimeType *mtype = mMimeTypeArray[i]; mtype->GetType(type); if (type.Equals(aName)) { return mtype; } } // Now let's check with the MIME service. nsCOMPtr<nsIMIMEService> mimeSrv = do_GetService("@mozilla.org/mime;1"); if (mimeSrv) { nsCOMPtr<nsIMIMEInfo> mimeInfo; mimeSrv->GetFromTypeAndExtension(NS_ConvertUTF16toUTF8(aName), EmptyCString(), getter_AddRefs(mimeInfo)); if (mimeInfo) { // Now we check whether we can really claim to support this type nsHandlerInfoAction action = nsIHandlerInfo::saveToDisk; mimeInfo->GetPreferredAction(&action); if (action != nsIMIMEInfo::handleInternally) { bool hasHelper = false; mimeInfo->GetHasDefaultHandler(&hasHelper); if (!hasHelper) { nsCOMPtr<nsIHandlerApp> helper; mimeInfo->GetPreferredApplicationHandler(getter_AddRefs(helper)); if (!helper) { // mime info from the OS may not have a PreferredApplicationHandler // so just check for an empty default description nsAutoString defaultDescription; mimeInfo->GetDefaultDescription(defaultDescription); if (defaultDescription.IsEmpty()) { // no support; just leave return nsnull; } } } } // If we got here, we support this type! Say so. nsCOMPtr<nsIDOMMimeType> helper, entry; if (!(helper = new nsHelperMimeType(aName)) || !(entry = new nsMimeType(nsnull, helper)) || !mMimeTypeArray.AppendObject(entry)) { *aResult = NS_ERROR_OUT_OF_MEMORY; return nsnull; } return entry; } } return nsnull; }
void nsMimeTypeArray::Refresh() { Clear(); GetMimeTypes(); }