LCOV - code coverage report
Current view: directory - xpcom/build - Omnijar.h (source / functions) Found Hit Coverage
Test: app.info Lines: 6 0 0.0 %
Date: 2012-06-02 Functions: 2 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Michael Wu <mwu@mozilla.com>
      24                 :  *   Mike Hommey <mh@glandium.org>
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      28                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef mozilla_Omnijar_h
      41                 : #define mozilla_Omnijar_h
      42                 : 
      43                 : #include "nscore.h"
      44                 : #include "nsCOMPtr.h"
      45                 : #include "nsString.h"
      46                 : #include "nsIFile.h"
      47                 : #include "nsZipArchive.h"
      48                 : 
      49                 : class nsIURI;
      50                 : 
      51                 : namespace mozilla {
      52                 : 
      53                 : class Omnijar {
      54                 : private:
      55                 : /**
      56                 :  * Store an nsIFile for an omni.jar. We can store two paths here, one
      57                 :  * for GRE (corresponding to resource://gre/) and one for APP
      58                 :  * (corresponding to resource:/// and resource://app/), but only
      59                 :  * store one when both point to the same location (unified).
      60                 :  */
      61                 : static nsIFile *sPath[2];
      62                 : 
      63                 : /**
      64                 :  * Cached nsZipArchives for the corresponding sPath
      65                 :  */
      66                 : static nsZipArchive *sReader[2];
      67                 : 
      68                 : /**
      69                 :  * Has Omnijar::Init() been called?
      70                 :  */
      71                 : static bool sInitialized;
      72                 : 
      73                 : public:
      74                 : enum Type {
      75                 :     GRE = 0,
      76                 :     APP = 1
      77                 : };
      78                 : 
      79                 : /**
      80                 :  * Returns whether SetBase has been called at least once with
      81                 :  * a valid nsIFile
      82                 :  */
      83                 : static inline bool
      84               0 : IsInitialized()
      85                 : {
      86               0 :     return sInitialized;
      87                 : }
      88                 : 
      89                 : /**
      90                 :  * Initializes the Omnijar API with the given directory or file for GRE and
      91                 :  * APP. Each of the paths given can be:
      92                 :  * - a file path, pointing to the omnijar file,
      93                 :  * - a directory path, pointing to a directory containing an "omni.jar" file,
      94                 :  * - nsnull for autodetection of an "omni.jar" file.
      95                 :  */
      96                 : static void Init(nsIFile *aGrePath = nsnull, nsIFile *aAppPath = nsnull);
      97                 : 
      98                 : /**
      99                 :  * Cleans up the Omnijar API
     100                 :  */
     101                 : static void CleanUp();
     102                 : 
     103                 : /**
     104                 :  * Returns an nsIFile pointing to the omni.jar file for GRE or APP.
     105                 :  * Returns nsnull when there is no corresponding omni.jar.
     106                 :  * Also returns nsnull for APP in the unified case.
     107                 :  */
     108                 : static inline already_AddRefed<nsIFile>
     109                 : GetPath(Type aType)
     110                 : {
     111                 :     NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized");
     112                 :     nsCOMPtr<nsIFile> path = sPath[aType];
     113                 :     return path.forget();
     114                 : }
     115                 : 
     116                 : /**
     117                 :  * Returns whether GRE or APP use an omni.jar. Returns PR_False for
     118                 :  * APP when using an omni.jar in the unified case.
     119                 :  */
     120                 : static inline bool
     121                 : HasOmnijar(Type aType)
     122                 : {
     123                 :     NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized");
     124                 :     return !!sPath[aType];
     125                 : }
     126                 : 
     127                 : /**
     128                 :  * Returns a nsZipArchive pointer for the omni.jar file for GRE or
     129                 :  * APP. Returns nsnull in the same cases GetPath() would.
     130                 :  */
     131                 : static inline already_AddRefed<nsZipArchive>
     132               0 : GetReader(Type aType)
     133                 : {
     134               0 :     NS_ABORT_IF_FALSE(IsInitialized(), "Omnijar not initialized");
     135               0 :     nsRefPtr<nsZipArchive> reader = sReader[aType];
     136               0 :     return reader.forget();
     137                 : }
     138                 : 
     139                 : /**
     140                 :  * Returns a nsZipArchive pointer for the given path IAOI the given
     141                 :  * path is the omni.jar for either GRE or APP.
     142                 :  */
     143                 : static already_AddRefed<nsZipArchive> GetReader(nsIFile *aPath);
     144                 : 
     145                 : /**
     146                 :  * Returns the URI string corresponding to the omni.jar or directory
     147                 :  * for GRE or APP. i.e. jar:/path/to/omni.jar!/ for omni.jar and
     148                 :  * /path/to/base/dir/ otherwise. Returns an empty string for APP in
     149                 :  * the unified case.
     150                 :  * The returned URI is guaranteed to end with a slash.
     151                 :  */
     152                 : static nsresult GetURIString(Type aType, nsACString &result);
     153                 : 
     154                 : private:
     155                 : /**
     156                 :  * Used internally, respectively by Init() and CleanUp()
     157                 :  */
     158                 : static void InitOne(nsIFile *aPath, Type aType);
     159                 : static void CleanUpOne(Type aType);
     160                 : 
     161                 : }; /* class Omnijar */
     162                 : 
     163                 : } /* namespace mozilla */
     164                 : 
     165                 : #endif /* mozilla_Omnijar_h */

Generated by: LCOV version 1.7