NS_IMETHODIMP nsMIMEInfoUnix::GetHasDefaultHandler(bool *_retval) { // if mDefaultApplication is set, it means the application has been set from // either /etc/mailcap or ${HOME}/.mailcap, in which case we don't want to // give the GNOME answer. if (mDefaultApplication) return nsMIMEInfoImpl::GetHasDefaultHandler(_retval); *_retval = false; nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mSchemeOrType); if (!mimeInfo) { nsAutoCString ext; nsresult rv = GetPrimaryExtension(ext); if (NS_SUCCEEDED(rv)) { mimeInfo = nsGNOMERegistry::GetFromExtension(ext); } } if (mimeInfo) *_retval = true; if (*_retval) return NS_OK; #if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS) HildonURIAction *action = hildon_uri_get_default_action(mSchemeOrType.get(), nullptr); if (action) { *_retval = true; hildon_uri_action_unref(action); return NS_OK; } #endif #if defined(MOZ_ENABLE_CONTENTACTION) ContentAction::Action action = ContentAction::Action::defaultActionForFile(QUrl(), QString(mSchemeOrType.get())); if (action.isValid()) { *_retval = true; return NS_OK; } #endif return NS_OK; }
NS_IMETHODIMP nsMIMEInfoUnix::GetHasDefaultHandler(bool *_retval) { *_retval = PR_FALSE; nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromType(mSchemeOrType); if (!mimeInfo) { nsCAutoString ext; nsresult rv = GetPrimaryExtension(ext); if (NS_SUCCEEDED(rv)) { mimeInfo = nsGNOMERegistry::GetFromExtension(ext); } } if (mimeInfo) *_retval = PR_TRUE; if (*_retval) return NS_OK; #if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS) HildonURIAction *action = hildon_uri_get_default_action(mSchemeOrType.get(), nsnull); if (action) { *_retval = PR_TRUE; hildon_uri_action_unref(action); return NS_OK; } #endif #if defined(MOZ_ENABLE_CONTENTACTION) ContentAction::Action action = ContentAction::Action::defaultActionForFile(QUrl(), QString(mSchemeOrType.get())); if (action.isValid()) { *_retval = PR_TRUE; return NS_OK; } #endif // If we didn't find a VFS handler, fallback. return nsMIMEInfoImpl::GetHasDefaultHandler(_retval); }
/** * Returns a list of nsILocalHandlerApp objects containing local * handlers associated with this mimeinfo. Implemented per * platform using information in this object to generate the * best list. Typically used for an "open with" style user * option. * * @return nsIArray of nsILocalHandlerApp */ NS_IMETHODIMP nsMIMEInfoWin::GetPossibleLocalHandlers(nsIArray **_retval) { nsresult rv; *_retval = nsnull; nsCOMPtr<nsIMutableArray> appList = do_CreateInstance("@mozilla.org/array;1"); if (!appList) return NS_ERROR_FAILURE; nsTArray<nsString> trackList; nsCAutoString fileExt; GetPrimaryExtension(fileExt); nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1"); if (!regKey) return NS_ERROR_FAILURE; nsCOMPtr<nsIWindowsRegKey> appKey = do_CreateInstance("@mozilla.org/windows-registry-key;1"); if (!appKey) return NS_ERROR_FAILURE; nsAutoString workingRegistryPath; bool extKnown = false; if (fileExt.IsEmpty()) { extKnown = true; // Mime type discovery is possible in some cases, through // HKEY_CLASSES_ROOT\MIME\Database\Content Type, however, a number // of file extensions related to mime type are simply not defined, // (application/rss+xml & application/atom+xml are good examples) // in which case we can only provide a generic list. nsCAutoString mimeType; GetMIMEType(mimeType); if (!mimeType.IsEmpty()) { workingRegistryPath.AppendLiteral("MIME\\Database\\Content Type\\"); workingRegistryPath.Append(NS_ConvertASCIItoUTF16(mimeType)); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if(NS_SUCCEEDED(rv)) { nsAutoString mimeFileExt; if (NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(), mimeFileExt))) { CopyUTF16toUTF8(mimeFileExt, fileExt); extKnown = false; } } } } nsAutoString fileExtToUse; if (fileExt.First() != '.') fileExtToUse = PRUnichar('.'); fileExtToUse.Append(NS_ConvertUTF8toUTF16(fileExt)); // Note, the order in which these occur has an effect on the // validity of the resulting display list. if (!extKnown) { // 1) Get the default handler if it exists workingRegistryPath = fileExtToUse; rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { nsAutoString appProgId; if (NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(), appProgId))) { // Bug 358297 - ignore the embedded internet explorer handler if (appProgId != NS_LITERAL_STRING("XPSViewer.Document")) { nsAutoString appFilesystemCommand; if (GetProgIDVerbCommandHandler(appProgId, appFilesystemCommand, false) && !IsPathInList(appFilesystemCommand, trackList)) { ProcessPath(appList, trackList, appFilesystemCommand); } } } regKey->Close(); } // 2) list HKEY_CLASSES_ROOT\.ext\OpenWithList\ workingRegistryPath = fileExtToUse; workingRegistryPath.AppendLiteral("\\OpenWithList"); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appName; if (NS_FAILED(regKey->GetValueName(index, appName))) continue; // HKEY_CLASSES_ROOT\Applications\firefox.exe = "path params" nsAutoString appFilesystemCommand; if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } regKey->Close(); } // 3) List HKEY_CLASSES_ROOT\.ext\OpenWithProgids, with the // different step of resolving the progids for the command handler. workingRegistryPath = fileExtToUse; workingRegistryPath.AppendLiteral("\\OpenWithProgids"); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { // HKEY_CLASSES_ROOT\.ext\OpenWithProgids\Windows.XPSReachViewer nsAutoString appProgId; if (NS_FAILED(regKey->GetValueName(index, appProgId))) continue; nsAutoString appFilesystemCommand; if (!GetProgIDVerbCommandHandler(appProgId, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } regKey->Close(); } // 4) Add any non configured applications located in the MRU list // HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ // Explorer\FileExts\.ext\OpenWithList workingRegistryPath = NS_LITERAL_STRING("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\"); workingRegistryPath += fileExtToUse; workingRegistryPath.AppendLiteral("\\OpenWithList"); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appName, appValue; if (NS_FAILED(regKey->GetValueName(index, appName))) continue; if (appName.EqualsLiteral("MRUList")) continue; if (NS_FAILED(regKey->ReadStringValue(appName, appValue))) continue; // HKEY_CLASSES_ROOT\Applications\firefox.exe = "path params" nsAutoString appFilesystemCommand; if (!GetAppsVerbCommandHandler(appValue, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } } // 5) Add any non configured progids in the MRU list, with the // different step of resolving the progids for the command handler. // HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ // Explorer\FileExts\.ext\OpenWithProgids workingRegistryPath = NS_LITERAL_STRING("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\"); workingRegistryPath += fileExtToUse; workingRegistryPath.AppendLiteral("\\OpenWithProgids"); regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appIndex, appProgId; if (NS_FAILED(regKey->GetValueName(index, appProgId))) continue; nsAutoString appFilesystemCommand; if (!GetProgIDVerbCommandHandler(appProgId, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } regKey->Close(); } // 6) Check the perceived type value, and use this to lookup the perceivedtype // open with list. // http://msdn2.microsoft.com/en-us/library/aa969373.aspx workingRegistryPath = fileExtToUse; regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { nsAutoString perceivedType; rv = regKey->ReadStringValue(NS_LITERAL_STRING("PerceivedType"), perceivedType); if (NS_SUCCEEDED(rv)) { nsAutoString openWithListPath(NS_LITERAL_STRING("SystemFileAssociations\\")); openWithListPath.Append(perceivedType); // no period openWithListPath.Append(NS_LITERAL_STRING("\\OpenWithList")); nsresult rv = appKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, openWithListPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appName; if (NS_FAILED(regKey->GetValueName(index, appName))) continue; // HKEY_CLASSES_ROOT\Applications\firefox.exe = "path params" nsAutoString appFilesystemCommand; if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } } } } } // extKnown == false // 7) list global HKEY_CLASSES_ROOT\*\OpenWithList\ // Listing general purpose handlers, not specific to a mime type or file extension workingRegistryPath = NS_LITERAL_STRING("*\\OpenWithList"); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetValueCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appName; if (NS_FAILED(regKey->GetValueName(index, appName))) continue; // HKEY_CLASSES_ROOT\Applications\firefox.exe = "path params" nsAutoString appFilesystemCommand; if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } regKey->Close(); } // 8) General application's list - not file extension specific on windows workingRegistryPath = NS_LITERAL_STRING("Applications"); rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, workingRegistryPath, nsIWindowsRegKey::ACCESS_ENUMERATE_SUB_KEYS| nsIWindowsRegKey::ACCESS_QUERY_VALUE); if (NS_SUCCEEDED(rv)) { PRUint32 count = 0; if (NS_SUCCEEDED(regKey->GetChildCount(&count)) && count > 0) { for (PRUint32 index = 0; index < count; index++) { nsAutoString appName; if (NS_FAILED(regKey->GetChildName(index, appName))) continue; // HKEY_CLASSES_ROOT\Applications\firefox.exe = "path params" nsAutoString appFilesystemCommand; if (!GetAppsVerbCommandHandler(appName, appFilesystemCommand, false) || IsPathInList(appFilesystemCommand, trackList)) continue; ProcessPath(appList, trackList, appFilesystemCommand); } } } // Return to the caller *_retval = appList; NS_ADDREF(*_retval); return NS_OK; }