Bug 1163388 - patch 1 - make nsIDOMFile an empty interface, r=ehsan

This commit is contained in:
Andrea Marchesini 2015-05-18 14:51:54 +01:00
parent 737bb25dd5
commit 338c67e420
21 changed files with 108 additions and 133 deletions

View File

@ -177,7 +177,6 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,
nsTArray<nsRefPtr<File>>& aFileList)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length()));
nsresult rv;
if (!array) {
return NS_ERROR_OUT_OF_MEMORY;
@ -188,14 +187,12 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,
nsRefPtr<File> file = aFileList[i];
nsString filename;
rv = file->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);
file->GetName(filename);
str = JS_NewUCStringCopyZ(aCx, filename.get());
NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY);
if (NS_FAILED(rv) ||
!JS_DefineElement(aCx, array, i, str, JSPROP_ENUMERATE)) {
if (!JS_DefineElement(aCx, array, i, str, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
}
@ -217,8 +214,7 @@ ArchiveRequest::GetFileResult(JSContext* aCx,
nsRefPtr<File> file = aFileList[i];
nsString filename;
nsresult rv = file->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);
file->GetName(filename);
if (filename == mFilename) {
if (!ToJSValue(aCx, file, aValue)) {

View File

@ -553,17 +553,16 @@ File::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return FileBinding::Wrap(aCx, this, aGivenProto);
}
NS_IMETHODIMP
void
File::GetName(nsAString& aFileName)
{
mImpl->GetName(aFileName);
return NS_OK;
}
NS_IMETHODIMP
File::GetPath(nsAString& aPath)
void
File::GetPath(nsAString& aPath, ErrorResult& aRv)
{
return mImpl->GetPath(aPath);
mImpl->GetPath(aPath, aRv);
}
Date
@ -583,53 +582,16 @@ File::GetLastModified(ErrorResult& aRv)
return mImpl->GetLastModified(aRv);
}
NS_IMETHODIMP
File::GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate)
{
ErrorResult rv;
Date value = GetLastModifiedDate(rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
if (!value.ToDateObject(aCx, aDate)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
File::GetMozFullPath(nsAString& aFileName)
{
ErrorResult rv;
GetMozFullPath(aFileName, rv);
return rv.StealNSResult();
}
void
File::GetMozFullPath(nsAString& aFilename, ErrorResult& aRv)
{
mImpl->GetMozFullPath(aFilename, aRv);
}
NS_IMETHODIMP
File::GetMozFullPathInternal(nsAString& aFileName)
void
File::GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv)
{
ErrorResult rv;
mImpl->GetMozFullPathInternal(aFileName, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP
File::GetMozLastModifiedDate(int64_t* aDate)
{
MOZ_ASSERT(aDate);
ErrorResult rv;
*aDate = GetLastModified(rv);
return rv.StealNSResult();
mImpl->GetMozFullPathInternal(aFileName, aRv);
}
// Makes sure that aStart and aEnd is less then or equal to aSize and greater
@ -817,12 +779,11 @@ BlobImplBase::GetName(nsAString& aName)
aName = mName;
}
nsresult
BlobImplBase::GetPath(nsAString& aPath)
void
BlobImplBase::GetPath(nsAString& aPath, ErrorResult& aRv)
{
NS_ASSERTION(mIsFile, "Should only be called on files");
aPath = mPath;
return NS_OK;
}
void

View File

@ -245,15 +245,18 @@ public:
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
// XPCOM GetName is OK
void GetName(nsAString& aName);
int64_t GetLastModified(ErrorResult& aRv);
Date GetLastModifiedDate(ErrorResult& aRv);
void GetPath(nsAString& aName, ErrorResult& aRv);
void GetMozFullPath(nsAString& aFilename, ErrorResult& aRv);
void GetMozFullPathInternal(nsAString& aName, ErrorResult& aRv);
protected:
virtual bool HasFileInterface() const override { return true; }
@ -276,7 +279,7 @@ public:
virtual void GetName(nsAString& aName) = 0;
virtual nsresult GetPath(nsAString& aName) = 0;
virtual void GetPath(nsAString& aName, ErrorResult& aRv) = 0;
virtual int64_t GetLastModified(ErrorResult& aRv) = 0;
@ -404,7 +407,7 @@ public:
virtual void GetName(nsAString& aName) override;
virtual nsresult GetPath(nsAString& aName) override;
virtual void GetPath(nsAString& aName, ErrorResult& aRv) override;
virtual int64_t GetLastModified(ErrorResult& aRv) override;

View File

@ -366,8 +366,7 @@ MultipartBlobImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
}
// Pre-cache modified date.
int64_t unusedDate;
aRv = blob->GetMozLastModifiedDate(&unusedDate);
blob->GetLastModified(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -58,6 +58,7 @@
#include "nsIContentViewer.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileBinding.h"
#include "mozilla/dom/DOMRect.h"
#include <algorithm>
@ -2858,15 +2859,13 @@ nsDOMWindowUtils::GetFilePath(JS::HandleValue aFile, JSContext* aCx,
JSObject* obj = aFile.toObjectOrNull();
nsISupports* nativeObj =
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(nativeObj);
if (file) {
File* file = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(File, obj, file))) {
nsString filePath;
nsresult rv = file->GetMozFullPathInternal(filePath);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
ErrorResult rv;
file->GetMozFullPathInternal(filePath, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
_retval = filePath;

View File

@ -58,20 +58,9 @@ interface nsIDOMBlob : nsISupports
// nsIDOMBlob to Blob safely. Our chain is:
// - Blob -> nsIDOMBlob
// - File -> nsIDOMFile and Blob
[scriptable, builtinclass, uuid(cc28cf12-f1d4-44ff-843f-9289aa14613b)]
[scriptable, builtinclass, uuid(26e292a6-f5aa-4560-b523-ae22a4c7dfca)]
interface nsIDOMFile : nsISupports
{
readonly attribute DOMString name;
readonly attribute DOMString path;
[implicit_jscontext]
readonly attribute jsval lastModifiedDate;
readonly attribute DOMString mozFullPath;
// This performs no security checks!
[noscript] readonly attribute DOMString mozFullPathInternal;
[noscript] readonly attribute int64_t mozLastModifiedDate;
// Empty interface used by addons and some test to check if the object is a
// blob or file. This interface will be removed by bug 1163388
};

View File

@ -794,7 +794,7 @@ BluetoothOppManager::RetrieveSentFileName()
{
mFileName.Truncate();
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(mBlob);
nsRefPtr<File> file = static_cast<Blob*>(mBlob.get()).ToFile();
if (file) {
file->GetName(mFileName);
}

View File

@ -11,15 +11,13 @@
#include "BluetoothProfileManagerBase.h"
#include "nsAutoPtr.h"
#include "nsClassHashtable.h"
#include "nsIDOMFile.h"
#include "nsIObserver.h"
#include "nsTObserverArray.h"
#include "nsThreadUtils.h"
class nsIDOMBlob;
namespace mozilla {
namespace dom {
class Blob;
class BlobChild;
class BlobParent;
}
@ -241,7 +239,7 @@ public:
virtual void
SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void

View File

@ -266,7 +266,7 @@ BluetoothServiceChildProcess::SendFile(
void
BluetoothServiceChildProcess::SendFile(
const nsAString& aDeviceAddress,
nsIDOMBlob* aBlobChild,
Blob* aBlobChild,
BluetoothReplyRunnable* aRunnable)
{
// Parent-process-only method

View File

@ -111,7 +111,7 @@ public:
virtual void
SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) override;
virtual void

View File

@ -4161,7 +4161,7 @@ BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
void
BluetoothDBusService::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());

View File

@ -174,7 +174,7 @@ public:
virtual void
SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) override;
virtual void

View File

@ -73,16 +73,17 @@ namespace {
static bool sInShutdown = false;
}
class mozilla::dom::bluetooth::SendFileBatch {
class mozilla::dom::bluetooth::SendFileBatch
{
public:
SendFileBatch(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob)
SendFileBatch(const nsAString& aDeviceAddress, Blob* aBlob)
: mDeviceAddress(aDeviceAddress)
{
mBlobs.AppendElement(aBlob);
}
nsString mDeviceAddress;
nsCOMArray<nsIDOMBlob> mBlobs;
nsTArray<nsRefPtr<Blob>> mBlobs;
};
NS_IMETHODIMP
@ -385,14 +386,14 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<BlobImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = Blob::Create(nullptr, impl);
nsRefPtr<Blob> blob = Blob::Create(nullptr, impl);
return SendFile(aDeviceAddress, blob.get());
return SendFile(aDeviceAddress, blob);
}
bool
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob)
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -406,7 +407,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
void
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob)
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -766,7 +767,7 @@ BluetoothOppManager::RetrieveSentFileName()
{
mFileName.Truncate();
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(mBlob);
nsRefPtr<File> file = mBlob->ToFile();
if (file) {
file->GetName(mFileName);
}

View File

@ -14,13 +14,13 @@
#include "mozilla/ipc/SocketBase.h"
#include "nsCOMArray.h"
class nsIDOMBlob;
class nsIOutputStream;
class nsIInputStream;
class nsIVolumeMountLock;
namespace mozilla {
namespace dom {
class Blob;
class BlobParent;
}
}
@ -51,7 +51,7 @@ public:
bool Listen();
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
bool SendFile(const nsAString& aDeviceAddress, Blob* aBlob);
bool StopSendingFile();
bool ConfirmReceivingFile(bool aConfirm);
@ -96,7 +96,7 @@ private:
void NotifyAboutFileChange();
bool AcquireSdcardMountLock();
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob);
void AppendBlobToSend(const nsAString& aDeviceAddress, Blob* aBlob);
void DiscardBlobsToSend();
bool ProcessNextBatch();
void ConnectInternal(const nsAString& aDeviceAddress);
@ -193,7 +193,7 @@ private:
nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
int mCurrentBlobIndex;
nsCOMPtr<nsIDOMBlob> mBlob;
nsRefPtr<Blob> mBlob;
nsTArray<SendFileBatch> mBatches;
/**

View File

@ -493,18 +493,23 @@ NS_IMPL_ISUPPORTS(DirPickerRecursiveFileEnumerator, nsISimpleEnumerator)
* where the file picker can create Blobs.
*/
static already_AddRefed<nsIFile>
DOMFileToLocalFile(nsIDOMFile* aDomFile)
DOMFileToLocalFile(File* aDomFile)
{
nsString path;
nsresult rv = aDomFile->GetMozFullPathInternal(path);
if (NS_FAILED(rv) || path.IsEmpty()) {
ErrorResult rv;
aDomFile->GetMozFullPathInternal(path, rv);
if (rv.Failed() || path.IsEmpty()) {
rv.SuppressException();
return nullptr;
}
nsCOMPtr<nsIFile> localFile;
rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(path), true,
getter_AddRefs(localFile));
NS_ENSURE_SUCCESS(rv, nullptr);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
return nullptr;
}
return localFile.forget();
}
@ -969,7 +974,11 @@ HTMLInputElement::InitFilePicker(FilePickerType aType)
aType != FILE_PICKER_DIRECTORY) {
nsString path;
oldFiles[0]->GetMozFullPathInternal(path);
ErrorResult error;
oldFiles[0]->GetMozFullPathInternal(path, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
nsCOMPtr<nsIFile> localFile;
rv = NS_NewLocalFile(path, false, getter_AddRefs(localFile));
@ -1708,7 +1717,12 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
// XXX We'd love to assert that this can't happen, but some mochitests
// use SpecialPowers to circumvent our more sane security model.
if (!mFiles.IsEmpty()) {
return mFiles[0]->GetMozFullPath(aValue);
ErrorResult rv;
mFiles[0]->GetMozFullPath(aValue, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
return NS_OK;
}
else {
aValue.Truncate();
@ -1716,8 +1730,10 @@ HTMLInputElement::GetValueInternal(nsAString& aValue) const
#endif
} else {
// Just return the leaf name
if (mFiles.IsEmpty() || NS_FAILED(mFiles[0]->GetName(aValue))) {
if (mFiles.IsEmpty()) {
aValue.Truncate();
} else {
mFiles[0]->GetName(aValue);
}
}
@ -2307,11 +2323,16 @@ HTMLInputElement::FlushFrames()
}
void
HTMLInputElement::MozGetFileNameArray(nsTArray< nsString >& aArray)
HTMLInputElement::MozGetFileNameArray(nsTArray<nsString>& aArray,
ErrorResult& aRv)
{
for (uint32_t i = 0; i < mFiles.Length(); i++) {
nsString str;
mFiles[i]->GetMozFullPathInternal(str);
mFiles[i]->GetMozFullPathInternal(str, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
aArray.AppendElement(str);
}
}
@ -2326,8 +2347,12 @@ HTMLInputElement::MozGetFileNameArray(uint32_t* aLength, char16_t*** aFileNames)
return NS_ERROR_DOM_SECURITY_ERR;
}
ErrorResult rv;
nsTArray<nsString> array;
MozGetFileNameArray(array);
MozGetFileNameArray(array, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
*aLength = array.Length();
char16_t** ret =
@ -2687,7 +2712,11 @@ HTMLInputElement::AfterSetFiles(bool aSetValueChanged)
if (mFiles.IsEmpty()) {
mFirstFilePath.Truncate();
} else {
mFiles[0]->GetMozFullPath(mFirstFilePath);
ErrorResult rv;
mFiles[0]->GetMozFullPath(mFirstFilePath, rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
}
}
#endif

View File

@ -713,7 +713,7 @@ public:
int32_t GetTextLength(ErrorResult& aRv);
void MozGetFileNameArray(nsTArray< nsString >& aFileNames);
void MozGetFileNameArray(nsTArray<nsString>& aFileNames, ErrorResult& aRv);
void MozSetFileNameArray(const Sequence< nsString >& aFileNames, ErrorResult& aRv);
void MozSetFileArray(const Sequence<OwningNonNull<File>>& aFiles);

View File

@ -451,15 +451,13 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
nsCOMPtr<nsIInputStream> fileStream;
if (aFile) {
nsAutoString filename16;
rv = aFile->GetName(filename16);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
aFile->GetName(filename16);
ErrorResult error;
nsAutoString filepath16;
rv = aFile->GetPath(filepath16);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
aFile->GetPath(filepath16, error);
if (NS_WARN_IF(error.Failed())) {
return error.StealNSResult();
}
if (!filepath16.IsEmpty()) {

View File

@ -334,14 +334,14 @@ StructuredCloneWriteCallback(JSContext* aCx,
nsRefPtr<File> file = blob->ToFile();
if (file) {
int64_t lastModifiedDate;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
file->GetMozLastModifiedDate(&lastModifiedDate)));
ErrorResult rv;
int64_t lastModifiedDate = file->GetLastModified(rv);
MOZ_ALWAYS_TRUE(!rv.Failed());
lastModifiedDate = NativeEndian::swapToLittleEndian(lastModifiedDate);
nsString name;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(file->GetName(name)));
file->GetName(name);
NS_ConvertUTF16toUTF8 convName(name);
uint32_t convNameLength =

View File

@ -2064,8 +2064,8 @@ public:
virtual void
GetName(nsAString& aName) override;
virtual nsresult
GetPath(nsAString& aPath) override;
virtual void
GetPath(nsAString& aPath, ErrorResult& aRv) override;
virtual int64_t
GetLastModified(ErrorResult& aRv) override;
@ -2742,11 +2742,11 @@ RemoteBlobImpl::GetName(nsAString& aName)
mBlobImpl->GetName(aName);
}
nsresult
void
BlobParent::
RemoteBlobImpl::GetPath(nsAString& aPath)
RemoteBlobImpl::GetPath(nsAString& aPath, ErrorResult& aRv)
{
return mBlobImpl->GetPath(aPath);
mBlobImpl->GetPath(aPath, aRv);
}
int64_t

View File

@ -45,6 +45,8 @@ partial interface File {
readonly attribute Date lastModifiedDate;
[GetterThrows, ChromeOnly]
readonly attribute DOMString mozFullPath;
readonly attribute DOMString path;
[GetterThrows, ChromeOnly]
readonly attribute DOMString mozFullPath;
};

View File

@ -148,7 +148,7 @@ partial interface HTMLInputElement {
[GetterThrows]
readonly attribute long textLength;
[ChromeOnly]
[Throws, ChromeOnly]
sequence<DOMString> mozGetFileNameArray();
[ChromeOnly, Throws]