2009-10-07 01:30:26 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-07 01:30:26 -07:00
|
|
|
|
2009-11-09 12:05:16 -08:00
|
|
|
#ifndef nsDOMFileReader_h__
|
|
|
|
#define nsDOMFileReader_h__
|
2009-10-07 01:30:26 -07:00
|
|
|
|
|
|
|
#include "nsISupportsUtils.h"
|
2011-09-29 09:06:35 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsWeakReference.h"
|
2009-10-07 01:30:26 -07:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsIJSNativeInitializer.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
|
|
|
|
#include "nsIDOMFile.h"
|
2009-11-09 12:05:16 -08:00
|
|
|
#include "nsIDOMFileReader.h"
|
2009-10-07 01:30:26 -07:00
|
|
|
#include "nsIDOMFileList.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStreamLoader.h"
|
|
|
|
#include "nsIChannel.h"
|
2009-11-22 22:23:23 -08:00
|
|
|
#include "prmem.h"
|
2009-10-07 01:30:26 -07:00
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
#include "FileIOObject.h"
|
2009-10-07 01:30:26 -07:00
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
class nsDOMFileReader : public mozilla::dom::FileIOObject,
|
2009-11-09 12:05:16 -08:00
|
|
|
public nsIDOMFileReader,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsSupportsWeakReference,
|
2012-06-03 09:33:52 -07:00
|
|
|
public nsIJSNativeInitializer
|
2009-10-07 01:30:26 -07:00
|
|
|
{
|
|
|
|
public:
|
2009-11-09 12:05:16 -08:00
|
|
|
nsDOMFileReader();
|
|
|
|
virtual ~nsDOMFileReader();
|
2009-10-07 01:30:26 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2009-11-09 12:05:16 -08:00
|
|
|
NS_DECL_NSIDOMFILEREADER
|
2009-10-07 01:30:26 -07:00
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
|
|
|
|
|
2009-10-07 01:30:26 -07:00
|
|
|
// nsIInterfaceRequestor
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
2011-09-29 12:18:58 -07:00
|
|
|
NS_DECL_EVENT_HANDLER(load)
|
|
|
|
NS_DECL_EVENT_HANDLER(loadend)
|
|
|
|
NS_DECL_EVENT_HANDLER(loadstart)
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
// nsIJSNativeInitializer
|
|
|
|
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
2009-10-07 01:30:26 -07:00
|
|
|
PRUint32 argc, jsval* argv);
|
|
|
|
|
2011-09-29 09:06:35 -07:00
|
|
|
// FileIOObject overrides
|
|
|
|
NS_IMETHOD DoAbort(nsAString& aEvent);
|
|
|
|
NS_IMETHOD DoOnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
|
|
|
|
nsresult aStatus, nsAString& aSuccessEvent,
|
|
|
|
nsAString& aTerminationEvent);
|
|
|
|
NS_IMETHOD DoOnDataAvailable(nsIRequest* aRequest, nsISupports* aContext,
|
|
|
|
nsIInputStream* aInputStream, PRUint32 aOffset,
|
|
|
|
PRUint32 aCount);
|
2009-10-07 01:30:26 -07:00
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
|
2011-06-30 17:50:44 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsDOMFileReader,
|
2011-09-29 09:06:35 -07:00
|
|
|
FileIOObject)
|
2011-06-30 17:50:44 -07:00
|
|
|
void RootResultArrayBuffer();
|
|
|
|
|
2009-10-07 01:30:26 -07:00
|
|
|
protected:
|
2009-11-24 17:53:17 -08:00
|
|
|
enum eDataFormat {
|
2011-06-30 17:50:44 -07:00
|
|
|
FILE_AS_ARRAYBUFFER,
|
2009-11-24 17:53:17 -08:00
|
|
|
FILE_AS_BINARY,
|
|
|
|
FILE_AS_TEXT,
|
|
|
|
FILE_AS_DATAURL
|
|
|
|
};
|
|
|
|
|
2011-06-30 17:50:44 -07:00
|
|
|
nsresult ReadFileContent(JSContext* aCx, nsIDOMBlob *aFile, const nsAString &aCharset, eDataFormat aDataFormat);
|
2010-10-07 09:36:23 -07:00
|
|
|
nsresult GetAsText(const nsACString &aCharset,
|
2009-10-07 01:30:26 -07:00
|
|
|
const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
|
2010-10-13 16:25:33 -07:00
|
|
|
nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, PRUint32 aDataLen, nsAString &aResult);
|
2009-10-07 01:30:26 -07:00
|
|
|
nsresult ConvertStream(const char *aFileData, PRUint32 aDataLen, const char *aCharset, nsAString &aResult);
|
|
|
|
|
2009-11-22 22:23:23 -08:00
|
|
|
void FreeFileData() {
|
|
|
|
PR_Free(mFileData);
|
2012-07-30 07:20:58 -07:00
|
|
|
mFileData = nullptr;
|
2009-11-22 22:23:23 -08:00
|
|
|
mDataLen = 0;
|
|
|
|
}
|
|
|
|
|
2009-10-07 01:30:26 -07:00
|
|
|
char *mFileData;
|
2010-10-13 16:25:33 -07:00
|
|
|
nsCOMPtr<nsIDOMBlob> mFile;
|
2010-10-07 09:36:23 -07:00
|
|
|
nsCString mCharset;
|
2009-10-07 01:30:26 -07:00
|
|
|
PRUint32 mDataLen;
|
2009-11-24 17:53:17 -08:00
|
|
|
|
|
|
|
eDataFormat mDataFormat;
|
2009-10-07 01:30:26 -07:00
|
|
|
|
2009-11-09 12:05:16 -08:00
|
|
|
nsString mResult;
|
2009-10-07 01:30:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2011-06-30 17:50:44 -07:00
|
|
|
|
|
|
|
JSObject* mResultArrayBuffer;
|
2009-10-07 01:30:26 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|