/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
NS_INTERFACE_MAP_BEGIN(nsMIMEInfoBase)
NS_INTERFACE_MAP_ENTRY(nsIHandlerInfo) // This is only an nsIMIMEInfo if it's a MIME handler.
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMIMEInfo, mClass == eMIMEInfo)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHandlerInfo)
NS_INTERFACE_MAP_END
// nsMIMEInfoImpl methods
// Constructors for a MIME handler.
nsMIMEInfoBase::nsMIMEInfoBase(constchar* aMIMEType)
: mSchemeOrType(aMIMEType),
mClass(eMIMEInfo),
mAlwaysAskBeforeHandling(
mozilla::StaticPrefs::
browser_download_always_ask_before_handling_new_types()) {}
// Constructor for a handler that lets the caller specify whether this is a // MIME handler or a protocol handler. In the long run, these will be distinct // classes (f.e. nsMIMEInfo and nsProtocolInfo), but for now we reuse this class // for both and distinguish between the two kinds of handlers via the aClass // argument to this method, which can be either eMIMEInfo or eProtocolInfo.
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass)
: mSchemeOrType(aType),
mClass(aClass),
mAlwaysAskBeforeHandling(
mozilla::StaticPrefs::
browser_download_always_ask_before_handling_new_types() ||
aClass != eMIMEInfo) {}
// it doesn't make any sense to call this on protocol handlers
NS_ASSERTION(mClass == eMIMEInfo, "nsMIMEInfoBase should have mClass == eMIMEInfo");
if (AutomationOnlyCheckIfLaunchStubbed(aFile)) { return NS_OK;
}
if (mPreferredAction == useSystemDefault) { return LaunchDefaultWithFile(aFile);
}
if (mPreferredAction == useHelperApp) { if (!mPreferredApplication) return NS_ERROR_FILE_NOT_FOUND;
#ifdef XP_UNIX
nsCOMPtr<nsIGIOHandlerApp> handler =
do_QueryInterface(mPreferredApplication, &rv); if (NS_SUCCEEDED(rv)) { return handler->LaunchFile(aFile->NativePath());
} #endif // 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);
bool nsMIMEInfoBase::AutomationOnlyCheckIfLaunchStubbed(nsIFile* aFile) { // This is pretty gross and hacky, but otherwise we can't automatically // test this, and we keep breaking edgecases around this, so... if (!xpc::IsInAutomation()) { returnfalse;
}
nsAutoString path;
aFile->GetPath(path);
nsCOMPtr<nsISupportsPRBool> canOpen =
do_CreateInstance("@mozilla.org/supports-PRBool;1");
canOpen->SetData(true);
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
observerService->NotifyObservers(canOpen, "test-only-opening-downloaded-file",
path.get()); bool data = true;
canOpen->GetData(&data); return !data;
}
NS_IMETHODIMP
nsMIMEInfoBase::LaunchWithURI(nsIURI* aURI,
mozilla::dom::BrowsingContext* aBrowsingContext) { // This is only being called with protocol handlers
NS_ASSERTION(mClass == eProtocolInfo, "nsMIMEInfoBase should be a protocol handler");
if (mPreferredAction == useSystemDefault) { // First, ensure we're not accidentally going to call ourselves. // That'd lead to an infinite loop (see bug 215554).
nsCOMPtr<nsIExternalProtocolService> extProtService =
do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID); if (!extProtService) { return NS_ERROR_FAILURE;
}
nsAutoCString scheme;
aURI->GetScheme(scheme); bool isDefault = false;
nsresult rv =
extProtService->IsCurrentAppOSDefaultForProtocol(scheme, &isDefault); if (NS_SUCCEEDED(rv) && isDefault) { // Lie. This will trip the handler service into showing a dialog asking // what the user wants. return NS_ERROR_FILE_NOT_FOUND;
} return LoadUriInternal(aURI);
}
if (mPreferredAction == useHelperApp) { if (!mPreferredApplication) return NS_ERROR_FILE_NOT_FOUND;
EnsureAppDetailsAvailable();
nsCOMPtr<nsILocalHandlerApp> localPreferredHandler =
do_QueryInterface(mPreferredApplication); if (localPreferredHandler) {
nsCOMPtr<nsIFile> executable;
localPreferredHandler->GetExecutable(getter_AddRefs(executable));
executable = GetCanonicalExecutable(executable); bool isOurExecutable = false; if (!executable ||
NS_FAILED(executable->Equals(sOurAppFile, &isOurExecutable)) ||
isOurExecutable) { // Lie. This will trip the handler service into showing a dialog asking // what the user wants. return NS_ERROR_FILE_NOT_FOUND;
}
} return mPreferredApplication->LaunchWithURI(aURI, aBrowsingContext);
}
// nsMIMEInfoImpl implementation
NS_IMETHODIMP
nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription) { if (mDefaultAppDescription.IsEmpty()) {
nsCOMPtr<nsIFile> defaultApp = GetDefaultApplication(); if (defaultApp) { // Don't want to cache this, just in case someone resets the app // without changing the description....
defaultApp->GetLeafName(aDefaultDescription); return NS_OK;
}
}
aDefaultDescription = mDefaultAppDescription;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.