Merge m-c to b2g-inbound a=merge

This commit is contained in:
Wes Kocher 2014-10-08 17:17:46 -07:00
commit 18fdfc5f13
420 changed files with 5691 additions and 5511 deletions

View File

@ -181,7 +181,7 @@ FilePicker.prototype = {
}
// The name to be shown can be part of the message, or can be taken from
// the DOMFile (if the blob is a DOMFile).
// the File (if the blob is a File).
let name = data.result.name;
if (!name &&
(data.result.blob instanceof this.mParent.File) &&
@ -207,9 +207,9 @@ FilePicker.prototype = {
}
}
let file = new this.mParent.File(data.result.blob,
{ name: name,
type: data.result.blob.type });
let file = new this.mParent.File([data.result.blob],
name,
{ type: data.result.blob.type });
if (file) {
this.fireSuccess(file);

View File

@ -67,7 +67,7 @@ var testCases = [
},
fileName: 'test5.txt'},
// case 6: returns file without name. This case may fail because we
// need to make sure the DOMFile can be sent through
// need to make sure the File can be sent through
// sendAsyncMessage API.
{ pickedResult: { success: true,
result: {
@ -96,7 +96,7 @@ function handleMessage(data) {
break;
case 'file-picked-posted':
is(fileInput.value, activeTestCase.fileName,
'DOMFile should be able to send through message.');
'File should be able to send through message.');
processTestCase();
break;
}

View File

@ -2,6 +2,7 @@
/*.dylib
/certutil
/firefox-bin
/gtest/***
/pk12util
/ssltunnel
/webapprt-stub

View File

@ -398,8 +398,7 @@ panel[noactions] > richlistbox > richlistitem[type~="action"] > .ac-url-box > .a
visibility: visible;
}
#urlbar:not([actiontype]) > #urlbar-display-box,
#urlbar:not([actiontype="switchtab"]) > #urlbar-display-box > .urlbar-display-switchtab {
#urlbar:not([actiontype="switchtab"]) > #urlbar-display-box {
display: none;
}

View File

@ -3,7 +3,7 @@
Cu.import("resource://gre/modules/NetUtil.jsm");
function test() {
var file = new File(new Blob(['test'], {type: 'text/plain'}), {name: 'test-name'});
var file = new File([new Blob(['test'], {type: 'text/plain'})], "test-name");
var url = URL.createObjectURL(file);
var channel = NetUtil.newChannel(url);

View File

@ -425,7 +425,7 @@ this.GoogleImporter.prototype = {
if (Object.keys(adr).length) {
adr.pref = (addressNode.getAttribute("primary") == "true");
adr.type = [getFieldType(addressNode)];
contacts.adr.push(adr);
contact.adr.push(adr);
}
}
}

View File

@ -58,6 +58,13 @@
// Local mocks
var mockContact = {
name: ["Mr Smith"],
email: [{
value: "smith@invalid.com"
}]
};
var mockClient = {
requestCallUrl: noop,
requestCallUrlInfo: noop
@ -254,7 +261,8 @@
Example({summary: "Connecting", dashed: "true",
style: {width: "260px", height: "265px"}},
React.DOM.div({className: "fx-embedded"},
DesktopPendingConversationView({callState: "gather", calleeId: "Mr Smith"})
DesktopPendingConversationView({callState: "gather",
contact: mockContact})
)
)
),

View File

@ -58,6 +58,13 @@
// Local mocks
var mockContact = {
name: ["Mr Smith"],
email: [{
value: "smith@invalid.com"
}]
};
var mockClient = {
requestCallUrl: noop,
requestCallUrlInfo: noop
@ -254,7 +261,8 @@
<Example summary="Connecting" dashed="true"
style={{width: "260px", height: "265px"}}>
<div className="fx-embedded">
<DesktopPendingConversationView callState={"gather"} calleeId="Mr Smith" />
<DesktopPendingConversationView callState={"gather"}
contact={mockContact} />
</div>
</Example>
</Section>

View File

@ -19,7 +19,7 @@ if [ -f /c/builds/google-oauth-api.key ]; then
else
_google_oauth_api_keyfile=/e/builds/google-oauth-api.key
fi
ac_add_options --with-google-api-keyfile=${_google_oauth_api_keyfile}
ac_add_options --with-google-oauth-api-keyfile=${_google_oauth_api_keyfile}
# Needed to enable breakpad in application.ini
export MOZILLA_OFFICIAL=1

View File

@ -17,7 +17,7 @@ if [ -f /c/builds/google-oauth-api.key ]; then
else
_google_oauth_api_keyfile=/e/builds/google-oauth-api.key
fi
ac_add_options --with-google-api-keyfile=${_google_oauth_api_keyfile}
ac_add_options --with-google-oauth-api-keyfile=${_google_oauth_api_keyfile}
# Needed to enable breakpad in application.ini
export MOZILLA_OFFICIAL=1

View File

@ -47,7 +47,7 @@ define([AC_OUTPUT_SUBDIRS],
dnl from msys (this script) to python (below), we have to resort to hacks,
dnl storing the environment and command line arguments from a msys process
dnl (perl), and reading it from python.
dumpenv="$PERL $srcdir/build/win32/dumpenv4python.pl $ac_configure_args | "
dumpenv="$PERL $_topsrcdir/build/win32/dumpenv4python.pl $ac_configure_args | "
;;
esac

View File

@ -1423,7 +1423,6 @@ if test "$GNU_CC"; then
# -Wendif-labels - catches `#else FOO` and `#endif FOO` not in comment
# -Wenum-compare - catches comparison of different enum types
# -Wignored-qualifiers - catches returns types with qualifiers like const
# -Wimplicit-int - catches C variable declaration without a type
# -Wint-to-pointer-cast - catches cast to pointer from integer of different size
# -Wmultichar - catches multicharacter integer constants like 'THIS'
# -Wnonnull - catches NULL used with functions arguments marked as non-null
@ -1450,7 +1449,6 @@ if test "$GNU_CC"; then
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=endif-labels"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=enum-compare"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=ignored-qualifiers"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=implicit-int"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=int-to-pointer-cast"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=multichar"
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Werror=nonnull"
@ -6964,6 +6962,7 @@ if test "$NS_DISABLE_LOGGING"; then
AC_DEFINE(NS_DISABLE_LOGGING)
else
AC_DEFINE(MOZ_LOGGING)
AC_DEFINE(FORCE_PR_LOG)
fi
dnl ========================================================
@ -9059,9 +9058,15 @@ dnl ========================================================
# Android: bug 864843
# B2G: bug 866301
if test "$MOZ_WIDGET_TOOLKIT" = "android" ||
test "$MOZ_BUILD_APP" = "b2g"; then
if test "$MOZ_WIDGET_TOOLKIT" = "android"; then
_INTL_API=no
elif test "$MOZ_BUILD_APP" = "b2g"; then
if test "$MOZ_WIDGET_TOOLKIT" = "cocoa"; then
# nsCollationMacUC needs ICU
_INTL_API=yes
else
_INTL_API=no
fi
else
_INTL_API=yes
fi

View File

@ -0,0 +1,88 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_dom_BlobSet_h
#define mozilla_dom_BlobSet_h
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/File.h"
namespace mozilla {
namespace dom {
class BlobSet {
public:
BlobSet()
: mData(nullptr), mDataLen(0), mDataBufferLen(0)
{}
~BlobSet()
{
moz_free(mData);
}
nsresult AppendVoidPtr(const void* aData, uint32_t aLength);
nsresult AppendString(const nsAString& aString, bool nativeEOL, JSContext* aCx);
nsresult AppendBlobImpl(FileImpl* aBlobImpl);
nsresult AppendBlobImpls(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls);
nsTArray<nsRefPtr<FileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }
already_AddRefed<File> GetBlobInternal(nsISupports* aParent,
const nsACString& aContentType);
protected:
bool ExpandBufferSize(uint64_t aSize)
{
using mozilla::CheckedUint32;
if (mDataBufferLen >= mDataLen + aSize) {
mDataLen += aSize;
return true;
}
// Start at 1 or we'll loop forever.
CheckedUint32 bufferLen =
std::max<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
while (bufferLen.isValid() && bufferLen.value() < mDataLen + aSize)
bufferLen *= 2;
if (!bufferLen.isValid())
return false;
void* data = moz_realloc(mData, bufferLen.value());
if (!data)
return false;
mData = data;
mDataBufferLen = bufferLen.value();
mDataLen += aSize;
return true;
}
void Flush() {
if (mData) {
// If we have some data, create a blob for it
// and put it on the stack
nsRefPtr<FileImpl> blobImpl =
new FileImplMemory(mData, mDataLen, EmptyString());
mBlobImpls.AppendElement(blobImpl);
mData = nullptr; // The nsDOMMemoryFile takes ownership of the buffer
mDataLen = 0;
mDataBufferLen = 0;
}
}
nsTArray<nsRefPtr<FileImpl>> mBlobImpls;
void* mData;
uint64_t mDataLen;
uint64_t mDataBufferLen;
};
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_BlobSet_h

View File

@ -3,36 +3,31 @@
* 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/. */
#ifndef nsDOMFile_h__
#define nsDOMFile_h__
#ifndef mozilla_dom_File_h
#define mozilla_dom_File_h
#include "mozilla/Attributes.h"
#include "nsICharsetDetectionObserver.h"
#include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIInputStream.h"
#include "nsIJSNativeInitializer.h"
#include "nsIMutable.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIXMLHttpRequest.h"
#include "nsAutoPtr.h"
#include "nsFileStreams.h"
#include "nsTemporaryFileInputStream.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/LinkedList.h"
#include <stdint.h>
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/dom/DOMError.h"
#include "mozilla/dom/Date.h"
#include "mozilla/dom/indexedDB/FileInfo.h"
#include "mozilla/dom/indexedDB/FileManager.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/UnionTypes.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIFile.h"
#include "nsIMutable.h"
#include "nsIXMLHttpRequest.h"
#include "nsString.h"
#include "nsTemporaryFileInputStream.h"
#include "nsWrapperCache.h"
#include "nsWeakReference.h"
class nsDOMMultipartFile;
@ -40,17 +35,17 @@ class nsIFile;
class nsIInputStream;
class nsIClassInfo;
#define PIDOMFILEIMPL_IID \
#define PIFILEIMPL_IID \
{ 0x218ee173, 0xf44f, 0x4d30, \
{ 0xab, 0x0c, 0xd6, 0x66, 0xea, 0xc2, 0x84, 0x47 } }
class PIDOMFileImpl : public nsISupports
class PIFileImpl : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(PIDOMFILEIMPL_IID)
NS_DECLARE_STATIC_IID_ACCESSOR(PIFILEIMPL_IID)
};
NS_DEFINE_STATIC_IID_ACCESSOR(PIDOMFileImpl, PIDOMFILEIMPL_IID)
NS_DEFINE_STATIC_IID_ACCESSOR(PIFileImpl, PIFILEIMPL_IID)
namespace mozilla {
namespace dom {
@ -59,13 +54,16 @@ namespace indexedDB {
class FileInfo;
};
class DOMFileImpl;
struct BlobPropertyBag;
struct ChromeFilePropertyBag;
struct FilePropertyBag;
class FileImpl;
class DOMFile MOZ_FINAL : public nsIDOMFile
class File MOZ_FINAL : public nsIDOMFile
, public nsIXHRSendable
, public nsIMutable
, public nsIJSNativeInitializer
, public nsSupportsWeakReference
, public nsWrapperCache
{
public:
NS_DECL_NSIDOMBLOB
@ -74,68 +72,68 @@ public:
NS_DECL_NSIMUTABLE
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DOMFile, nsIDOMFile)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(File, nsIDOMFile)
static already_AddRefed<DOMFile>
Create(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
uint64_t aLastModifiedDate);
static already_AddRefed<DOMFile>
Create(const nsAString& aName, const nsAString& aContentType,
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength);
static already_AddRefed<DOMFile>
Create(const nsAString& aContentType, uint64_t aLength);
static already_AddRefed<DOMFile>
Create(const nsAString& aContentType, uint64_t aStart,
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType, uint64_t aStart,
uint64_t aLength);
static already_AddRefed<DOMFile>
CreateMemoryFile(void* aMemoryBuffer, uint64_t aLength,
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName, const nsAString& aContentType,
uint64_t aLastModifiedDate);
static already_AddRefed<DOMFile>
CreateMemoryFile(void* aMemoryBuffer, uint64_t aLength,
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<DOMFile>
CreateTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength,
static already_AddRefed<File>
CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile);
static already_AddRefed<DOMFile>
CreateFromFile(const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo);
static already_AddRefed<DOMFile>
CreateFromFile(const nsAString& aName, const nsAString& aContentType,
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo);
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo);
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile, const nsAString& aName,
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType);
explicit DOMFile(DOMFileImpl* aImpl)
: mImpl(aImpl)
{
MOZ_ASSERT(mImpl);
}
File(nsISupports* aParent, FileImpl* aImpl);
DOMFileImpl* Impl() const
FileImpl* Impl() const
{
return mImpl;
}
const nsTArray<nsRefPtr<DOMFileImpl>>* GetSubBlobImpls() const;
const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const;
bool IsSizeUnknown() const;
@ -146,59 +144,119 @@ public:
void SetLazyData(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate);
already_AddRefed<nsIDOMBlob>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType);
already_AddRefed<File>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv);
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
const JS::CallArgs& aArgs) MOZ_OVERRIDE;
// WebIDL methods
nsISupports* GetParentObject() const
{
return mParent;
}
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv);
// File constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aName,
const FilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
File& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
nsIFile* aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
uint64_t GetSize(ErrorResult& aRv);
// XPCOM GetType is OK
// XPCOM GetName is OK
int64_t GetLastModified(ErrorResult& aRv);
Date GetLastModifiedDate(ErrorResult& aRv);
void GetMozFullPath(nsAString& aFilename, ErrorResult& aRv);
already_AddRefed<File> Slice(const Optional<int64_t>& aStart,
const Optional<int64_t>& aEnd,
const nsAString& aContentType,
ErrorResult& aRv);
private:
~DOMFile() {};
~File() {};
// The member is the real backend implementation of this DOMFile/DOMBlob.
// The member is the real backend implementation of this File/Blob.
// It's thread-safe and not CC-able and it's the only element that is moved
// between threads.
// Note: we should not store any other state in this class!
const nsRefPtr<DOMFileImpl> mImpl;
const nsRefPtr<FileImpl> mImpl;
nsCOMPtr<nsISupports> mParent;
};
// This is the abstract class for any DOMFile backend. It must be nsISupports
// This is the abstract class for any File backend. It must be nsISupports
// because this class must be ref-counted and it has to work with IPC.
class DOMFileImpl : public PIDOMFileImpl
class FileImpl : public PIFileImpl
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
DOMFileImpl() {}
FileImpl() {}
virtual nsresult GetName(nsAString& aName) = 0;
virtual void GetName(nsAString& aName) = 0;
virtual nsresult GetPath(nsAString& aName) = 0;
virtual nsresult
GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate) = 0;
virtual int64_t GetLastModified(ErrorResult& aRv) = 0;
virtual nsresult GetMozFullPath(nsAString& aName) = 0;
virtual void GetMozFullPath(nsAString& aName, ErrorResult& aRv) = 0;
virtual nsresult GetMozFullPathInternal(nsAString &aFileName) = 0;
virtual void GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) = 0;
virtual nsresult GetSize(uint64_t* aSize) = 0;
virtual uint64_t GetSize(ErrorResult& aRv) = 0;
virtual nsresult GetType(nsAString& aType) = 0;
virtual void GetType(nsAString& aType) = 0;
virtual nsresult GetMozLastModifiedDate(uint64_t* aDate) = 0;
already_AddRefed<FileImpl>
Slice(const Optional<int64_t>& aStart, const Optional<int64_t>& aEnd,
const nsAString& aContentType, ErrorResult& aRv);
nsresult Slice(int64_t aStart, int64_t aEnd, const nsAString& aContentType,
uint8_t aArgc, DOMFileImpl** aBlobImpl);
virtual already_AddRefed<DOMFileImpl>
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) = 0;
const nsAString& aContentType, ErrorResult& aRv) = 0;
virtual const nsTArray<nsRefPtr<DOMFileImpl>>*
virtual const nsTArray<nsRefPtr<FileImpl>>*
GetSubBlobImpls() const = 0;
virtual nsresult GetInternalStream(nsIInputStream** aStream) = 0;
@ -232,9 +290,6 @@ public:
virtual bool IsFile() const = 0;
virtual nsresult Initialize(nsISupports* aOwner, JSContext* aCx,
JSObject* aObj, const JS::CallArgs& aArgs) = 0;
// These 2 methods are used when the implementation has to CC something.
virtual void Unlink() = 0;
virtual void Traverse(nsCycleCollectionTraversalCallback &aCb) = 0;
@ -245,13 +300,13 @@ public:
}
protected:
virtual ~DOMFileImpl() {}
virtual ~FileImpl() {}
};
class DOMFileImplBase : public DOMFileImpl
class FileImplBase : public FileImpl
{
public:
DOMFileImplBase(const nsAString& aName, const nsAString& aContentType,
FileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate)
: mIsFile(true)
, mImmutable(false)
@ -265,7 +320,7 @@ public:
mContentType.SetIsVoid(false);
}
DOMFileImplBase(const nsAString& aName, const nsAString& aContentType,
FileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength)
: mIsFile(true)
, mImmutable(false)
@ -279,7 +334,7 @@ public:
mContentType.SetIsVoid(false);
}
DOMFileImplBase(const nsAString& aContentType, uint64_t aLength)
FileImplBase(const nsAString& aContentType, uint64_t aLength)
: mIsFile(false)
, mImmutable(false)
, mContentType(aContentType)
@ -291,7 +346,7 @@ public:
mContentType.SetIsVoid(false);
}
DOMFileImplBase(const nsAString& aContentType, uint64_t aStart,
FileImplBase(const nsAString& aContentType, uint64_t aStart,
uint64_t aLength)
: mIsFile(false)
, mImmutable(false)
@ -306,34 +361,41 @@ public:
mContentType.SetIsVoid(false);
}
virtual nsresult GetName(nsAString& aName) MOZ_OVERRIDE;
virtual void GetName(nsAString& aName) MOZ_OVERRIDE;
virtual nsresult GetPath(nsAString& aName) MOZ_OVERRIDE;
virtual nsresult GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate) MOZ_OVERRIDE;
virtual int64_t GetLastModified(ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetMozFullPath(nsAString& aName) MOZ_OVERRIDE;
virtual void GetMozFullPath(nsAString& aName, ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetMozFullPathInternal(nsAString& aFileName) MOZ_OVERRIDE;
virtual void GetMozFullPathInternal(nsAString& aFileName,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE
{
return mLength;
}
virtual nsresult GetType(nsAString& aType) MOZ_OVERRIDE;
virtual void GetType(nsAString& aType) MOZ_OVERRIDE;
virtual nsresult GetMozLastModifiedDate(uint64_t* aDate) MOZ_OVERRIDE;
virtual already_AddRefed<DOMFileImpl>
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE
{
return nullptr;
}
virtual const nsTArray<nsRefPtr<DOMFileImpl>>*
virtual const nsTArray<nsRefPtr<FileImpl>>*
GetSubBlobImpls() const MOZ_OVERRIDE
{
return nullptr;
}
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE
{
return NS_ERROR_NOT_IMPLEMENTED;
}
virtual int64_t GetFileId() MOZ_OVERRIDE;
@ -400,17 +462,11 @@ public:
return mLength == UINT64_MAX;
}
virtual nsresult Initialize(nsISupports* aOwner, JSContext* aCx,
JSObject* aObj, const JS::CallArgs& aArgs)
{
return NS_OK;
}
virtual void Unlink() {}
virtual void Traverse(nsCycleCollectionTraversalCallback &aCb) {}
protected:
virtual ~DOMFileImplBase() {}
virtual ~FileImplBase() {}
indexedDB::FileInfo* GetFileInfo() const
{
@ -440,25 +496,22 @@ protected:
* This class may be used off the main thread, and in particular, its
* constructor and destructor may not run on the same thread. Be careful!
*/
class DOMFileImplMemory MOZ_FINAL : public DOMFileImplBase
class FileImplMemory MOZ_FINAL : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
DOMFileImplMemory(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLastModifiedDate)
: DOMFileImplBase(aName, aContentType, aLength, aLastModifiedDate)
FileImplMemory(void* aMemoryBuffer, uint64_t aLength, const nsAString& aName,
const nsAString& aContentType, uint64_t aLastModifiedDate)
: FileImplBase(aName, aContentType, aLength, aLastModifiedDate)
, mDataOwner(new DataOwner(aMemoryBuffer, aLength))
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
}
DOMFileImplMemory(void* aMemoryBuffer,
uint64_t aLength,
FileImplMemory(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
: FileImplBase(aContentType, aLength)
, mDataOwner(new DataOwner(aMemoryBuffer, aLength))
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
@ -466,9 +519,9 @@ public:
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual already_AddRefed<DOMFileImpl>
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
virtual bool IsMemoryFile() const MOZ_OVERRIDE
{
@ -521,29 +574,29 @@ public:
private:
// Create slice
DOMFileImplMemory(const DOMFileImplMemory* aOther, uint64_t aStart,
FileImplMemory(const FileImplMemory* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aOther->mStart + aStart, aLength)
: FileImplBase(aContentType, aOther->mStart + aStart, aLength)
, mDataOwner(aOther->mDataOwner)
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
mImmutable = aOther->mImmutable;
}
~DOMFileImplMemory() {}
~FileImplMemory() {}
// Used when backed by a memory store
nsRefPtr<DataOwner> mDataOwner;
};
class DOMFileImplTemporaryFileBlob MOZ_FINAL : public DOMFileImplBase
class FileImplTemporaryFileBlob MOZ_FINAL : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
DOMFileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
FileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
: FileImplBase(aContentType, aLength)
, mLength(aLength)
, mStartPos(aStartPos)
, mContentType(aContentType)
@ -553,21 +606,21 @@ public:
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual already_AddRefed<DOMFileImpl>
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
private:
DOMFileImplTemporaryFileBlob(const DOMFileImplTemporaryFileBlob* aOther,
FileImplTemporaryFileBlob(const FileImplTemporaryFileBlob* aOther,
uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
: FileImplBase(aContentType, aLength)
, mLength(aLength)
, mStartPos(aStart)
, mFileDescOwner(aOther->mFileDescOwner)
, mContentType(aContentType) {}
~DOMFileImplTemporaryFileBlob() {}
~FileImplTemporaryFileBlob() {}
uint64_t mLength;
uint64_t mStartPos;
@ -575,14 +628,14 @@ private:
nsString mContentType;
};
class DOMFileImplFile : public DOMFileImplBase
class FileImplFile : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
explicit DOMFileImplFile(nsIFile* aFile)
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
explicit FileImplFile(nsIFile* aFile)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -593,8 +646,8 @@ public:
mFile->GetLeafName(mName);
}
DOMFileImplFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
FileImplFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -609,9 +662,9 @@ public:
}
// Create as a file
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile)
: DOMFileImplBase(aName, aContentType, aLength, UINT64_MAX)
: FileImplBase(aName, aContentType, aLength, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -619,10 +672,10 @@ public:
NS_ASSERTION(mFile, "must have file");
}
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
uint64_t aLastModificationDate)
: DOMFileImplBase(aName, aContentType, aLength, aLastModificationDate)
: FileImplBase(aName, aContentType, aLength, aLastModificationDate)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -631,9 +684,9 @@ public:
}
// Create as a file with custom name
DOMFileImplFile(nsIFile* aFile, const nsAString& aName,
FileImplFile(nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType)
: DOMFileImplBase(aName, aContentType, UINT64_MAX, UINT64_MAX)
: FileImplBase(aName, aContentType, UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -646,10 +699,10 @@ public:
}
// Create as a stored file
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(aName, aContentType, aLength, UINT64_MAX)
: FileImplBase(aName, aContentType, aLength, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -659,9 +712,9 @@ public:
}
// Create as a stored blob
DOMFileImplFile(const nsAString& aContentType, uint64_t aLength,
FileImplFile(const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(aContentType, aLength)
: FileImplBase(aContentType, aLength)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -671,8 +724,8 @@ public:
}
// Create as a file to be later initialized
DOMFileImplFile()
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
FileImplFile()
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mWholeFile(true)
, mStoredFile(false)
{
@ -682,24 +735,23 @@ public:
}
// Overrides
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual nsresult GetType(nsAString& aType) MOZ_OVERRIDE;
virtual nsresult GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aLastModifiedDate) MOZ_OVERRIDE;
virtual nsresult GetMozLastModifiedDate(uint64_t* aLastModifiedDate) MOZ_OVERRIDE;
virtual nsresult GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE;
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE;
virtual void GetType(nsAString& aType) MOZ_OVERRIDE;
virtual int64_t GetLastModified(ErrorResult& aRv) MOZ_OVERRIDE;
virtual void GetMozFullPathInternal(nsAString& aFullPath,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetInternalStream(nsIInputStream**) MOZ_OVERRIDE;
void SetPath(const nsAString& aFullPath);
protected:
virtual ~DOMFileImplFile() {}
virtual ~FileImplFile() {}
private:
// Create slice
DOMFileImplFile(const DOMFileImplFile* aOther, uint64_t aStart,
FileImplFile(const FileImplFile* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aOther->mStart + aStart, aLength)
: FileImplBase(aContentType, aOther->mStart + aStart, aLength)
, mFile(aOther->mFile)
, mWholeFile(false)
, mStoredFile(aOther->mStoredFile)
@ -724,9 +776,9 @@ private:
}
}
virtual already_AddRefed<DOMFileImpl>
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
virtual bool IsStoredFile() const MOZ_OVERRIDE
{
@ -743,21 +795,18 @@ private:
bool mStoredFile;
};
} // dom namespace
} // file namespace
class nsDOMFileList MOZ_FINAL : public nsIDOMFileList,
class FileList MOZ_FINAL : public nsIDOMFileList,
public nsWrapperCache
{
~nsDOMFileList() {}
~FileList() {}
public:
explicit nsDOMFileList(nsISupports *aParent) : mParent(aParent)
explicit FileList(nsISupports *aParent) : mParent(aParent)
{
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMFileList)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList)
NS_DECL_NSIDOMFILELIST
@ -773,12 +822,20 @@ public:
mParent = nullptr;
}
bool Append(nsIDOMFile *aFile) { return mFiles.AppendObject(aFile); }
bool Append(File *aFile) { return mFiles.AppendElement(aFile); }
bool Remove(uint32_t aIndex) {
if (aIndex < mFiles.Length()) {
mFiles.RemoveElementAt(aIndex);
return true;
}
return false;
}
bool Remove(uint32_t aIndex) { return mFiles.RemoveObjectAt(aIndex); }
void Clear() { return mFiles.Clear(); }
static nsDOMFileList* FromSupports(nsISupports* aSupports)
static FileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
@ -792,26 +849,29 @@ public:
}
#endif
return static_cast<nsDOMFileList*>(aSupports);
return static_cast<FileList*>(aSupports);
}
nsIDOMFile* Item(uint32_t aIndex)
File* Item(uint32_t aIndex)
{
return mFiles.SafeObjectAt(aIndex);
return mFiles.SafeElementAt(aIndex);
}
nsIDOMFile* IndexedGetter(uint32_t aIndex, bool& aFound)
File* IndexedGetter(uint32_t aIndex, bool& aFound)
{
aFound = aIndex < static_cast<uint32_t>(mFiles.Count());
return aFound ? mFiles.ObjectAt(aIndex) : nullptr;
aFound = aIndex < mFiles.Length();
return aFound ? mFiles.ElementAt(aIndex) : nullptr;
}
uint32_t Length()
{
return mFiles.Count();
return mFiles.Length();
}
private:
nsCOMArray<nsIDOMFile> mFiles;
nsTArray<nsRefPtr<File>> mFiles;
nsISupports *mParent;
};
#endif
} // dom namespace
} // file namespace
#endif // mozilla_dom_File_h

