LCOV - code coverage report
Current view: directory - content/base/src - nsDOMFileReader.h (source / functions) Found Hit Coverage
Test: app.info Lines: 7 7 100.0 %
Date: 2012-06-02 Functions: 17 13 76.5 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       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 mozila.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Corporation
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2007
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsDOMFileReader_h__
      39                 : #define nsDOMFileReader_h__
      40                 : 
      41                 : #include "nsISupportsUtils.h"      
      42                 : #include "nsString.h"
      43                 : #include "nsWeakReference.h"
      44                 : #include "nsIStreamListener.h"     
      45                 : #include "nsIInterfaceRequestor.h" 
      46                 : #include "nsJSUtils.h"             
      47                 : #include "nsTArray.h"              
      48                 : #include "nsIJSNativeInitializer.h"
      49                 : #include "prtime.h"                
      50                 : #include "nsITimer.h"              
      51                 : #include "nsICharsetDetector.h"
      52                 : #include "nsICharsetDetectionObserver.h"
      53                 : 
      54                 : #include "nsIDOMFile.h"
      55                 : #include "nsIDOMFileReader.h"
      56                 : #include "nsIDOMFileList.h"
      57                 : #include "nsIInputStream.h"
      58                 : #include "nsCOMPtr.h"
      59                 : #include "nsIStreamLoader.h"
      60                 : #include "nsIChannel.h"
      61                 : #include "prmem.h"
      62                 : 
      63                 : #include "FileIOObject.h"
      64                 : 
      65                 : class nsDOMFileReader : public mozilla::dom::FileIOObject,
      66                 :                         public nsIDOMFileReader,
      67                 :                         public nsIInterfaceRequestor,
      68                 :                         public nsSupportsWeakReference,
      69                 :                         public nsIJSNativeInitializer,
      70                 :                         public nsICharsetDetectionObserver
      71                 : {
      72                 : public:
      73                 :   nsDOMFileReader();
      74                 :   virtual ~nsDOMFileReader();
      75                 : 
      76                 :   NS_DECL_ISUPPORTS_INHERITED
      77                 : 
      78                 :   NS_DECL_NSIDOMFILEREADER
      79                 : 
      80              58 :   NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
      81                 : 
      82                 :   // nsIInterfaceRequestor 
      83                 :   NS_DECL_NSIINTERFACEREQUESTOR
      84                 : 
      85                 :   NS_DECL_EVENT_HANDLER(load)
      86                 :   NS_DECL_EVENT_HANDLER(loadend)
      87                 :   NS_DECL_EVENT_HANDLER(loadstart)
      88                 : 
      89                 :   // nsIJSNativeInitializer                                                
      90                 :   NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj, 
      91                 :                         PRUint32 argc, jsval* argv);
      92                 : 
      93                 :   // nsICharsetDetectionObserver
      94                 :   NS_IMETHOD Notify(const char *aCharset, nsDetectionConfident aConf);
      95                 : 
      96                 :   // FileIOObject overrides
      97                 :   NS_IMETHOD DoAbort(nsAString& aEvent);
      98                 :   NS_IMETHOD DoOnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
      99                 :                              nsresult aStatus, nsAString& aSuccessEvent,
     100                 :                              nsAString& aTerminationEvent);
     101                 :   NS_IMETHOD DoOnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
     102                 :                                nsIInputStream* aInputStream, PRUint32 aOffset,
     103                 :                                PRUint32 aCount);
     104                 : 
     105                 :   nsresult Init();
     106                 : 
     107            1486 :   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsDOMFileReader,
     108                 :                                                          FileIOObject)
     109                 :   void RootResultArrayBuffer();
     110                 : 
     111                 : protected:
     112                 :   enum eDataFormat {
     113                 :     FILE_AS_ARRAYBUFFER,
     114                 :     FILE_AS_BINARY,
     115                 :     FILE_AS_TEXT,
     116                 :     FILE_AS_DATAURL
     117                 :   };
     118                 : 
     119                 :   nsresult ReadFileContent(JSContext* aCx, nsIDOMBlob *aFile, const nsAString &aCharset, eDataFormat aDataFormat); 
     120                 :   nsresult GetAsText(const nsACString &aCharset,
     121                 :                      const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
     122                 :   nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, PRUint32 aDataLen, nsAString &aResult); 
     123                 :   nsresult GuessCharset(const char *aFileData, PRUint32 aDataLen, nsACString &aCharset); 
     124                 :   nsresult ConvertStream(const char *aFileData, PRUint32 aDataLen, const char *aCharset, nsAString &aResult); 
     125                 : 
     126               6 :   void FreeFileData() {
     127               6 :     PR_Free(mFileData);
     128               6 :     mFileData = nsnull;
     129               6 :     mDataLen = 0;
     130               6 :   }
     131                 : 
     132                 :   char *mFileData;
     133                 :   nsCOMPtr<nsIDOMBlob> mFile;
     134                 :   nsCString mCharset;
     135                 :   PRUint32 mDataLen;
     136                 : 
     137                 :   eDataFormat mDataFormat;
     138                 : 
     139                 :   nsString mResult;
     140                 :   nsCOMPtr<nsIPrincipal> mPrincipal;
     141                 :   
     142                 :   JSObject* mResultArrayBuffer;
     143                 : };
     144                 : 
     145                 : #endif

Generated by: LCOV version 1.7