2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-10-07 17:16:11 +00: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/. */
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
#ifndef mozilla_dom_MultipartBlobImpl_h
|
|
|
|
#define mozilla_dom_MultipartBlobImpl_h
|
2014-10-07 17:16:11 +00:00
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-10-08 16:15:22 +00:00
|
|
|
#include "mozilla/CheckedInt.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-10-08 16:15:22 +00:00
|
|
|
#include "mozilla/dom/BlobBinding.h"
|
|
|
|
#include "mozilla/dom/FileBinding.h"
|
2014-10-07 17:16:11 +00:00
|
|
|
#include <algorithm>
|
2015-06-17 18:12:23 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2016-04-11 18:31:34 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
class MultipartBlobImpl final : public BlobImplBase
|
2014-10-07 17:16:11 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// Create as a file
|
2015-12-04 21:15:46 +00:00
|
|
|
static already_AddRefed<MultipartBlobImpl>
|
|
|
|
Create(const nsTArray<RefPtr<BlobImpl>>& aBlobImpls,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aContentType,
|
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
|
|
|
// Create as a blob
|
2015-12-04 21:15:46 +00:00
|
|
|
static already_AddRefed<MultipartBlobImpl>
|
|
|
|
Create(const nsTArray<RefPtr<BlobImpl>>& aBlobImpls,
|
|
|
|
const nsAString& aContentType,
|
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
|
|
|
// Create as a file to be later initialized
|
2015-05-12 12:11:03 +00:00
|
|
|
explicit MultipartBlobImpl(const nsAString& aName)
|
|
|
|
: BlobImplBase(aName, EmptyString(), UINT64_MAX),
|
2014-10-08 16:15:22 +00:00
|
|
|
mIsFromNsIFile(false)
|
2014-10-07 17:16:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create as a blob to be later initialized
|
2015-05-12 12:11:03 +00:00
|
|
|
MultipartBlobImpl()
|
|
|
|
: BlobImplBase(EmptyString(), UINT64_MAX),
|
2014-10-08 16:15:22 +00:00
|
|
|
mIsFromNsIFile(false)
|
2014-10-07 17:16:11 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-04 21:15:46 +00:00
|
|
|
void InitializeBlob(ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2016-06-01 10:33:09 +00:00
|
|
|
void InitializeBlob(JSContext* aCx,
|
|
|
|
const Sequence<Blob::BlobPart>& aData,
|
|
|
|
const nsAString& aContentType,
|
|
|
|
bool aNativeEOL,
|
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-05-12 12:09:51 +00:00
|
|
|
void InitializeChromeFile(Blob& aData,
|
2014-10-08 16:15:23 +00:00
|
|
|
const ChromeFilePropertyBag& aBag,
|
2014-10-08 16:15:22 +00:00
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
void InitializeChromeFile(nsPIDOMWindowInner* aWindow,
|
2014-10-08 16:15:22 +00:00
|
|
|
const nsAString& aData,
|
2014-10-08 16:15:23 +00:00
|
|
|
const ChromeFilePropertyBag& aBag,
|
2014-10-08 16:15:22 +00:00
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
void InitializeChromeFile(nsPIDOMWindowInner* aWindow,
|
2014-10-08 16:15:22 +00:00
|
|
|
nsIFile* aData,
|
2014-10-08 16:15:23 +00:00
|
|
|
const ChromeFilePropertyBag& aBag,
|
2014-10-08 16:15:22 +00:00
|
|
|
bool aIsFromNsIFile,
|
|
|
|
ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
virtual already_AddRefed<BlobImpl>
|
2014-10-08 16:15:22 +00:00
|
|
|
CreateSlice(uint64_t aStart, uint64_t aLength,
|
|
|
|
const nsAString& aContentType,
|
2015-03-21 16:28:04 +00:00
|
|
|
ErrorResult& aRv) override;
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint64_t GetSize(ErrorResult& aRv) override
|
2014-10-07 17:16:11 +00:00
|
|
|
{
|
2014-10-08 16:15:22 +00:00
|
|
|
return mLength;
|
2014-10-07 17:16:11 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 14:36:37 +00:00
|
|
|
virtual void GetInternalStream(nsIInputStream** aInputStream,
|
|
|
|
ErrorResult& aRv) override;
|
2014-10-08 16:15:22 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
virtual const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const override
|
2014-10-07 17:16:11 +00:00
|
|
|
{
|
2015-07-28 22:59:56 +00:00
|
|
|
return mBlobImpls.Length() ? &mBlobImpls : nullptr;
|
2014-10-07 17:16:11 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:15:22 +00:00
|
|
|
virtual void GetMozFullPathInternal(nsAString& aFullPath,
|
2015-06-03 00:11:16 +00:00
|
|
|
ErrorResult& aRv) const override;
|
2014-10-08 16:15:22 +00:00
|
|
|
|
2015-01-13 22:15:04 +00:00
|
|
|
virtual nsresult
|
2015-03-21 16:28:04 +00:00
|
|
|
SetMutable(bool aMutable) override;
|
2015-01-13 22:15:04 +00:00
|
|
|
|
2014-10-08 16:15:22 +00:00
|
|
|
void SetName(const nsAString& aName)
|
|
|
|
{
|
|
|
|
mName = aName;
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool MayBeClonedToOtherThreads() const override;
|
2015-01-11 21:35:24 +00:00
|
|
|
|
2014-10-07 17:16:11 +00:00
|
|
|
protected:
|
2015-12-04 21:15:46 +00:00
|
|
|
MultipartBlobImpl(const nsTArray<RefPtr<BlobImpl>>& aBlobImpls,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aContentType)
|
|
|
|
: BlobImplBase(aName, aContentType, UINT64_MAX),
|
|
|
|
mBlobImpls(aBlobImpls),
|
|
|
|
mIsFromNsIFile(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MultipartBlobImpl(const nsTArray<RefPtr<BlobImpl>>& aBlobImpls,
|
|
|
|
const nsAString& aContentType)
|
|
|
|
: BlobImplBase(aContentType, UINT64_MAX),
|
|
|
|
mBlobImpls(aBlobImpls),
|
|
|
|
mIsFromNsIFile(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
virtual ~MultipartBlobImpl() {}
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-12-04 21:15:46 +00:00
|
|
|
void SetLengthAndModifiedDate(ErrorResult& aRv);
|
2014-10-07 17:16:11 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<BlobImpl>> mBlobImpls;
|
2014-10-08 16:15:22 +00:00
|
|
|
bool mIsFromNsIFile;
|
2014-10-07 17:16:11 +00:00
|
|
|
};
|
|
|
|
|
2016-04-11 18:31:34 +00:00
|
|
|
} // dom namespace
|
|
|
|
} // mozilla namespace
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
#endif // mozilla_dom_MultipartBlobImpl_h
|