View File

@ -43,7 +43,6 @@ EXPORTS += [
'nsCopySupport.h',
'nsDeprecatedOperationList.h',
'nsDocElementCreatedNotificationRunner.h',
'nsDOMFile.h',
'nsHostObjectProtocolHandler.h',
'nsIAttribute.h',
'nsIContent.h',
@ -67,9 +66,11 @@ EXPORTS += [
]
EXPORTS.mozilla.dom += [
'BlobSet.h',
'DirectionalityUtils.h',
'Element.h',
'ElementInlines.h',
'File.h',
'FragmentOrElement.h',
'FromParser.h',
]

View File

@ -1669,6 +1669,7 @@ public:
JSObject** aResult);
static nsresult CreateBlobBuffer(JSContext* aCx,
nsISupports* aParent,
const nsACString& aData,
JS::MutableHandle<JS::Value> aBlob);

1307
content/base/src/File.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,12 +4,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FileIOObject.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ProgressEvent.h"
#include "mozilla/EventDispatcher.h"
#include "nsDOMFile.h"
#include "nsComponentManagerUtils.h"
#include "nsError.h"
#include "nsIDOMEvent.h"
#include "mozilla/dom/ProgressEvent.h"
#include "nsComponentManagerUtils.h"
#define ERROR_STR "error"
#define ABORT_STR "abort"

View File

