1
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Mozilla browser.
15
* The Initial Developer of the Original Code is Netscape
16
* Communications, Inc. Portions created by Netscape are
17
* Copyright (C) 1999, Mozilla. All Rights Reserved.
20
* Scott MacGregor <mscott@netscape.com>
21
* Christian Biesinger <cbiesinger@web.de>
24
#include <LaunchServices.h>
26
#include "nsMIMEInfoMac.h"
27
#include "nsILocalFileMac.h"
30
nsMIMEInfoMac::LaunchWithFile(nsIFile* aFile)
34
if (mPreferredAction == useHelperApp)
35
application = mPreferredApplication;
36
else if (mPreferredAction == useSystemDefault)
37
application = mDefaultApplication;
39
return NS_ERROR_INVALID_ARG;
43
nsCOMPtr<nsILocalFileMac> app = do_QueryInterface(application, &rv);
44
if (NS_FAILED(rv)) return rv;
46
nsCOMPtr<nsILocalFile> docToLoad = do_QueryInterface(aFile, &rv);
47
if (NS_FAILED(rv)) return rv;
49
return app->LaunchWithDoc(docToLoad, PR_FALSE);
52
// We didn't get an application to handle the file from aMIMEInfo, ask LaunchServices directly
54
nsCOMPtr <nsILocalFileMac> tempFile = do_QueryInterface(aFile, &rv);
55
if (NS_FAILED(rv)) return rv;
58
tempFile->GetFSRef(&tempFileRef);
61
if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
63
nsCOMPtr<nsILocalFileMac> app(do_CreateInstance("@mozilla.org/file/local;1"));
64
if (!app) return NS_ERROR_FAILURE;
65
app->InitWithFSRef(&appFSRef);
67
nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aFile, &rv);
68
if (NS_FAILED(rv)) return rv;
70
rv = app->LaunchWithDoc(docToLoad, PR_FALSE);