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; }
nsresult nsMIMEInfoImpl::LaunchDefaultWithFile(nsIFile* aFile) { if (!mDefaultApplication) return NS_ERROR_FILE_NOT_FOUND; return LaunchWithIProcess(mDefaultApplication, aFile); }
NS_IMETHODIMP nsLocalHandlerApp::LaunchWithURI(nsIURI *aURI, nsIInterfaceRequestor *aWindowContext) { // pass the entire URI to the handler. nsCAutoString spec; aURI->GetAsciiSpec(spec); return LaunchWithIProcess(spec); }
nsresult nsMIMEInfoImpl::LaunchDefaultWithFile(nsIFile* aFile) { if (!mDefaultApplication) return NS_ERROR_FILE_NOT_FOUND; nsAutoCString nativePath; aFile->GetNativePath(nativePath); return LaunchWithIProcess(mDefaultApplication, nativePath); }
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; }
nsresult nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile) { nsCAutoString nativePath; aFile->GetNativePath(nativePath); nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); if (vfs) { nsCOMPtr<nsIGnomeVFSMimeApp> app; if (NS_SUCCEEDED(vfs->GetAppForMimeType(mType, getter_AddRefs(app))) && app) return app->Launch(nativePath); } if (!mDefaultApplication) return NS_ERROR_FILE_NOT_FOUND; return LaunchWithIProcess(mDefaultApplication, nativePath); }
nsresult nsMIMEInfoUnix::LaunchDefaultWithFile(nsIFile *aFile) { // 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::LaunchDefaultWithFile(aFile); nsAutoCString nativePath; aFile->GetNativePath(nativePath); #if (MOZ_PLATFORM_MAEMO == 5) && defined (MOZ_ENABLE_GNOMEVFS) if(NS_SUCCEEDED(LaunchDefaultWithDBus(PromiseFlatCString(nativePath).get()))) return NS_OK; #endif #if defined(MOZ_ENABLE_CONTENTACTION) QUrl uri = QUrl::fromLocalFile(QString::fromUtf8(nativePath.get())); ContentAction::Action action = ContentAction::Action::defaultActionForFile(uri, QString(mSchemeOrType.get())); if (action.isValid()) { action.trigger(); return NS_OK; } return NS_ERROR_FAILURE; #endif nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); nsAutoCString uriSpec; if (giovfs) { // nsGIOMimeApp->Launch wants a URI string instead of local file nsresult rv; nsCOMPtr<nsIIOService> ioservice = do_GetService(NS_IOSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> uri; rv = ioservice->NewFileURI(aFile, getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); uri->GetSpec(uriSpec); } nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); if (giovfs) { nsCOMPtr<nsIGIOMimeApp> app; if (NS_SUCCEEDED(giovfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app) return app->Launch(uriSpec); } else if (gnomevfs) { /* Fallback to GnomeVFS */ nsCOMPtr<nsIGnomeVFSMimeApp> app; if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(mSchemeOrType, getter_AddRefs(app))) && app) return app->Launch(nativePath); } // If we haven't got an app we try to get a valid one by searching for the // extension mapped type nsRefPtr<nsMIMEInfoBase> mimeInfo = nsGNOMERegistry::GetFromExtension(nativePath); if (mimeInfo) { nsAutoCString type; mimeInfo->GetType(type); if (giovfs) { nsCOMPtr<nsIGIOMimeApp> app; if (NS_SUCCEEDED(giovfs->GetAppForMimeType(type, getter_AddRefs(app))) && app) return app->Launch(uriSpec); } else if (gnomevfs) { nsCOMPtr<nsIGnomeVFSMimeApp> app; if (NS_SUCCEEDED(gnomevfs->GetAppForMimeType(type, getter_AddRefs(app))) && app) return app->Launch(nativePath); } } if (!mDefaultApplication) return NS_ERROR_FILE_NOT_FOUND; return LaunchWithIProcess(mDefaultApplication, nativePath); }
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; }