Bug 825285 - Part a: Don't pass around ArchiveReaderOptions; r=khuey
authorMs2ger <ms2ger@gmail.com>
Sun, 10 Mar 2013 08:54:42 +0100
changeset 124308 10fa33c73a0b394a4d809b693ede7f8f861db366
parent 124307 1feae6162b87d7e0a78f4cc96077ff89dd0e3e78
child 124309 c79295994ef86186cb1fb712d7aa3c41c805be37
push idunknown
push userunknown
push dateunknown
reviewerskhuey
bugs825285
milestone22.0a1
Bug 825285 - Part a: Don't pass around ArchiveReaderOptions; r=khuey
dom/file/ArchiveReader.cpp
dom/file/ArchiveReader.h
dom/file/ArchiveZipEvent.cpp
dom/file/ArchiveZipEvent.h
--- a/dom/file/ArchiveReader.cpp
+++ b/dom/file/ArchiveReader.cpp
@@ -64,18 +64,20 @@ ArchiveReader::Initialize(nsISupports* a
   nsCOMPtr<nsIDOMBlob> blob;
   blob = do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj));
   if (!blob) {
     return NS_ERROR_INVALID_ARG;
   }
 
   // Extra param is an object
   if (aArgc > 1) {
-    nsresult rv = mOptions.Init(aCx, &aArgv[1]);
+    mozilla::idl::ArchiveReaderOptions options;
+    nsresult rv = options.Init(aCx, &aArgv[1]);
     NS_ENSURE_SUCCESS(rv, rv);
+    mEncoding = options.encoding;
   }
 
   mWindow = do_QueryInterface(aOwner);
   if (!mWindow) {
     return NS_ERROR_UNEXPECTED;
   }
 
   mBlob = blob;
@@ -135,17 +137,17 @@ ArchiveReader::OpenArchive()
   // Target:
   nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
   NS_ASSERTION(target, "Must have stream transport service");
 
   // Here a Event to make everything async:
   nsRefPtr<ArchiveReaderEvent> event;
 
   /* FIXME: If we want to support more than 1 format we should check the content type here: */
-  event = new ArchiveReaderZipEvent(this, mOptions);
+  event = new ArchiveReaderZipEvent(this, mEncoding);
   rv = target->Dispatch(event, NS_DISPATCH_NORMAL);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // In order to be sure that this object exists when the event finishes its task,
   // we increase the refcount here:
   AddRef();
 
   return NS_OK;
--- a/dom/file/ArchiveReader.h
+++ b/dom/file/ArchiveReader.h
@@ -92,14 +92,14 @@ protected:
   nsTArray<nsRefPtr<ArchiveRequest> > mRequests;
 
   // Everything related to the blobs and the status:
   struct {
     nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
     nsresult status;
   } mData;
 
-  mozilla::idl::ArchiveReaderOptions mOptions;
+  nsString mEncoding;
 };
 
 END_FILE_NAMESPACE
 
 #endif // mozilla_dom_file_domarchivereader_h__
--- a/dom/file/ArchiveZipEvent.cpp
+++ b/dom/file/ArchiveZipEvent.cpp
@@ -17,39 +17,39 @@ using namespace mozilla::dom;
 USING_FILE_NAMESPACE
 
 #ifndef PATH_MAX
 #  define PATH_MAX 65536 // The filename length is stored in 2 bytes
 #endif
 
 ArchiveZipItem::ArchiveZipItem(const char* aFilename,
                                const ZipCentral& aCentralStruct,
-                               const mozilla::idl::ArchiveReaderOptions& aOptions)
+                               const nsAString& aEncoding)
 : mFilename(aFilename),
   mCentralStruct(aCentralStruct),