@ -0,0 +1,353 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "MultipartFileImpl.h"
#include "jsfriendapi.h"
#include "mozilla/dom/BlobSet.h"
#include "mozilla/dom/FileBinding.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfoID.h"
#include "nsIMultiplexInputStream.h"
#include "nsStringStream.h"
#include "nsTArray.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#include "nsIXPConnect.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS_INHERITED0(MultipartFileImpl, FileImpl)
nsresult
MultipartFileImpl::GetInternalStream(nsIInputStream** aStream)
{
nsresult rv;
*aStream = nullptr;
nsCOMPtr<nsIMultiplexInputStream> stream =
do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
uint32_t i;
for (i = 0; i < mBlobImpls.Length(); i++) {
nsCOMPtr<nsIInputStream> scratchStream;
FileImpl* blobImpl = mBlobImpls.ElementAt(i).get();
rv = blobImpl->GetInternalStream(getter_AddRefs(scratchStream));
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AppendStream(scratchStream);
NS_ENSURE_SUCCESS(rv, rv);
}
return CallQueryInterface(stream, aStream);
}
already_AddRefed<FileImpl>
MultipartFileImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
// If we clamped to nothing we create an empty blob
nsTArray<nsRefPtr<FileImpl>> blobImpls;
uint64_t length = aLength;
uint64_t skipStart = aStart;
// Prune the list of blobs if we can
uint32_t i;
for (i = 0; length && skipStart && i < mBlobImpls.Length(); i++) {
FileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (skipStart < l) {
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);
nsRefPtr<FileImpl> firstBlobImpl =
blobImpl->CreateSlice(skipStart, upperBound,
aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// Avoid wrapping a single blob inside an MultipartFileImpl
if (length == upperBound) {
return firstBlobImpl.forget();
}
blobImpls.AppendElement(firstBlobImpl);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobImpls.Length(); i++) {
FileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (length < l) {
nsRefPtr<FileImpl> lastBlobImpl =
blobImpl->CreateSlice(0, length, aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
blobImpls.AppendElement(lastBlobImpl);
} else {
blobImpls.AppendElement(blobImpl);
}
length -= std::min<uint64_t>(l, length);
}
// we can create our blob now
nsRefPtr<FileImpl> impl =
new MultipartFileImpl(blobImpls, aContentType);
return impl.forget();
}
void
MultipartFileImpl::InitializeBlob()
{
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeBlob(
JSContext* aCx,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv)
{
mContentType = aContentType;
BlobSet blobSet;
for (uint32_t i = 0, len = aData.Length(); i < len; ++i) {
const OwningArrayBufferOrArrayBufferViewOrBlobOrString& data = aData[i];
if (data.IsBlob()) {
nsRefPtr<File> file = data.GetAsBlob().get();
blobSet.AppendBlobImpl(file->Impl());
}
else if (data.IsString()) {
aRv = blobSet.AppendString(data.GetAsString(), aNativeEOL, aCx);
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBufferView()) {
const ArrayBufferView& buffer = data.GetAsArrayBufferView();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else {
MOZ_CRASH("Impossible blob data type.");
}
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::SetLengthAndModifiedDate()
{
MOZ_ASSERT(mLength == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == UINT64_MAX);
uint64_t totalLength = 0;
for (uint32_t index = 0, count = mBlobImpls.Length(); index < count; index++) {
nsRefPtr<FileImpl>& blob = mBlobImpls[index];
#ifdef DEBUG
MOZ_ASSERT(!blob->IsSizeUnknown());
MOZ_ASSERT(!blob->IsDateUnknown());
#endif
ErrorResult error;
uint64_t subBlobLength = blob->GetSize(error);
MOZ_ALWAYS_TRUE(!error.Failed());
MOZ_ASSERT(UINT64_MAX - subBlobLength >= totalLength);
totalLength += subBlobLength;
}
mLength = totalLength;
if (mIsFile) {
// We cannot use PR_Now() because bug 493756 and, for this reason:
// var x = new Date(); var f = new File(...);
// x.getTime() < f.dateModified.getTime()
// could fail.
mLastModificationDate = JS_Now();
}
}
void
MultipartFileImpl::GetMozFullPathInternal(nsAString& aFilename,
ErrorResult& aRv)
{
if (!mIsFromNsIFile || mBlobImpls.Length() == 0) {
FileImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
FileImpl* blobImpl = mBlobImpls.ElementAt(0).get();
if (!blobImpl) {
FileImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
blobImpl->GetMozFullPathInternal(aFilename, aRv);
}
void
MultipartFileImpl::InitializeChromeFile(File& aBlob,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
if (mImmutable) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
mName = aBag.mName;
mContentType = aBag.mType;
mIsFromNsIFile = true;
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
aBlob.GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(aBlob.Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
nsIFile* aFile,
const ChromeFilePropertyBag& aBag,
bool aIsFromNsIFile,
ErrorResult& aRv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
if (mImmutable) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
mName = aBag.mName;
mContentType = aBag.mType;
mIsFromNsIFile = aIsFromNsIFile;
bool exists;
aRv = aFile->Exists(&exists);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (!exists) {
aRv.Throw(NS_ERROR_FILE_NOT_FOUND);
return;
}
bool isDir;
aRv = aFile->IsDirectory(&isDir);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (isDir) {
aRv.Throw(NS_ERROR_FILE_IS_DIRECTORY);
return;
}
if (mName.IsEmpty()) {
aFile->GetLeafName(mName);
}
nsRefPtr<File> blob = File::CreateFromFile(aWindow, aFile);
// Pre-cache size.
uint64_t unused;
aRv = blob->GetSize(&unused);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
// Pre-cache modified date.
aRv = blob->GetMozLastModifiedDate(&unused);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<File*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
nsCOMPtr<nsIFile> file;
aRv = NS_NewLocalFile(aData, false, getter_AddRefs(file));
if (NS_WARN_IF(aRv.Failed())) {
return;
}
InitializeChromeFile(aWindow, file, aBag, false, aRv);
}

View File

@ -0,0 +1,123 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef mozilla_dom_MultipartFileImpl_h
#define mozilla_dom_MultipartFileImpl_h
#include "mozilla/Attributes.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/FileBinding.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
class MultipartFileImpl MOZ_FINAL : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
MultipartFileImpl(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls,
const nsAString& aName,
const nsAString& aContentType)
: FileImplBase(aName, aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsIFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a blob
MultipartFileImpl(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls,
const nsAString& aContentType)
: FileImplBase(aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsIFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a file to be later initialized
explicit MultipartFileImpl(const nsAString& aName)
: FileImplBase(aName, EmptyString(), UINT64_MAX),
mIsFromNsIFile(false)
{
}
// Create as a blob to be later initialized
MultipartFileImpl()
: FileImplBase(EmptyString(), UINT64_MAX),
mIsFromNsIFile(false)
{
}
void InitializeBlob();
void InitializeBlob(
JSContext* aCx,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv);
void InitializeChromeFile(File& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
void InitializeChromeFile(nsPIDOMWindow* aWindow,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
void InitializeChromeFile(nsPIDOMWindow* aWindow,
nsIFile* aData,
const ChromeFilePropertyBag& aBag,
bool aIsFromNsIFile,
ErrorResult& aRv);
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE
{
return mLength;
}
virtual nsresult GetInternalStream(nsIInputStream** aInputStream) MOZ_OVERRIDE;
virtual const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const MOZ_OVERRIDE
{
return &mBlobImpls;
}
virtual void GetMozFullPathInternal(nsAString& aFullPath,
ErrorResult& aRv) MOZ_OVERRIDE;
void SetName(const nsAString& aName)
{
mName = aName;
}
void SetFromNsIFile(bool aValue)
{
mIsFromNsIFile = aValue;
}
protected:
virtual ~MultipartFileImpl() {}
void SetLengthAndModifiedDate();
nsTArray<nsRefPtr<FileImpl>> mBlobImpls;
bool mIsFromNsIFile;
};
#endif // mozilla_dom_MultipartFileImpl_h

View File

@ -11,6 +11,7 @@
#include "jsfriendapi.h"
#include "js/OldDebugAPI.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
@ -38,7 +39,6 @@
#include "mozilla/Preferences.h"
#include "xpcpublic.h"
#include "nsContentPolicyUtils.h"
#include "nsDOMFile.h"
#include "nsWrapperCacheInlines.h"
#include "nsIObserverService.h"
#include "nsIWebSocketChannel.h"
@ -898,7 +898,7 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
JS::Rooted<JS::Value> jsData(cx);
if (isBinary) {
if (mBinaryType == dom::BinaryType::Blob) {
rv = nsContentUtils::CreateBlobBuffer(cx, aData, &jsData);
rv = nsContentUtils::CreateBlobBuffer(cx, GetOwner(), aData, &jsData);
NS_ENSURE_SUCCESS(rv, rv);
} else if (mBinaryType == dom::BinaryType::Arraybuffer) {
JS::Rooted<JSObject*> arrayBuf(cx);
@ -1194,20 +1194,19 @@ WebSocket::Send(const nsAString& aData,
}
void
WebSocket::Send(nsIDOMBlob* aData,
ErrorResult& aRv)
WebSocket::Send(File& aData, ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsCOMPtr<nsIInputStream> msgStream;
nsresult rv = aData->GetInternalStream(getter_AddRefs(msgStream));
nsresult rv = aData.GetInternalStream(getter_AddRefs(msgStream));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
uint64_t msgLength;
rv = aData->GetSize(&msgLength);
rv = aData.GetSize(&msgLength);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;

View File

@ -32,6 +32,8 @@
namespace mozilla {
namespace dom {
class File;
class WebSocket MOZ_FINAL : public DOMEventTargetHelper,
public nsIInterfaceRequestor,
public nsIWebSocketListener,
@ -131,7 +133,7 @@ public: // WebIDL interface:
// webIDL: void send(DOMString|Blob|ArrayBufferView data);
void Send(const nsAString& aData,
ErrorResult& aRv);
void Send(nsIDOMBlob* aData,
void Send(File& aData,
ErrorResult& aRv);
void Send(const ArrayBuffer& aData,
ErrorResult& aRv);

View File

@ -42,7 +42,7 @@ if CONFIG['MOZ_WEBRTC']:
'nsDOMDataChannel.h',
'nsDOMDataChannelDeclarations.h',
]
SOURCES += [
UNIFIED_SOURCES += [
'nsDOMDataChannel.cpp',
]
LOCAL_INCLUDES += [
@ -99,10 +99,12 @@ UNIFIED_SOURCES += [
'DOMStringList.cpp',
'Element.cpp',
'EventSource.cpp',
'File.cpp',
'FileIOObject.cpp',
'FragmentOrElement.cpp',
'ImportManager.cpp',
'Link.cpp',
'MultipartFileImpl.cpp',
'NodeIterator.cpp',
'nsAtomListUtils.cpp',
'nsAttrAndChildArray.cpp',
@ -122,11 +124,10 @@ UNIFIED_SOURCES += [
'nsCSPService.cpp',
'nsCSPUtils.cpp',
'nsDataDocumentContentPolicy.cpp',
'nsDocument.cpp',
'nsDocumentEncoder.cpp',
'nsDOMAttributeMap.cpp',
'nsDOMBlobBuilder.cpp',
'nsDOMCaretPosition.cpp',
'nsDOMFile.cpp',
'nsDOMFileReader.cpp',
'nsDOMMutationObserver.cpp',
'nsDOMSerializer.cpp',
@ -150,6 +151,7 @@ UNIFIED_SOURCES += [
'nsMixedContentBlocker.cpp',
'nsNameSpaceManager.cpp',
'nsNoDataProtocolContentPolicy.cpp',
'nsNodeInfoManager.cpp',
'nsNodeUtils.cpp',
'nsPlainTextSerializer.cpp',
'nsPropertyTable.cpp',
@ -184,12 +186,6 @@ SOURCES += [
'nsImageLoadingContent.cpp',
]
# These files cannot be built in unified mode because they use FORCE_PR_LOG
SOURCES += [
'nsDocument.cpp',
'nsNodeInfoManager.cpp',
]
# These files cannot be built in unified mode because of OS X headers.
SOURCES += [
'nsContentUtils.cpp',

View File

@ -90,6 +90,7 @@
#include "nsICategoryManager.h"
#include "nsIChannelEventSink.h"
#include "nsIChannelPolicy.h"
#include "nsICharsetDetectionObserver.h"
#include "nsIChromeRegistry.h"
#include "nsIConsoleService.h"
#include "nsIContent.h"
@ -5992,20 +5993,26 @@ nsContentUtils::CreateArrayBuffer(JSContext *aCx, const nsACString& aData,
// TODO: bug 704447: large file support
nsresult
nsContentUtils::CreateBlobBuffer(JSContext* aCx,
nsISupports* aParent,
const nsACString& aData,
JS::MutableHandle<JS::Value> aBlob)
{
uint32_t blobLen = aData.Length();
void* blobData = moz_malloc(blobLen);
nsCOMPtr<nsIDOMBlob> blob;
nsRefPtr<File> blob;
if (blobData) {
memcpy(blobData, aData.BeginReading(), blobLen);
blob = mozilla::dom::DOMFile::CreateMemoryFile(blobData, blobLen,
blob = mozilla::dom::File::CreateMemoryFile(aParent, blobData, blobLen,
EmptyString());
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
return nsContentUtils::WrapNative(aCx, blob, aBlob);
if (!WrapNewBindingObject(aCx, blob, aBlob)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
void

View File

@ -1,520 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsDOMBlobBuilder.h"
#include "jsfriendapi.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/FileBinding.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfoID.h"
#include "nsIMultiplexInputStream.h"
#include "nsStringStream.h"
#include "nsTArray.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#include "nsIXPConnect.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS_INHERITED0(DOMMultipartFileImpl, DOMFileImpl)
nsresult
DOMMultipartFileImpl::GetSize(uint64_t* aLength)
{
*aLength = mLength;
return NS_OK;
}
nsresult
DOMMultipartFileImpl::GetInternalStream(nsIInputStream** aStream)
{
nsresult rv;
*aStream = nullptr;
nsCOMPtr<nsIMultiplexInputStream> stream =
do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
uint32_t i;
for (i = 0; i < mBlobImpls.Length(); i++) {
nsCOMPtr<nsIInputStream> scratchStream;
DOMFileImpl* blobImpl = mBlobImpls.ElementAt(i).get();
rv = blobImpl->GetInternalStream(getter_AddRefs(scratchStream));
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AppendStream(scratchStream);
NS_ENSURE_SUCCESS(rv, rv);
}
return CallQueryInterface(stream, aStream);
}
already_AddRefed<DOMFileImpl>
DOMMultipartFileImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
{
// If we clamped to nothing we create an empty blob
nsTArray<nsRefPtr<DOMFileImpl>> blobImpls;
uint64_t length = aLength;
uint64_t skipStart = aStart;
// Prune the list of blobs if we can
uint32_t i;
for (i = 0; length && skipStart && i < mBlobImpls.Length(); i++) {
DOMFileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l;
nsresult rv = blobImpl->GetSize(&l);
NS_ENSURE_SUCCESS(rv, nullptr);
if (skipStart < l) {
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);
nsRefPtr<DOMFileImpl> firstImpl;
rv = blobImpl->Slice(skipStart, skipStart + upperBound, aContentType, 3,
getter_AddRefs(firstImpl));
NS_ENSURE_SUCCESS(rv, nullptr);
// Avoid wrapping a single blob inside an DOMMultipartFileImpl
if (length == upperBound) {
return firstImpl.forget();
}
blobImpls.AppendElement(firstImpl);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobImpls.Length(); i++) {
DOMFileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l;
nsresult rv = blobImpl->GetSize(&l);
NS_ENSURE_SUCCESS(rv, nullptr);
if (length < l) {
nsRefPtr<DOMFileImpl> lastBlob;
rv = blobImpl->Slice(0, length, aContentType, 3,
getter_AddRefs(lastBlob));
NS_ENSURE_SUCCESS(rv, nullptr);
blobImpls.AppendElement(lastBlob);
} else {
blobImpls.AppendElement(blobImpl);
}
length -= std::min<uint64_t>(l, length);
}
// we can create our blob now
nsRefPtr<DOMFileImpl> impl =
new DOMMultipartFileImpl(blobImpls, aContentType);
return impl.forget();
}
/* static */ nsresult
DOMMultipartFileImpl::NewFile(const nsAString& aName, nsISupports** aNewObject)
{
nsCOMPtr<nsISupports> file =
do_QueryObject(new DOMFile(new DOMMultipartFileImpl(aName)));
file.forget(aNewObject);
return NS_OK;
}
/* static */ nsresult
DOMMultipartFileImpl::NewBlob(nsISupports** aNewObject)
{
nsCOMPtr<nsISupports> file =
do_QueryObject(new DOMFile(new DOMMultipartFileImpl()));
file.forget(aNewObject);
return NS_OK;
}
static nsIDOMBlob*
GetXPConnectNative(JSContext* aCx, JSObject* aObj) {
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, aObj));
return blob;
}
nsresult
DOMMultipartFileImpl::Initialize(nsISupports* aOwner,
JSContext* aCx,
JSObject* aObj,
const JS::CallArgs& aArgs)
{
if (!mIsFile) {
return InitBlob(aCx, aArgs.length(), aArgs.array(), GetXPConnectNative);
}
if (!nsContentUtils::IsCallerChrome()) {
return InitFile(aCx, aArgs.length(), aArgs.array());
}
if (aArgs.length() > 0) {
JS::Value* argv = aArgs.array();
if (argv[0].isObject()) {
JS::Rooted<JSObject*> obj(aCx, &argv[0].toObject());
if (JS_IsArrayObject(aCx, obj)) {
return InitFile(aCx, aArgs.length(), aArgs.array());
}
}
}
return InitChromeFile(aCx, aArgs.length(), aArgs.array());
}
nsresult
DOMMultipartFileImpl::InitBlob(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv,
UnwrapFuncPtr aUnwrapFunc)
{
bool nativeEOL = false;
if (aArgc > 1) {
BlobPropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]))) {
return NS_ERROR_TYPE_ERR;
}
mContentType = d.mType;
nativeEOL = d.mEndings == EndingTypes::Native;
}
if (aArgc > 0) {
return ParseBlobArrayArgument(aCx, aArgv[0], nativeEOL, aUnwrapFunc);
}
SetLengthAndModifiedDate();
return NS_OK;
}
nsresult
DOMMultipartFileImpl::ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
bool aNativeEOL,
UnwrapFuncPtr aUnwrapFunc)
{
if (!aValue.isObject()) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (!JS_IsArrayObject(aCx, obj)) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
BlobSet blobSet;
uint32_t length;
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &length));
for (uint32_t i = 0; i < length; ++i) {
JS::Rooted<JS::Value> element(aCx);
if (!JS_GetElement(aCx, obj, i, &element))
return NS_ERROR_TYPE_ERR;
if (element.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &element.toObject());
nsCOMPtr<nsIDOMBlob> blob = aUnwrapFunc(aCx, obj);
if (blob) {
nsRefPtr<DOMFileImpl> blobImpl =
static_cast<DOMFile*>(blob.get())->Impl();
// Flatten so that multipart blobs will never nest
const nsTArray<nsRefPtr<DOMFileImpl>>* subBlobImpls =
blobImpl->GetSubBlobImpls();
if (subBlobImpls) {
blobSet.AppendBlobImpls(*subBlobImpls);
} else {
blobSet.AppendBlobImpl(blobImpl);
}
continue;
}
if (JS_IsArrayBufferViewObject(obj)) {
nsresult rv = blobSet.AppendVoidPtr(
JS_GetArrayBufferViewData(obj),
JS_GetArrayBufferViewByteLength(obj));
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
if (JS_IsArrayBufferObject(obj)) {
nsresult rv = blobSet.AppendArrayBuffer(obj);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
}
// coerce it to a string
JSString* str = JS::ToString(aCx, element);
NS_ENSURE_TRUE(str, NS_ERROR_TYPE_ERR);
nsresult rv = blobSet.AppendString(str, aNativeEOL, aCx);
NS_ENSURE_SUCCESS(rv, rv);
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
return NS_OK;
}
void
DOMMultipartFileImpl::SetLengthAndModifiedDate()
{
MOZ_ASSERT(mLength == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == UINT64_MAX);
uint64_t totalLength = 0;
for (uint32_t index = 0, count = mBlobImpls.Length(); index < count; index++) {
nsRefPtr<DOMFileImpl>& blob = mBlobImpls[index];
#ifdef DEBUG
MOZ_ASSERT(!blob->IsSizeUnknown());
MOZ_ASSERT(!blob->IsDateUnknown());
#endif
uint64_t subBlobLength;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetSize(&subBlobLength)));
MOZ_ASSERT(UINT64_MAX - subBlobLength >= totalLength);
totalLength += subBlobLength;
}
mLength = totalLength;
if (mIsFile) {
mLastModificationDate = PR_Now();
}
}
nsresult
DOMMultipartFileImpl::GetMozFullPathInternal(nsAString& aFilename)
{
if (!mIsFromNsiFile || mBlobImpls.Length() == 0) {
return DOMFileImplBase::GetMozFullPathInternal(aFilename);
}
DOMFileImpl* blobImpl = mBlobImpls.ElementAt(0).get();
if (!blobImpl) {
return DOMFileImplBase::GetMozFullPathInternal(aFilename);
}
return blobImpl->GetMozFullPathInternal(aFilename);
}
nsresult
DOMMultipartFileImpl::InitChromeFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv)
{
nsresult rv;
NS_ASSERTION(!mImmutable, "Something went wrong ...");
NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
if (aArgc > 1) {
FilePropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]))) {
return NS_ERROR_TYPE_ERR;
}
mName = d.mName;
mContentType = d.mType;
}
// We expect to get a path to represent as a File object or
// Blob object, an nsIFile, or an nsIDOMFile.
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIDOMBlob> blob;
if (!aArgv[0].isString()) {
// Lets see if it's an nsIFile
if (!aArgv[0].isObject()) {
return NS_ERROR_UNEXPECTED; // We're not interested
}
JSObject* obj = &aArgv[0].toObject();
nsISupports* supports =
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
if (!supports) {
return NS_ERROR_UNEXPECTED;
}
blob = do_QueryInterface(supports);
file = do_QueryInterface(supports);
if (!blob && !file) {
return NS_ERROR_UNEXPECTED;
}
mIsFromNsiFile = true;
} else {
// It's a string
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[0]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, str)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
rv = NS_NewLocalFile(xpcomStr, false, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
}
if (file) {
bool exists;
rv = file->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
bool isDir;
rv = file->IsDirectory(&isDir);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_FALSE(isDir, NS_ERROR_FILE_IS_DIRECTORY);
if (mName.IsEmpty()) {
file->GetLeafName(mName);
}
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(file);
// Pre-cache size.
uint64_t unused;
rv = domFile->GetSize(&unused);
NS_ENSURE_SUCCESS(rv, rv);
// Pre-cache modified date.
rv = domFile->GetMozLastModifiedDate(&unused);
NS_ENSURE_SUCCESS(rv, rv);
blob = domFile.forget();
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<DOMFile*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
return NS_OK;
}
nsresult
DOMMultipartFileImpl::InitFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
if (aArgc < 2) {
return NS_ERROR_TYPE_ERR;
}
// File name
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, str)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
mName = xpcomStr;
// Optional params
bool nativeEOL = false;
if (aArgc > 2) {
BlobPropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[2]))) {
return NS_ERROR_TYPE_ERR;
}
mContentType = d.mType;
nativeEOL = d.mEndings == EndingTypes::Native;
}
return ParseBlobArrayArgument(aCx, aArgv[0], nativeEOL, GetXPConnectNative);
}
nsresult
BlobSet::AppendVoidPtr(const void* aData, uint32_t aLength)
{
NS_ENSURE_ARG_POINTER(aData);
uint64_t offset = mDataLen;
if (!ExpandBufferSize(aLength))
return NS_ERROR_OUT_OF_MEMORY;
memcpy((char*)mData + offset, aData, aLength);
return NS_OK;
}
nsresult
BlobSet::AppendString(JSString* aString, bool nativeEOL, JSContext* aCx)
{
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, aString)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
nsCString utf8Str = NS_ConvertUTF16toUTF8(xpcomStr);
if (nativeEOL) {
if (utf8Str.FindChar('\r') != kNotFound) {
utf8Str.ReplaceSubstring("\r\n", "\n");
utf8Str.ReplaceSubstring("\r", "\n");
}
#ifdef XP_WIN
utf8Str.ReplaceSubstring("\n", "\r\n");
#endif
}
return AppendVoidPtr((void*)utf8Str.Data(),
utf8Str.Length());
}
nsresult
BlobSet::AppendBlobImpl(DOMFileImpl* aBlobImpl)
{
NS_ENSURE_ARG_POINTER(aBlobImpl);
Flush();
mBlobImpls.AppendElement(aBlobImpl);
return NS_OK;
}
nsresult
BlobSet::AppendBlobImpls(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls)
{
Flush();
mBlobImpls.AppendElements(aBlobImpls);
return NS_OK;
}
nsresult
BlobSet::AppendArrayBuffer(JSObject* aBuffer)
{
return AppendVoidPtr(JS_GetArrayBufferData(aBuffer),
JS_GetArrayBufferByteLength(aBuffer));
}

View File

@ -1,198 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef nsDOMBlobBuilder_h
#define nsDOMBlobBuilder_h
#include "nsDOMFile.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Attributes.h"
#include <algorithm>
#define NS_DOMMULTIPARTBLOB_CID { 0x47bf0b43, 0xf37e, 0x49ef, \
{ 0x81, 0xa0, 0x18, 0xba, 0xc0, 0x57, 0xb5, 0xcc } }
#define NS_DOMMULTIPARTBLOB_CONTRACTID "@mozilla.org/dom/multipart-blob;1"
#define NS_DOMMULTIPARTFILE_CID { 0xc3361f77, 0x60d1, 0x4ea9, \
{ 0x94, 0x96, 0xdf, 0x5d, 0x6f, 0xcd, 0xd7, 0x8f } }
#define NS_DOMMULTIPARTFILE_CONTRACTID "@mozilla.org/dom/multipart-file;1"
using namespace mozilla::dom;
class DOMMultipartFileImpl MOZ_FINAL : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
DOMMultipartFileImpl(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls,
const nsAString& aName,
const nsAString& aContentType)
: DOMFileImplBase(aName, aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsiFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a blob
DOMMultipartFileImpl(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsiFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a file to be later initialized
explicit DOMMultipartFileImpl(const nsAString& aName)
: DOMFileImplBase(aName, EmptyString(), UINT64_MAX),
mIsFromNsiFile(false)
{
}
// Create as a blob to be later initialized
DOMMultipartFileImpl()
: DOMFileImplBase(EmptyString(), UINT64_MAX),
mIsFromNsiFile(false)
{
}
virtual nsresult
Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
const JS::CallArgs& aArgs) MOZ_OVERRIDE;
typedef nsIDOMBlob* (*UnwrapFuncPtr)(JSContext*, JSObject*);
nsresult InitBlob(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv,
UnwrapFuncPtr aUnwrapFunc);
nsresult InitFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv);
nsresult InitChromeFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv);
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual nsresult GetInternalStream(nsIInputStream** aInputStream) MOZ_OVERRIDE;
static nsresult NewFile(const nsAString& aName, nsISupports** aNewObject);
// DOMClassInfo constructor (for Blob([b1, "foo"], { type: "image/png" }))
static nsresult NewBlob(nsISupports* *aNewObject);
// DOMClassInfo constructor (for File([b1, "foo"], { type: "image/png",
// name: "foo.png" }))
inline static nsresult NewFile(nsISupports** aNewObject)
{
// Initialization will set the filename, so we can pass in an empty string
// for now.
return NewFile(EmptyString(), aNewObject);
}
virtual const nsTArray<nsRefPtr<DOMFileImpl>>* GetSubBlobImpls() const MOZ_OVERRIDE
{
return &mBlobImpls;
}
virtual nsresult GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE;
protected:
virtual ~DOMMultipartFileImpl() {}
nsresult ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
bool aNativeEOL, UnwrapFuncPtr aUnwrapFunc);
void SetLengthAndModifiedDate();
nsTArray<nsRefPtr<DOMFileImpl>> mBlobImpls;
bool mIsFromNsiFile;
};
class BlobSet {
public:
BlobSet()
: mData(nullptr), mDataLen(0), mDataBufferLen(0)
{}
~BlobSet()
{
moz_free(mData);
}
nsresult AppendVoidPtr(const void* aData, uint32_t aLength);
nsresult AppendString(JSString* aString, bool nativeEOL, JSContext* aCx);
nsresult AppendBlobImpl(DOMFileImpl* aBlobImpl);
nsresult AppendArrayBuffer(JSObject* aBuffer);
nsresult AppendBlobImpls(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls);
nsTArray<nsRefPtr<DOMFileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }
already_AddRefed<nsIDOMBlob>
GetBlobInternal(const nsACString& aContentType)
{
nsCOMPtr<nsIDOMBlob> blob = new DOMFile(
new DOMMultipartFileImpl(GetBlobImpls(), NS_ConvertASCIItoUTF16(aContentType)));
return blob.forget();
}
protected:
bool ExpandBufferSize(uint64_t aSize)
{
using mozilla::CheckedUint32;
if (mDataBufferLen >= mDataLen + aSize) {
mDataLen += aSize;
return true;
}
// Start at 1 or we'll loop forever.
CheckedUint32 bufferLen =
std::max<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
while (bufferLen.isValid() && bufferLen.value() < mDataLen + aSize)
bufferLen *= 2;
if (!bufferLen.isValid())
return false;
void* data = moz_realloc(mData, bufferLen.value());
if (!data)
return false;
mData = data;
mDataBufferLen = bufferLen.value();
mDataLen += aSize;
return true;
}
void Flush() {
if (mData) {
// If we have some data, create a blob for it
// and put it on the stack
nsRefPtr<DOMFileImpl> blobImpl =
new DOMFileImplMemory(mData, mDataLen, EmptyString());
mBlobImpls.AppendElement(blobImpl);
mData = nullptr; // The nsDOMMemoryFile takes ownership of the buffer
mDataLen = 0;
mDataBufferLen = 0;
}
}
nsTArray<nsRefPtr<DOMFileImpl>> mBlobImpls;
void* mData;
uint64_t mDataLen;
uint64_t mDataBufferLen;
};
#endif

View File

@ -6,10 +6,6 @@
#include "nsDOMDataChannel.h"
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG
#endif
#include "base/basictypes.h"
#include "prlog.h"
@ -22,10 +18,10 @@ extern PRLogModuleInfo* GetDataChannelLog();
#include "nsDOMDataChannelDeclarations.h"
#include "nsDOMDataChannel.h"
#include "nsIDOMFile.h"
#include "nsIDOMDataChannel.h"
#include "nsIDOMMessageEvent.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsError.h"
@ -34,7 +30,6 @@ extern PRLogModuleInfo* GetDataChannelLog();
#include "nsCycleCollectionParticipant.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsNetUtil.h"
#include "nsDOMFile.h"
#include "DataChannel.h"
@ -272,19 +267,19 @@ nsDOMDataChannel::Send(const nsAString& aData, ErrorResult& aRv)
}
void
nsDOMDataChannel::Send(nsIDOMBlob* aData, ErrorResult& aRv)
nsDOMDataChannel::Send(File& aData, ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsCOMPtr<nsIInputStream> msgStream;
nsresult rv = aData->GetInternalStream(getter_AddRefs(msgStream));
nsresult rv = aData.GetInternalStream(getter_AddRefs(msgStream));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
uint64_t msgLength;
rv = aData->GetSize(&msgLength);
rv = aData.GetSize(&msgLength);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
@ -393,7 +388,7 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
if (aBinary) {
if (mBinaryType == DC_BINARY_TYPE_BLOB) {
rv = nsContentUtils::CreateBlobBuffer(cx, aData, &jsData);
rv = nsContentUtils::CreateBlobBuffer(cx, GetOwner(), aData, &jsData);
NS_ENSURE_SUCCESS(rv, rv);
} else if (mBinaryType == DC_BINARY_TYPE_ARRAYBUFFER) {
JS::Rooted<JSObject*> arrayBuf(cx);

View File

@ -17,6 +17,10 @@
namespace mozilla {
namespace dom {
class File;
}
class DataChannel;
};
@ -66,7 +70,7 @@ public:
static_cast<int>(aType));
}
void Send(const nsAString& aData, mozilla::ErrorResult& aRv);
void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv);
void Send(mozilla::dom::File& aData, mozilla::ErrorResult& aRv);
void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv);
void Send(const mozilla::dom::ArrayBufferView& aData,
mozilla::ErrorResult& aRv);

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,6 @@
#include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsDOMClassInfoID.h"
#include "nsDOMFile.h"
#include "nsError.h"
#include "nsIFile.h"
#include "nsNetCID.h"
@ -20,6 +19,7 @@
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Base64.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileReaderBinding.h"
#include "xpcpublic.h"
#include "nsDOMJSUtils.h"
@ -186,7 +186,8 @@ nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aFile, JSContext* aCx)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
ReadAsArrayBuffer(aCx, aFile, rv);
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsArrayBuffer(aCx, *file, rv);
return rv.ErrorCode();
}
@ -195,7 +196,8 @@ nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aFile)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
ReadAsBinaryString(aFile, rv);
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsBinaryString(*file, rv);
return rv.ErrorCode();
}
@ -205,7 +207,8 @@ nsDOMFileReader::ReadAsText(nsIDOMBlob* aFile,
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
ReadAsText(aFile, aCharset, rv);
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsText(*file, aCharset, rv);
return rv.ErrorCode();
}
@ -214,7 +217,8 @@ nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
ReadAsDataURL(aFile, rv);
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsDataURL(*file, rv);
return rv.ErrorCode();
}
@ -366,13 +370,11 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
void
nsDOMFileReader::ReadFileContent(JSContext* aCx,
nsIDOMBlob* aFile,
File& aFile,
const nsAString &aCharset,
eDataFormat aDataFormat,
ErrorResult& aRv)
{
MOZ_ASSERT(aFile);
//Implicit abort to clear any other activity going on
Abort();
mError = nullptr;
@ -382,7 +384,7 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx,
mReadyState = nsIDOMFileReader::EMPTY;
FreeFileData();
mFile = aFile;
mFile = &aFile;
mDataFormat = aDataFormat;
CopyUTF16toUTF8(aCharset, mCharset);

View File

@ -19,13 +19,18 @@
#include "nsITimer.h"
#include "nsIAsyncInputStream.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileReader.h"
#include "nsIDOMFileList.h"
#include "nsCOMPtr.h"
#include "FileIOObject.h"
namespace mozilla {
namespace dom {
class File;
}
}
class nsDOMFileReader : public mozilla::dom::FileIOObject,
public nsIDOMFileReader,
public nsIInterfaceRequestor,
@ -33,6 +38,7 @@ class nsDOMFileReader : public mozilla::dom::FileIOObject,
{
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::GlobalObject GlobalObject;
typedef mozilla::dom::File File;
public:
nsDOMFileReader();
@ -62,21 +68,18 @@ public:
// WebIDL
static already_AddRefed<nsDOMFileReader>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
void ReadAsArrayBuffer(JSContext* aCx, nsIDOMBlob* aBlob, ErrorResult& aRv)
void ReadAsArrayBuffer(JSContext* aCx, File& aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(aCx, aBlob, EmptyString(), FILE_AS_ARRAYBUFFER, aRv);
}
void ReadAsText(nsIDOMBlob* aBlob, const nsAString& aLabel, ErrorResult& aRv)
void ReadAsText(File& aBlob, const nsAString& aLabel, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, aLabel, FILE_AS_TEXT, aRv);
}
void ReadAsDataURL(nsIDOMBlob* aBlob, ErrorResult& aRv)
void ReadAsDataURL(File& aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, EmptyString(), FILE_AS_DATAURL, aRv);
}
@ -99,9 +102,8 @@ public:
using FileIOObject::SetOnerror;
IMPL_EVENT_HANDLER(loadend)
void ReadAsBinaryString(nsIDOMBlob* aBlob, ErrorResult& aRv)
void ReadAsBinaryString(File& aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, EmptyString(), FILE_AS_BINARY, aRv);
}
@ -122,7 +124,7 @@ protected:
FILE_AS_DATAURL
};
void ReadFileContent(JSContext* aCx, nsIDOMBlob* aBlob,
void ReadFileContent(JSContext* aCx, File& aBlob,
const nsAString &aCharset, eDataFormat aDataFormat,
ErrorResult& aRv);
nsresult GetAsText(nsIDOMBlob *aFile, const nsACString &aCharset,

View File

@ -18,10 +18,6 @@
#include "mozilla/Likely.h"
#include <algorithm>
#ifdef MOZ_LOGGING
// so we can get logging even in release builds
#define FORCE_PR_LOG 1
#endif
#include "prlog.h"
#include "plstr.h"
#include "prprf.h"

View File

@ -5,7 +5,8 @@
#include "nsFormData.h"
#include "nsIVariant.h"
#include "nsIInputStream.h"
#include "nsIDOMFile.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/FormDataBinding.h"
@ -21,9 +22,34 @@ nsFormData::nsFormData(nsISupports* aOwner)
// -------------------------------------------------------------------------
// nsISupports
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsFormData, mOwner)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormData)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFormData)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
ImplCycleCollectionUnlink(tmp->mFormData[i].fileValue);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFormData)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
ImplCycleCollectionTraverse(cb,tmp->mFormData[i].fileValue,
"mFormData[i].fileValue", 0);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsFormData)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormData)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMFormData)
@ -48,7 +74,7 @@ nsFormData::Append(const nsAString& aName, const nsAString& aValue)
}
void
nsFormData::Append(const nsAString& aName, nsIDOMBlob* aBlob,
nsFormData::Append(const nsAString& aName, File& aBlob,
const Optional<nsAString>& aFilename)
{
nsString filename;
@ -57,7 +83,7 @@ nsFormData::Append(const nsAString& aName, nsIDOMBlob* aBlob,
} else {
filename.SetIsVoid(true);
}
AddNameFilePair(aName, aBlob, filename);
AddNameFilePair(aName, &aBlob, filename);
}
// -------------------------------------------------------------------------
@ -80,9 +106,10 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
nsMemory::Free(iid);
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
nsRefPtr<File> blob = static_cast<File*>(domBlob.get());
if (domBlob) {
Optional<nsAString> temp;
Append(aName, domBlob, temp);
Append(aName, *blob, temp);
return NS_OK;
}
}

