2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-10 11:30:11 -08:00
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-04 00:14:47 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsMIMEInfoMac.h"
|
|
|
|
#include "nsILocalFileMac.h"
|
2007-07-17 15:59:58 -07:00
|
|
|
#include "nsIFileURL.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-03 09:22:16 -07:00
|
|
|
// We override this to make sure app bundles display their pretty name (without .app suffix)
|
|
|
|
NS_IMETHODIMP nsMIMEInfoMac::GetDefaultDescription(nsAString& aDefaultDescription)
|
|
|
|
{
|
|
|
|
if (mDefaultApplication) {
|
|
|
|
nsCOMPtr<nsILocalFileMac> macFile = do_QueryInterface(mDefaultApplication);
|
|
|
|
if (macFile) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isPackage;
|
2008-09-03 09:22:16 -07:00
|
|
|
(void)macFile->IsPackage(&isPackage);
|
|
|
|
if (isPackage)
|
|
|
|
return macFile->GetBundleDisplayName(aDefaultDescription);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsMIMEInfoImpl::GetDefaultDescription(aDefaultDescription);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2007-08-20 17:47:47 -07:00
|
|
|
nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-04 00:14:47 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-07-05 12:31:44 -07:00
|
|
|
nsCOMPtr<nsIFile> application;
|
2007-07-17 15:59:58 -07:00
|
|
|
nsresult rv;
|
2007-08-20 17:47:47 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mClass == eMIMEInfo, "only MIME infos are currently allowed"
|
|
|
|
"to pass content by value");
|
2007-07-17 15:59:58 -07:00
|
|
|
|
2007-07-05 12:31:44 -07:00
|
|
|
if (mPreferredAction == useHelperApp) {
|
2007-07-17 15:59:58 -07:00
|
|
|
|
2007-08-20 17:47:47 -07:00
|
|
|
// we don't yet support passing content by value (rather than reference)
|
|
|
|
// to web apps. at some point, we will probably want to.
|
2007-07-17 15:59:58 -07:00
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandlerApp =
|
|
|
|
do_QueryInterface(mPreferredApplication, &rv);
|
2007-07-05 12:31:44 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-17 15:59:58 -07:00
|
|
|
|
2007-07-05 12:31:44 -07:00
|
|
|
rv = localHandlerApp->GetExecutable(getter_AddRefs(application));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-17 15:59:58 -07:00
|
|
|
|
2007-07-28 20:38:52 -07:00
|
|
|
} else if (mPreferredAction == useSystemDefault) {
|
2007-03-22 10:30:00 -07:00
|
|
|
application = mDefaultApplication;
|
2007-07-28 20:38:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-17 15:59:58 -07:00
|
|
|
// if we've already got an app, just QI so we have the launchWithDoc method
|
|
|
|
nsCOMPtr<nsILocalFileMac> app;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (application) {
|
2007-07-17 15:59:58 -07:00
|
|
|
app = do_QueryInterface(application, &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-07-17 15:59:58 -07:00
|
|
|
} else {
|
|
|
|
// otherwise ask LaunchServices for an app directly
|
2007-08-20 17:47:47 -07:00
|
|
|
nsCOMPtr<nsILocalFileMac> tempFile = do_QueryInterface(aFile, &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-07-17 15:59:58 -07:00
|
|
|
FSRef tempFileRef;
|
|
|
|
tempFile->GetFSRef(&tempFileRef);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-17 15:59:58 -07:00
|
|
|
FSRef appFSRef;
|
2012-07-30 07:20:58 -07:00
|
|
|
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nullptr) == noErr)
|
2007-07-17 15:59:58 -07:00
|
|
|
{
|
|
|
|
app = (do_CreateInstance("@mozilla.org/file/local;1"));
|
|
|
|
if (!app) return NS_ERROR_FAILURE;
|
|
|
|
app->InitWithFSRef(&appFSRef);
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-05 19:08:30 -07:00
|
|
|
return app->LaunchWithDoc(aFile, false);
|
2008-03-04 00:14:47 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-08-20 17:47:47 -07:00
|
|
|
}
|
|
|
|
|
2007-07-25 21:24:25 -07:00
|
|
|
nsresult
|
|
|
|
nsMIMEInfoMac::LoadUriInternal(nsIURI *aURI)
|
|
|
|
{
|
2009-06-23 12:09:19 -07:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-07-25 21:24:25 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2009-06-23 12:09:19 -07:00
|
|
|
|
2007-07-25 21:24:25 -07:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2009-06-23 12:09:19 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString uri;
|
2009-06-23 12:09:19 -07:00
|
|
|
aURI->GetSpec(uri);
|
2007-07-25 21:24:25 -07:00
|
|
|
if (!uri.IsEmpty()) {
|
2009-06-23 12:09:19 -07:00
|
|
|
CFURLRef myURLRef = ::CFURLCreateWithBytes(kCFAllocatorDefault,
|
|
|
|
(const UInt8*)uri.get(),
|
|
|
|
strlen(uri.get()),
|
|
|
|
kCFStringEncodingUTF8,
|
|
|
|
NULL);
|
|
|
|
if (myURLRef) {
|
|
|
|
OSStatus status = ::LSOpenCFURLRef(myURLRef, NULL);
|
|
|
|
if (status == noErr)
|
|
|
|
rv = NS_OK;
|
|
|
|
::CFRelease(myURLRef);
|
|
|
|
}
|
2007-07-25 21:24:25 -07:00
|
|
|
}
|
2009-06-23 12:09:19 -07:00
|
|
|
|
2007-07-25 21:24:25 -07:00
|
|
|
return rv;
|
2009-06-23 12:09:19 -07:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-07-25 21:24:25 -07:00
|
|
|
}
|