~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/uriloader/exthandler/mac/nsMIMEInfoMac.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
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/
 
7
 * 
 
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.
 
12
 * 
 
13
 * The Original Code is the Mozilla browser.
 
14
 * 
 
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.
 
18
 * 
 
19
 * Contributor(s):
 
20
 *   Scott MacGregor <mscott@netscape.com>
 
21
 *   Christian Biesinger <cbiesinger@web.de>
 
22
 */
 
23
 
 
24
#include <LaunchServices.h>
 
25
 
 
26
#include "nsMIMEInfoMac.h"
 
27
#include "nsILocalFileMac.h"
 
28
 
 
29
NS_IMETHODIMP
 
30
nsMIMEInfoMac::LaunchWithFile(nsIFile* aFile)
 
31
{
 
32
  nsIFile* application;
 
33
 
 
34
  if (mPreferredAction == useHelperApp)
 
35
    application = mPreferredApplication;
 
36
  else if (mPreferredAction == useSystemDefault)
 
37
    application = mDefaultApplication;
 
38
  else
 
39
    return NS_ERROR_INVALID_ARG;
 
40
 
 
41
  if (application) {
 
42
    nsresult rv;
 
43
    nsCOMPtr<nsILocalFileMac> app = do_QueryInterface(application, &rv);
 
44
    if (NS_FAILED(rv)) return rv;
 
45
 
 
46
    nsCOMPtr<nsILocalFile> docToLoad = do_QueryInterface(aFile, &rv);
 
47
    if (NS_FAILED(rv)) return rv;
 
48
 
 
49
    return app->LaunchWithDoc(docToLoad, PR_FALSE); 
 
50
  }
 
51
#ifdef XP_MACOSX
 
52
  // We didn't get an application to handle the file from aMIMEInfo, ask LaunchServices directly
 
53
  nsresult rv;
 
54
  nsCOMPtr <nsILocalFileMac> tempFile = do_QueryInterface(aFile, &rv);
 
55
  if (NS_FAILED(rv)) return rv;
 
56
  
 
57
  FSRef tempFileRef;
 
58
  tempFile->GetFSRef(&tempFileRef);
 
59
 
 
60
  FSRef appFSRef;
 
61
  if (::LSGetApplicationForItem(&tempFileRef, kLSRolesAll, &appFSRef, nsnull) == noErr)
 
62
  {
 
63
    nsCOMPtr<nsILocalFileMac> app(do_CreateInstance("@mozilla.org/file/local;1"));
 
64
    if (!app) return NS_ERROR_FAILURE;
 
65
    app->InitWithFSRef(&appFSRef);
 
66
    
 
67
    nsCOMPtr <nsILocalFile> docToLoad = do_QueryInterface(aFile, &rv);
 
68
    if (NS_FAILED(rv)) return rv;
 
69
    
 
70
    rv = app->LaunchWithDoc(docToLoad, PR_FALSE); 
 
71
  }
 
72
  return rv;
 
73
#endif
 
74
}