View File

@ -6,7 +6,6 @@
#define nsFormData_h__
#include "mozilla/Attributes.h"
#include "nsIDOMFile.h"
#include "nsIDOMFormData.h"
#include "nsIXMLHttpRequest.h"
#include "nsFormSubmission.h"
@ -15,12 +14,11 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
class nsIDOMFile;
namespace mozilla {
class ErrorResult;
namespace dom {
class File;
class HTMLFormElement;
class GlobalObject;
} // namespace dom
@ -57,7 +55,7 @@ public:
const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement,
mozilla::ErrorResult& aRv);
void Append(const nsAString& aName, const nsAString& aValue);
void Append(const nsAString& aName, nsIDOMBlob* aBlob,
void Append(const nsAString& aName, mozilla::dom::File& aBlob,
const mozilla::dom::Optional<nsAString>& aFilename);
// nsFormSubmission

View File

@ -27,10 +27,10 @@
#include "nsIScriptSecurityManager.h"
#include "nsIJSRuntimeService.h"
#include "nsIDOMClassInfo.h"
#include "nsIDOMFile.h"
#include "xpcpublic.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/ScriptSettings.h"
@ -204,7 +204,7 @@ BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType*
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
const nsTArray<nsRefPtr<File>>& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
@ -255,8 +255,13 @@ UnpackClonedMessageData(const ClonedMessageData& aData)
auto* blob =
static_cast<typename BlobTraits<Flavor>::BlobType*>(blobs[i]);
MOZ_ASSERT(blob);
nsCOMPtr<nsIDOMBlob> domBlob = blob->GetBlob();
MOZ_ASSERT(domBlob);
nsRefPtr<FileImpl> blobImpl = blob->GetBlobImpl();
MOZ_ASSERT(blobImpl);
// This object will be duplicated with a correct parent before being
// exposed to JS.
nsRefPtr<File> domBlob = new File(nullptr, blobImpl);
cloneData.mClosure.mBlobs.AppendElement(domBlob);
}
}

View File

@ -10,14 +10,15 @@
#include "nsClassHashtable.h"
#include "nsNetUtil.h"
#include "nsIPrincipal.h"
#include "nsDOMFile.h"
#include "DOMMediaStream.h"
#include "mozilla/dom/MediaSource.h"
#include "nsIMemoryReporter.h"
#include "mozilla/dom/File.h"
#include "mozilla/Preferences.h"
#include "mozilla/LoadInfo.h"
using mozilla::dom::DOMFileImpl;
using mozilla::dom::FileImpl;
using mozilla::ErrorResult;
using mozilla::LoadInfo;
// -----------------------------------------------------------------------
@ -496,7 +497,7 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
return NS_ERROR_DOM_BAD_URI;
}
nsCOMPtr<PIDOMFileImpl> blobImpl = do_QueryInterface(info->mObject);
nsCOMPtr<PIFileImpl> blobImpl = do_QueryInterface(info->mObject);
if (!blobImpl) {
return NS_ERROR_DOM_BAD_URI;
}
@ -510,7 +511,7 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
}
#endif
DOMFileImpl* blob = static_cast<DOMFileImpl*>(blobImpl.get());
FileImpl* blob = static_cast<FileImpl*>(blobImpl.get());
nsCOMPtr<nsIInputStream> stream;
nsresult rv = blob->GetInternalStream(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, rv);
@ -522,19 +523,19 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
NS_ENSURE_SUCCESS(rv, rv);
nsString type;
rv = blob->GetType(type);
NS_ENSURE_SUCCESS(rv, rv);
blob->GetType(type);
if (blob->IsFile()) {
nsString filename;
rv = blob->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);
blob->GetName(filename);
channel->SetContentDispositionFilename(filename);
}
uint64_t size;
rv = blob->GetSize(&size);
NS_ENSURE_SUCCESS(rv, rv);
ErrorResult error;
uint64_t size = blob->GetSize(error);
if (NS_WARN_IF(error.Failed())) {
return error.ErrorCode();
}
nsCOMPtr<nsILoadInfo> loadInfo =
new mozilla::LoadInfo(info->mPrincipal,
@ -595,12 +596,12 @@ NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream)
*aStream = nullptr;
nsCOMPtr<PIDOMFileImpl> blobImpl = do_QueryInterface(GetDataObject(aURI));
nsCOMPtr<PIFileImpl> blobImpl = do_QueryInterface(GetDataObject(aURI));
if (!blobImpl) {
return NS_ERROR_DOM_BAD_URI;
}
DOMFileImpl* blob = static_cast<DOMFileImpl*>(blobImpl.get());
FileImpl* blob = static_cast<FileImpl*>(blobImpl.get());
return blob->GetInternalStream(aStream);
}

