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