-  mOptions(aOptions)
+  mEncoding(aEncoding)
 {
   MOZ_COUNT_CTOR(ArchiveZipItem);
 }
 
 ArchiveZipItem::~ArchiveZipItem()
 {
   MOZ_COUNT_DTOR(ArchiveZipItem);
 }
 
 nsresult
 ArchiveZipItem::ConvertFilename()
 {
-  if (mOptions.encoding.IsEmpty()) {
+  if (mEncoding.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
   nsString filenameU;
   nsresult rv = nsContentUtils::ConvertStringFromCharset(
-                  NS_ConvertUTF16toUTF8(mOptions.encoding),
+                  NS_ConvertUTF16toUTF8(mEncoding),
                   mFilename, filenameU);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (filenameU.IsEmpty()) {
     return NS_ERROR_FAILURE;
   }
 
   mFilenameU = filenameU;
@@ -106,19 +106,19 @@ uint16_t
 ArchiveZipItem::StrToInt16(const uint8_t* aStr)
 {
   return (uint16_t) ((aStr [0]) | (aStr [1] << 8));
 }
 
 // ArchiveReaderZipEvent
 
 ArchiveReaderZipEvent::ArchiveReaderZipEvent(ArchiveReader* aArchiveReader,
-                                             const mozilla::idl::ArchiveReaderOptions& aOptions)
+                                             const nsAString& aEncoding)
 : ArchiveReaderEvent(aArchiveReader),
-  mOptions(aOptions)
+  mEncoding(aEncoding)
 {
 }
 
 // NOTE: this runs in a different thread!!
 nsresult
 ArchiveReaderZipEvent::Exec()
 {
   uint32_t centralOffset(0);
@@ -196,17 +196,17 @@ ArchiveReaderZipEvent::Exec()
     if (NS_FAILED(rv) || ret != filenameLen) {
       return RunShare(NS_ERROR_UNEXPECTED);
     }
 
     filename[filenameLen] = 0;
 
     // We ignore the directories:
     if (filename[filenameLen - 1] != '/') {
-      mFileList.AppendElement(new ArchiveZipItem(filename, centralStruct, mOptions));
+      mFileList.AppendElement(new ArchiveZipItem(filename, centralStruct, mEncoding));
     }
 
     // Ignore the rest
     seekableStream->Seek(nsISeekableStream::NS_SEEK_CUR, extraLen + commentLen);
   }
 
   return RunShare(NS_OK);
 }
--- a/dom/file/ArchiveZipEvent.h
+++ b/dom/file/ArchiveZipEvent.h
@@ -19,17 +19,17 @@ BEGIN_FILE_NAMESPACE
 /**
  * ArchiveZipItem - ArchiveItem for ArchiveReaderZipEvent
  */
 class ArchiveZipItem : public ArchiveItem
 {
 public:
   ArchiveZipItem(const char* aFilename,
                  const ZipCentral& aCentralStruct,
-                 const mozilla::idl::ArchiveReaderOptions& aOptions);
+                 const nsAString& aEncoding);
   virtual ~ArchiveZipItem();
 
   nsresult GetFilename(nsString& aFilename);
 
   // From zipItem to DOMFile:
   virtual nsIDOMFile* File(ArchiveReader* aArchiveReader);
 
 public: // for the event
@@ -40,30 +40,30 @@ private:
   nsresult ConvertFilename();
 
 private: // data
   nsCString mFilename;
 
   nsString mFilenameU;
   ZipCentral mCentralStruct;
 
-  mozilla::idl::ArchiveReaderOptions mOptions;
+  nsString mEncoding;
 };
 
 /**
  * ArchiveReaderEvent implements the ArchiveReaderEvent for the ZIP format
  */
 class ArchiveReaderZipEvent : public ArchiveReaderEvent
 {
 public:
   ArchiveReaderZipEvent(ArchiveReader* aArchiveReader,
-                        const mozilla::idl::ArchiveReaderOptions& aOptions);
+                        const nsAString& aEncoding);
 
   nsresult Exec();
 
 private:
-  mozilla::idl::ArchiveReaderOptions mOptions;
+  nsString mEncoding;
 };
 
 END_FILE_NAMESPACE
 
 #endif // mozilla_dom_file_domarchivezipevent_h__