View File

@ -32,10 +32,6 @@
using namespace mozilla;
using mozilla::dom::NodeInfo;
#ifdef MOZ_LOGGING
// so we can get logging even in release builds
#define FORCE_PR_LOG 1
#endif
#include "prlog.h"
#ifdef PR_LOGGING

View File

@ -10,12 +10,13 @@
#include <unistd.h>
#endif
#include "mozilla/ArrayUtils.h"
#include "mozilla/dom/BlobSet.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/MemoryReporting.h"
#include "nsDOMBlobBuilder.h"
#include "nsIDOMDocument.h"
#include "mozilla/dom/ProgressEvent.h"
#include "nsIJARChannel.h"
@ -56,7 +57,6 @@
#include "nsIContentSecurityPolicy.h"
#include "nsAsyncRedirectVerifyHelper.h"
#include "nsStringBuffer.h"
#include "nsDOMFile.h"
#include "nsIFileChannel.h"
#include "mozilla/Telemetry.h"
#include "jsfriendapi.h"
@ -784,8 +784,9 @@ nsXMLHttpRequest::CreatePartialBlob()
if (mLoadTotal == mLoadTransferred) {
mResponseBlob = mDOMFile;
} else {
mResponseBlob =
mDOMFile->CreateSlice(0, mDataAvailable, EmptyString());
ErrorResult rv;
mResponseBlob = mDOMFile->CreateSlice(0, mDataAvailable,
EmptyString(), rv);
}
return;
}
@ -800,7 +801,7 @@ nsXMLHttpRequest::CreatePartialBlob()
mChannel->GetContentType(contentType);
}
mResponseBlob = mBlobSet->GetBlobInternal(contentType);
mResponseBlob = mBlobSet->GetBlobInternal(GetOwner(), contentType);
}
/* attribute AString responseType; */
@ -1007,7 +1008,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx,
return;
}
aRv = nsContentUtils::WrapNative(aCx, mResponseBlob, aResponse);
WrapNewBindingObject(aCx, mResponseBlob, aResponse);
return;
}
case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
@ -1897,8 +1898,7 @@ bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request)
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mDOMFile =
DOMFile::CreateFromFile(file, EmptyString(),
mDOMFile = File::CreateFromFile(GetOwner(), file, EmptyString(),
NS_ConvertASCIItoUTF16(contentType));
mBlobSet = nullptr;
@ -2243,7 +2243,7 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
// Also, no-store response cannot be written in persistent cache.
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mResponseBlob = mBlobSet->GetBlobInternal(contentType);
mResponseBlob = mBlobSet->GetBlobInternal(GetOwner(), contentType);
mBlobSet = nullptr;
}
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
@ -2618,7 +2618,8 @@ nsXMLHttpRequest::GetRequestBody(nsIVariant* aVariant,
case nsXMLHttpRequest::RequestBody::Blob:
{
nsresult rv;
nsCOMPtr<nsIXHRSendable> sendable = do_QueryInterface(value.mBlob, &rv);
nsCOMPtr<nsIDOMBlob> blob = value.mBlob;
nsCOMPtr<nsIXHRSendable> sendable = do_QueryInterface(blob, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return ::GetRequestBody(sendable, aResult, aContentLength, aContentType, aCharset);

View File

@ -41,8 +41,6 @@
#endif
class AsyncVerifyRedirectCallbackForwarder;
class BlobSet;
class nsDOMFile;
class nsFormData;
class nsIJARChannel;
class nsILoadGroup;
@ -52,7 +50,8 @@ class nsIJSID;
namespace mozilla {
namespace dom {
class DOMFile;
class BlobSet;
class File;
}
// A helper for building up an ArrayBuffer object's data
@ -350,9 +349,9 @@ private:
{
mValue.mArrayBufferView = aArrayBufferView;
}
explicit RequestBody(nsIDOMBlob* aBlob) : mType(Blob)
explicit RequestBody(mozilla::dom::File& aBlob) : mType(Blob)
{
mValue.mBlob = aBlob;
mValue.mBlob = &aBlob;
}
explicit RequestBody(nsIDocument* aDocument) : mType(Document)
{
@ -384,7 +383,7 @@ private:
union Value {
const mozilla::dom::ArrayBuffer* mArrayBuffer;
const mozilla::dom::ArrayBufferView* mArrayBufferView;
nsIDOMBlob* mBlob;
mozilla::dom::File* mBlob;
nsIDocument* mDocument;
const nsAString* mString;
nsFormData* mFormData;
@ -440,9 +439,8 @@ public:
{
aRv = Send(RequestBody(&aArrayBufferView));
}
void Send(nsIDOMBlob* aBlob, ErrorResult& aRv)
void Send(mozilla::dom::File& aBlob, ErrorResult& aRv)
{
NS_ASSERTION(aBlob, "Null should go to string version");
aRv = Send(RequestBody(aBlob));
}
void Send(nsIDocument& aDoc, ErrorResult& aRv)
@ -672,13 +670,13 @@ protected:
// It is either a cached blob-response from the last call to GetResponse,
// but is also explicitly set in OnStopRequest.
nsCOMPtr<nsIDOMBlob> mResponseBlob;
nsRefPtr<mozilla::dom::File> mResponseBlob;
// Non-null only when we are able to get a os-file representation of the
// response, i.e. when loading from a file.
nsRefPtr<mozilla::dom::DOMFile> mDOMFile;
nsRefPtr<mozilla::dom::File> mDOMFile;
// We stream data to mBlobSet when response type is "blob" or "moz-blob"
// and mDOMFile is null.
nsAutoPtr<BlobSet> mBlobSet;
nsAutoPtr<mozilla::dom::BlobSet> mBlobSet;
nsString mOverrideMimeType;

View File

@ -33,13 +33,13 @@ function createFileWithData(fileData) {
return testFile;
}
/** Test for Bug 914381. DOMFile's created in JS using an nsIFile should allow mozGetFullPathInternal calls to succeed **/
/** Test for Bug 914381. File's created in JS using an nsIFile should allow mozGetFullPathInternal calls to succeed **/
var file = createFileWithData("Test bug 914381");
var f = File(file);
var f = new File(file);
is(f.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, file.path, "mozFullPath returns path if created with nsIFile");
f = File(file.path);
f = new File(file.path);
is(f.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, "", "mozFullPath returns blank if created with a string");
</script>

View File

@ -20,65 +20,65 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=721569
<script class="testbody" type="text/javascript;version=1.7">
"use strict";
/** Test for Bug 721569 **/
var blob = Blob();
var blob = new Blob();
ok(blob, "Blob should exist");
ok(blob.size !== undefined, "Blob should have a size property");
ok(blob.type !== undefined, "Blob should have a type property");
ok(blob.slice, "Blob should have a slice method");
blob = Blob([], {type: null});
blob = new Blob([], {type: null});
ok(blob, "Blob should exist");
is(blob.type, "null", "Blob type should be stringified");
blob = Blob([], {type: undefined});
blob = new Blob([], {type: undefined});
ok(blob, "Blob should exist");
is(blob.type, "", "Blob type should be treated as missing");
try {
blob = Blob([]);
blob = new Blob([]);
ok(true, "an empty blobParts argument should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = Blob(null);
blob = new Blob(null);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a null blobParts member should throw");
}
try {
blob = Blob([], null);
blob = new Blob([], null);
ok(true, "a null options member should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = Blob([], undefined);
blob = new Blob([], undefined);
ok(true, "an undefined options member should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = Blob([], false);
blob = new Blob([], false);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a boolean options member should throw");
}
try {
blob = Blob([], 0);
blob = new Blob([], 0);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a numeric options member should throw");
}
try {
blob = Blob([], "");
blob = new Blob([], "");
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a string options member should throw");
@ -100,13 +100,13 @@ ok(true, "a string options member should throw");
is(JSON.stringify(called), JSON.stringify(["endings", "type"]), "dictionary members should be get in lexicographical order");
})();
let blob1 = Blob(["squiggle"]);
let blob1 = new Blob(["squiggle"]);
ok(blob1 instanceof Blob, "Blob constructor should produce Blobs");
ok(!(blob1 instanceof File), "Blob constructor should not produce Files");
is(blob1.type, "", "Blob constructor with no options should return Blob with empty type");
is(blob1.size, 8, "Blob constructor should return Blob with correct size");
let blob2 = Blob(["steak"], {type: "content/type"});
let blob2 = new Blob(["steak"], {type: "content/type"});
ok(blob2 instanceof Blob, "Blob constructor should produce Blobs");
ok(!(blob2 instanceof File), "Blob constructor should not produce Files");
is(blob2.type, "content/type", "Blob constructor with a type option should return Blob with the type");

View File

@ -13,7 +13,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=403852
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=403852">Mozilla Bug 403852</a>
<p id="display">
<input id="fileList" type="file"></input>
<canvas id="canvas"></canvas>
</p>
<div id="content" style="display: none">
</div>
@ -37,10 +36,14 @@ ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
var d = new Date(testFile.lastModifiedTime);
ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same.");
var cf = document.getElementById("canvas").mozGetAsFile("canvFile");
var x = new Date();
var y = cf.lastModifiedDate;
// In our implementation of File object, lastModifiedDate is unknown only for new objects.
// Using canvas or input[type=file] elements, we 'often' have a valid lastModifiedDate values.
// For canvas we use memory files and the lastModifiedDate is now().
var f = new File([new Blob(['test'], {type: 'text/plain'})], "test-name");
var y = f.lastModifiedDate;
var z = new Date();
ok((x.getTime() <= y.getTime()) && (y.getTime() <= z.getTime()), "lastModifiedDate of file which does not have last modified date should be current time");

View File

@ -16,7 +16,6 @@
#include "mozilla/gfx/Rect.h"
class nsICanvasRenderingContextInternal;
class nsIDOMFile;
class nsITimerCallback;
namespace mozilla {
@ -31,6 +30,7 @@ class SourceSurface;
namespace dom {
class File;
class FileCallback;
class HTMLCanvasPrintState;
class PrintCallback;
@ -102,7 +102,7 @@ public:
{
SetHTMLBoolAttr(nsGkAtoms::moz_opaque, aValue, aRv);
}
already_AddRefed<nsIDOMFile> MozGetAsFile(const nsAString& aName,
already_AddRefed<File> MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv);
already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,

View File

@ -12,6 +12,7 @@
#include "mozilla/Base64.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/CanvasRenderingContext2D.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLCanvasElementBinding.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/MouseEvent.h"
@ -23,7 +24,6 @@
#include "nsAttrValueInlines.h"
#include "nsContentUtils.h"
#include "nsDisplayList.h"
#include "nsDOMFile.h"
#include "nsDOMJSUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsITimer.h"
@ -549,9 +549,9 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
, mFileCallback(aCallback) {}
// This is called on main thread.
nsresult ReceiveBlob(already_AddRefed<DOMFile> aBlob)
nsresult ReceiveBlob(already_AddRefed<File> aBlob)
{
nsRefPtr<DOMFile> blob = aBlob;
nsRefPtr<File> blob = aBlob;
uint64_t size;
nsresult rv = blob->GetSize(&size);
if (NS_SUCCEEDED(rv)) {
@ -560,8 +560,10 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
JS_updateMallocCounter(jsapi.cx(), size);
}
nsRefPtr<File> newBlob = new File(mGlobal, blob->Impl());
mozilla::ErrorResult error;
mFileCallback->Call(blob, error);
mFileCallback->Call(*newBlob, error);
mGlobal = nullptr;
mFileCallback = nullptr;
@ -585,14 +587,15 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
callback);
}
already_AddRefed<nsIDOMFile>
already_AddRefed<File>
HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv)
{
nsCOMPtr<nsIDOMFile> file;
aRv = MozGetAsFile(aName, aType, getter_AddRefs(file));
return file.forget();
nsRefPtr<File> tmp = static_cast<File*>(file.get());
return tmp.forget();
}
NS_IMETHODIMP
@ -635,9 +638,11 @@ HTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
JS_updateMallocCounter(cx, imgSize);
}
// The DOMFile takes ownership of the buffer
nsRefPtr<DOMFile> file =
DOMFile::CreateMemoryFile(imgData, (uint32_t)imgSize, aName, type,
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScopeObject());
// The File takes ownership of the buffer
nsRefPtr<File> file =
File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type,
PR_Now());
file.forget(aResult);

View File

@ -73,9 +73,9 @@
#include "nsIRadioGroupContainer.h"
// input type=file
#include "mozilla/dom/File.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
#include "nsDOMFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIContentPrefService.h"
#include "nsIMIMEService.h"
@ -236,11 +236,11 @@ class HTMLInputElementState MOZ_FINAL : public nsISupports
mValue = aValue;
}
const nsTArray<nsCOMPtr<nsIDOMFile> >& GetFiles() {
const nsTArray<nsRefPtr<File>>& GetFiles() {
return mFiles;
}
void SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles) {
void SetFiles(const nsTArray<nsRefPtr<File>>& aFiles) {
mFiles.Clear();
mFiles.AppendElements(aFiles);
}
@ -255,7 +255,7 @@ class HTMLInputElementState MOZ_FINAL : public nsISupports
~HTMLInputElementState() {}
nsString mValue;
nsTArray<nsCOMPtr<nsIDOMFile> > mFiles;
nsTArray<nsRefPtr<File>> mFiles;
bool mChecked;
bool mCheckedSet;
};
@ -316,7 +316,7 @@ UploadLastDir::ContentPrefCallback::HandleError(nsresult error)
namespace {
/**
* This enumerator returns nsDOMFileFile objects after wrapping a single
* This enumerator returns File objects after wrapping a single
* nsIFile representing a directory. It enumerates the files under that
* directory and its subdirectories as a flat list of files, ignoring/skipping
* over symbolic links.
@ -374,7 +374,9 @@ public:
if (!mNextFile) {
return NS_ERROR_FAILURE;
}
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(mNextFile);
// The parent for this object will be set on the main thread.
nsRefPtr<File> domFile = File::CreateFromFile(nullptr, mNextFile);
nsCString relDescriptor;
nsresult rv =
mNextFile->GetRelativeDescriptor(mTopDirsParent, relDescriptor);
@ -387,8 +389,7 @@ public:
MOZ_ASSERT(length >= 0);
if (length > 0) {
// Note that we leave the trailing "/" on the path.
DOMFileImplFile* fileImpl =
static_cast<DOMFileImplFile*>(domFile->Impl());
FileImplFile* fileImpl = static_cast<FileImplFile*>(domFile->Impl());
MOZ_ASSERT(fileImpl);
fileImpl->SetPath(Substring(path, 0, uint32_t(length)));
}
@ -512,7 +513,7 @@ public:
NS_IMETHOD Run() {
if (!NS_IsMainThread()) {
// Build up list of nsDOMFileFile objects on this dedicated thread:
// Build up list of File objects on this dedicated thread:
nsCOMPtr<nsISimpleEnumerator> iter =
new DirPickerRecursiveFileEnumerator(mTopDir);
bool hasMore = true;
@ -521,7 +522,7 @@ public:
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
MOZ_ASSERT(domFile);
mFileList.AppendElement(domFile);
mFileList.AppendElement(static_cast<File*>(domFile.get()));
mFileListLength = mFileList.Length();
if (mCanceled) {
MOZ_ASSERT(!mInput, "This is bad - how did this happen?");
@ -551,6 +552,13 @@ public:
return NS_OK;
}
// Recreate File with the correct parent object.
nsCOMPtr<nsIGlobalObject> global = mInput->OwnerDoc()->GetScopeObject();
for (uint32_t i = 0; i < mFileList.Length(); ++i) {
MOZ_ASSERT(!mFileList[i]->GetParentObject());
mFileList[i] = new File(global, mFileList[i]->Impl());
}
// The text control frame (if there is one) isn't going to send a change
// event because it will think this is done by a script.
// So, we can safely send one by ourself.
@ -594,7 +602,7 @@ public:
private:
nsRefPtr<HTMLInputElement> mInput;
nsCOMPtr<nsIFile> mTopDir;
nsTArray<nsCOMPtr<nsIDOMFile> > mFileList;
nsTArray<nsRefPtr<File>> mFileList;
// We access the list length on both threads, so we need the indirection of
// this atomic member to make the access thread safe:
@ -620,7 +628,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
if (mode == static_cast<int16_t>(nsIFilePicker::modeGetFolder)) {
// Directory picking is different, since we still need to do more I/O to
// build up the list of nsDOMFileFile objects. Since this may block for a
// build up the list of File objects. Since this may block for a
// long time, we need to build the list off on another dedicated thread to
// avoid blocking any other activities that the browser is carrying out.
@ -655,7 +663,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
}
// Collect new selected filenames
nsTArray<nsCOMPtr<nsIDOMFile> > newFiles;
nsTArray<nsRefPtr<File>> newFiles;
if (mode == static_cast<int16_t>(nsIFilePicker::modeOpenMultiple)) {
nsCOMPtr<nsISimpleEnumerator> iter;
nsresult rv = mFilePicker->GetDomfiles(getter_AddRefs(iter));
@ -672,7 +680,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
MOZ_ASSERT(domFile);
newFiles.AppendElement(domFile);
newFiles.AppendElement(static_cast<File*>(domFile.get()));
}
} else {
MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen));
@ -680,7 +688,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(domFile));
NS_ENSURE_SUCCESS(rv, rv);
if (domFile) {
newFiles.AppendElement(domFile);
newFiles.AppendElement(static_cast<File*>(domFile.get()));
}
}
@ -936,7 +944,7 @@ HTMLInputElement::InitFilePicker(FilePickerType aType)
// Set default directry and filename
nsAutoString defaultName;
const nsTArray<nsCOMPtr<nsIDOMFile> >& oldFiles = GetFilesInternal();
const nsTArray<nsRefPtr<File>>& oldFiles = GetFilesInternal();
nsCOMPtr<nsIFilePickerShownCallback> callback =
new HTMLInputElement::nsFilePickerShownCallback(this, filePicker);
@ -1716,7 +1724,7 @@ HTMLInputElement::IsValueEmpty() const
void
HTMLInputElement::ClearFiles(bool aSetValueChanged)
{
nsTArray<nsCOMPtr<nsIDOMFile> > files;
nsTArray<nsRefPtr<File>> files;
SetFiles(files, aSetValueChanged);
}
@ -2310,7 +2318,7 @@ HTMLInputElement::MozGetFileNameArray(uint32_t* aLength, char16_t*** aFileNames)
void
HTMLInputElement::MozSetFileNameArray(const Sequence< nsString >& aFileNames)
{
nsTArray<nsCOMPtr<nsIDOMFile> > files;
nsTArray<nsRefPtr<File>> files;
for (uint32_t i = 0; i < aFileNames.Length(); ++i) {
nsCOMPtr<nsIFile> file;
@ -2328,7 +2336,8 @@ HTMLInputElement::MozSetFileNameArray(const Sequence< nsString >& aFileNames)
}
if (file) {
nsCOMPtr<nsIDOMFile> domFile = DOMFile::CreateFromFile(file);
nsCOMPtr<nsIGlobalObject> global = OwnerDoc()->GetScopeObject();
nsRefPtr<File> domFile = File::CreateFromFile(global, file);
files.AppendElement(domFile);
} else {
continue; // Not much we can do if the file doesn't exist
@ -2564,7 +2573,7 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
}
void
HTMLInputElement::SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles,
HTMLInputElement::SetFiles(const nsTArray<nsRefPtr<File>>& aFiles,
bool aSetValueChanged)
{
mFiles.Clear();
@ -2577,14 +2586,14 @@ void
HTMLInputElement::SetFiles(nsIDOMFileList* aFiles,
bool aSetValueChanged)
{
nsRefPtr<FileList> files = static_cast<FileList*>(aFiles);
mFiles.Clear();
if (aFiles) {
uint32_t listLength;
aFiles->GetLength(&listLength);
for (uint32_t i = 0; i < listLength; i++) {
nsCOMPtr<nsIDOMFile> file;
aFiles->Item(i, getter_AddRefs(file));
nsRefPtr<File> file = files->Item(i);
mFiles.AppendElement(file);
}
}
@ -2632,7 +2641,7 @@ HTMLInputElement::FireChangeEventIfNeeded()
false);
}
nsDOMFileList*
FileList*
HTMLInputElement::GetFiles()
{
if (mType != NS_FORM_INPUT_FILE) {
@ -2640,7 +2649,7 @@ HTMLInputElement::GetFiles()
}
if (!mFileList) {
mFileList = new nsDOMFileList(static_cast<nsIContent*>(this));
mFileList = new FileList(static_cast<nsIContent*>(this));
UpdateFileList();
}
@ -2784,7 +2793,7 @@ HTMLInputElement::UpdateFileList()
if (mFileList) {
mFileList->Clear();
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
for (uint32_t i = 0; i < files.Length(); ++i) {
if (!mFileList->Append(files[i])) {
return NS_ERROR_FAILURE;
@ -5367,7 +5376,7 @@ HTMLInputElement::SetSelectionEnd(int32_t aSelectionEnd)
NS_IMETHODIMP
HTMLInputElement::GetFiles(nsIDOMFileList** aFileList)
{
nsRefPtr<nsDOMFileList> list = GetFiles();
nsRefPtr<FileList> list = GetFiles();
list.forget(aFileList);
return NS_OK;
}
@ -5634,7 +5643,7 @@ HTMLInputElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
if (mType == NS_FORM_INPUT_FILE) {
// Submit files
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
for (uint32_t i = 0; i < files.Length(); ++i) {
aFormSubmission->AddNameFilePair(name, files[i], NullString());
@ -5882,7 +5891,7 @@ HTMLInputElement::RestoreState(nsPresState* aState)
break;
case VALUE_MODE_FILENAME:
{
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = inputState->GetFiles();
const nsTArray<nsRefPtr<File>>& files = inputState->GetFiles();
SetFiles(files, true);
}
break;
@ -6392,7 +6401,7 @@ HTMLInputElement::IsValueMissing() const
return IsValueEmpty();
case VALUE_MODE_FILENAME:
{
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
return files.IsEmpty();
}
case VALUE_MODE_DEFAULT_ON:

View File

@ -24,7 +24,6 @@
#include "nsContentUtils.h"
#include "nsTextEditorState.h"
class nsDOMFileList;
class nsIRadioGroupContainer;
class nsIRadioGroupVisitor;
class nsIRadioVisitor;
@ -38,6 +37,8 @@ namespace dom {
class Date;
class DirPickerFileListBuilderTask;
class File;
class FileList;
class UploadLastDir MOZ_FINAL : public nsIObserver, public nsSupportsWeakReference {
@ -210,12 +211,12 @@ public:
void GetDisplayFileName(nsAString& aFileName) const;
const nsTArray<nsCOMPtr<nsIDOMFile> >& GetFilesInternal() const
const nsTArray<nsRefPtr<File>>& GetFilesInternal() const
{
return mFiles;
}
void SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles, bool aSetValueChanged);
void SetFiles(const nsTArray<nsRefPtr<File>>& aFiles, bool aSetValueChanged);
void SetFiles(nsIDOMFileList* aFiles, bool aSetValueChanged);
// Called when a nsIFilePicker or a nsIColorPicker terminate.
@ -432,7 +433,7 @@ public:
// XPCOM GetForm() is OK
nsDOMFileList* GetFiles();
FileList* GetFiles();
void OpenDirectoryPicker(ErrorResult& aRv);
void CancelDirectoryPickerScanIfRunning();
@ -1251,9 +1252,9 @@ protected:
* the frame. Whenever the frame wants to change the filename it has to call
* SetFileNames to update this member.
*/
nsTArray<nsCOMPtr<nsIDOMFile> > mFiles;
nsTArray<nsRefPtr<File>> mFiles;
nsRefPtr<nsDOMFileList> mFileList;
nsRefPtr<FileList> mFileList;
nsRefPtr<DirPickerFileListBuilderTask> mDirPickerFileListBuilderTask;

View File

@ -52,11 +52,11 @@ function runTest() {
fd.append("empty", blob);
fd.append("explicit", blob, "explicit-file-name");
fd.append("explicit-empty", blob, "");
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: 'testname'}));
file = new File([blob], 'testname', {type: 'text/plain'});
fd.append("file-name", file);
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: ''}));
file = new File([blob], '', {type: 'text/plain'});
fd.append("empty-file-name", file);
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: 'testname'}));
file = new File([blob], 'testname', {type: 'text/plain'});
fd.append("file-name-overwrite", file, "overwrite");
xhr.responseType = 'json';
xhr.send(fd);

