NS_IMETHODIMP nsMIMEInfoBase::LaunchWithFile(nsIFile* aFile) { nsresult rv; // it doesn't make any sense to call this on protocol handlers NS_ASSERTION(mClass == eMIMEInfo, "nsMIMEInfoBase should have mClass == eMIMEInfo"); if (mPreferredAction == useSystemDefault) { return LaunchDefaultWithFile(aFile); } if (mPreferredAction == useHelperApp) { if (!mPreferredApplication) return NS_ERROR_FILE_NOT_FOUND; // at the moment, we only know how to hand files off to local handlers nsCOMPtr<nsILocalHandlerApp> localHandler = do_QueryInterface(mPreferredApplication, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIFile> executable; rv = localHandler->GetExecutable(getter_AddRefs(executable)); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString path; aFile->GetNativePath(path); return LaunchWithIProcess(executable, path); } return NS_ERROR_INVALID_ARG; }
NS_IMETHODIMP nsMIMEInfoBase::LaunchWithFile(nsIFile* aFile) { if (mPreferredAction == useHelperApp) { if (!mPreferredApplication) return NS_ERROR_FILE_NOT_FOUND; return LaunchWithIProcess(mPreferredApplication, aFile); } else if (mPreferredAction == useSystemDefault) { return LaunchDefaultWithFile(aFile); } return NS_ERROR_INVALID_ARG; }
NS_IMETHODIMP nsMIMEInfoWin::LaunchWithFile(nsIFile* aFile) { nsresult rv; // it doesn't make any sense to call this on protocol handlers NS_ASSERTION(mClass == eMIMEInfo, "nsMIMEInfoBase should have mClass == eMIMEInfo"); if (mPreferredAction == useSystemDefault) { return LaunchDefaultWithFile(aFile); } if (mPreferredAction == useHelperApp) { if (!mPreferredApplication) return NS_ERROR_FILE_NOT_FOUND; // at the moment, we only know how to hand files off to local handlers nsCOMPtr<nsILocalHandlerApp> localHandler = do_QueryInterface(mPreferredApplication, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIFile> executable; rv = localHandler->GetExecutable(getter_AddRefs(executable)); NS_ENSURE_SUCCESS(rv, rv); nsAutoString path; aFile->GetPath(path); // Deal with local dll based handlers nsCString filename; executable->GetNativeLeafName(filename); if (filename.Length() > 4) { nsCString extension(Substring(filename, filename.Length() - 4, 4)); if (extension.LowerCaseEqualsLiteral(".dll")) { nsAutoString args; // executable is rundll32, everything else is a list of parameters, // including the dll handler. nsCOMPtr<nsILocalFile> locFile(do_QueryInterface(aFile)); if (!GetDllLaunchInfo(executable, locFile, args, false)) return NS_ERROR_INVALID_ARG; WCHAR rundll32Path[MAX_PATH + sizeof(RUNDLL32_EXE) / sizeof(WCHAR) + 1] = {L'\0'}; if (!GetSystemDirectoryW(rundll32Path, MAX_PATH)) { return NS_ERROR_FILE_NOT_FOUND; } lstrcatW(rundll32Path, RUNDLL32_EXE); SHELLEXECUTEINFOW seinfo; memset(&seinfo, 0, sizeof(seinfo)); seinfo.cbSize = sizeof(SHELLEXECUTEINFOW); seinfo.fMask = NULL; seinfo.hwnd = NULL; seinfo.lpVerb = NULL; seinfo.lpFile = rundll32Path; seinfo.lpParameters = args.get(); seinfo.lpDirectory = NULL; seinfo.nShow = SW_SHOWNORMAL; if (ShellExecuteExW(&seinfo)) return NS_OK; switch ((LONG_PTR)seinfo.hInstApp) { case 0: case SE_ERR_OOM: return NS_ERROR_OUT_OF_MEMORY; case SE_ERR_ACCESSDENIED: return NS_ERROR_FILE_ACCESS_DENIED; case SE_ERR_ASSOCINCOMPLETE: case SE_ERR_NOASSOC: return NS_ERROR_UNEXPECTED; case SE_ERR_DDEBUSY: case SE_ERR_DDEFAIL: case SE_ERR_DDETIMEOUT: return NS_ERROR_NOT_AVAILABLE; case SE_ERR_DLLNOTFOUND: return NS_ERROR_FAILURE; case SE_ERR_SHARE: return NS_ERROR_FILE_IS_LOCKED; default: switch(GetLastError()) { case ERROR_FILE_NOT_FOUND: return NS_ERROR_FILE_NOT_FOUND; case ERROR_PATH_NOT_FOUND: return NS_ERROR_FILE_UNRECOGNIZED_PATH; case ERROR_BAD_FORMAT: return NS_ERROR_FILE_CORRUPTED; } } return NS_ERROR_FILE_EXECUTION_FAILED; } } return LaunchWithIProcess(executable, path); } return NS_ERROR_INVALID_ARG; }