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