Skip to content

Commit

Permalink
Bug 1159401 - Split Blob and File classes, r=bz
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf committed May 12, 2015
1 parent 17d5829 commit c6f881b
Show file tree
Hide file tree
Showing 106 changed files with 956 additions and 768 deletions.
4 changes: 2 additions & 2 deletions dom/archivereader/ArchiveEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ArchiveReaderEvent::RunShare(nsresult aStatus)
void
ArchiveReaderEvent::ShareMainThread()
{
nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
nsTArray<nsRefPtr<File>> fileList;

if (!NS_FAILED(mStatus)) {
// This extra step must run in the main thread:
Expand All @@ -131,7 +131,7 @@ ArchiveReaderEvent::ShareMainThread()
}

// This is a File:
nsRefPtr<nsIDOMFile> file = item->File(mArchiveReader);
nsRefPtr<File> file = item->GetFile(mArchiveReader);
if (file) {
fileList.AppendElement(file);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/archivereader/ArchiveEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ArchiveItem : public nsISupports
virtual nsresult GetFilename(nsString& aFilename) = 0;

// Generate a File
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) = 0;
virtual already_AddRefed<File> GetFile(ArchiveReader* aArchiveReader) = 0;

protected:
virtual ~ArchiveItem();
Expand Down
6 changes: 3 additions & 3 deletions dom/archivereader/ArchiveReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ USING_ARCHIVEREADER_NAMESPACE

/* static */ already_AddRefed<ArchiveReader>
ArchiveReader::Constructor(const GlobalObject& aGlobal,
File& aBlob,
Blob& aBlob,
const ArchiveReaderOptions& aOptions,
ErrorResult& aError)
{
Expand All @@ -46,7 +46,7 @@ ArchiveReader::Constructor(const GlobalObject& aGlobal,
return reader.forget();
}

ArchiveReader::ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader::ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding)
: mFileImpl(aBlob.Impl())
, mWindow(aWindow)
Expand Down Expand Up @@ -136,7 +136,7 @@ ArchiveReader::OpenArchive()

// Data received from the dispatched event:
void
ArchiveReader::Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
ArchiveReader::Ready(nsTArray<nsRefPtr<File>>& aFileList,
nsresult aStatus)
{
mStatus = READY;
Expand Down
11 changes: 5 additions & 6 deletions dom/archivereader/ArchiveReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

#include "nsCOMArray.h"
#include "nsIChannel.h"
#include "nsIDOMFile.h"
#include "mozilla/Attributes.h"

namespace mozilla {
namespace dom {
struct ArchiveReaderOptions;
class Blob;
class File;
class FileImpl;
class GlobalObject;
Expand All @@ -40,10 +40,10 @@ class ArchiveReader final : public nsISupports,
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)

static already_AddRefed<ArchiveReader>
Constructor(const GlobalObject& aGlobal, File& aBlob,
Constructor(const GlobalObject& aGlobal, Blob& aBlob,
const ArchiveReaderOptions& aOptions, ErrorResult& aError);

ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding);

nsIDOMWindow* GetParentObject() const
Expand All @@ -69,8 +69,7 @@ class ArchiveReader final : public nsISupports,
return mFileImpl;
}

void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult aStatus);
void Ready(nsTArray<nsRefPtr<File>>& aFileList, nsresult aStatus);

private:
~ArchiveReader();
Expand Down Expand Up @@ -108,7 +107,7 @@ class ArchiveReader final : public nsISupports,

// Everything related to the blobs and the status:
struct {
nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
nsTArray<nsRefPtr<File>> fileList;
nsresult status;
} mData;

Expand Down
30 changes: 17 additions & 13 deletions dom/archivereader/ArchiveRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ ArchiveRequest::OpGetFiles()
}

nsresult
ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
ArchiveRequest::ReaderReady(nsTArray<nsRefPtr<File>>& aFileList,
nsresult aStatus)
{
if (NS_FAILED(aStatus)) {
Expand Down Expand Up @@ -174,7 +174,7 @@ ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult
ArchiveRequest::GetFilenamesResult(JSContext* aCx,
JS::Value* aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length()));
nsresult rv;
Expand All @@ -185,7 +185,7 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,

JS::Rooted<JSString*> str(aCx);
for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];

nsString filename;
rv = file->GetName(filename);
Expand All @@ -211,18 +211,21 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,
nsresult
ArchiveRequest::GetFileResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];

