2004-02-24 01:49:28 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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/. */
|
2004-02-24 01:49:28 +03:00
|
|
|
|
2010-03-10 22:30:11 +03:00
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
2004-02-24 01:49:28 +03:00
|
|
|
|
2008-03-04 11:14:47 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2004-02-24 01:49:28 +03:00
|
|
|
#include "nsMIMEInfoMac.h"
|
|
|
|
#include "nsILocalFileMac.h"
|
2007-07-18 02:59:58 +04:00
|
|
|
#include "nsIFileURL.h"
|
2004-02-24 01:49:28 +03:00
|
|
|
|
2008-09-03 20:22:16 +04: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-29 10:19:26 +04:00
|
|
|
bool isPackage;
|
2008-09-03 20:22:16 +04:00
|
|
|
(void)macFile->IsPackage(&isPackage);
|
|
|
|
if (isPackage)
|
|
|
|
return macFile->GetBundleDisplayName(aDefaultDescription);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsMIMEInfoImpl::GetDefaultDescription(aDefaultDescription);
|
|
|
|
}
|
|
|
|
|
2004-02-24 01:49:28 +03:00
|
|
|
NS_IMETHODIMP
|
2007-08-21 04:47:47 +04:00
|
|
|
nsMIMEInfoMac::LaunchWithFile(nsIFile *aFile)
|
2004-02-24 01:49:28 +03:00
|
|
|
{
|
2008-03-04 11:14:47 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-07-05 23:31:44 +04:00
|
|
|
nsCOMPtr<nsIFile> application;
|
2007-07-18 02:59:58 +04:00
|
|
|
nsresult rv;
|
2007-08-21 04:47:47 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(mClass == eMIMEInfo, "only MIME infos are currently allowed"
|
|
|
|
"to pass content by value");
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-05 23:31:44 +04:00
|
|
|
if (mPreferredAction == useHelperApp) {
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-08-21 04:47:47 +04: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-18 02:59:58 +04:00
|
|
|
nsCOMPtr<nsILocalHandlerApp> localHandlerApp =
|
|
|
|
do_QueryInterface(mPreferredApplication, &rv);
|
2007-07-05 23:31:44 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-05 23:31:44 +04:00
|
|
|
rv = localHandlerApp->GetExecutable(getter_AddRefs(application));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-18 02:59:58 +04:00
|
|
|
|
2007-07-29 07:38:52 +04:00
|
|
|
} else if (mPreferredAction == useSystemDefault) {
|
2004-02-24 01:49:28 +03:00
|
|
|
application = mDefaultApplication;
|
2007-07-29 07:38:52 +04:00
|
|
|
}
|
2004-02-24 01:49:28 +03:00
|
|
|
else
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
// if we've already got an app, just QI so we have the launchWithDoc method
|
|
|
|
nsCOMPtr<nsILocalFileMac> app;
|
2004-02-24 01:49:28 +03:00
|
|
|
if (application) {
|
2007-07-18 02:59:58 +04:00
|
|
|
app = do_QueryInterface(application, &rv);
|
2004-02-24 01:49:28 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-07-18 02:59:58 +04:00
|
|
|
} else {
|
|
|
|
// otherwise ask LaunchServices for an app directly
|
2007-08-21 04:47:47 +04:00
|
|
|
nsCOMPtr<nsILocalFileMac> tempFile = do_QueryInterface(aFile, &rv);
|
2004-02-24 01:49:28 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
FSRef tempFileRef;
|
|
|
|
tempFile->GetFSRef(&tempFileRef);
|
2004-02-24 01:49:28 +03:00
|
|
|
|
2007-07-18 02:59:58 +04:00
|
|
|
FSRef appFSRef;
|
|
|
|
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
|
|
|
|
{
|
|
|
|
app = (do_CreateInstance("@mozilla.org/file/local;1"));
|
|
|
|
if (!app) return NS_ERROR_FAILURE;
|
|
|
|
app->InitWithFSRef(&appFSRef);
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2004-02-24 01:49:28 +03:00
|
|
|
}
|
2012-06-06 06:08:30 +04:00
|
|
|
return app->LaunchWithDoc(aFile, false);
|
2008-03-04 11:14:47 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-08-21 04:47:47 +04:00
|
|
|
}
|
|
|
|
|
2007-07-26 08:24:25 +04:00
|
|
|
nsresult
|
|
|
|
nsMIMEInfoMac::LoadUriInternal(nsIURI *aURI)
|
|
|
|
{
|
2009-06-23 23:09:19 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-07-26 08:24:25 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2009-06-23 23:09:19 +04:00
|
|
|
|
2007-07-26 08:24:25 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2009-06-23 23:09:19 +04:00
|
|
|
|
2007-07-26 08:24:25 +04:00
|
|
|
nsCAutoString uri;
|
2009-06-23 23:09:19 +04:00
|
|
|
aURI->GetSpec(uri);
|
2007-07-26 08:24:25 +04:00
|
|
|
if (!uri.IsEmpty()) {
|
2009-06-23 23:09:19 +04: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-26 08:24:25 +04:00
|
|
|
}
|
2009-06-23 23:09:19 +04:00
|
|
|
|
2007-07-26 08:24:25 +04:00
|
|
|
return rv;
|
2009-06-23 23:09:19 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-07-26 08:24:25 +04:00
|
|
|
}
|