View File

@ -5,8 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "EncodedBufferCache.h"
#include "mozilla/dom/File.h"
#include "nsAnonymousTemporaryFile.h"
#include "nsDOMFile.h"
#include "prio.h"
namespace mozilla {
@ -39,14 +39,15 @@ EncodedBufferCache::AppendBuffer(nsTArray<uint8_t> & aBuf)
}
already_AddRefed<nsIDOMBlob>
EncodedBufferCache::ExtractBlob(const nsAString &aContentType)
already_AddRefed<dom::File>
EncodedBufferCache::ExtractBlob(nsISupports* aParent,
const nsAString &aContentType)
{
MutexAutoLock lock(mMutex);
nsCOMPtr<nsIDOMBlob> blob;
nsRefPtr<dom::File> blob;
if (mTempFileEnabled) {
// generate new temporary file to write
blob = dom::DOMFile::CreateTemporaryFileBlob(mFD, 0, mDataSize,
blob = dom::File::CreateTemporaryFileBlob(aParent, mFD, 0, mDataSize,
aContentType);
// fallback to memory blob
mTempFileEnabled = false;
@ -62,7 +63,8 @@ EncodedBufferCache::ExtractBlob(const nsAString &aContentType)
mEncodedBuffers.ElementAt(i).Length());
offset += mEncodedBuffers.ElementAt(i).Length();
}
blob = dom::DOMFile::CreateMemoryFile(blobData, mDataSize, aContentType);
blob = dom::File::CreateMemoryFile(aParent, blobData, mDataSize,
aContentType);
mEncodedBuffers.Clear();
} else
return nullptr;

View File

@ -16,6 +16,10 @@ class nsIDOMBlob;
namespace mozilla {
namespace dom {
class File;
}
class ReentrantMonitor;
/**
* Data is moved into a temporary file when it grows beyond
@ -39,7 +43,7 @@ public:
// aBuf will append to mEncodedBuffers or temporary File, aBuf also be cleared
void AppendBuffer(nsTArray<uint8_t> & aBuf);
// Read all buffer from memory or file System, also Remove the temporary file or clean the buffers in memory.
already_AddRefed<nsIDOMBlob> ExtractBlob(const nsAString &aContentType);
already_AddRefed<dom::File> ExtractBlob(nsISupports* aParent, const nsAString &aContentType);
private:
//array for storing the encoded data.

View File

@ -4,9 +4,6 @@
* 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/. */
// We want this available in opt builds
#define FORCE_PR_LOG
#include "Latency.h"
#include "nsThreadUtils.h"
#include "prlog.h"

View File

@ -15,11 +15,11 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/AudioStreamTrack.h"
#include "mozilla/dom/BlobEvent.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/RecordErrorEvent.h"
#include "mozilla/dom/VideoStreamTrack.h"
#include "nsError.h"
#include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIPrincipal.h"
#include "nsMimeTypes.h"
#include "nsProxyRelease.h"
@ -389,7 +389,8 @@ public:
already_AddRefed<nsIDOMBlob> GetEncodedData()
{
MOZ_ASSERT(NS_IsMainThread());
return mEncodedBufferCache->ExtractBlob(mMimeType);
return mEncodedBufferCache->ExtractBlob(mRecorder->GetParentObject(),
mMimeType);
}
bool IsEncoderError()
@ -920,7 +921,10 @@ MediaRecorder::CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob)
BlobEventInit init;
init.mBubbles = false;
init.mCancelable = false;
init.mData = aBlob;
nsCOMPtr<nsIDOMBlob> blob = aBlob;
init.mData = static_cast<File*>(blob.get());
nsRefPtr<BlobEvent> event =
BlobEvent::Constructor(this,
NS_LITERAL_STRING("dataavailable"),

View File

@ -310,7 +310,9 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo,
mIndexReady = true;
}
mInfo.mVideo.mHasVideo = mVideo.mActive = mDemuxer->HasValidVideo();
// To decode, we need valid video and a place to put it.
mInfo.mVideo.mHasVideo = mVideo.mActive = mDemuxer->HasValidVideo() &&
mDecoder->GetImageContainer();
const VideoDecoderConfig& video = mDemuxer->VideoConfig();
// If we have video, we *only* allow H.264 to be decoded.
if (mInfo.mVideo.mHasVideo && strcmp(video.mime_type, "video/avc")) {

View File

@ -15,14 +15,20 @@
namespace mozilla {
nsresult
CaptureTask::TaskComplete(already_AddRefed<dom::DOMFile> aBlob, nsresult aRv)
CaptureTask::TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv)
{
MOZ_ASSERT(NS_IsMainThread());
DetachStream();
nsresult rv;
nsRefPtr<dom::DOMFile> blob(aBlob);
nsRefPtr<dom::File> blob(aBlob);
// We have to set the parent because the blob has been generated with a valid one.
if (blob) {
blob = new dom::File(mImageCapture->GetParentObject(), blob->Impl());
}
if (mPrincipalChanged) {
aRv = NS_ERROR_DOM_SECURITY_ERR;
IC_LOG("MediaStream principal should not change during TakePhoto().");
@ -98,9 +104,9 @@ CaptureTask::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
public:
explicit EncodeComplete(CaptureTask* aTask) : mTask(aTask) {}
nsresult ReceiveBlob(already_AddRefed<dom::DOMFile> aBlob) MOZ_OVERRIDE
nsresult ReceiveBlob(already_AddRefed<dom::File> aBlob) MOZ_OVERRIDE
{
nsRefPtr<dom::DOMFile> blob(aBlob);
nsRefPtr<dom::File> blob(aBlob);
mTask->TaskComplete(blob.forget(), NS_OK);
mTask = nullptr;
return NS_OK;

View File

@ -13,8 +13,8 @@
namespace mozilla {
namespace dom {
class File;
class ImageCapture;
class DOMFile;
}
/**
@ -51,7 +51,7 @@ public:
//
// Note:
// this function should be called on main thread.
nsresult TaskComplete(already_AddRefed<dom::DOMFile> aBlob, nsresult aRv);
nsresult TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv);
// Add listeners into MediaStream and PrincipalChangeObserver. It should be on
// main thread only.

View File

@ -7,11 +7,11 @@
#include "ImageCapture.h"
#include "mozilla/dom/BlobEvent.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ImageCaptureError.h"
#include "mozilla/dom/ImageCaptureErrorEvent.h"
#include "mozilla/dom/ImageCaptureErrorEventBinding.h"
#include "mozilla/dom/VideoStreamTrack.h"
#include "nsDOMFile.h"
#include "nsIDocument.h"
#include "CaptureTask.h"
#include "MediaEngine.h"
@ -102,9 +102,9 @@ ImageCapture::TakePhotoByMediaEngine()
mPrincipalChanged = true;
}
nsresult PhotoComplete(already_AddRefed<DOMFile> aBlob) MOZ_OVERRIDE
nsresult PhotoComplete(already_AddRefed<File> aBlob) MOZ_OVERRIDE
{
nsRefPtr<DOMFile> blob = aBlob;
nsRefPtr<File> blob = aBlob;
if (mPrincipalChanged) {
return PhotoError(NS_ERROR_DOM_SECURITY_ERR);
@ -172,7 +172,7 @@ ImageCapture::TakePhoto(ErrorResult& aResult)
}
nsresult
ImageCapture::PostBlobEvent(nsIDOMBlob* aBlob)
ImageCapture::PostBlobEvent(File* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
if (!CheckPrincipal()) {

View File

@ -32,6 +32,7 @@ PRLogModuleInfo* GetICLog();
namespace dom {
class File;
class VideoStreamTrack;
/**
@ -79,7 +80,7 @@ public:
ImageCapture(VideoStreamTrack* aVideoStreamTrack, nsPIDOMWindow* aOwnerWindow);
// Post a Blob event to script.
nsresult PostBlobEvent(nsIDOMBlob* aBlob);
nsresult PostBlobEvent(File* aBlob);
// Post an error event to script.
// aErrorCode should be one of error codes defined in ImageCaptureError.h.

View File

@ -140,6 +140,7 @@ UNIFIED_SOURCES += [
'EncodedBufferCache.cpp',
'FileBlockCache.cpp',
"GraphDriver.cpp",
'Latency.cpp',
'MediaCache.cpp',
'MediaData.cpp',
'MediaDecoder.cpp',
@ -177,10 +178,8 @@ if CONFIG['OS_TARGET'] == 'WINNT':
SOURCES += [ 'ThreadPoolCOMListener.cpp' ]
# DecoderTraits.cpp needs to be built separately because of Mac OS X headers.
# Latency.cpp needs to be built separately because it forces NSPR logging.
SOURCES += [
'DecoderTraits.cpp',
'Latency.cpp',
]
FAIL_ON_WARNINGS = True

View File

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
class DOMFile;
class File;
}
struct VideoTrackConstraintsN;
@ -150,7 +150,7 @@ public:
// aBlob is the image captured by MediaEngineSource. It is
// called on main thread.
virtual nsresult PhotoComplete(already_AddRefed<dom::DOMFile> aBlob) = 0;
virtual nsresult PhotoComplete(already_AddRefed<dom::File> aBlob) = 0;
// It is called on main thread. aRv is the error code.
virtual nsresult PhotoError(nsresult aRv) = 0;

View File

@ -5,7 +5,7 @@
#include "MediaEngineDefault.h"
#include "nsCOMPtr.h"
#include "nsDOMFile.h"
#include "mozilla/dom/File.h"
#include "nsILocalFile.h"
#include "Layers.h"
#include "ImageContainer.h"
@ -208,7 +208,7 @@ MediaEngineDefaultVideoSource::Snapshot(uint32_t aDuration, nsIDOMFile** aFile)
return NS_OK;
}
nsCOMPtr<nsIDOMFile> domFile = dom::DOMFile::CreateFromFile(localFile);
nsCOMPtr<nsIDOMFile> domFile = dom::File::CreateFromFile(nullptr, localFile);
domFile.forget(aFile);
return NS_OK;
#endif

View File

@ -2,14 +2,6 @@
* 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/. */
#ifdef MOZ_LOGGING
#define FORCE_PR_LOG
#endif
#if defined(PR_LOG)
#error "This file must be #included before any IPDL-generated files or other files that #include prlog.h"
#endif
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"

View File

@ -10,10 +10,10 @@
#include "nsIThread.h"
#include "nsIRunnable.h"
#include "mozilla/dom/File.h"
#include "mozilla/Mutex.h"
#include "mozilla/Monitor.h"
#include "nsCOMPtr.h"
#include "nsDOMFile.h"
#include "nsThreadUtils.h"
#include "DOMMediaStream.h"
#include "nsDirectoryServiceDefs.h"

View File

@ -943,11 +943,11 @@ MediaEngineWebRTCVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLe
NS_IMETHOD Run()
{
nsRefPtr<dom::DOMFile> blob =
dom::DOMFile::CreateMemoryFile(mPhoto.Elements(), mPhoto.Length(), mMimeType);
nsRefPtr<dom::File> blob =
dom::File::CreateMemoryFile(nullptr, mPhoto.Elements(), mPhoto.Length(), mMimeType);
uint32_t callbackCounts = mCallbacks.Length();
for (uint8_t i = 0; i < callbackCounts; i++) {
nsRefPtr<dom::DOMFile> tempBlob = blob;
nsRefPtr<dom::File> tempBlob = blob;
mCallbacks[i]->PhotoComplete(tempBlob.forget());
}
// PhotoCallback needs to dereference on main thread.

View File

@ -53,6 +53,7 @@ UNIFIED_SOURCES += [
'LoadInfo.cpp',
'nsAboutRedirector.cpp',
'nsDefaultURIFixup.cpp',
'nsDocShell.cpp',
'nsDocShellEditorData.cpp',
'nsDocShellEnumerator.cpp',
'nsDocShellLoadInfo.cpp',
@ -63,11 +64,6 @@ UNIFIED_SOURCES += [
'SerializedLoadContext.cpp',
]
# nsDocShell.cpp cannot be built in unified mode because it forces NSPR logging.
SOURCES += [
'nsDocShell.cpp',
]
FAIL_ON_WARNINGS = True
MSVC_ENABLE_PGO = True

View File

@ -26,11 +26,6 @@
#include "mozilla/VisualEventTracer.h"
#include "URIUtils.h"
#ifdef MOZ_LOGGING
// so we can get logging even in release builds (but only for some things)
#define FORCE_PR_LOG 1
#endif
#include "nsIContent.h"
#include "nsIContentInlines.h"
#include "nsIDocument.h"

View File

@ -130,7 +130,7 @@ ArchiveReaderEvent::ShareMainThread()
}
}
// This is a nsDOMFile:
// This is a File:
nsRefPtr<nsIDOMFile> file = item->File(mArchiveReader);
if (file) {
fileList.AppendElement(file);

View File

@ -9,9 +9,9 @@
#include "ArchiveReader.h"
#include "mozilla/dom/File.h"
#include "nsISeekableStream.h"
#include "nsIMIMEService.h"
#include "nsDOMFile.h"
#include "ArchiveReaderCommon.h"
@ -35,7 +35,7 @@ public:
// Getter for the filename
virtual nsresult GetFilename(nsString& aFilename) = 0;
// Generate a DOMFile
// Generate a File
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) = 0;
protected:

View File

@ -14,8 +14,9 @@
#include "mozilla/dom/ArchiveReaderBinding.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -23,12 +24,10 @@ USING_ARCHIVEREADER_NAMESPACE
/* static */ already_AddRefed<ArchiveReader>
ArchiveReader::Constructor(const GlobalObject& aGlobal,
nsIDOMBlob* aBlob,
File& aBlob,
const ArchiveReaderOptions& aOptions,
ErrorResult& aError)
{
MOZ_ASSERT(aBlob);
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aError.Throw(NS_ERROR_UNEXPECTED);
@ -47,14 +46,13 @@ ArchiveReader::Constructor(const GlobalObject& aGlobal,
return reader.forget();
}
ArchiveReader::ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow,
ArchiveReader::ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding)
: mBlob(aBlob)
: mBlob(&aBlob)
, mWindow(aWindow)
, mStatus(NOT_STARTED)
, mEncoding(aEncoding)
{
MOZ_ASSERT(aBlob);
MOZ_ASSERT(aWindow);
}

View File

@ -19,6 +19,7 @@
namespace mozilla {
namespace dom {
struct ArchiveReaderOptions;
class File;
class GlobalObject;
} // namespace dom
} // namespace mozilla
@ -38,10 +39,10 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)
static already_AddRefed<ArchiveReader>
Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob,
Constructor(const GlobalObject& aGlobal, File& aBlob,
const ArchiveReaderOptions& aOptions, ErrorResult& aError);
ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow,
ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding);
nsIDOMWindow* GetParentObject() const
@ -75,7 +76,7 @@ private:
protected:
// The archive blob/file
nsCOMPtr<nsIDOMBlob> mBlob;
nsRefPtr<File> mBlob;
// The window is needed by the requests
nsCOMPtr<nsPIDOMWindow> mWindow;

View File

@ -74,7 +74,7 @@ ArchiveZipItem::GetFilename(nsString& aFilename)
return NS_OK;
}
// From zipItem to DOMFile:
// From zipItem to File:
nsIDOMFile*
ArchiveZipItem::File(ArchiveReader* aArchiveReader)
{
@ -84,7 +84,7 @@ ArchiveZipItem::File(ArchiveReader* aArchiveReader)
return nullptr;
}
return new DOMFile(
return new dom::File(aArchiveReader,
new ArchiveZipFileImpl(filename,
NS_ConvertUTF8toUTF16(GetType()),
StrToInt32(mCentralStruct.orglen),

View File

@ -30,7 +30,7 @@ protected:
public:
nsresult GetFilename(nsString& aFilename) MOZ_OVERRIDE;
// From zipItem to DOMFile:
// From zipItem to File:
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) MOZ_OVERRIDE;
public: // for the event

View File

@ -10,7 +10,9 @@
#include "nsIInputStream.h"
#include "zlib.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
using namespace mozilla::dom;
USING_ARCHIVEREADER_NAMESPACE
#define ZIP_CHUNK 16384
@ -396,15 +398,16 @@ ArchiveZipFileImpl::Traverse(nsCycleCollectionTraversalCallback &cb)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mArchiveReader);
}
already_AddRefed<mozilla::dom::DOMFileImpl>
already_AddRefed<mozilla::dom::FileImpl>
ArchiveZipFileImpl::CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType)
const nsAString& aContentType,
mozilla::ErrorResult& aRv)
{
nsRefPtr<DOMFileImpl> impl =
nsRefPtr<FileImpl> impl =
new ArchiveZipFileImpl(mFilename, mContentType, aStart, mLength, mCentral,
mArchiveReader);
return impl.forget();
}
NS_IMPL_ISUPPORTS_INHERITED0(ArchiveZipFileImpl, DOMFileImpl)
NS_IMPL_ISUPPORTS_INHERITED0(ArchiveZipFileImpl, FileImpl)