nsString filename;
nsresult rv = file->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);

if (filename == mFilename) {
return nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile),
aValue);
if (!ToJSValue(aCx, file, aValue)) {
return NS_ERROR_FAILURE;
}

return NS_OK;
}
}

Expand All @@ -232,21 +235,22 @@ ArchiveRequest::GetFileResult(JSContext* aCx,
nsresult
ArchiveRequest::GetFilesResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length()));
if (!array) {
return NS_ERROR_OUT_OF_MEMORY;
}

for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];

JS::Rooted<JS::Value> value(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile),
&value);
if (NS_FAILED(rv) ||
!JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) {
if (!ToJSValue(aCx, file, &value)) {
return NS_ERROR_FAILURE;
}

if (!JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
}
Expand Down
9 changes: 4 additions & 5 deletions dom/archivereader/ArchiveRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class ArchiveRequest : public mozilla::dom::DOMRequest
void OpGetFile(const nsAString& aFilename);
void OpGetFiles();

nsresult ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult aStatus);
nsresult ReaderReady(nsTArray<nsRefPtr<File>>& aFileList, nsresult aStatus);

public: // static
static already_AddRefed<ArchiveRequest> Create(nsPIDOMWindow* aOwner,
Expand All @@ -61,13 +60,13 @@ class ArchiveRequest : public mozilla::dom::DOMRequest

nsresult GetFilenamesResult(JSContext* aCx,
JS::Value* aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);
nsresult GetFileResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);
nsresult GetFilesResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);

protected:
// The reader:
Expand Down
8 changes: 5 additions & 3 deletions dom/archivereader/ArchiveZipEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ ArchiveZipItem::GetFilename(nsString& aFilename)
}

// From zipItem to File:
nsIDOMFile*
ArchiveZipItem::File(ArchiveReader* aArchiveReader)
already_AddRefed<File>
ArchiveZipItem::GetFile(ArchiveReader* aArchiveReader)
{
nsString filename;

if (NS_FAILED(GetFilename(filename))) {
return nullptr;
}

return new dom::File(aArchiveReader,
nsRefPtr<dom::File> file = dom::File::Create(aArchiveReader,
new ArchiveZipFileImpl(filename,
NS_ConvertUTF8toUTF16(GetType()),
StrToInt32(mCentralStruct.orglen),
mCentralStruct, aArchiveReader->GetFileImpl()));
MOZ_ASSERT(file);
return file.forget();
}

uint32_t
Expand Down
3 changes: 2 additions & 1 deletion dom/archivereader/ArchiveZipEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class ArchiveZipItem : public ArchiveItem
nsresult GetFilename(nsString& aFilename) override;

// From zipItem to File:
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) override;
virtual already_AddRefed<File>
GetFile(ArchiveReader* aArchiveReader) override;

public: // for the event
static uint32_t StrToInt32(const uint8_t* aStr);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/BlobSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BlobSet {

nsTArray<nsRefPtr<FileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }

already_AddRefed<File> GetBlobInternal(nsISupports* aParent,
already_AddRefed<Blob> GetBlobInternal(nsISupports* aParent,
const nsACString& aContentType);

protected:
Expand Down
14 changes: 7 additions & 7 deletions dom/base/Console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ ConsoleStructuredCloneCallbacksRead(JSContext* aCx,

JS::Rooted<JS::Value> val(aCx);
{
nsRefPtr<File> file =
new File(data->mParent, data->mFiles.ElementAt(aIndex));
if (!GetOrCreateDOMReflector(aCx, file, &val)) {
nsRefPtr<Blob> blob =
Blob::Create(data->mParent, data->mFiles.ElementAt(aIndex));
if (!ToJSValue(aCx, blob, &val)) {
return nullptr;
}
}
Expand All @@ -114,14 +114,14 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx,
static_cast<ConsoleStructuredCloneData*>(aClosure);
MOZ_ASSERT(data);

nsRefPtr<File> file;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, file)) &&
file->Impl()->MayBeClonedToOtherThreads()) {
nsRefPtr<Blob> blob;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
blob->Impl()->MayBeClonedToOtherThreads()) {
if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB, data->mFiles.Length())) {
return false;
}

data->mFiles.AppendElement(file->Impl());
data->mFiles.AppendElement(blob->Impl());
return true;
}

Expand Down
Loading

0 comments on commit c6f881b

Please sign in to comment.