Bug 1163388 - patch 2 - get rid of nsIDOMFile, r=ehsan

This commit is contained in:
Andrea Marchesini 2015-05-18 14:52:26 +01:00
parent d92f2c8a0a
commit 54e2145f4a
50 changed files with 162 additions and 195 deletions

View File

@ -1,6 +1,8 @@
const Cu = Components.utils;
const Ci = Components.interfaces;
Cu.importGlobalProperties(['File']);
const { Services } = Cu.import("resource://gre/modules/Services.jsm");
// Load a duplicated copy of the jsm to prevent messing with the currently running one
@ -25,7 +27,7 @@ function next() {
let steps = [
function getScreenshot() {
let screenshot = Screenshot.get();
assert.ok(screenshot instanceof Ci.nsIDOMFile,
assert.ok(screenshot instanceof File,
"Screenshot.get() returns a File");
next();
},

View File

@ -14,6 +14,8 @@ Cu.import("resource://gre/modules/AppsUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Webapps.jsm");
Cu.importGlobalProperties(['File']);
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
@ -284,7 +286,7 @@ this.ImportExport = {
throw "NoBlobFound";
}
let isFileBlob = aBlob instanceof Ci.nsIDOMFile;
let isFileBlob = aBlob instanceof File;
// We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) {
@ -498,7 +500,7 @@ this.ImportExport = {
throw "NoBlobFound";
}
let isFileBlob = aBlob instanceof Ci.nsIDOMFile;
let isFileBlob = aBlob instanceof File;
// We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) {

View File

@ -439,22 +439,6 @@ Blob::GetInternalStream(nsIInputStream** aStream)
////////////////////////////////////////////////////////////////////////////
// mozilla::dom::File implementation
NS_IMPL_CYCLE_COLLECTION_CLASS(File)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(File, Blob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(File, Blob)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile)
NS_INTERFACE_MAP_ENTRY(nsIDOMFile)
NS_INTERFACE_MAP_END_INHERITING(Blob)
NS_IMPL_ADDREF_INHERITED(File, Blob)
NS_IMPL_RELEASE_INHERITED(File, Blob)
File::File(nsISupports* aParent, BlobImpl* aImpl)
: Blob(aParent, aImpl)
{
@ -1282,9 +1266,9 @@ FileList::GetLength(uint32_t* aLength)
}
NS_IMETHODIMP
FileList::Item(uint32_t aIndex, nsIDOMFile **aFile)
FileList::Item(uint32_t aIndex, nsISupports** aFile)
{
nsRefPtr<File> file = Item(aIndex);
nsCOMPtr<nsIDOMBlob> file = Item(aIndex);
file.forget(aFile);
return NS_OK;
}

View File

@ -20,7 +20,7 @@
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsIDOMFile.h"
#include "nsIDOMBlob.h"
#include "nsIDOMFileList.h"
#include "nsIFile.h"
#include "nsIMutable.h"
@ -157,17 +157,10 @@ private:
};
class File final : public Blob
, public nsIDOMFile
{
friend class Blob;
public:
NS_DECL_NSIDOMFILE
NS_FORWARD_NSIDOMBLOB(Blob::)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(File, Blob);
// Note: BlobImpl must be a File in order to use this method.
// Check impl->IsFile().
static File*

View File

@ -9,7 +9,6 @@
#include "mozilla/DOMEventTargetHelper.h"
#include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsITimer.h"
#include "nsCOMPtr.h"
#include "nsIAsyncInputStream.h"

View File

@ -11,10 +11,10 @@ XPIDL_SOURCES += [
'nsIContentPolicy.idl',
'nsIContentPolicyBase.idl',
'nsIDocumentEncoder.idl',
'nsIDOMBlob.idl',
'nsIDOMDataChannel.idl',
'nsIDOMDOMCursor.idl',
'nsIDOMDOMRequest.idl',
'nsIDOMFile.idl',
'nsIDOMFileList.idl',
'nsIDOMFileReader.idl',
'nsIDOMFormData.idl',

View File

@ -2593,7 +2593,7 @@ nsDOMWindowUtils::GetContainerElement(nsIDOMElement** aResult)
NS_IMETHODIMP
nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
nsIDOMFile **aDOMFile)
nsISupports **aDOMFile)
{
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
@ -2609,8 +2609,8 @@ nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
return NS_ERROR_FAILURE;
}
nsRefPtr<File> file = File::CreateFromFile(innerWindow, aFile);
file.forget(aDOMFile);
nsCOMPtr<nsIDOMBlob> blob = File::CreateFromFile(innerWindow, aFile);
blob.forget(aDOMFile);
return NS_OK;
}

View File

@ -23,7 +23,6 @@
#include "nsIContentViewer.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMFile.h"
#include "nsPIDOMWindow.h"
#include "nsIWebNavigation.h"
#include "nsIWebProgress.h"

View File

@ -53,14 +53,3 @@ interface nsIDOMBlob : nsISupports
// Return true if this blob is a memory file.
[notxpcom] bool isMemoryFile();
};
// We want to avoid multiple inheritance of nsIDOMBlob so we can downcast from
// nsIDOMBlob to Blob safely. Our chain is:
// - Blob -> nsIDOMBlob
// - File -> nsIDOMFile and Blob
[scriptable, builtinclass, uuid(26e292a6-f5aa-4560-b523-ae22a4c7dfca)]
interface nsIDOMFile : nsISupports
{
// 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

@ -5,11 +5,10 @@
#include "nsISupports.idl"
interface nsIDOMFile;
[uuid(283aa7b2-da81-4c72-aea2-9797b440fe34)]
[uuid(57128a85-34de-42db-a252-84dd57724a59)]
interface nsIDOMFileList : nsISupports
{
readonly attribute unsigned long length;
nsIDOMFile item(in unsigned long index);
// returns a DOM File object
nsISupports item(in unsigned long index);
};

View File

@ -172,7 +172,7 @@ ToJSValue(JSContext* aCx,
}
// Accept objects that inherit from nsISupports but not nsWrapperCache (e.g.
// nsIDOMFile).
// DOM File).
template <class T>
MOZ_WARN_UNUSED_RESULT
typename EnableIf<!IsBaseOf<nsWrapperCache, T>::value &&

View File

@ -72,14 +72,14 @@ BEGIN_BLUETOOTH_NAMESPACE
class BluetoothOppManager::SendFileBatch final
{
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
@ -420,7 +420,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
bool
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob)
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -434,7 +434,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
void
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob)
Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
@ -794,7 +794,7 @@ BluetoothOppManager::RetrieveSentFileName()
{
mFileName.Truncate();
nsRefPtr<File> file = static_cast<Blob*>(mBlob.get()).ToFile();
nsRefPtr<File> file = static_cast<Blob*>(mBlob.get())->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;
}
}
@ -55,7 +55,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);
@ -102,7 +102,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);
@ -199,7 +199,7 @@ private:
nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
int mCurrentBlobIndex;
nsCOMPtr<nsIDOMBlob> mBlob;
nsRefPtr<Blob> mBlob;
nsTArray<SendFileBatch> mBatches;
/**

View File

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

View File

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

View File

@ -12,15 +12,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;
}
@ -295,7 +293,7 @@ public:
virtual void
SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob,
Blob* aBlob,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void

View File

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

View File

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

View File

@ -6,8 +6,6 @@
#include "InternalResponse.h"
#include "nsIDOMFile.h"
#include "mozilla/dom/InternalHeaders.h"
#include "nsStreamUtils.h"
#include "nsSerializationHelper.h"

View File

@ -647,16 +647,22 @@ HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv)
{
nsCOMPtr<nsIDOMFile> file;
nsCOMPtr<nsISupports> file;
aRv = MozGetAsFile(aName, aType, getter_AddRefs(file));
nsRefPtr<File> tmp = static_cast<File*>(file.get());
return tmp.forget();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(file);
nsRefPtr<Blob> domBlob = static_cast<Blob*>(blob.get());
MOZ_ASSERT(domBlob->IsFile());
return domBlob->ToFile();
}
NS_IMETHODIMP
HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
nsIDOMFile** aResult)
nsISupports** aResult)
{
OwnerDoc()->WarnOnceAbout(nsIDocument::eMozGetAsFile);
@ -672,7 +678,7 @@ HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
nsresult
HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
const nsAString& aType,
nsIDOMFile** aResult)
nsISupports** aResult)
{
nsCOMPtr<nsIInputStream> stream;
nsAutoString type(aType);
@ -696,7 +702,7 @@ HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScopeObject());
// The File takes ownership of the buffer
nsRefPtr<File> file =
nsCOMPtr<nsIDOMBlob> file =
File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type,
PR_Now());

View File

@ -237,7 +237,7 @@ protected:
nsAString& aDataURL);
nsresult MozGetAsBlobImpl(const nsAString& aName,
const nsAString& aType,
nsIDOMFile** aResult);
nsISupports** aResult);
void CallPrintCallback();
CanvasContextType mCurrentContextType;

View File

@ -405,7 +405,9 @@ public:
MOZ_ASSERT(blobImpl);
blobImpl->SetPath(Substring(path, 0, uint32_t(length)));
}
*aResult = domFile.forget().downcast<nsIDOMFile>().take();
nsCOMPtr<nsIDOMBlob> blob = domFile.get();
blob.forget(aResult);
LookupAndCacheNext();
return NS_OK;
}
@ -488,7 +490,7 @@ NS_IMPL_ISUPPORTS(DirPickerRecursiveFileEnumerator, nsISimpleEnumerator)
/**
* This may return nullptr if aDomFile's implementation of
* nsIDOMFile::mozFullPathInternal does not successfully return a non-empty
* File::mozFullPathInternal does not successfully return a non-empty
* string that is a valid path. This can happen on Firefox OS, for example,
* where the file picker can create Blobs.
*/
@ -537,9 +539,9 @@ public:
nsCOMPtr<nsISupports> tmp;
while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) {
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
MOZ_ASSERT(domFile);
mFileList.AppendElement(static_cast<File*>(domFile.get()));
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(tmp);
MOZ_ASSERT(domBlob);
mFileList.AppendElement(static_cast<File*>(domBlob.get()));
mFileListLength = mFileList.Length();
if (mCanceled) {
MOZ_ASSERT(!mInput, "This is bad - how did this happen?");
@ -696,20 +698,23 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) {
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
NS_WARN_IF_FALSE(domFile,
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(tmp);
NS_WARN_IF_FALSE(domBlob,
"Null file object from FilePicker's file enumerator?");
if (domFile) {
newFiles.AppendElement(static_cast<File*>(domFile.get()));
if (domBlob) {
newFiles.AppendElement(static_cast<File*>(domBlob.get()));
}
}
} else {
MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen));
nsCOMPtr<nsIDOMFile> domFile;
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(domFile));
nsCOMPtr<nsISupports> tmp;
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(rv, rv);
if (domFile) {
newFiles.AppendElement(static_cast<File*>(domFile.get()));
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(tmp);
if (blob) {
nsRefPtr<File> file = static_cast<Blob*>(blob.get())->ToFile();
newFiles.AppendElement(file);
}
}