View File

@ -8,7 +8,8 @@
#define mozilla_dom_archivereader_domarchivefile_h__
#include "mozilla/Attributes.h"
#include "nsDOMFile.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/File.h"
#include "ArchiveReader.h"
@ -18,9 +19,9 @@
BEGIN_ARCHIVEREADER_NAMESPACE
/**
* ArchiveZipFileImpl to DOMFileImpl
* ArchiveZipFileImpl to FileImpl
*/
class ArchiveZipFileImpl : public DOMFileImplBase
class ArchiveZipFileImpl : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
@ -30,7 +31,7 @@ public:
uint64_t aLength,
ZipCentral& aCentral,
ArchiveReader* aReader)
: DOMFileImplBase(aName, aContentType, aLength),
: FileImplBase(aName, aContentType, aLength),
mCentral(aCentral),
mArchiveReader(aReader),
mFilename(aName)
@ -45,7 +46,7 @@ public:
uint64_t aLength,
ZipCentral& aCentral,
ArchiveReader* aReader)
: DOMFileImplBase(aContentType, aStart, aLength),
: FileImplBase(aContentType, aStart, aLength),
mCentral(aCentral),
mArchiveReader(aReader),
mFilename(aName)
@ -71,9 +72,9 @@ protected:
MOZ_COUNT_DTOR(ArchiveZipFileImpl);
}
virtual already_AddRefed<DOMFileImpl> CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
private: // Data
ZipCentral mCentral;

View File

@ -88,8 +88,10 @@ public:
MOZ_ASSERT(NS_IsMainThread());
if (!mFailed) {
nsRefPtr<DOMFile> blob =
DOMFile::CreateMemoryFile(mImgData, mImgSize, mType);
// The correct parentObject has to be set by the mEncodeCompleteCallback.
nsRefPtr<File> blob =
File::CreateMemoryFile(nullptr, mImgData, mImgSize, mType);
MOZ_ASSERT(blob);
rv = mEncodeCompleteCallback->ReceiveBlob(blob.forget());
}

View File

