Revert "Clean up nsOSHelperAppService"
parent
3fd37a9acc
commit
4c580c7aac
|
@ -29,6 +29,8 @@
|
||||||
#define LOG(args) MOZ_LOG(mLog, mozilla::LogLevel::Debug, args)
|
#define LOG(args) MOZ_LOG(mLog, mozilla::LogLevel::Debug, args)
|
||||||
|
|
||||||
// helper methods: forward declarations...
|
// helper methods: forward declarations...
|
||||||
|
static nsresult GetExtensionFrom4xRegistryInfo(const nsACString& aMimeType,
|
||||||
|
nsString& aFileExtension);
|
||||||
static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
|
static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
|
||||||
nsString& aFileExtension);
|
nsString& aFileExtension);
|
||||||
|
|
||||||
|
@ -75,45 +77,79 @@ static nsresult GetExtensionFromWindowsMimeDatabase(const nsACString& aMimeType,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We have a serious problem!! I have this content type and the windows registry only gives me
|
||||||
|
// helper apps based on extension. Right now, we really don't have a good place to go for
|
||||||
|
// trying to figure out the extension for a particular mime type....One short term hack is to look
|
||||||
|
// this information in 4.x (it's stored in the windows regsitry).
|
||||||
|
static nsresult GetExtensionFrom4xRegistryInfo(const nsACString& aMimeType,
|
||||||
|
nsString& aFileExtension)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
||||||
|
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
||||||
|
if (!regKey)
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
nsresult rv = regKey->
|
||||||
|
Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||||
|
NS_LITERAL_STRING("Software\\Netscape\\Netscape Navigator\\Suffixes"),
|
||||||
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
rv = regKey->ReadStringValue(NS_ConvertASCIItoUTF16(aMimeType),
|
||||||
|
aFileExtension);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
aFileExtension.Insert(char16_t('.'), 0);
|
||||||
|
|
||||||
|
// this may be a comma separated list of extensions...just take the
|
||||||
|
// first one for now...
|
||||||
|
|
||||||
|
int32_t pos = aFileExtension.FindChar(char16_t(','));
|
||||||
|
if (pos > 0) {
|
||||||
|
// we have a comma separated list of types...
|
||||||
|
// truncate everything after the first comma (including the comma)
|
||||||
|
aFileExtension.Truncate(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists)
|
nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists)
|
||||||
{
|
{
|
||||||
// look up the protocol scheme in the windows registry....if we find a match then we have a handler for it...
|
// look up the protocol scheme in the windows registry....if we find a match then we have a handler for it...
|
||||||
*aHandlerExists = false;
|
*aHandlerExists = false;
|
||||||
if (aProtocolScheme && *aProtocolScheme)
|
if (aProtocolScheme && *aProtocolScheme)
|
||||||
{
|
{
|
||||||
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
|
// Vista: use new application association interface
|
||||||
wchar_t * pResult = nullptr;
|
if (mAppAssoc) {
|
||||||
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
|
wchar_t * pResult = nullptr;
|
||||||
// We are responsible for freeing returned strings.
|
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
|
||||||
HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
|
// We are responsible for freeing returned strings.
|
||||||
AT_URLPROTOCOL, AL_EFFECTIVE,
|
HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
|
||||||
&pResult);
|
AT_URLPROTOCOL, AL_EFFECTIVE,
|
||||||
if (SUCCEEDED(hr)) {
|
&pResult);
|
||||||
CoTaskMemFree(pResult);
|
if (SUCCEEDED(hr)) {
|
||||||
// Check the registry to see if it's a valid handler.
|
CoTaskMemFree(pResult);
|
||||||
nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
*aHandlerExists = true;
|
||||||
if (!regKey) {
|
|
||||||
return NS_ERROR_NOT_AVAILABLE;
|
|
||||||
}
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
|
HKEY hKey;
|
||||||
nsDependentString(scheme.get()),
|
LONG err = ::RegOpenKeyExW(HKEY_CLASSES_ROOT,
|
||||||
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
NS_ConvertASCIItoUTF16(aProtocolScheme).get(),
|
||||||
if (NS_FAILED(rv)) {
|
0,
|
||||||
// Open will fail if the registry key path doesn't exist.
|
KEY_QUERY_VALUE,
|
||||||
return NS_OK;
|
&hKey);
|
||||||
}
|
if (err == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
bool hasValue;
|
err = ::RegQueryValueExW(hKey, L"URL Protocol",
|
||||||
rv = regKey->HasValue(NS_LITERAL_STRING("URL Protocol"), &hasValue);
|
nullptr, nullptr, nullptr, nullptr);
|
||||||
if (NS_FAILED(rv)) {
|
*aHandlerExists = (err == ERROR_SUCCESS);
|
||||||
return NS_ERROR_FAILURE;
|
// close the key
|
||||||
}
|
::RegCloseKey(hKey);
|
||||||
if (!hasValue) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aHandlerExists = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,21 +180,40 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
|
if (mAppAssoc) {
|
||||||
wchar_t * pResult = nullptr;
|
// Vista: use new application association interface
|
||||||
// We are responsible for freeing returned strings.
|
wchar_t * pResult = nullptr;
|
||||||
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
|
// We are responsible for freeing returned strings.
|
||||||
AT_URLPROTOCOL, AL_EFFECTIVE,
|
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
|
||||||
&pResult);
|
AT_URLPROTOCOL, AL_EFFECTIVE,
|
||||||
if (SUCCEEDED(hr)) {
|
&pResult);
|
||||||
nsCOMPtr<nsIFile> app;
|
if (SUCCEEDED(hr)) {
|
||||||
nsAutoString appInfo(pResult);
|
nsCOMPtr<nsIFile> app;
|
||||||
CoTaskMemFree(pResult);
|
nsAutoString appInfo(pResult);
|
||||||
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
|
CoTaskMemFree(pResult);
|
||||||
return NS_OK;
|
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_ERROR_NOT_AVAILABLE;
|
nsCOMPtr<nsIFile> app;
|
||||||
|
GetDefaultAppInfo(buf, _retval, getter_AddRefs(app));
|
||||||
|
|
||||||
|
if (!_retval.Equals(buf))
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
// Fall back to full path
|
||||||
|
buf.AppendLiteral("\\shell\\open\\command");
|
||||||
|
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
|
||||||
|
buf,
|
||||||
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
rv = regKey->ReadStringValue(EmptyString(), _retval);
|
||||||
|
|
||||||
|
return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
|
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
|
||||||
|
@ -366,18 +421,36 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFl
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
// Retrieve the default application for this extension
|
// Retrieve the default application for this extension
|
||||||
NS_ENSURE_TRUE(mAppAssoc, nullptr);
|
if (mAppAssoc) {
|
||||||
nsString assocType(fileExtToUse);
|
// Vista: use the new application association COM interfaces
|
||||||
wchar_t * pResult = nullptr;
|
// for resolving helpers.
|
||||||
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
|
nsString assocType(fileExtToUse);
|
||||||
AT_FILEEXTENSION, AL_EFFECTIVE,
|
wchar_t * pResult = nullptr;
|
||||||
&pResult);
|
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
|
||||||
if (SUCCEEDED(hr)) {
|
AT_FILEEXTENSION, AL_EFFECTIVE,
|
||||||
found = true;
|
&pResult);
|
||||||
appInfo.Assign(pResult);
|
if (SUCCEEDED(hr)) {
|
||||||
CoTaskMemFree(pResult);
|
found = true;
|
||||||
} else {
|
appInfo.Assign(pResult);
|
||||||
found = false;
|
CoTaskMemFree(pResult);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
found = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
||||||
|
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
||||||
|
if (!regKey)
|
||||||
|
return nullptr;
|
||||||
|
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
|
||||||
|
fileExtToUse,
|
||||||
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
||||||
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(),
|
||||||
|
appInfo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bug 358297 - ignore the default handler, force the user to choose app
|
// Bug 358297 - ignore the default handler, force the user to choose app
|
||||||
|
@ -423,9 +496,14 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const nsAC
|
||||||
* We'll do extension-based lookup for this type later in this function.
|
* We'll do extension-based lookup for this type later in this function.
|
||||||
*/
|
*/
|
||||||
if (!aMIMEType.LowerCaseEqualsLiteral(APPLICATION_OCTET_STREAM)) {
|
if (!aMIMEType.LowerCaseEqualsLiteral(APPLICATION_OCTET_STREAM)) {
|
||||||
// try to use the windows mime database to see if there is a mapping to a file extension
|
// (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(aMIMEType, fileExtension);
|
||||||
LOG(("Windows mime database: extension '%s'\n", fileExtension.get()));
|
LOG(("Windows mime database: extension '%s'\n", fileExtension.get()));
|
||||||
|
if (fileExtension.IsEmpty()) {
|
||||||
|
GetExtensionFrom4xRegistryInfo(aMIMEType, fileExtension);
|
||||||
|
LOG(("4.x Registry: extension '%s'\n", fileExtension.get()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If we found an extension for the type, do the lookup
|
// If we found an extension for the type, do the lookup
|
||||||
RefPtr<nsMIMEInfoWin> mi;
|
RefPtr<nsMIMEInfoWin> mi;
|
||||||
|
|
Loading…
Reference in New Issue