View File

@ -18,7 +18,6 @@
#include "nsAttrValueInlines.h"
#include "nsISaveAsCharset.h"
#include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsStringStream.h"
#include "nsIURI.h"

View File

@ -27,7 +27,6 @@
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIDOMFile.h"
#include "nsIPrincipal.h"
namespace mozilla {
@ -328,7 +327,7 @@ IDBMutableFile::GetFileId() const
return mFileInfo->Id();
}
already_AddRefed<nsIDOMFile>
already_AddRefed<File>
IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle,
MetadataParameters* aMetadataParams)
{
@ -393,12 +392,10 @@ GetFileHelper::GetSuccessResult(JSContext* aCx,
auto fileHandle = static_cast<IDBFileHandle*>(mFileHandle.get());
nsCOMPtr<nsIDOMFile> domFile =
nsRefPtr<File> domFile =
mMutableFile->CreateFileObject(fileHandle, mParams);
nsresult rv =
nsContentUtils::WrapNative(aCx, domFile, &NS_GET_IID(nsIDOMFile), aVal);
if (NS_WARN_IF(NS_FAILED(rv))) {
if (!ToJSValue(aCx, domFile, aVal)) {
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
}

View File

@ -18,7 +18,6 @@
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
class nsIDOMFile;
class nsPIDOMWindow;
namespace mozilla {
@ -28,6 +27,7 @@ class ErrorResult;
namespace dom {
class DOMRequest;
class File;
class MetadataParameters;
namespace indexedDB {
@ -83,7 +83,7 @@ public:
return mFileInfo;
}
already_AddRefed<nsIDOMFile>
already_AddRefed<File>
CreateFileObject(IDBFileHandle* aFileHandle,
MetadataParameters* aMetadataParams);

View File

@ -17,7 +17,6 @@
#include "mozilla/dom/DOMStringList.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "nsIAppShell.h"
#include "nsIDOMFile.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsTHashtable.h"

View File

@ -94,12 +94,11 @@ function verifyBlob(blob1, blob2, fileId, blobReadHandler)
{
is(blob1 instanceof Components.interfaces.nsIDOMBlob, true,
"Instance of nsIDOMBlob");
is(blob1 instanceof Components.interfaces.nsIDOMFile,
blob2 instanceof Components.interfaces.nsIDOMFile,
"Instance of nsIDOMFile");
is(blob1 instanceof File, blob2 instanceof File,
"Instance of DOM File");
is(blob1.size, blob2.size, "Correct size");
is(blob1.type, blob2.type, "Correct type");
if (blob2 instanceof Components.interfaces.nsIDOMFile) {
if (blob2 instanceof File) {
is(blob1.name, blob2.name, "Correct name");
}
is(utils.getFileId(blob1), fileId, "Correct file id");

View File

@ -39,8 +39,6 @@ interface nsIDOMStyleSheet;
interface nsITransferable;
interface nsIQueryContentEventResult;
interface nsIDOMWindow;
interface nsIDOMBlob;
interface nsIDOMFile;
interface nsIFile;
interface nsIDOMClientRect;
interface nsIURI;
@ -51,7 +49,7 @@ interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest;
interface nsIObserver;
[scriptable, uuid(1a75c351-d115-4d51-94df-731dd1723a1f)]
[scriptable, uuid(34a42cdc-7a04-4e71-8a5c-63e092fba58e)]
interface nsIDOMWindowUtils : nsISupports {
/**
@ -1445,9 +1443,10 @@ interface nsIDOMWindowUtils : nsISupports {
in AString value2);
/**
* Wrap an nsIFile in an nsIDOMFile
* Wrap an nsIFile in an DOM File
* Returns a File object.
*/
nsIDOMFile wrapDOMFile(in nsIFile aFile);
nsISupports wrapDOMFile(in nsIFile aFile);
/**
* Get the type of the currently focused html input, if any.

View File

@ -16,11 +16,10 @@
*/
interface nsIDOMBlob;
interface nsIDOMFile;
interface nsIVariant;
interface nsIInputStreamCallback;
[uuid(8978d1c5-2981-4678-a1c3-b0b7bae04fbc)]
[uuid(2c984658-2e7c-4774-8ac5-cf1b39f8bec3)]
interface nsIDOMHTMLCanvasElement : nsISupports
{
attribute unsigned long width;
@ -38,7 +37,8 @@ interface nsIDOMHTMLCanvasElement : nsISupports
// Valid calls are
// mozGetAsFile(name); -- defaults to image/png
// mozGetAsFile(name, type); -- uses given type
nsIDOMFile mozGetAsFile(in DOMString name, [optional] in DOMString type);
// The return value is a File object.
nsISupports mozGetAsFile(in DOMString name, [optional] in DOMString type);
// A Mozilla-only extension to get a canvas context backed by double-buffered
// shared memory. Only privileged callers can call this.

View File

@ -8,7 +8,6 @@
#include "nsComponentManagerUtils.h"
#include "nsNetCID.h"
#include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIDOMWindow.h"
#include "nsIFile.h"
#include "nsISimpleEnumerator.h"

View File

@ -7,7 +7,6 @@
#ifndef mozilla_dom_FilePickerParent_h
#define mozilla_dom_FilePickerParent_h
#include "nsIDOMFile.h"
#include "nsIEventTarget.h"
#include "nsIFilePicker.h"
#include "nsCOMArray.h"

View File

@ -113,6 +113,7 @@ GetMediaManagerLog()
}
#define LOG(msg) PR_LOG(GetMediaManagerLog(), PR_LOG_DEBUG, msg)
using dom::File;
using dom::MediaStreamConstraints;
using dom::MediaTrackConstraintSet;
using dom::MediaTrackConstraints;
@ -264,53 +265,6 @@ private:
nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
};
/**
* Invoke the "onSuccess" callback in content. The callback will take a
* DOMBlob in the case of {picture:true}, and a MediaStream in the case of
* {audio:true} or {video:true}. There is a constructor available for each
* form. Do this only on the main thread.
*/
class SuccessCallbackRunnable : public nsRunnable
{
public:
SuccessCallbackRunnable(
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback>& aOnSuccess,
nsCOMPtr<nsIDOMGetUserMediaErrorCallback>& aOnFailure,
nsIDOMFile* aFile, uint64_t aWindowID)
: mFile(aFile)
, mWindowID(aWindowID)
, mManager(MediaManager::GetInstance())
{
mOnSuccess.swap(aOnSuccess);
mOnFailure.swap(aOnFailure);
}
NS_IMETHOD
Run()
{
// Only run if the window is still active.
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onSuccess = mOnSuccess.forget();
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onFailure = mOnFailure.forget();
if (!(mManager->IsWindowStillActive(mWindowID))) {
return NS_OK;
}
// This is safe since we're on main-thread, and the windowlist can only
// be invalidated from the main-thread (see OnNavigation)
onSuccess->OnSuccess(mFile);
return NS_OK;
}
private:
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
nsCOMPtr<nsIDOMFile> mFile;
uint64_t mWindowID;
nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
};
/**
* Invoke the GetUserMediaDevices success callback. Wrapped in a runnable
* so that it may be called on the main thread. The error callback is also

View File

@ -112,7 +112,7 @@ protected:
mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling
// This is only modified on MainThread (AllocImpl and DeallocImpl)
nsRefPtr<ICameraControl> mCameraControl;
nsCOMPtr<nsIDOMFile> mLastCapture;
nsRefPtr<dom::File> mLastCapture;
android::sp<android::GonkCameraSource> mCameraSource;

View File

@ -210,7 +210,7 @@ interface nsINfcContentHelper : nsISupports
*
* @param blob
* Raw data of the file to be sent. This object represents a file-like
* (nsIDOMFile) object of immutable, raw data. The blob data needs
* (DOM File) object of immutable, raw data. The blob data needs
* to be 'object wrapped' before calling this interface.
*
* @param sessionToken

View File

@ -8,7 +8,7 @@ let Cc = Components.classes;
let Ci = Components.interfaces;
let Cu = Components.utils;
Cu.importGlobalProperties(['Blob']);
Cu.importGlobalProperties(['Blob', 'File']);
Cu.import("resource://gre/modules/Services.jsm");
this.EXPORTED_SYMBOLS = ["SettingsDB", "SETTINGSDB_NAME", "SETTINGSSTORE_NAME"];
@ -209,7 +209,7 @@ SettingsDB.prototype = {
return "primitive";
} else if (Array.isArray(aObject)) {
return "array";
} else if (aObject instanceof Ci.nsIDOMFile) {
} else if (aObject instanceof File) {
return "file";
} else if (aObject instanceof Ci.nsIDOMBlob) {
return "blob";

View File

@ -8,6 +8,8 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.importGlobalProperties(['File']);
this.EXPORTED_SYMBOLS = ["SettingsRequestManager"];
Cu.import("resource://gre/modules/SettingsDB.jsm");
@ -245,7 +247,7 @@ let SettingsRequestManager = {
if (!aValue || !aValue.constructor) {
return false;
}
return (aValue.constructor.name == "Date") || (aValue instanceof Ci.nsIDOMFile) ||
return (aValue.constructor.name == "Date") || (aValue instanceof File) ||
(aValue instanceof Ci.nsIDOMBlob);
}
// We need to serialize settings objects, otherwise they can change between

View File

@ -18,7 +18,7 @@
#include "cert.h"
#include "certdb.h"
#include "CryptoTask.h"
#include "nsIDOMFile.h"
#include "nsIDOMBlob.h"
#include "nsIWifiService.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h"

View File

@ -28,7 +28,6 @@
#include "mozilla/dom/StructuredCloneTags.h"
#include "mozilla/dom/WindowBinding.h"
#include "nsZipArchive.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsWindowMemoryReporter.h"
#include "nsDOMClassInfo.h"

View File

@ -49,7 +49,7 @@
if (Array.isArray(a))
return 'array';
if (a instanceof Ci.nsIDOMFile)
if (a instanceof File)
return 'file';
if (a instanceof Ci.nsIDOMBlob)

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.importGlobalProperties(['Blob']);
Components.utils.importGlobalProperties(['Blob', 'File']);
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -31,7 +31,7 @@ BlobComponent.prototype =
// do some tests
do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File");
do_check_true(!(f1 instanceof File), "Should not be a DOM File");
do_check_true(f1.type == "text/xml", "Wrong type");

View File

@ -36,8 +36,8 @@ FileComponent.prototype =
var f2 = new File(file);
// do some tests
do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File");
do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File");
do_check_true(f1 instanceof File, "Should be a DOM File");
do_check_true(f2 instanceof File, "Should be a DOM File");
do_check_true(f1.name == "xpcshell.ini", "Should be the right file");
do_check_true(f2.name == "xpcshell.ini", "Should be the right file");

View File

@ -2,7 +2,7 @@
* 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/. */
Components.utils.importGlobalProperties(['Blob']);
Components.utils.importGlobalProperties(['Blob', 'File']);
const Ci = Components.interfaces;
@ -15,7 +15,7 @@ function run_test() {
// do some tests
do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File");
do_check_true(!(f1 instanceof File), "Should not be a DOM File");
do_check_true(f1.type == "text/xml", "Wrong type");

View File

@ -21,8 +21,8 @@ function run_test() {
var f2 = new File(file);
// do some tests
do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File");
do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File");
do_check_true(f1 instanceof File, "Should be a DOM File");
do_check_true(f2 instanceof File, "Should be a DOM File");
do_check_true(f1.name == "xpcshell.ini", "Should be the right file");
do_check_true(f2.name == "xpcshell.ini", "Should be the right file");

View File

@ -93,7 +93,7 @@ nsFilePicker.prototype = {
/* readonly attribute nsISimpleEnumerator files; */
get files() { return this.mFilesEnumerator; },
/* readonly attribute nsIDOMFile domfile; */
/* readonly attribute DOM File domfile; */
get domfile() {
let enumerator = this.domfiles;
return enumerator ? enumerator.mFiles[0] : null;

View File

@ -83,7 +83,7 @@ this.PropertyListUtils = Object.freeze({
* The reaon for failure is reported to the Error Console.
*/
read: function PLU_read(aFile, aCallback) {
if (!(aFile instanceof Ci.nsILocalFile || aFile instanceof Ci.nsIDOMFile))
if (!(aFile instanceof Ci.nsILocalFile || aFile instanceof File))
throw new Error("aFile is not a file object");
if (typeof(aCallback) != "function")
throw new Error("Invalid value for aCallback");

View File

@ -96,7 +96,7 @@ public:
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMFile> domFile = File::CreateFromFile(mParent, localFile);
nsCOMPtr<nsIDOMBlob> domFile = File::CreateFromFile(mParent, localFile);
domFile.forget(aResult);
return NS_OK;
}
@ -311,7 +311,7 @@ nsBaseFilePicker::GetMode(int16_t* aMode)
}
NS_IMETHODIMP
nsBaseFilePicker::GetDomfile(nsIDOMFile** aDomfile)
nsBaseFilePicker::GetDomfile(nsISupports** aDomfile)
{
nsCOMPtr<nsIFile> localFile;
nsresult rv = GetFile(getter_AddRefs(localFile));
@ -322,7 +322,7 @@ nsBaseFilePicker::GetDomfile(nsIDOMFile** aDomfile)
return NS_OK;
}
nsRefPtr<File> domFile = File::CreateFromFile(mParent, localFile);
nsCOMPtr<nsIDOMBlob> domFile = File::CreateFromFile(mParent, localFile);
domFile.forget(aDomfile);
return NS_OK;
}

View File

@ -37,7 +37,7 @@ public:
NS_IMETHOD SetAddToRecentDocs(bool aFlag);
NS_IMETHOD GetMode(int16_t *aMode);
NS_IMETHOD GetDomfile(nsIDOMFile** aDomfile);
NS_IMETHOD GetDomfile(nsISupports** aDomfile);
NS_IMETHOD GetDomfiles(nsISimpleEnumerator** aDomfiles);
protected:

View File

@ -165,7 +165,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
nsRefPtr<File> file = File::Create(mParent, blobImpl);
MOZ_ASSERT(file);
mDomfiles.AppendObject(file);
mDomfiles.AppendElement(file);
}
}
@ -178,7 +178,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
}
NS_IMETHODIMP
nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
nsFilePickerProxy::GetDomfile(nsISupports** aDomfile)
{
*aDomfile = nullptr;
if (mDomfiles.IsEmpty()) {
@ -186,13 +186,55 @@ nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
}
MOZ_ASSERT(mDomfiles.Length() == 1);
nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0];
domfile.forget(aDomfile);
nsCOMPtr<nsIDOMBlob> blob = mDomfiles[0].get();
blob.forget(aDomfile);
return NS_OK;
}
namespace {
class SimpleEnumerator final : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
explicit SimpleEnumerator(const nsTArray<nsRefPtr<File>>& aFiles)
: mFiles(aFiles)
, mIndex(0)
{}
NS_IMETHOD
HasMoreElements(bool* aRetvalue) override
{
MOZ_ASSERT(aRetvalue);
*aRetvalue = mFiles.Length() >= mIndex;
return NS_OK;
}
NS_IMETHOD
GetNext(nsISupports** aSupports) override
{
nsCOMPtr<nsIDOMBlob> blob = mFiles[mIndex++].get();
blob.forget(aSupports);
return NS_OK;
}
private:
~SimpleEnumerator()
{}
nsTArray<nsRefPtr<File>> mFiles;
uint32_t mIndex;
};
NS_IMPL_ISUPPORTS(SimpleEnumerator, nsISimpleEnumerator)
} // anonymous namespace
NS_IMETHODIMP
nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
{
return NS_NewArrayEnumerator(aDomfiles, mDomfiles);
nsRefPtr<SimpleEnumerator> enumerator = new SimpleEnumerator(mDomfiles);
enumerator.forget(aDomfiles);
return NS_OK;
}

View File

@ -18,6 +18,12 @@ class nsIWidget;
class nsIFile;
class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class File;
}
}
/**
This class creates a proxy file picker to be used in content processes.
The file picker just collects the initialization data and when Show() is
@ -45,7 +51,7 @@ public:
NS_IMETHODIMP GetFileURL(nsIURI** aFileURL) override;
NS_IMETHODIMP GetFiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP GetDomfile(nsIDOMFile** aFile) override;
NS_IMETHODIMP GetDomfile(nsISupports** aFile) override;
NS_IMETHODIMP GetDomfiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP Show(int16_t* aReturn) override;
@ -59,7 +65,7 @@ private:
~nsFilePickerProxy();
void InitNative(nsIWidget*, const nsAString&) override;
nsCOMArray<nsIDOMFile> mDomfiles;
nsTArray<nsRefPtr<mozilla::dom::File>> mDomfiles;
nsCOMPtr<nsIFilePickerShownCallback> mCallback;
int16_t mSelectedType;

View File

@ -8,7 +8,6 @@
interface nsIFile;
interface nsIURI;
interface nsIDOMFile;
interface nsIDOMWindow;
interface nsISimpleEnumerator;
@ -24,7 +23,7 @@ interface nsIFilePickerShownCallback : nsISupports
void done(in short aResult);
};
[scriptable, uuid(f93509a0-0434-11e3-8ffd-0800200c9a66)]
[scriptable, uuid(9840d564-42c8-4d78-9a4d-71002343c918)]
interface nsIFilePicker : nsISupports
{
const short modeOpen = 0; // Load a file or directory
@ -143,11 +142,11 @@ interface nsIFilePicker : nsISupports
readonly attribute nsISimpleEnumerator files;
/**
* Get the nsIDOMFile for the file.
* Get the DOM File for the file.
*
* @return Returns the file currently selected as File
*/
readonly attribute nsIDOMFile domfile;
readonly attribute nsISupports domfile;
/**
* Get the enumerator for the selected files