@ -7,8 +7,8 @@
#define ImageEncoder_h
#include "imgIEncoder.h"
#include "nsDOMFile.h"
#include "nsError.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLCanvasElementBinding.h"
#include "nsLayoutUtils.h"
#include "nsNetUtil.h"
@ -51,6 +51,8 @@ public:
// successful dispatching of the extraction step to the encoding thread.
// aEncodeCallback will be called on main thread when encoding process is
// success.
// Note: The callback has to set a valid parent for content for the generated
// Blob object.
static nsresult ExtractDataAsync(nsAString& aType,
const nsAString& aOptions,
bool aUsingCustomOptions,
@ -62,6 +64,8 @@ public:
// Extract an Image asynchronously. Its function is same as ExtractDataAsync
// except for the parameters. aImage is the uncompressed data. aEncodeCallback
// will be called on main thread when encoding process is success.
// Note: The callback has to set a valid parent for content for the generated
// Blob object.
static nsresult ExtractDataFromLayersImageAsync(nsAString& aType,
const nsAString& aOptions,
bool aUsingCustomOptions,
@ -111,7 +115,7 @@ class EncodeCompleteCallback
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodeCompleteCallback)
virtual nsresult ReceiveBlob(already_AddRefed<DOMFile> aBlob) = 0;
virtual nsresult ReceiveBlob(already_AddRefed<File> aBlob) = 0;
protected:
virtual ~EncodeCompleteCallback() {}

View File

@ -5,7 +5,9 @@
#include "MessagePort.h"
#include "MessageEvent.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MessageChannel.h"
#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/MessagePortList.h"
@ -16,7 +18,6 @@
#include "ScriptSettings.h"
#include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIPresShell.h"
@ -103,7 +104,37 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data,
void* closure)
{
if (tag == SCTAG_DOM_BLOB || tag == SCTAG_DOM_FILELIST) {
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
if (tag == SCTAG_DOM_BLOB) {
NS_ASSERTION(!data, "Data should be empty");
// What we get back from the reader is a FileImpl.
// From that we create a new File.
FileImpl* blobImpl;
if (JS_ReadBytes(reader, &blobImpl, sizeof(blobImpl))) {
MOZ_ASSERT(blobImpl);
// nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
JS::Rooted<JS::Value> val(cx);
{
nsRefPtr<File> blob = new File(scInfo->mPort->GetParentObject(),
blobImpl);
if (!WrapNewBindingObject(cx, blob, &val)) {
return nullptr;
}
}
return &val.toObject();
}
}
if (tag == SCTAG_DOM_FILELIST) {
NS_ASSERTION(!data, "Data should be empty");
nsISupports* supports;
@ -134,6 +165,19 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
// See if this is a File/Blob object.
{
File* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&
JS_WriteBytes(writer, &blobImpl, sizeof(blobImpl))) {
scInfo->mEvent->StoreISupports(blobImpl);
return true;
}
}
}
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -141,11 +185,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native();
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(supports);
if (blob) {
scTag = SCTAG_DOM_BLOB;
}
nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list) {
scTag = SCTAG_DOM_FILELIST;

View File

@ -13,6 +13,7 @@
#include "nsMimeTypeArray.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/DesktopNotification.h"
#include "mozilla/dom/File.h"
#include "nsGeolocation.h"
#include "nsIHttpProtocolHandler.h"
#include "nsIContentPolicy.h"
@ -371,6 +372,8 @@ Navigator::GetAcceptLanguages(nsTArray<nsString>& aLanguages)
{
MOZ_ASSERT(NS_IsMainThread());
aLanguages.Clear();
// E.g. "de-de, en-us,en".
const nsAdoptingString& acceptLang =
Preferences::GetLocalizedString("intl.accept_languages");
@ -1155,14 +1158,14 @@ Navigator::SendBeacon(const nsAString& aUrl,
in = strStream;
} else if (aData.Value().IsBlob()) {
nsCOMPtr<nsIDOMBlob> blob = aData.Value().GetAsBlob();
rv = blob->GetInternalStream(getter_AddRefs(in));
File& blob = aData.Value().GetAsBlob();
rv = blob.GetInternalStream(getter_AddRefs(in));
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
nsAutoString type;
rv = blob->GetType(type);
rv = blob.GetType(type);
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);
return false;

View File

@ -25,7 +25,6 @@ class nsPIDOMWindow;
class nsIDOMNavigatorSystemMessages;
class nsDOMCameraManager;
class nsDOMDeviceStorage;
class nsIDOMBlob;
class nsIPrincipal;
class nsIURI;

View File

@ -6,8 +6,8 @@
#include "URL.h"
#include "nsGlobalWindow.h"
#include "nsDOMFile.h"
#include "DOMMediaStream.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaSource.h"
#include "mozilla/dom/URLBinding.h"
#include "nsHostObjectProtocolHandler.h"
@ -111,15 +111,12 @@ URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
void
URL::CreateObjectURL(const GlobalObject& aGlobal,
nsIDOMBlob* aBlob,
File& aBlob,
const objectURLOptions& aOptions,
nsString& aResult,
ErrorResult& aError)
{
DOMFile* blob = static_cast<DOMFile*>(aBlob);
MOZ_ASSERT(blob);
CreateObjectURLInternal(aGlobal, blob->Impl(),
CreateObjectURLInternal(aGlobal, aBlob.Impl(),
NS_LITERAL_CSTRING(BLOBURI_SCHEME), aOptions, aResult,
aError);
}

View File

@ -23,6 +23,7 @@ class DOMMediaStream;
namespace dom {
class File;
class MediaSource;
class GlobalObject;
struct objectURLOptions;
@ -53,7 +54,7 @@ public:
const nsAString& aBase, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal,
nsIDOMBlob* aBlob,
File& aBlob,
const objectURLOptions& aOptions,
nsString& aResult,
ErrorResult& aError);

View File

@ -235,7 +235,7 @@ EnumerateWindowNamedProperties(JSContext* aCx, JS::Handle<JSObject*> aWrapper,
JS::AutoIdVector& aProps)
{
JSAutoCompartment ac(aCx, aObj);
return js::GetProxyHandler(aObj)->getOwnPropertyNames(aCx, aObj, aProps);
return js::GetProxyHandler(aObj)->ownPropertyKeys(aCx, aObj, aProps);
}
const NativePropertyHooks sWindowNamedPropertiesNativePropertyHooks[] = { {

View File

@ -94,6 +94,7 @@ UNIFIED_SOURCES += [
'nsGlobalWindowCommands.cpp',
'nsHistory.cpp',
'nsIGlobalObject.cpp',
'nsJSEnvironment.cpp',
'nsJSTimeoutHandler.cpp',
'nsJSUtils.cpp',
'nsLocation.cpp',
@ -123,8 +124,6 @@ SOURCES += [
'nsDOMWindowUtils.cpp',
# This file has a #error "Never include windows.h in this file!"
'nsGlobalWindow.cpp',
# This file forces NSPR logging.
'nsJSEnvironment.cpp',
# nsPluginArray.cpp includes npapi.h indirectly, and that includes a lot of system headers
'nsPluginArray.cpp',
]

View File

@ -35,7 +35,6 @@
#include "nsIXPConnect.h"
#include "xptcall.h"
#include "nsTArray.h"
#include "nsDOMBlobBuilder.h"
// General helper includes
#include "nsGlobalWindow.h"
@ -101,10 +100,6 @@
#endif
#include "nsIDOMXPathNSResolver.h"
// Drag and drop
#include "nsIDOMFile.h"
#include "nsDOMBlobBuilder.h" // nsDOMMultipartFile
#include "nsIEventListenerService.h"
#include "nsIMessageManager.h"
@ -294,11 +289,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(XPathNSResolver, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Blob, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(File, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -372,8 +362,6 @@ struct nsConstructorFuncMapData
static const nsConstructorFuncMapData kConstructorFuncMap[] =
{
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(Blob, DOMMultipartFileImpl::NewBlob)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, DOMMultipartFileImpl::NewFile)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
};
#undef NS_DEFINE_CONSTRUCTOR_FUNC_DATA
@ -795,15 +783,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathNSResolver)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Blob, nsIDOMBlob)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(File, nsIDOMFile)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMFile)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozSmsMessage, nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_END

View File

@ -43,9 +43,6 @@ DOMCI_CLASS(XSLTProcessor)
// DOM Level 3 XPath objects
DOMCI_CLASS(XPathNSResolver)
DOMCI_CLASS(Blob)
DOMCI_CLASS(File)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozMmsMessage)
DOMCI_CLASS(MozMobileMessageThread)

View File

@ -48,11 +48,11 @@
#include "nsComputedDOMStyle.h"
#include "nsIPresShell.h"
#include "nsCSSProps.h"
#include "nsDOMFile.h"
#include "nsTArrayHelpers.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/DOMRect.h"
#include <algorithm>
@ -74,7 +74,6 @@
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "nsDOMBlobBuilder.h"
#include "nsPrintfCString.h"
#include "nsViewportInfo.h"
#include "nsIFormControl.h"
@ -2853,7 +2852,15 @@ nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
return NS_ERROR_FAILURE;
}
nsRefPtr<DOMFile> file = DOMFile::CreateFromFile(aFile);
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsPIDOMWindow* innerWindow = window->GetCurrentInnerWindow();
if (!innerWindow) {
return NS_ERROR_FAILURE;
}
nsRefPtr<File> file = File::CreateFromFile(innerWindow, aFile);
file.forget(aDOMFile);
return NS_OK;
}

View File

@ -122,7 +122,6 @@
#include "nsAutoPtr.h"
#include "nsContentUtils.h"
#include "nsCSSProps.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIURIFixup.h"
#ifndef DEBUG
@ -175,10 +174,6 @@
#include "nsISupportsPrimitives.h"
#include "nsXPCOMCID.h"
#include "mozIThirdPartyUtil.h"
#ifdef MOZ_LOGGING
// so we can get logging even in release builds
#define FORCE_PR_LOG 1
#endif
#include "prlog.h"
#include "prenv.h"
#include "prprf.h"
@ -629,7 +624,7 @@ public:
JS::Handle<jsid> id,
JS::MutableHandle<JSPropertyDescriptor> desc)
const MOZ_OVERRIDE;
virtual bool getOwnPropertyNames(JSContext *cx,
virtual bool ownPropertyKeys(JSContext *cx,
JS::Handle<JSObject*> proxy,
JS::AutoIdVector &props) const MOZ_OVERRIDE;
virtual bool delete_(JSContext *cx, JS::Handle<JSObject*> proxy,
@ -815,7 +810,7 @@ nsOuterWindowProxy::defineProperty(JSContext* cx,
}
bool
nsOuterWindowProxy::getOwnPropertyNames(JSContext *cx,
nsOuterWindowProxy::ownPropertyKeys(JSContext *cx,
JS::Handle<JSObject*> proxy,
JS::AutoIdVector &props) const
{
@ -825,7 +820,7 @@ nsOuterWindowProxy::getOwnPropertyNames(JSContext *cx,
}
JS::AutoIdVector innerProps(cx);
if (!js::Wrapper::getOwnPropertyNames(cx, proxy, innerProps)) {
if (!js::Wrapper::ownPropertyKeys(cx, proxy, innerProps)) {
return false;
}
return js::AppendUnique(cx, props, innerProps);
@ -940,7 +935,7 @@ nsOuterWindowProxy::keys(JSContext *cx, JS::Handle<JSObject*> proxy,
JS::AutoIdVector &props) const
{
// BaseProxyHandler::keys seems to do what we want here: call
// getOwnPropertyNames and then filter out the non-enumerable properties.
// ownPropertyKeys and then filter out the non-enumerable properties.
return js::BaseProxyHandler::keys(cx, proxy, props);
}
@ -7878,19 +7873,33 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data,
void* closure)
{
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
if (tag == SCTAG_DOM_BLOB) {
NS_ASSERTION(!data, "Data should be empty");
// What we get back from the reader is a DOMFileImpl.
// From that we create a new DOMFile.
nsISupports* supports;
if (JS_ReadBytes(reader, &supports, sizeof(supports))) {
nsCOMPtr<nsIDOMBlob> file = new DOMFile(static_cast<DOMFileImpl*>(supports));
// What we get back from the reader is a FileImpl.
// From that we create a new File.
FileImpl* blobImpl;
if (JS_ReadBytes(reader, &blobImpl, sizeof(blobImpl))) {
MOZ_ASSERT(blobImpl);
// nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
JS::Rooted<JS::Value> val(cx);
if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, file, &val))) {
return val.toObjectOrNull();
{
nsRefPtr<File> blob = new File(scInfo->window, blobImpl);
if (!WrapNewBindingObject(cx, blob, &val)) {
return nullptr;
}
}
return &val.toObject();
}
}
if (tag == SCTAG_DOM_FILELIST) {
@ -7924,6 +7933,19 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
// See if this is a File/Blob object.
{
File* blob = nullptr;
if (scInfo->subsumes && NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&
JS_WriteBytes(writer, &blobImpl, sizeof(blobImpl))) {
scInfo->event->StoreISupports(blobImpl);
return true;
}
}
}
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -7931,13 +7953,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native();
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(supports);
if (blob && scInfo->subsumes) {
scTag = SCTAG_DOM_BLOB;
DOMFile* file = static_cast<DOMFile*>(blob.get());
supports = file->Impl();
}
nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list && scInfo->subsumes)
scTag = SCTAG_DOM_FILELIST;

View File

@ -73,10 +73,6 @@
#endif
#include "AccessCheck.h"
#ifdef MOZ_LOGGING
// Force PR_LOGGING so we can get JS strict warnings even in release builds
#define FORCE_PR_LOG 1
#endif
#include "prlog.h"
#include "prthread.h"

View File

@ -1,7 +1,7 @@
this.EXPORTED_SYMBOLS = ['checkFromJSM'];
this.checkFromJSM = function checkFromJSM(ok, is) {
Components.utils.importGlobalProperties(['URL']);
Components.utils.importGlobalProperties(['URL', 'Blob']);
var url = new URL('http://www.example.com');
is(url.href, "http://www.example.com/", "JSM should have URL");

View File

@ -50,7 +50,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
a.port1.onmessage = function(evt) {
ok(tests.length, "We are waiting for a message");
if (typeof(tests[0]) == 'object') {
is(typeof(tests[0]), typeof(evt.data), "Value ok: " + tests[0]);
} else {
is(tests[0], evt.data, "Value ok: " + tests[0]);
}
tests.shift();
runTest();
}

View File

@ -1395,7 +1395,7 @@ XrayDefineProperty(JSContext* cx, JS::Handle<JSObject*> wrapper,
template<typename SpecType>
bool
XrayEnumerateAttributesOrMethods(JSContext* cx, JS::Handle<JSObject*> wrapper,
XrayAttributeOrMethodKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
JS::Handle<JSObject*> obj,
const Prefable<const SpecType>* list,
jsid* ids, const SpecType* specList,
@ -1418,9 +1418,9 @@ XrayEnumerateAttributesOrMethods(JSContext* cx, JS::Handle<JSObject*> wrapper,
return true;
}
#define ENUMERATE_IF_DEFINED(fieldName) { \
#define ADD_KEYS_IF_DEFINED(fieldName) { \
if (nativeProperties->fieldName##s && \
!XrayEnumerateAttributesOrMethods(cx, wrapper, obj, \
!XrayAttributeOrMethodKeys(cx, wrapper, obj, \
nativeProperties->fieldName##s, \
nativeProperties->fieldName##Ids, \
nativeProperties->fieldName##Specs, \
@ -1431,7 +1431,7 @@ XrayEnumerateAttributesOrMethods(JSContext* cx, JS::Handle<JSObject*> wrapper,
bool
XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
XrayOwnPropertyKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
JS::Handle<JSObject*> obj,
unsigned flags, JS::AutoIdVector& props,
DOMObjectType type,
@ -1440,19 +1440,19 @@ XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
MOZ_ASSERT(type != eNamedPropertiesObject);
if (IsInstance(type)) {
ENUMERATE_IF_DEFINED(unforgeableMethod);
ENUMERATE_IF_DEFINED(unforgeableAttribute);
ADD_KEYS_IF_DEFINED(unforgeableMethod);
ADD_KEYS_IF_DEFINED(unforgeableAttribute);
if (type == eGlobalInstance && GlobalPropertiesAreOwn()) {
ENUMERATE_IF_DEFINED(method);
ENUMERATE_IF_DEFINED(attribute);
ADD_KEYS_IF_DEFINED(method);
ADD_KEYS_IF_DEFINED(attribute);
}
} else if (type == eInterface) {
ENUMERATE_IF_DEFINED(staticMethod);
ENUMERATE_IF_DEFINED(staticAttribute);
ADD_KEYS_IF_DEFINED(staticMethod);
ADD_KEYS_IF_DEFINED(staticAttribute);
} else if (type != eGlobalInterfacePrototype || !GlobalPropertiesAreOwn()) {
MOZ_ASSERT(IsInterfacePrototype(type));
ENUMERATE_IF_DEFINED(method);
ENUMERATE_IF_DEFINED(attribute);
ADD_KEYS_IF_DEFINED(method);
ADD_KEYS_IF_DEFINED(attribute);
}
if (nativeProperties->constants) {
@ -1474,14 +1474,13 @@ XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
return true;
}
#undef ENUMERATE_IF_DEFINED
#undef ADD_KEYS_IF_DEFINED
bool
XrayEnumerateNativeProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
XrayOwnNativePropertyKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
const NativePropertyHooks* nativePropertyHooks,
DOMObjectType type,
JS::Handle<JSObject*> obj, unsigned flags,
JS::AutoIdVector& props)
DOMObjectType type, JS::Handle<JSObject*> obj,
unsigned flags, JS::AutoIdVector& props)
{
MOZ_ASSERT(type != eNamedPropertiesObject);
@ -1502,14 +1501,14 @@ XrayEnumerateNativeProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
nativePropertyHooks->mNativeProperties;
if (nativeProperties.regular &&
!XrayEnumerateProperties(cx, wrapper, obj, flags, props, type,
!XrayOwnPropertyKeys(cx, wrapper, obj, flags, props, type,
nativeProperties.regular)) {
return false;
}
if (nativeProperties.chromeOnly &&
xpc::AccessCheck::isChrome(js::GetObjectCompartment(wrapper)) &&
!XrayEnumerateProperties(cx, wrapper, obj, flags, props, type,
!XrayOwnPropertyKeys(cx, wrapper, obj, flags, props, type,
nativeProperties.chromeOnly)) {
return false;
}
@ -1518,7 +1517,7 @@ XrayEnumerateNativeProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
}
bool
XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
XrayOwnPropertyKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
JS::Handle<JSObject*> obj,
unsigned flags, JS::AutoIdVector& props)
{
@ -1542,7 +1541,7 @@ XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
}
return (type == eGlobalInterfacePrototype && GlobalPropertiesAreOwn()) ||
XrayEnumerateNativeProperties(cx, wrapper, nativePropertyHooks, type,
XrayOwnNativePropertyKeys(cx, wrapper, nativePropertyHooks, type,
obj, flags, props);
}

View File

@ -2344,8 +2344,8 @@ XrayDefineProperty(JSContext* cx, JS::Handle<JSObject*> wrapper,
JS::MutableHandle<JSPropertyDescriptor> desc, bool* defined);
/**
* This enumerates indexed or named properties of obj and operations, attributes
* and constants of the interfaces for obj.
* Add to props the property keys of all indexed or named properties of obj and
* operations, attributes and constants of the interfaces for obj.
*
* wrapper is the Xray JS object.
* obj is the target object of the Xray, a binding's instance object or a
@ -2353,7 +2353,7 @@ XrayDefineProperty(JSContext* cx, JS::Handle<JSObject*> wrapper,
* flags are JSITER_* flags.
*/
bool
XrayEnumerateProperties(JSContext* cx, JS::Handle<JSObject*> wrapper,
XrayOwnPropertyKeys(JSContext* cx, JS::Handle<JSObject*> wrapper,
JS::Handle<JSObject*> obj,
unsigned flags, JS::AutoIdVector& props);

View File

@ -136,13 +136,10 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/BarProps.h',
},
'Blob': [
{
'headerFile': 'nsIDOMFile.h',
'Blob': {
'nativeType': 'mozilla::dom::File',
'headerFile': 'mozilla/dom/File.h',
},
{
'workers': True,
}],
'BatteryManager': {
'nativeType': 'mozilla::dom::battery::BatteryManager',
@ -404,8 +401,7 @@ DOMInterfaces = {
},
'FileList': {
'nativeType': 'nsDOMFileList',
'headerFile': 'nsDOMFile.h',
'headerFile': 'mozilla/dom/File.h',
},
'FileReader': {
@ -1798,7 +1794,6 @@ addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList')
addExternalIface('Counter')
addExternalIface('CSSRule')
addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel')
addExternalIface('File')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
@ -1827,6 +1822,7 @@ addExternalIface('nsIDOMCrypto', nativeType='nsIDOMCrypto',
headerFile='Crypto.h')
addExternalIface('nsIInputStreamCallback', nativeType='nsIInputStreamCallback',
headerFile='nsIAsyncInputStream.h')
addExternalIface('nsIFile', nativeType='nsIFile', notflattened=True)
addExternalIface('nsIMessageBroadcaster', nativeType='nsIMessageBroadcaster',
headerFile='nsIMessageManager.h', notflattened=True)
addExternalIface('nsISelectionListener', nativeType='nsISelectionListener')

View File

@ -9652,7 +9652,7 @@ class CGEnumerateOwnProperties(CGAbstractStaticMethod):
"EnumerateOwnProperties", "bool", args)
def definition_body(self):
return "return js::GetProxyHandler(obj)->getOwnPropertyNames(cx, wrapper, props);\n"
return "return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);\n"
class CGEnumerateOwnPropertiesViaGetOwnPropertyNames(CGAbstractBindingMethod):
@ -10410,7 +10410,7 @@ class CGDOMJSProxyHandler_ownPropNames(ClassMethod):
if UseHolderForUnforgeable(self.descriptor):
addUnforgeable = dedent("""
if (!js::GetPropertyNames(cx, ${holder}, flags, &props)) {
if (!js::GetPropertyKeys(cx, ${holder}, flags, &props)) {
return false;
}
""")
@ -10447,7 +10447,7 @@ class CGDOMJSProxyHandler_ownPropNames(ClassMethod):
JS::Rooted<JSObject*> expando(cx);
if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
!js::GetPropertyNames(cx, expando, flags, &props)) {
!js::GetPropertyKeys(cx, expando, flags, &props)) {
return false;
}
@ -10761,7 +10761,7 @@ class CGDOMJSProxyHandler_slice(ClassMethod):
self.descriptor = descriptor
def getBody(self):
# Just like getOwnPropertyNames we'll assume that we have no holes, so
# Just like ownPropertyKeys we'll assume that we have no holes, so
# we have all properties from 0 to length. If that ever changes
# (unlikely), we'll need to do something a bit more clever with how we
# forward on to our ancestor.

View File

@ -278,7 +278,7 @@ BaseDOMProxyHandler::enumerate(JSContext* cx, JS::Handle<JSObject*> proxy,
return false;
}
return keys(cx, proxy, props) &&
(!proto || js::GetPropertyNames(cx, proto, 0, &props));
(!proto || js::GetPropertyKeys(cx, proto, 0, &props));
}
bool
@ -295,7 +295,7 @@ BaseDOMProxyHandler::unwatch(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Han
}
bool
BaseDOMProxyHandler::getOwnPropertyNames(JSContext* cx,
BaseDOMProxyHandler::ownPropertyKeys(JSContext* cx,
JS::Handle<JSObject*> proxy,
JS::AutoIdVector& props) const
{

View File

@ -65,7 +65,7 @@ public:
JS::Handle<JSObject*> callable) const MOZ_OVERRIDE;
bool unwatch(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::Handle<jsid> id) const MOZ_OVERRIDE;
virtual bool getOwnPropertyNames(JSContext* cx, JS::Handle<JSObject*> proxy,
virtual bool ownPropertyKeys(JSContext* cx, JS::Handle<JSObject*> proxy,
JS::AutoIdVector &props) const MOZ_OVERRIDE;
// We override keys() and implement it directly instead of using the
// default implementation, which would getOwnPropertyNames and then
@ -75,9 +75,9 @@ public:
JS::AutoIdVector &props) const MOZ_OVERRIDE;
protected:
// Hook for subclasses to implement shared getOwnPropertyNames()/keys()
// Hook for subclasses to implement shared ownPropertyKeys()/keys()
// functionality. The "flags" argument is either JSITER_OWNONLY (for keys())
// or JSITER_OWNONLY | JSITER_HIDDEN (for getOwnPropertyNames()).
// or JSITER_OWNONLY | JSITER_HIDDEN (for ownPropertyKeys()).
virtual bool ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy,
unsigned flags,
JS::AutoIdVector& props) const = 0;

View File

@ -16,6 +16,7 @@
#include "mozilla/dom/BluetoothDiscoveryStateChangedEvent.h"
#include "mozilla/dom/BluetoothStatusChangedEvent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/LazyIdleThread.h"
@ -770,7 +771,7 @@ BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv)
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, ErrorResult& aRv)
File& aBlob, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
@ -790,7 +791,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
if (XRE_GetProcessType() == GeckoProcessType_Default) {
// In-process transfer
bs->SendFile(aDeviceAddress, aBlob, results);
bs->SendFile(aDeviceAddress, &aBlob, results);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
@ -798,7 +799,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
return nullptr;
}
BlobChild* actor = cc->GetOrCreateActorForBlob(aBlob);
BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
if (!actor) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;

View File

@ -15,6 +15,7 @@
namespace mozilla {
namespace dom {
class File;
class DOMRequest;
struct MediaMetaData;
struct MediaPlayStatus;
@ -133,7 +134,7 @@ public:
GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv);
already_AddRefed<DOMRequest>
SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob,
SendFile(const nsAString& aDeviceAddress, File& aBlob,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv);

View File

@ -15,6 +15,7 @@
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/dom/File.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
@ -22,7 +23,6 @@
#include "nsCExternalHandlerService.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMFile.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsIMIMEService.h"
@ -35,6 +35,7 @@
USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::ipc;
namespace {
@ -349,7 +350,8 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
return SendFile(aDeviceAddress, blob.get());
}

View File

@ -14,6 +14,7 @@
#include "ObexBase.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
@ -22,7 +23,6 @@
#include "nsCExternalHandlerService.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMFile.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsIMIMEService.h"
@ -35,6 +35,7 @@
USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::ipc;
using mozilla::TimeDuration;
using mozilla::TimeStamp;
@ -371,7 +372,8 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
return SendFile(aDeviceAddress, blob.get());
}

View File

@ -580,7 +580,8 @@ BrowserElementParent.prototype = {
}
else {
debug("Got error in gotDOMRequestResult.");
Services.DOMRequest.fireErrorAsync(req, data.json.errorMsg);
Services.DOMRequest.fireErrorAsync(req,
Cu.cloneInto(data.json.errorMsg, this._window));
}
},

View File

@ -10,6 +10,7 @@
#include "nsThread.h"
#include "DeviceStorage.h"
#include "DeviceStorageFileDescriptor.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/MediaManager.h"
@ -20,7 +21,6 @@
#include "nsIDOMDeviceStorage.h"
#include "nsIDOMEventListener.h"
#include "nsIScriptSecurityManager.h"
#include "nsDOMFile.h"
#include "Navigator.h"
#include "nsXULAppAPI.h"
#include "DOMCameraManager.h"
@ -1437,7 +1437,7 @@ void
nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPicture != nullptr);
MOZ_ASSERT(aPicture);
nsRefPtr<Promise> promise = mTakePicturePromise.forget();
if (promise) {
@ -1445,15 +1445,17 @@ nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
promise->MaybeResolve(picture);
}
nsRefPtr<File> blob = static_cast<File*>(aPicture);
nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
mTakePictureOnErrorCb = nullptr;
if (cb) {
ErrorResult ignored;
cb->Call(aPicture, ignored);
cb->Call(*blob, ignored);
}
BlobEventInit eventInit;
eventInit.mData = aPicture;
eventInit.mData = blob;
nsRefPtr<BlobEvent> event = BlobEvent::Constructor(this,
NS_LITERAL_STRING("picture"),

Some files were not shown because too many files have changed in this diff Show More