uriloader/exthandler/nsMIMEInfoImpl.h

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim:set ts=4 sw=4 sts=4 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef __nsmimeinfoimpl_h___
     7 #define __nsmimeinfoimpl_h___
     9 #include "nsIMIMEInfo.h"
    10 #include "nsIAtom.h"
    11 #include "nsString.h"
    12 #include "nsTArray.h"
    13 #include "nsIMutableArray.h"
    14 #include "nsIFile.h"
    15 #include "nsCOMPtr.h"
    16 #include "nsIURI.h"
    17 #include "nsIProcess.h"
    19 /** 
    20  * UTF8 moz-icon URI string for the default handler application's icon, if 
    21  * available.
    22  */
    23 #define PROPERTY_DEFAULT_APP_ICON_URL "defaultApplicationIconURL"
    24 /** 
    25  * UTF8 moz-icon URI string for the user's preferred handler application's 
    26  * icon, if available.
    27  */
    28 #define PROPERTY_CUSTOM_APP_ICON_URL "customApplicationIconURL"
    30 /**
    31  * Basic implementation of nsIMIMEInfo. Incomplete - it is meant to be
    32  * subclassed, and GetHasDefaultHandler as well as LaunchDefaultWithFile need to
    33  * be implemented.
    34  */
    35 class nsMIMEInfoBase : public nsIMIMEInfo {
    36   public:
    37     NS_DECL_THREADSAFE_ISUPPORTS
    39     // I'd use NS_DECL_NSIMIMEINFO, but I don't want GetHasDefaultHandler
    40     NS_IMETHOD GetFileExtensions(nsIUTF8StringEnumerator **_retval);
    41     NS_IMETHOD SetFileExtensions(const nsACString & aExtensions);
    42     NS_IMETHOD ExtensionExists(const nsACString & aExtension, bool *_retval);
    43     NS_IMETHOD AppendExtension(const nsACString & aExtension);
    44     NS_IMETHOD GetPrimaryExtension(nsACString & aPrimaryExtension);
    45     NS_IMETHOD SetPrimaryExtension(const nsACString & aPrimaryExtension);
    46     NS_IMETHOD GetType(nsACString & aType);
    47     NS_IMETHOD GetMIMEType(nsACString & aMIMEType);
    48     NS_IMETHOD GetDescription(nsAString & aDescription);
    49     NS_IMETHOD SetDescription(const nsAString & aDescription);
    50     NS_IMETHOD Equals(nsIMIMEInfo *aMIMEInfo, bool *_retval);
    51     NS_IMETHOD GetPreferredApplicationHandler(nsIHandlerApp * *aPreferredAppHandler);
    52     NS_IMETHOD SetPreferredApplicationHandler(nsIHandlerApp * aPreferredAppHandler);
    53     NS_IMETHOD GetPossibleApplicationHandlers(nsIMutableArray * *aPossibleAppHandlers);
    54     NS_IMETHOD GetDefaultDescription(nsAString & aDefaultDescription);
    55     NS_IMETHOD LaunchWithFile(nsIFile *aFile);
    56     NS_IMETHOD LaunchWithURI(nsIURI *aURI,
    57                              nsIInterfaceRequestor *aWindowContext);
    58     NS_IMETHOD GetPreferredAction(nsHandlerInfoAction *aPreferredAction);
    59     NS_IMETHOD SetPreferredAction(nsHandlerInfoAction aPreferredAction);
    60     NS_IMETHOD GetAlwaysAskBeforeHandling(bool *aAlwaysAskBeforeHandling);
    61     NS_IMETHOD SetAlwaysAskBeforeHandling(bool aAlwaysAskBeforeHandling); 
    62     NS_IMETHOD GetPossibleLocalHandlers(nsIArray **_retval); 
    64     enum HandlerClass {
    65       eMIMEInfo,
    66       eProtocolInfo
    67     };
    69     // nsMIMEInfoBase methods
    70     nsMIMEInfoBase(const char *aMIMEType = "") NS_HIDDEN;
    71     nsMIMEInfoBase(const nsACString& aMIMEType) NS_HIDDEN;
    72     nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass) NS_HIDDEN;
    73     virtual ~nsMIMEInfoBase();        // must be virtual, as the the base class's Release should call the subclass's destructor
    75     void SetMIMEType(const nsACString & aMIMEType) { mSchemeOrType = aMIMEType; }
    77     void SetDefaultDescription(const nsString& aDesc) { mDefaultAppDescription = aDesc; }
    79     /**
    80      * Copies basic data of this MIME Info Implementation to the given other
    81      * MIME Info. The data consists of the MIME Type, the (default) description,
    82      * the MacOS type and creator, and the extension list (this object's
    83      * extension list will replace aOther's list, not append to it). This
    84      * function also ensures that aOther's primary extension will be the same as
    85      * the one of this object.
    86      */
    87     void CopyBasicDataTo(nsMIMEInfoBase* aOther);
    89     /**
    90      * Return whether this MIMEInfo has any extensions
    91      */
    92     bool HasExtensions() const { return mExtensions.Length() != 0; }
    94   protected:
    95     /**
    96      * Launch the default application for the given file.
    97      * For even more control over the launching, override launchWithFile.
    98      * Also see the comment about nsIMIMEInfo in general, above.
    99      *
   100      * @param aFile The file that should be opened
   101      */
   102     virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile) = 0;
   104     /**
   105      * Loads the URI with the OS default app.
   106      *
   107      * @param aURI The URI to pass off to the OS.
   108      */
   109     virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI) = 0;
   111     static already_AddRefed<nsIProcess> InitProcess(nsIFile* aApp,
   112                                                     nsresult* aResult);
   114     /**
   115      * This method can be used to launch the file or URI with a single 
   116      * argument (typically either a file path or a URI spec).  This is 
   117      * meant as a helper method for implementations of
   118      * LaunchWithURI/LaunchDefaultWithFile.
   119      *
   120      * @param aApp The application to launch (may not be null)
   121      * @param aArg The argument to pass on the command line
   122      */
   123     static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp,
   124                                                    const nsCString &aArg);
   125     static NS_HIDDEN_(nsresult) LaunchWithIProcess(nsIFile* aApp,
   126                                                    const nsString &aArg);
   128     /**
   129      * Given a file: nsIURI, return the associated nsIFile
   130      *
   131      * @param  aURI      the file: URI in question
   132      * @param  aFile     the associated nsIFile (out param)
   133      */
   134     static NS_HIDDEN_(nsresult) GetLocalFileFromURI(nsIURI *aURI,
   135                                                     nsIFile **aFile);
   137     // member variables
   138     nsTArray<nsCString>    mExtensions; ///< array of file extensions associated w/ this MIME obj
   139     nsString               mDescription; ///< human readable description
   140     nsCString              mSchemeOrType;
   141     HandlerClass           mClass;
   142     nsCOMPtr<nsIHandlerApp> mPreferredApplication;
   143     nsCOMPtr<nsIMutableArray> mPossibleApplications;
   144     nsHandlerInfoAction    mPreferredAction; ///< preferred action to associate with this type
   145     nsString               mPreferredAppDescription;
   146     nsString               mDefaultAppDescription;
   147     bool                   mAlwaysAskBeforeHandling;
   148 };
   151 /**
   152  * This is a complete implementation of nsIMIMEInfo, and contains all necessary
   153  * methods. However, depending on your platform you may want to use a different
   154  * way of launching applications. This class stores the default application in a
   155  * member variable and provides a function for setting it. For local
   156  * applications, launching is done using nsIProcess, native path of the file to
   157  * open as first argument.
   158  */
   159 class nsMIMEInfoImpl : public nsMIMEInfoBase {
   160   public:
   161     nsMIMEInfoImpl(const char *aMIMEType = "") : nsMIMEInfoBase(aMIMEType) {}
   162     nsMIMEInfoImpl(const nsACString& aMIMEType) : nsMIMEInfoBase(aMIMEType) {}
   163     nsMIMEInfoImpl(const nsACString& aType, HandlerClass aClass) :
   164       nsMIMEInfoBase(aType, aClass) {}
   165     virtual ~nsMIMEInfoImpl() {}
   167     // nsIMIMEInfo methods
   168     NS_IMETHOD GetHasDefaultHandler(bool *_retval);
   169     NS_IMETHOD GetDefaultDescription(nsAString& aDefaultDescription);
   171     // additional methods
   172     /**
   173      * Sets the default application. Supposed to be only called by the OS Helper
   174      * App Services; the default application is immutable after it is first set.
   175      */
   176     void SetDefaultApplication(nsIFile* aApp) { if (!mDefaultApplication) mDefaultApplication = aApp; }
   178   protected:
   179     // nsMIMEInfoBase methods
   180     /**
   181      * The base class implementation is to use LaunchWithIProcess in combination
   182      * with mDefaultApplication. Subclasses can override that behaviour.
   183      */
   184     virtual NS_HIDDEN_(nsresult) LaunchDefaultWithFile(nsIFile* aFile);
   186     /**
   187      * Loads the URI with the OS default app.  This should be overridden by each
   188      * OS's implementation.
   189      */
   190     virtual NS_HIDDEN_(nsresult) LoadUriInternal(nsIURI *aURI) = 0;
   192     nsCOMPtr<nsIFile>      mDefaultApplication; ///< default application associated with this type.
   193 };
   195 #endif //__nsmimeinfoimpl_h___

mercurial