mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 14:52:16 +00:00
Bug 1585284
- Use nsIGlobalObject in any Blob/File CTOR, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D49392 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
3ae961a2da
commit
6797e45278
@ -398,7 +398,7 @@ void BodyUtil::ConsumeArrayBuffer(JSContext* aCx,
|
||||
}
|
||||
|
||||
// static
|
||||
already_AddRefed<Blob> BodyUtil::ConsumeBlob(nsISupports* aParent,
|
||||
already_AddRefed<Blob> BodyUtil::ConsumeBlob(nsIGlobalObject* aParent,
|
||||
const nsString& aMimeType,
|
||||
uint32_t aInputLength,
|
||||
uint8_t* aInput,
|
||||
|
@ -36,7 +36,7 @@ class BodyUtil final {
|
||||
* Creates an in-memory blob from an array. The blob takes ownership of
|
||||
* |aInput|, which must be allocated by |malloc|.
|
||||
*/
|
||||
static already_AddRefed<Blob> ConsumeBlob(nsISupports* aParent,
|
||||
static already_AddRefed<Blob> ConsumeBlob(nsIGlobalObject* aParent,
|
||||
const nsString& aMimeType,
|
||||
uint32_t aInputLength,
|
||||
uint8_t* aInput, ErrorResult& aRv);
|
||||
|
@ -164,7 +164,7 @@ PostMessageEvent::Run() {
|
||||
|
||||
StructuredCloneHolder* holder;
|
||||
if (mHolder.constructed<StructuredCloneHolder>()) {
|
||||
mHolder.ref<StructuredCloneHolder>().Read(ToSupports(targetWindow), cx,
|
||||
mHolder.ref<StructuredCloneHolder>().Read(targetWindow->AsGlobal(), cx,
|
||||
&messageData, rv);
|
||||
holder = &mHolder.ref<StructuredCloneHolder>();
|
||||
} else {
|
||||
|
@ -233,7 +233,7 @@ StructuredCloneHolder::StructuredCloneHolder(
|
||||
: StructuredCloneHolderBase(aScope),
|
||||
mSupportsCloning(aSupportsCloning == CloningSupported),
|
||||
mSupportsTransferring(aSupportsTransferring == TransferringSupported),
|
||||
mParent(nullptr)
|
||||
mGlobal(nullptr)
|
||||
#ifdef DEBUG
|
||||
,
|
||||
mCreationEventTarget(GetCurrentThreadEventTarget())
|
||||
@ -266,16 +266,16 @@ void StructuredCloneHolder::Write(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
||||
}
|
||||
}
|
||||
|
||||
void StructuredCloneHolder::Read(nsISupports* aParent, JSContext* aCx,
|
||||
void StructuredCloneHolder::Read(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aValue,
|
||||
ErrorResult& aRv) {
|
||||
MOZ_ASSERT_IF(
|
||||
mStructuredCloneScope == StructuredCloneScope::SameProcessSameThread,
|
||||
mCreationEventTarget->IsOnCurrentThread());
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(aGlobal);
|
||||
|
||||
mozilla::AutoRestore<nsISupports*> guard(mParent);
|
||||
mParent = aParent;
|
||||
mozilla::AutoRestore<nsIGlobalObject*> guard(mGlobal);
|
||||
mGlobal = aGlobal;
|
||||
|
||||
if (!StructuredCloneHolderBase::Read(aCx, aValue)) {
|
||||
JS_ClearPendingException(aCx);
|
||||
@ -293,15 +293,17 @@ void StructuredCloneHolder::Read(nsISupports* aParent, JSContext* aCx,
|
||||
}
|
||||
}
|
||||
|
||||
void StructuredCloneHolder::ReadFromBuffer(nsISupports* aParent, JSContext* aCx,
|
||||
void StructuredCloneHolder::ReadFromBuffer(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
JSStructuredCloneData& aBuffer,
|
||||
JS::MutableHandle<JS::Value> aValue,
|
||||
ErrorResult& aRv) {
|
||||
ReadFromBuffer(aParent, aCx, aBuffer, JS_STRUCTURED_CLONE_VERSION, aValue,
|
||||
ReadFromBuffer(aGlobal, aCx, aBuffer, JS_STRUCTURED_CLONE_VERSION, aValue,
|
||||
aRv);
|
||||
}
|
||||
|
||||
void StructuredCloneHolder::ReadFromBuffer(nsISupports* aParent, JSContext* aCx,
|
||||
void StructuredCloneHolder::ReadFromBuffer(nsIGlobalObject* aGlobal,
|
||||
JSContext* aCx,
|
||||
JSStructuredCloneData& aBuffer,
|
||||
uint32_t aAlgorithmVersion,
|
||||
JS::MutableHandle<JS::Value> aValue,
|
||||
@ -312,8 +314,8 @@ void StructuredCloneHolder::ReadFromBuffer(nsISupports* aParent, JSContext* aCx,
|
||||
|
||||
MOZ_ASSERT(!mBuffer, "ReadFromBuffer() must be called without a Write().");
|
||||
|
||||
mozilla::AutoRestore<nsISupports*> guard(mParent);
|
||||
mParent = aParent;
|
||||
mozilla::AutoRestore<nsIGlobalObject*> guard(mGlobal);
|
||||
mGlobal = aGlobal;
|
||||
|
||||
if (!JS_ReadStructuredClone(aCx, aBuffer, aAlgorithmVersion,
|
||||
mStructuredCloneScope, aValue, &sCallbacks,
|
||||
@ -353,10 +355,10 @@ JSObject* StructuredCloneHolder::ReadFullySerializableObjects(
|
||||
// the casting between JSPrincipals* and nsIPrincipal* we can't use
|
||||
// getter_AddRefs above and have to already_AddRefed here.
|
||||
nsCOMPtr<nsIPrincipal> principal =
|
||||
already_AddRefed<nsIPrincipal>(nsJSPrincipals::get(prin));
|
||||
already_AddRefed<nsIPrincipal>(nsJSPrincipals::get(prin));
|
||||
|
||||
nsresult rv = nsContentUtils::WrapNative(
|
||||
aCx, principal, &NS_GET_IID(nsIPrincipal), &result);
|
||||
aCx, principal, &NS_GET_IID(nsIPrincipal), &result);
|
||||
if (NS_FAILED(rv)) {
|
||||
xpc::Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
|
||||
return nullptr;
|
||||
@ -449,7 +451,7 @@ JSObject* ReadBlob(JSContext* aCx, uint32_t aIndex,
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(blobImpl->SetMutable(false));
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(aHolder->ParentDuringRead(), blobImpl);
|
||||
RefPtr<Blob> blob = Blob::Create(aHolder->GlobalDuringRead(), blobImpl);
|
||||
if (!ToJSValue(aCx, blob, &val)) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -521,7 +523,7 @@ already_AddRefed<Directory> ReadDirectoryInternal(
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(aHolder->ParentDuringRead(), file);
|
||||
Directory::Create(aHolder->GlobalDuringRead(), file);
|
||||
return directory.forget();
|
||||
}
|
||||
|
||||
@ -560,7 +562,7 @@ JSObject* ReadFileList(JSContext* aCx, JSStructuredCloneReader* aReader,
|
||||
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
{
|
||||
RefPtr<FileList> fileList = new FileList(aHolder->ParentDuringRead());
|
||||
RefPtr<FileList> fileList = new FileList(aHolder->GlobalDuringRead());
|
||||
|
||||
uint32_t zero, index;
|
||||
// |index| is the index of the first blobImpl.
|
||||
@ -585,7 +587,7 @@ JSObject* ReadFileList(JSContext* aCx, JSStructuredCloneReader* aReader,
|
||||
|
||||
MOZ_ALWAYS_SUCCEEDS(blobImpl->SetMutable(false));
|
||||
|
||||
RefPtr<File> file = File::Create(aHolder->ParentDuringRead(), blobImpl);
|
||||
RefPtr<File> file = File::Create(aHolder->GlobalDuringRead(), blobImpl);
|
||||
if (!fileList->Append(file)) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -638,7 +640,7 @@ JSObject* ReadFormData(JSContext* aCx, JSStructuredCloneReader* aReader,
|
||||
// See the serialization of the FormData for the format.
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
{
|
||||
RefPtr<FormData> formData = new FormData(aHolder->ParentDuringRead());
|
||||
RefPtr<FormData> formData = new FormData(aHolder->GlobalDuringRead());
|
||||
|
||||
Optional<nsAString> thirdArg;
|
||||
for (uint32_t i = 0; i < aCount; ++i) {
|
||||
@ -663,7 +665,7 @@ JSObject* ReadFormData(JSContext* aCx, JSStructuredCloneReader* aReader,
|
||||
RefPtr<BlobImpl> blobImpl = aHolder->BlobImpls()[indexOrLengthOfString];
|
||||
MOZ_ALWAYS_SUCCEEDS(blobImpl->SetMutable(false));
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(aHolder->ParentDuringRead(), blobImpl);
|
||||
RefPtr<Blob> blob = Blob::Create(aHolder->GlobalDuringRead(), blobImpl);
|
||||
MOZ_ASSERT(blob);
|
||||
|
||||
ErrorResult rv;
|
||||
@ -838,7 +840,7 @@ JSObject* ReadInputStream(JSContext* aCx, uint32_t aIndex,
|
||||
nsCOMPtr<nsIInputStream> inputStream = aHolder->InputStreams()[aIndex];
|
||||
|
||||
nsresult rv = nsContentUtils::WrapNative(
|
||||
aCx, inputStream, &NS_GET_IID(nsIInputStream), &result);
|
||||
aCx, inputStream, &NS_GET_IID(nsIInputStream), &result);
|
||||
if (NS_FAILED(rv)) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -895,9 +897,8 @@ JSObject* StructuredCloneHolder::CustomReadHandler(
|
||||
// This can be null.
|
||||
JS::RootedObject result(aCx);
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(mParent);
|
||||
// aIndex is the index of the cloned image.
|
||||
result = ImageBitmap::ReadStructuredClone(aCx, aReader, parent,
|
||||
result = ImageBitmap::ReadStructuredClone(aCx, aReader, mGlobal,
|
||||
GetSurfaces(), aIndex);
|
||||
}
|
||||
return result;
|
||||
@ -1032,10 +1033,8 @@ bool StructuredCloneHolder::CustomReadTransferHandler(
|
||||
MOZ_ASSERT(aExtraData < mPortIdentifiers.Length());
|
||||
const MessagePortIdentifier& portIdentifier = mPortIdentifiers[aExtraData];
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
|
||||
|
||||
ErrorResult rv;
|
||||
RefPtr<MessagePort> port = MessagePort::Create(global, portIdentifier, rv);
|
||||
RefPtr<MessagePort> port = MessagePort::Create(mGlobal, portIdentifier, rv);
|
||||
if (NS_WARN_IF(rv.Failed())) {
|
||||
rv.SuppressException();
|
||||
return false;
|
||||
@ -1060,9 +1059,8 @@ bool StructuredCloneHolder::CustomReadTransferHandler(
|
||||
MOZ_ASSERT(aContent);
|
||||
OffscreenCanvasCloneData* data =
|
||||
static_cast<OffscreenCanvasCloneData*>(aContent);
|
||||
nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(mParent);
|
||||
RefPtr<OffscreenCanvas> canvas =
|
||||
OffscreenCanvas::CreateFromCloneData(parent, data);
|
||||
OffscreenCanvas::CreateFromCloneData(mGlobal, data);
|
||||
delete data;
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
@ -1081,8 +1079,8 @@ bool StructuredCloneHolder::CustomReadTransferHandler(
|
||||
StructuredCloneScope::SameProcessDifferentThread)) {
|
||||
MOZ_ASSERT(aContent);
|
||||
ImageBitmapCloneData* data = static_cast<ImageBitmapCloneData*>(aContent);
|
||||
nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(mParent);
|
||||
RefPtr<ImageBitmap> bitmap = ImageBitmap::CreateFromCloneData(parent, data);
|
||||
RefPtr<ImageBitmap> bitmap =
|
||||
ImageBitmap::CreateFromCloneData(mGlobal, data);
|
||||
delete data;
|
||||
|
||||
JS::Rooted<JS::Value> value(aCx);
|
||||
|
@ -13,13 +13,13 @@
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
# include "nsIThread.h"
|
||||
#endif
|
||||
|
||||
class nsIGlobalObject;
|
||||
class nsIInputStream;
|
||||
|
||||
namespace mozilla {
|
||||
@ -162,7 +162,7 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
|
||||
JS::Handle<JS::Value> aTransfer,
|
||||
JS::CloneDataPolicy cloneDataPolicy, ErrorResult& aRv);
|
||||
|
||||
void Read(nsISupports* aParent, JSContext* aCx,
|
||||
void Read(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aValue, ErrorResult& aRv);
|
||||
|
||||
// Call this method to know if this object is keeping some DOM object alive.
|
||||
@ -191,9 +191,9 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
|
||||
|
||||
StructuredCloneScope CloneScope() const { return mStructuredCloneScope; }
|
||||
|
||||
// The parent object is set internally just during the Read(). This method
|
||||
// The global object is set internally just during the Read(). This method
|
||||
// can be used by read functions to retrieve it.
|
||||
nsISupports* ParentDuringRead() const { return mParent; }
|
||||
nsIGlobalObject* GlobalDuringRead() const { return mGlobal; }
|
||||
|
||||
// This must be called if the transferring has ports generated by Read().
|
||||
// MessagePorts are not thread-safe and they must be retrieved in the thread
|
||||
@ -270,11 +270,11 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
|
||||
// If you receive a buffer from IPC, you can use this method to retrieve a
|
||||
// JS::Value. It can happen that you want to pre-populate the array of Blobs
|
||||
// and/or the PortIdentifiers.
|
||||
void ReadFromBuffer(nsISupports* aParent, JSContext* aCx,
|
||||
void ReadFromBuffer(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JSStructuredCloneData& aBuffer,
|
||||
JS::MutableHandle<JS::Value> aValue, ErrorResult& aRv);
|
||||
|
||||
void ReadFromBuffer(nsISupports* aParent, JSContext* aCx,
|
||||
void ReadFromBuffer(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
JSStructuredCloneData& aBuffer,
|
||||
uint32_t aAlgorithmVersion,
|
||||
JS::MutableHandle<JS::Value> aValue, ErrorResult& aRv);
|
||||
@ -304,7 +304,7 @@ class StructuredCloneHolder : public StructuredCloneHolderBase {
|
||||
nsTArray<RefPtr<gfx::DataSourceSurface>> mClonedSurfaces;
|
||||
|
||||
// This raw pointer is only set within ::Read() and is unset by the end.
|
||||
nsISupports* MOZ_NON_OWNING_REF mParent;
|
||||
nsIGlobalObject* MOZ_NON_OWNING_REF mGlobal;
|
||||
|
||||
// This array contains the ports once we've finished the reading. It's
|
||||
// generated from the mPortIdentifiers array.
|
||||
|
@ -284,7 +284,7 @@ nsresult nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
|
||||
if (aBinary) {
|
||||
if (mBinaryType == DC_BINARY_TYPE_BLOB) {
|
||||
RefPtr<Blob> blob =
|
||||
Blob::CreateStringBlob(GetOwner(), aData, EmptyString());
|
||||
Blob::CreateStringBlob(GetOwnerGlobal(), aData, EmptyString());
|
||||
MOZ_ASSERT(blob);
|
||||
|
||||
if (!ToJSValue(cx, blob, &jsData)) {
|
||||
|
@ -72,7 +72,7 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct ConsoleStructuredCloneData {
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
nsTArray<RefPtr<BlobImpl>> mBlobs;
|
||||
};
|
||||
|
||||
@ -291,7 +291,7 @@ class ConsoleRunnable : public StructuredCloneHolderBase {
|
||||
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
{
|
||||
RefPtr<Blob> blob = Blob::Create(mClonedData.mParent,
|
||||
RefPtr<Blob> blob = Blob::Create(mClonedData.mGlobal,
|
||||
mClonedData.mBlobs.ElementAt(aIndex));
|
||||
if (!ToJSValue(aCx, blob, &val)) {
|
||||
return nullptr;
|
||||
@ -451,7 +451,7 @@ class ConsoleRunnable : public StructuredCloneHolderBase {
|
||||
|
||||
JS::Rooted<JS::Value> argumentsValue(aCx);
|
||||
bool ok = Read(aCx, &argumentsValue);
|
||||
mClonedData.mParent = nullptr;
|
||||
mClonedData.mGlobal = nullptr;
|
||||
|
||||
if (!ok) {
|
||||
return;
|
||||
@ -657,7 +657,8 @@ class ConsoleWorkerRunnable : public WorkerProxyToMainThreadRunnable,
|
||||
return;
|
||||
}
|
||||
|
||||
RunConsole(jsapi.cx(), aWorkerPrivate, outerWindow, aWindow);
|
||||
RunConsole(jsapi.cx(), aWindow->AsGlobal(), aWorkerPrivate, outerWindow,
|
||||
aWindow);
|
||||
}
|
||||
|
||||
void RunWindowless(WorkerPrivate* aWorkerPrivate) {
|
||||
@ -688,7 +689,12 @@ class ConsoleWorkerRunnable : public WorkerProxyToMainThreadRunnable,
|
||||
|
||||
JSAutoRealm ar(cx, global);
|
||||
|
||||
RunConsole(cx, aWorkerPrivate, nullptr, nullptr);
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = xpc::NativeGlobal(global);
|
||||
if (NS_WARN_IF(!globalObject)) {
|
||||
return;
|
||||
}
|
||||
|
||||
RunConsole(cx, globalObject, aWorkerPrivate, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void RunBackOnWorkerThreadForCleanup(WorkerPrivate* aWorkerPrivate) override {
|
||||
@ -702,7 +708,8 @@ class ConsoleWorkerRunnable : public WorkerProxyToMainThreadRunnable,
|
||||
virtual bool PreDispatch(JSContext* aCx) = 0;
|
||||
|
||||
// This method is called in the main-thread.
|
||||
virtual void RunConsole(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
||||
virtual void RunConsole(JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
nsPIDOMWindowOuter* aOuterWindow,
|
||||
nsPIDOMWindowInner* aInnerWindow) = 0;
|
||||
|
||||
@ -735,9 +742,11 @@ class ConsoleCallDataWorkerRunnable final : public ConsoleWorkerRunnable {
|
||||
return StoreConsoleData(aCx, mCallData);
|
||||
}
|
||||
|
||||
void RunConsole(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
||||
void RunConsole(JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
nsPIDOMWindowOuter* aOuterWindow,
|
||||
nsPIDOMWindowInner* aInnerWindow) override {
|
||||
MOZ_ASSERT(aGlobal);
|
||||
MOZ_ASSERT(aWorkerPrivate);
|
||||
AssertIsOnMainThread();
|
||||
|
||||
@ -768,12 +777,11 @@ class ConsoleCallDataWorkerRunnable final : public ConsoleWorkerRunnable {
|
||||
mCallData->SetIDs(id, innerID);
|
||||
}
|
||||
|
||||
// Now we could have the correct window (if we are not window-less).
|
||||
mClonedData.mParent = aInnerWindow;
|
||||
mClonedData.mGlobal = aGlobal;
|
||||
|
||||
ProcessCallData(aCx, mConsole, mCallData);
|
||||
|
||||
mClonedData.mParent = nullptr;
|
||||
mClonedData.mGlobal = nullptr;
|
||||
}
|
||||
|
||||
virtual void ReleaseData() override {
|
||||
@ -856,17 +864,18 @@ class ConsoleProfileWorkerRunnable final : public ConsoleWorkerRunnable {
|
||||
return StoreProfileData(aCx, mArguments);
|
||||
}
|
||||
|
||||
void RunConsole(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
||||
void RunConsole(JSContext* aCx, nsIGlobalObject* aGlobal,
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
nsPIDOMWindowOuter* aOuterWindow,
|
||||
nsPIDOMWindowInner* aInnerWindow) override {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(aGlobal);
|
||||
|
||||
// Now we could have the correct window (if we are not window-less).
|
||||
mClonedData.mParent = aInnerWindow;
|
||||
mClonedData.mGlobal = aGlobal;
|
||||
|
||||
ProcessProfileData(aCx, mName, mAction);
|
||||
|
||||
mClonedData.mParent = nullptr;
|
||||
mClonedData.mGlobal = nullptr;
|
||||
}
|
||||
|
||||
virtual void ReleaseData() override {}
|
||||
|
@ -286,14 +286,21 @@ already_AddRefed<File> DataTransferItem::GetAsFile(
|
||||
|
||||
if (RefPtr<Blob> blob = do_QueryObject(supports)) {
|
||||
mCachedFile = blob->ToFile();
|
||||
} else if (nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(supports)) {
|
||||
MOZ_ASSERT(blobImpl->IsFile());
|
||||
mCachedFile = File::Create(mDataTransfer, blobImpl);
|
||||
} else if (nsCOMPtr<nsIFile> ifile = do_QueryInterface(supports)) {
|
||||
mCachedFile = File::CreateFromFile(mDataTransfer, ifile);
|
||||
} else {
|
||||
MOZ_ASSERT(false, "One of the above code paths should be taken");
|
||||
return nullptr;
|
||||
nsCOMPtr<nsIGlobalObject> global = GetGlobalFromDataTransfer();
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (nsCOMPtr<BlobImpl> blobImpl = do_QueryInterface(supports)) {
|
||||
MOZ_ASSERT(blobImpl->IsFile());
|
||||
mCachedFile = File::Create(global, blobImpl);
|
||||
} else if (nsCOMPtr<nsIFile> ifile = do_QueryInterface(supports)) {
|
||||
mCachedFile = File::CreateFromFile(global, ifile);
|
||||
} else {
|
||||
MOZ_ASSERT(false, "One of the above code paths should be taken");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,20 +315,8 @@ already_AddRefed<FileSystemEntry> DataTransferItem::GetAsEntry(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global;
|
||||
// This is annoying, but DataTransfer may have various things as parent.
|
||||
nsCOMPtr<EventTarget> target =
|
||||
do_QueryInterface(mDataTransfer->GetParentObject());
|
||||
if (target) {
|
||||
global = target->GetOwnerGlobal();
|
||||
} else {
|
||||
RefPtr<Event> event = do_QueryObject(mDataTransfer->GetParentObject());
|
||||
if (event) {
|
||||
global = event->GetParentObject();
|
||||
}
|
||||
}
|
||||
|
||||
if (!global) {
|
||||
nsCOMPtr<nsIGlobalObject> global = GetGlobalFromDataTransfer();
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -390,7 +385,12 @@ already_AddRefed<File> DataTransferItem::CreateFileFromInputStream(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return File::CreateMemoryFile(mDataTransfer, data, available, fileName, mType,
|
||||
nsCOMPtr<nsIGlobalObject> global = GetGlobalFromDataTransfer();
|
||||
if (NS_WARN_IF(!global)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return File::CreateMemoryFile(global, data, available, fileName, mType,
|
||||
PR_Now());
|
||||
}
|
||||
|
||||
@ -551,5 +551,23 @@ already_AddRefed<nsIVariant> DataTransferItem::Data(nsIPrincipal* aPrincipal,
|
||||
return variant.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIGlobalObject>
|
||||
DataTransferItem::GetGlobalFromDataTransfer() {
|
||||
nsCOMPtr<nsIGlobalObject> global;
|
||||
// This is annoying, but DataTransfer may have various things as parent.
|
||||
nsCOMPtr<EventTarget> target =
|
||||
do_QueryInterface(mDataTransfer->GetParentObject());
|
||||
if (target) {
|
||||
global = target->GetOwnerGlobal();
|
||||
} else {
|
||||
RefPtr<Event> event = do_QueryObject(mDataTransfer->GetParentObject());
|
||||
if (event) {
|
||||
global = event->GetParentObject();
|
||||
}
|
||||
}
|
||||
|
||||
return global.forget();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -105,6 +105,8 @@ class DataTransferItem final : public nsISupports, public nsWrapperCache {
|
||||
~DataTransferItem() {}
|
||||
already_AddRefed<File> CreateFileFromInputStream(nsIInputStream* aStream);
|
||||
|
||||
already_AddRefed<nsIGlobalObject> GetGlobalFromDataTransfer();
|
||||
|
||||
// The index in the 2d mIndexedItems array
|
||||
uint32_t mIndex;
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "mozilla/dom/WorkerCommon.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "MultipartBlobImpl.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "StreamBlobImpl.h"
|
||||
@ -25,12 +26,12 @@ namespace dom {
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(Blob)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Blob)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Blob)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Blob)
|
||||
@ -67,43 +68,43 @@ void Blob::MakeValidBlobType(nsAString& aType) {
|
||||
}
|
||||
|
||||
/* static */
|
||||
Blob* Blob::Create(nsISupports* aParent, BlobImpl* aImpl) {
|
||||
Blob* Blob::Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl) {
|
||||
MOZ_ASSERT(aImpl);
|
||||
|
||||
return aImpl->IsFile() ? new File(aParent, aImpl) : new Blob(aParent, aImpl);
|
||||
return aImpl->IsFile() ? new File(aGlobal, aImpl) : new Blob(aGlobal, aImpl);
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Blob> Blob::CreateEmptyBlob(nsISupports* aParent,
|
||||
already_AddRefed<Blob> Blob::CreateEmptyBlob(nsIGlobalObject* aGlobal,
|
||||
const nsAString& aContentType) {
|
||||
RefPtr<Blob> blob = Blob::Create(aParent, new EmptyBlobImpl(aContentType));
|
||||
RefPtr<Blob> blob = Blob::Create(aGlobal, new EmptyBlobImpl(aContentType));
|
||||
MOZ_ASSERT(!blob->mImpl->IsFile());
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Blob> Blob::CreateStringBlob(nsISupports* aParent,
|
||||
already_AddRefed<Blob> Blob::CreateStringBlob(nsIGlobalObject* aGlobal,
|
||||
const nsACString& aData,
|
||||
const nsAString& aContentType) {
|
||||
RefPtr<BlobImpl> blobImpl = StringBlobImpl::Create(aData, aContentType);
|
||||
RefPtr<Blob> blob = Blob::Create(aParent, blobImpl);
|
||||
RefPtr<Blob> blob = Blob::Create(aGlobal, blobImpl);
|
||||
MOZ_ASSERT(!blob->mImpl->IsFile());
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Blob> Blob::CreateMemoryBlob(nsISupports* aParent,
|
||||
already_AddRefed<Blob> Blob::CreateMemoryBlob(nsIGlobalObject* aGlobal,
|
||||
void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aContentType) {
|
||||
RefPtr<Blob> blob = Blob::Create(
|
||||
aParent, new MemoryBlobImpl(aMemoryBuffer, aLength, aContentType));
|
||||
aGlobal, new MemoryBlobImpl(aMemoryBuffer, aLength, aContentType));
|
||||
MOZ_ASSERT(!blob->mImpl->IsFile());
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
Blob::Blob(nsISupports* aParent, BlobImpl* aImpl)
|
||||
: mImpl(aImpl), mParent(aParent) {
|
||||
Blob::Blob(nsIGlobalObject* aGlobal, BlobImpl* aImpl)
|
||||
: mImpl(aImpl), mGlobal(aGlobal) {
|
||||
MOZ_ASSERT(mImpl);
|
||||
}
|
||||
|
||||
@ -124,7 +125,7 @@ already_AddRefed<File> Blob::ToFile() {
|
||||
if (HasFileInterface()) {
|
||||
file = static_cast<File*>(this);
|
||||
} else {
|
||||
file = new File(mParent, mImpl);
|
||||
file = new File(mGlobal, mImpl);
|
||||
}
|
||||
|
||||
return file.forget();
|
||||
@ -143,7 +144,7 @@ already_AddRefed<File> Blob::ToFile(const nsAString& aName,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<File> file = new File(mParent, impl);
|
||||
RefPtr<File> file = new File(mGlobal, impl);
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
@ -156,7 +157,7 @@ already_AddRefed<Blob> Blob::CreateSlice(uint64_t aStart, uint64_t aLength,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(mParent, impl);
|
||||
RefPtr<Blob> blob = Blob::Create(mGlobal, impl);
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
@ -182,7 +183,7 @@ already_AddRefed<Blob> Blob::Slice(const Optional<int64_t>& aStart,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(mParent, impl);
|
||||
RefPtr<Blob> blob = Blob::Create(mGlobal, impl);
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
@ -228,7 +229,10 @@ already_AddRefed<Blob> Blob::Constructor(
|
||||
|
||||
MOZ_ASSERT(!impl->IsFile());
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(aGlobal.GetAsSupports(), impl);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(global, impl);
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
@ -261,8 +265,7 @@ already_AddRefed<Promise> Blob::ArrayBuffer(ErrorResult& aRv) {
|
||||
|
||||
already_AddRefed<Promise> Blob::ConsumeBody(
|
||||
BodyConsumer::ConsumeType aConsumeType, ErrorResult& aRv) {
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
|
||||
if (NS_WARN_IF(!global)) {
|
||||
if (NS_WARN_IF(!mGlobal)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
@ -273,7 +276,7 @@ already_AddRefed<Promise> Blob::ConsumeBody(
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
mainThreadEventTarget = workerPrivate->MainThreadEventTarget();
|
||||
} else {
|
||||
mainThreadEventTarget = global->EventTargetFor(TaskCategory::Other);
|
||||
mainThreadEventTarget = mGlobal->EventTargetFor(TaskCategory::Other);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mainThreadEventTarget);
|
||||
@ -284,7 +287,7 @@ already_AddRefed<Promise> Blob::ConsumeBody(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return BodyConsumer::Create(global, mainThreadEventTarget, inputStream,
|
||||
return BodyConsumer::Create(mGlobal, mainThreadEventTarget, inputStream,
|
||||
nullptr, aConsumeType, VoidCString(),
|
||||
VoidString(), VoidCString(),
|
||||
MutableBlobStorage::eOnlyInMemory, aRv);
|
||||
@ -353,15 +356,14 @@ void Blob::Stream(JSContext* aCx, JS::MutableHandle<JSObject*> aStream,
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
|
||||
if (NS_WARN_IF(!global)) {
|
||||
if (NS_WARN_IF(!mGlobal)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<BlobBodyStreamHolder> holder = new BlobBodyStreamHolder();
|
||||
|
||||
BodyStream::Create(aCx, holder, global, stream, aRv);
|
||||
BodyStream::Create(aCx, holder, mGlobal, stream, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
class nsIGlobalObject;
|
||||
class nsIInputStream;
|
||||
|
||||
namespace mozilla {
|
||||
@ -48,19 +49,19 @@ class Blob : public nsIMutable,
|
||||
typedef OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString BlobPart;
|
||||
|
||||
// This creates a Blob or a File based on the type of BlobImpl.
|
||||
static Blob* Create(nsISupports* aParent, BlobImpl* aImpl);
|
||||
static Blob* Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
||||
|
||||
static already_AddRefed<Blob> CreateEmptyBlob(nsISupports* aParent,
|
||||
static already_AddRefed<Blob> CreateEmptyBlob(nsIGlobalObject* aGlobal,
|
||||
const nsAString& aContentType);
|
||||
|
||||
static already_AddRefed<Blob> CreateStringBlob(nsISupports* aParent,
|
||||
static already_AddRefed<Blob> CreateStringBlob(nsIGlobalObject* aGlobal,
|
||||
const nsACString& aData,
|
||||
const nsAString& aContentType);
|
||||
|
||||
// The returned Blob takes ownership of aMemoryBuffer. aMemoryBuffer will be
|
||||
// freed by free so it must be allocated by malloc or something
|
||||
// compatible with it.
|
||||
static already_AddRefed<Blob> CreateMemoryBlob(nsISupports* aParent,
|
||||
static already_AddRefed<Blob> CreateMemoryBlob(nsIGlobalObject* aGlobal,
|
||||
void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aContentType);
|
||||
@ -97,7 +98,7 @@ class Blob : public nsIMutable,
|
||||
static void MakeValidBlobType(nsAString& aType);
|
||||
|
||||
// WebIDL methods
|
||||
nsISupports* GetParentObject() const { return mParent; }
|
||||
nsIGlobalObject* GetParentObject() const { return mGlobal; }
|
||||
|
||||
bool IsMemoryFile() const;
|
||||
|
||||
@ -132,7 +133,7 @@ class Blob : public nsIMutable,
|
||||
|
||||
protected:
|
||||
// File constructor should never be used directly. Use Blob::Create instead.
|
||||
Blob(nsISupports* aParent, BlobImpl* aImpl);
|
||||
Blob(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
||||
virtual ~Blob();
|
||||
|
||||
virtual bool HasFileInterface() const { return false; }
|
||||
@ -147,7 +148,7 @@ class Blob : public nsIMutable,
|
||||
RefPtr<BlobImpl> mImpl;
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(Blob, NS_DOM_BLOB_IID)
|
||||
|
@ -18,61 +18,61 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
File::File(nsISupports* aParent, BlobImpl* aImpl) : Blob(aParent, aImpl) {
|
||||
File::File(nsIGlobalObject* aGlobal, BlobImpl* aImpl) : Blob(aGlobal, aImpl) {
|
||||
MOZ_ASSERT(aImpl->IsFile());
|
||||
}
|
||||
|
||||
File::~File() {}
|
||||
|
||||
/* static */
|
||||
File* File::Create(nsISupports* aParent, BlobImpl* aImpl) {
|
||||
File* File::Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl) {
|
||||
MOZ_ASSERT(aImpl);
|
||||
MOZ_ASSERT(aImpl->IsFile());
|
||||
|
||||
return new File(aParent, aImpl);
|
||||
return new File(aGlobal, aImpl);
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<File> File::Create(nsISupports* aParent,
|
||||
already_AddRefed<File> File::Create(nsIGlobalObject* aGlobal,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType,
|
||||
uint64_t aLength,
|
||||
int64_t aLastModifiedDate) {
|
||||
RefPtr<File> file = new File(
|
||||
aParent, new BaseBlobImpl(NS_LITERAL_STRING("BaseBlobImpl"), aName,
|
||||
aGlobal, new BaseBlobImpl(NS_LITERAL_STRING("BaseBlobImpl"), aName,
|
||||
aContentType, aLength, aLastModifiedDate));
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<File> File::CreateMemoryFile(nsISupports* aParent,
|
||||
already_AddRefed<File> File::CreateMemoryFile(nsIGlobalObject* aGlobal,
|
||||
void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType,
|
||||
int64_t aLastModifiedDate) {
|
||||
RefPtr<File> file =
|
||||
new File(aParent, new MemoryBlobImpl(aMemoryBuffer, aLength, aName,
|
||||
new File(aGlobal, new MemoryBlobImpl(aMemoryBuffer, aLength, aName,
|
||||
aContentType, aLastModifiedDate));
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<File> File::CreateFromFile(nsISupports* aParent,
|
||||
already_AddRefed<File> File::CreateFromFile(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aFile) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
RefPtr<File> file = new File(aParent, new FileBlobImpl(aFile));
|
||||
RefPtr<File> file = new File(aGlobal, new FileBlobImpl(aFile));
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<File> File::CreateFromFile(nsISupports* aParent,
|
||||
already_AddRefed<File> File::CreateFromFile(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aFile,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||
RefPtr<File> file =
|
||||
new File(aParent, new FileBlobImpl(aFile, aName, aContentType));
|
||||
new File(aGlobal, new FileBlobImpl(aFile, aName, aContentType));
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
@ -132,7 +132,10 @@ already_AddRefed<File> File::Constructor(const GlobalObject& aGlobal,
|
||||
impl->SetLastModified(aBag.mLastModified.Value());
|
||||
}
|
||||
|
||||
RefPtr<File> file = new File(aGlobal.GetAsSupports(), impl);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
RefPtr<File> file = new File(global, impl);
|
||||
return file.forget();
|
||||
}
|
||||
|
||||
|
@ -25,9 +25,9 @@ class File final : public Blob {
|
||||
public:
|
||||
// Note: BlobImpl must be a File in order to use this method.
|
||||
// Check impl->IsFile().
|
||||
static File* Create(nsISupports* aParent, BlobImpl* aImpl);
|
||||
static File* Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
||||
|
||||
static already_AddRefed<File> Create(nsISupports* aParent,
|
||||
static already_AddRefed<File> Create(nsIGlobalObject* aGlobal,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType,
|
||||
uint64_t aLength,
|
||||
@ -36,7 +36,7 @@ class File final : public Blob {
|
||||
// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
|
||||
// freed by free so it must be allocated by malloc or something
|
||||
// compatible with it.
|
||||
static already_AddRefed<File> CreateMemoryFile(nsISupports* aParent,
|
||||
static already_AddRefed<File> CreateMemoryFile(nsIGlobalObject* aGlobal,
|
||||
void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aName,
|
||||
@ -49,10 +49,10 @@ class File final : public Blob {
|
||||
// order to use nsIMIMEService.
|
||||
// Would be nice if we try to avoid to use this method outside the
|
||||
// main-thread to avoid extra runnables.
|
||||
static already_AddRefed<File> CreateFromFile(nsISupports* aParent,
|
||||
static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aFile);
|
||||
|
||||
static already_AddRefed<File> CreateFromFile(nsISupports* aParent,
|
||||
static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aFile,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType);
|
||||
@ -98,7 +98,7 @@ class File final : public Blob {
|
||||
private:
|
||||
// File constructor should never be used directly. Use Blob::Create or
|
||||
// File::Create.
|
||||
File(nsISupports* aParent, BlobImpl* aImpl);
|
||||
File(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
|
||||
~File();
|
||||
};
|
||||
|
||||
|
@ -215,7 +215,9 @@ class CreateBlobRunnable final : public Runnable,
|
||||
nsCOMPtr<nsISupports> parent(std::move(mParent));
|
||||
RefPtr<MutableBlobStorageCallback> callback(std::move(mCallback));
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(parent, aBlobImpl);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(parent);
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(global, aBlobImpl);
|
||||
callback->BlobStoreCompleted(mBlobStorage, blob, NS_OK);
|
||||
}
|
||||
|
||||
@ -391,7 +393,9 @@ void MutableBlobStorage::GetBlobWhenReady(
|
||||
blobImpl = new EmptyBlobImpl(NS_ConvertUTF8toUTF16(aContentType));
|
||||
}
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(aParent, blobImpl);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aParent);
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(global, blobImpl);
|
||||
RefPtr<BlobCreationDoneRunnable> runnable =
|
||||
new BlobCreationDoneRunnable(this, aCallback, blob, NS_OK);
|
||||
|
||||
|
@ -27,7 +27,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Directory)
|
||||
tmp->mFileSystem->Unlink();
|
||||
tmp->mFileSystem = nullptr;
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
@ -35,7 +35,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Directory)
|
||||
if (tmp->mFileSystem) {
|
||||
tmp->mFileSystem->Traverse(cb);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Directory)
|
||||
@ -57,29 +57,35 @@ already_AddRefed<Directory> Directory::Constructor(const GlobalObject& aGlobal,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Create(aGlobal.GetAsSupports(), path);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
if (NS_WARN_IF(!global)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Create(global, path);
|
||||
}
|
||||
|
||||
/* static */
|
||||
already_AddRefed<Directory> Directory::Create(nsISupports* aParent,
|
||||
already_AddRefed<Directory> Directory::Create(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aFile,
|
||||
FileSystemBase* aFileSystem) {
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(aGlobal);
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
RefPtr<Directory> directory = new Directory(aParent, aFile, aFileSystem);
|
||||
RefPtr<Directory> directory = new Directory(aGlobal, aFile, aFileSystem);
|
||||
return directory.forget();
|
||||
}
|
||||
|
||||
Directory::Directory(nsISupports* aParent, nsIFile* aFile,
|
||||
Directory::Directory(nsIGlobalObject* aGlobal, nsIFile* aFile,
|
||||
FileSystemBase* aFileSystem)
|
||||
: mParent(aParent), mFile(aFile) {
|
||||
: mGlobal(aGlobal), mFile(aFile) {
|
||||
MOZ_ASSERT(aFile);
|
||||
|
||||
// aFileSystem can be null. In this case we create a OSFileSystem when needed.
|
||||
if (aFileSystem) {
|
||||
// More likely, this is a OSFileSystem. This object keeps a reference of
|
||||
// mParent but it's not cycle collectable and to avoid manual
|
||||
// mGlobal but it's not cycle collectable and to avoid manual
|
||||
// addref/release, it's better to have 1 object per directory. For this
|
||||
// reason we clone it here.
|
||||
mFileSystem = aFileSystem->Clone();
|
||||
@ -88,7 +94,7 @@ Directory::Directory(nsISupports* aParent, nsIFile* aFile,
|
||||
|
||||
Directory::~Directory() {}
|
||||
|
||||
nsISupports* Directory::GetParentObject() const { return mParent; }
|
||||
nsIGlobalObject* Directory::GetParentObject() const { return mGlobal; }
|
||||
|
||||
JSObject* Directory::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
@ -183,7 +189,7 @@ FileSystemBase* Directory::GetFileSystem(ErrorResult& aRv) {
|
||||
}
|
||||
|
||||
RefPtr<OSFileSystem> fs = new OSFileSystem(path);
|
||||
fs->Init(mParent);
|
||||
fs->Init(mGlobal);
|
||||
|
||||
mFileSystem = fs;
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ class Directory final : public nsISupports, public nsWrapperCache {
|
||||
const nsAString& aRealPath,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static already_AddRefed<Directory> Create(nsISupports* aParent,
|
||||
static already_AddRefed<Directory> Create(nsIGlobalObject* aGlobal,
|
||||
nsIFile* aDirectory,
|
||||
FileSystemBase* aFileSystem = 0);
|
||||
|
||||
// ========= Begin WebIDL bindings. ===========
|
||||
|
||||
nsISupports* GetParentObject() const;
|
||||
nsIGlobalObject* GetParentObject() const;
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
@ -86,7 +86,7 @@ class Directory final : public nsISupports, public nsWrapperCache {
|
||||
nsIFile* GetInternalNsIFile() const { return mFile; }
|
||||
|
||||
private:
|
||||
Directory(nsISupports* aParent, nsIFile* aFile,
|
||||
Directory(nsIGlobalObject* aGlobal, nsIFile* aFile,
|
||||
FileSystemBase* aFileSystem = nullptr);
|
||||
~Directory();
|
||||
|
||||
@ -95,7 +95,7 @@ class Directory final : public nsISupports, public nsWrapperCache {
|
||||
*/
|
||||
nsresult DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
RefPtr<FileSystemBase> mFileSystem;
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
|
||||
|
@ -21,7 +21,7 @@ void FileSystemBase::Shutdown() {
|
||||
mShutdown = true;
|
||||
}
|
||||
|
||||
nsISupports* FileSystemBase::GetParentObject() const {
|
||||
nsIGlobalObject* FileSystemBase::GetParentObject() const {
|
||||
AssertIsOnOwningThread();
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class FileSystemBase {
|
||||
|
||||
virtual bool ShouldCreateDirectory() = 0;
|
||||
|
||||
virtual nsISupports* GetParentObject() const;
|
||||
virtual nsIGlobalObject* GetParentObject() const;
|
||||
|
||||
virtual void GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
||||
ErrorResult& aRv) const;
|
||||
|
@ -37,12 +37,8 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
|
||||
MOZ_ASSERT(aDirectory);
|
||||
aFileSystem->AssertIsOnOwningThread();
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> globalObject =
|
||||
do_QueryInterface(aFileSystem->GetParentObject());
|
||||
if (NS_WARN_IF(!globalObject)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = aFileSystem->GetParentObject();
|
||||
MOZ_ASSERT(globalObject);
|
||||
|
||||
RefPtr<GetDirectoryListingTaskChild> task = new GetDirectoryListingTaskChild(
|
||||
globalObject, aFileSystem, aDirectory, aTargetPath, aFilters);
|
||||
@ -123,8 +119,10 @@ void GetDirectoryListingTaskChild::SetSuccessRequestResult(
|
||||
RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(d.blob());
|
||||
MOZ_ASSERT(blobImpl);
|
||||
|
||||
RefPtr<File> file =
|
||||
File::Create(mFileSystem->GetParentObject(), blobImpl);
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = mFileSystem->GetParentObject();
|
||||
MOZ_ASSERT(globalObject);
|
||||
|
||||
RefPtr<File> file = File::Create(globalObject, blobImpl);
|
||||
MOZ_ASSERT(file);
|
||||
|
||||
ofd->SetAsFile() = file;
|
||||
|
@ -30,8 +30,7 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
|
||||
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
||||
MOZ_ASSERT(aFileSystem);
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> globalObject =
|
||||
do_QueryInterface(aFileSystem->GetParentObject());
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = aFileSystem->GetParentObject();
|
||||
if (NS_WARN_IF(!globalObject)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
@ -91,7 +90,10 @@ void GetFileOrDirectoryTaskChild::SetSuccessRequestResult(
|
||||
RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(r.blob());
|
||||
MOZ_ASSERT(blobImpl);
|
||||
|
||||
mResultFile = File::Create(mFileSystem->GetParentObject(), blobImpl);
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = mFileSystem->GetParentObject();
|
||||
MOZ_ASSERT(globalObject);
|
||||
|
||||
mResultFile = File::Create(globalObject, blobImpl);
|
||||
MOZ_ASSERT(mResultFile);
|
||||
break;
|
||||
}
|
||||
|
@ -32,8 +32,7 @@ already_AddRefed<GetFilesTaskChild> GetFilesTaskChild::Create(
|
||||
MOZ_ASSERT(aDirectory);
|
||||
aFileSystem->AssertIsOnOwningThread();
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> globalObject =
|
||||
do_QueryInterface(aFileSystem->GetParentObject());
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = aFileSystem->GetParentObject();
|
||||
if (NS_WARN_IF(!globalObject)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
@ -107,12 +106,15 @@ void GetFilesTaskChild::SetSuccessRequestResult(
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> globalObject = mFileSystem->GetParentObject();
|
||||
MOZ_ASSERT(globalObject);
|
||||
|
||||
for (uint32_t i = 0; i < r.data().Length(); ++i) {
|
||||
const FileSystemFileResponse& data = r.data()[i];
|
||||
RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(data.blob());
|
||||
MOZ_ASSERT(blobImpl);
|
||||
|
||||
mTargetData[i] = File::Create(mFileSystem->GetParentObject(), blobImpl);
|
||||
mTargetData[i] = File::Create(globalObject, blobImpl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,29 +25,24 @@ already_AddRefed<FileSystemBase> OSFileSystem::Clone() {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
RefPtr<OSFileSystem> fs = new OSFileSystem(mLocalRootPath);
|
||||
if (mParent) {
|
||||
fs->Init(mParent);
|
||||
if (mGlobal) {
|
||||
fs->Init(mGlobal);
|
||||
}
|
||||
|
||||
return fs.forget();
|
||||
}
|
||||
|
||||
void OSFileSystem::Init(nsISupports* aParent) {
|
||||
void OSFileSystem::Init(nsIGlobalObject* aGlobal) {
|
||||
AssertIsOnOwningThread();
|
||||
MOZ_ASSERT(!mParent, "No duple Init() calls");
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(!mGlobal, "No duple Init() calls");
|
||||
MOZ_ASSERT(aGlobal);
|
||||
|
||||
mParent = aParent;
|
||||
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<nsIGlobalObject> obj = do_QueryInterface(aParent);
|
||||
MOZ_ASSERT(obj);
|
||||
#endif
|
||||
mGlobal = aGlobal;
|
||||
}
|
||||
|
||||
nsISupports* OSFileSystem::GetParentObject() const {
|
||||
nsIGlobalObject* OSFileSystem::GetParentObject() const {
|
||||
AssertIsOnOwningThread();
|
||||
return mParent;
|
||||
return mGlobal;
|
||||
}
|
||||
|
||||
bool OSFileSystem::IsSafeFile(nsIFile* aFile) const {
|
||||
@ -68,14 +63,14 @@ bool OSFileSystem::IsSafeDirectory(Directory* aDir) const {
|
||||
|
||||
void OSFileSystem::Unlink() {
|
||||
AssertIsOnOwningThread();
|
||||
mParent = nullptr;
|
||||
mGlobal = nullptr;
|
||||
}
|
||||
|
||||
void OSFileSystem::Traverse(nsCycleCollectionTraversalCallback& cb) {
|
||||
AssertIsOnOwningThread();
|
||||
|
||||
OSFileSystem* tmp = this;
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal);
|
||||
}
|
||||
|
||||
void OSFileSystem::SerializeDOMPath(nsAString& aOutput) const {
|
||||
|
@ -16,7 +16,7 @@ class OSFileSystem final : public FileSystemBase {
|
||||
public:
|
||||
explicit OSFileSystem(const nsAString& aRootDir);
|
||||
|
||||
void Init(nsISupports* aParent);
|
||||
void Init(nsIGlobalObject* aGlobal);
|
||||
|
||||
// Overrides FileSystemBase
|
||||
|
||||
@ -29,7 +29,7 @@ class OSFileSystem final : public FileSystemBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual nsISupports* GetParentObject() const override;
|
||||
virtual nsIGlobalObject* GetParentObject() const override;
|
||||
|
||||
virtual bool IsSafeFile(nsIFile* aFile) const override;
|
||||
|
||||
@ -44,7 +44,7 @@ class OSFileSystem final : public FileSystemBase {
|
||||
private:
|
||||
virtual ~OSFileSystem() {}
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
};
|
||||
|
||||
class OSFileSystemParent final : public FileSystemBase {
|
||||
@ -60,7 +60,7 @@ class OSFileSystemParent final : public FileSystemBase {
|
||||
|
||||
virtual bool ShouldCreateDirectory() override { return false; }
|
||||
|
||||
virtual nsISupports* GetParentObject() const override {
|
||||
virtual nsIGlobalObject* GetParentObject() const override {
|
||||
MOZ_CRASH("This should not be called on the PBackground thread.");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -883,8 +883,8 @@ nsresult HTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
|
||||
do_QueryInterface(OwnerDoc()->GetScopeObject());
|
||||
|
||||
// The File takes ownership of the buffer
|
||||
RefPtr<File> file =
|
||||
File::CreateMemoryFile(win, imgData, imgSize, aName, type, PR_Now());
|
||||
RefPtr<File> file = File::CreateMemoryFile(win->AsGlobal(), imgData, imgSize,
|
||||
aName, type, PR_Now());
|
||||
|
||||
file.forget(aResult);
|
||||
return NS_OK;
|
||||
|
@ -2076,7 +2076,7 @@ void HTMLInputElement::MozSetDirectory(const nsAString& aDirectoryPath,
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(window, file);
|
||||
RefPtr<Directory> directory = Directory::Create(window->AsGlobal(), file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
nsTArray<OwningFileOrDirectory> array;
|
||||
@ -6112,7 +6112,7 @@ static nsTArray<OwningFileOrDirectory> RestoreFileContentData(
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<File> file = File::Create(aWindow, it.get_BlobImpl());
|
||||
RefPtr<File> file = File::Create(aWindow->AsGlobal(), it.get_BlobImpl());
|
||||
MOZ_ASSERT(file);
|
||||
|
||||
OwningFileOrDirectory* element = res.AppendElement();
|
||||
@ -6126,7 +6126,8 @@ static nsTArray<OwningFileOrDirectory> RestoreFileContentData(
|
||||
continue;
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow, file);
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(aWindow->AsGlobal(), file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
OwningFileOrDirectory* element = res.AppendElement();
|
||||
|
@ -874,7 +874,7 @@ class MediaRecorder::Session : public PrincipalChangeObserver<MediaStreamTrack>,
|
||||
RefPtr<BlobStorer> storer = MakeAndAddRef<BlobStorer>();
|
||||
MaybeCreateMutableBlobStorage();
|
||||
mMutableBlobStorage->GetBlobWhenReady(
|
||||
mRecorder->GetOwner(), NS_ConvertUTF16toUTF8(mMimeType), storer);
|
||||
mRecorder->GetOwnerGlobal(), NS_ConvertUTF16toUTF8(mMimeType), storer);
|
||||
mMutableBlobStorage = nullptr;
|
||||
|
||||
storer->Promise()->Then(
|
||||
|
@ -48,7 +48,7 @@ nsresult CaptureTask::TaskComplete(already_AddRefed<dom::Blob> aBlob,
|
||||
// We have to set the parent because the blob has been generated with a valid
|
||||
// one.
|
||||
if (blob) {
|
||||
blob = dom::Blob::Create(mImageCapture->GetParentObject(), blob->Impl());
|
||||
blob = dom::Blob::Create(mImageCapture->GetOwnerGlobal(), blob->Impl());
|
||||
}
|
||||
|
||||
if (mPrincipalChanged) {
|
||||
|
@ -512,7 +512,7 @@ nsresult PresentationConnection::DoReceiveMessage(const nsACString& aData,
|
||||
if (aIsBinary) {
|
||||
if (mBinaryType == PresentationConnectionBinaryType::Blob) {
|
||||
RefPtr<Blob> blob =
|
||||
Blob::CreateStringBlob(GetOwner(), aData, EmptyString());
|
||||
Blob::CreateStringBlob(GetOwnerGlobal(), aData, EmptyString());
|
||||
MOZ_ASSERT(blob);
|
||||
|
||||
if (!ToJSValue(cx, blob, &jsData)) {
|
||||
|
@ -1051,7 +1051,7 @@ nsresult ExtractBytesFromData(
|
||||
}
|
||||
} // namespace
|
||||
|
||||
PushMessageData::PushMessageData(nsISupports* aOwner,
|
||||
PushMessageData::PushMessageData(nsIGlobalObject* aOwner,
|
||||
nsTArray<uint8_t>&& aBytes)
|
||||
: mOwner(aOwner), mBytes(std::move(aBytes)) {}
|
||||
|
||||
@ -1149,7 +1149,7 @@ already_AddRefed<PushEvent> PushEvent::Constructor(
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
e->mData = new PushMessageData(aOwner, std::move(bytes));
|
||||
e->mData = new PushMessageData(aOwner->GetOwnerGlobal(), std::move(bytes));
|
||||
}
|
||||
return e.forget();
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ class PushMessageData final : public nsISupports, public nsWrapperCache {
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
nsISupports* GetParentObject() const { return mOwner; }
|
||||
nsIGlobalObject* GetParentObject() const { return mOwner; }
|
||||
|
||||
void Json(JSContext* cx, JS::MutableHandle<JS::Value> aRetval,
|
||||
ErrorResult& aRv);
|
||||
@ -192,10 +192,10 @@ class PushMessageData final : public nsISupports, public nsWrapperCache {
|
||||
ErrorResult& aRv);
|
||||
already_AddRefed<mozilla::dom::Blob> Blob(ErrorResult& aRv);
|
||||
|
||||
PushMessageData(nsISupports* aOwner, nsTArray<uint8_t>&& aBytes);
|
||||
PushMessageData(nsIGlobalObject* aOwner, nsTArray<uint8_t>&& aBytes);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsCOMPtr<nsIGlobalObject> mOwner;
|
||||
nsTArray<uint8_t> mBytes;
|
||||
nsString mDecodedText;
|
||||
~PushMessageData();
|
||||
|
@ -1701,7 +1701,7 @@ XMLHttpRequestMainThread::OnDataAvailable(nsIRequest* request,
|
||||
rv = NS_GetBlobForBlobURI(blobURI, getter_AddRefs(blobImpl));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (blobImpl) {
|
||||
mResponseBlob = Blob::Create(GetOwner(), blobImpl);
|
||||
mResponseBlob = Blob::Create(GetOwnerGlobal(), blobImpl);
|
||||
}
|
||||
if (!mResponseBlob) {
|
||||
rv = NS_ERROR_FILE_NOT_FOUND;
|
||||
@ -2143,7 +2143,7 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest* request, nsresult status) {
|
||||
// mBlobStorage can be null if the channel is non-file non-cacheable
|
||||
// and if the response length is zero.
|
||||
MaybeCreateBlobStorage();
|
||||
mBlobStorage->GetBlobWhenReady(GetOwner(), contentType, this);
|
||||
mBlobStorage->GetBlobWhenReady(GetOwnerGlobal(), contentType, this);
|
||||
waitingForBlobCreation = true;
|
||||
|
||||
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
|
||||
|
@ -331,7 +331,7 @@ static void AppendBlobImplAsDirectory(nsTArray<OwningFileOrDirectory>& aArray,
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(inner, file);
|
||||
RefPtr<Directory> directory = Directory::Create(inner->AsGlobal(), file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
OwningFileOrDirectory* element = aArray.AppendElement();
|
||||
|
@ -37,6 +37,8 @@ namespace {
|
||||
nsresult LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
|
||||
bool aIsDirectory, nsIFile* aFile,
|
||||
nsISupports** aResult) {
|
||||
MOZ_ASSERT(aWindow);
|
||||
|
||||
if (aIsDirectory) {
|
||||
#ifdef DEBUG
|
||||
bool isDir;
|
||||
@ -44,14 +46,14 @@ nsresult LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
|
||||
MOZ_ASSERT(isDir);
|
||||
#endif
|
||||
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow, aFile);
|
||||
RefPtr<Directory> directory = Directory::Create(aWindow->AsGlobal(), aFile);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
directory.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
RefPtr<File> file = File::CreateFromFile(aWindow, aFile);
|
||||
RefPtr<File> file = File::CreateFromFile(aWindow->AsGlobal(), aFile);
|
||||
file.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -119,6 +121,10 @@ class nsBaseFilePickerEnumerator : public nsSimpleEnumerator {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (!mParent) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return LocalFileToDirectoryOrBlob(
|
||||
mParent, mMode == nsIFilePicker::modeGetFolder, localFile, aResult);
|
||||
}
|
||||
@ -378,6 +384,10 @@ nsBaseFilePicker::GetDomFileOrDirectory(nsISupports** aValue) {
|
||||
|
||||
auto* innerParent = mParent ? mParent->GetCurrentInnerWindow() : nullptr;
|
||||
|
||||
if (!innerParent) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return LocalFileToDirectoryOrBlob(
|
||||
innerParent, mMode == nsIFilePicker::modeGetFolder, localFile, aValue);
|
||||
}
|
||||
|
@ -146,6 +146,13 @@ nsFilePickerProxy::Open(nsIFilePickerShownCallback* aCallback) {
|
||||
|
||||
mozilla::ipc::IPCResult nsFilePickerProxy::Recv__delete__(
|
||||
const MaybeInputData& aData, const int16_t& aResult) {
|
||||
nsPIDOMWindowInner* inner =
|
||||
mParent ? mParent->GetCurrentInnerWindow() : nullptr;
|
||||
|
||||
if (NS_WARN_IF(!inner)) {
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
if (aData.type() == MaybeInputData::TInputBlobs) {
|
||||
const nsTArray<IPCBlob>& blobs = aData.get_InputBlobs().blobs();
|
||||
for (uint32_t i = 0; i < blobs.Length(); ++i) {
|
||||
@ -156,9 +163,7 @@ mozilla::ipc::IPCResult nsFilePickerProxy::Recv__delete__(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
nsPIDOMWindowInner* inner =
|
||||
mParent ? mParent->GetCurrentInnerWindow() : nullptr;
|
||||
RefPtr<File> file = File::Create(inner, blobImpl);
|
||||
RefPtr<File> file = File::Create(inner->AsGlobal(), blobImpl);
|
||||
MOZ_ASSERT(file);
|
||||
|
||||
OwningFileOrDirectory* element = mFilesOrDirectories.AppendElement();
|
||||
@ -172,8 +177,7 @@ mozilla::ipc::IPCResult nsFilePickerProxy::Recv__delete__(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
RefPtr<Directory> directory =
|
||||
Directory::Create(mParent->GetCurrentInnerWindow(), file);
|
||||
RefPtr<Directory> directory = Directory::Create(inner->AsGlobal(), file);
|
||||
MOZ_ASSERT(directory);
|
||||
|
||||
OwningFileOrDirectory* element = mFilesOrDirectories.AppendElement();
|
||||
|
Loading…
Reference in New Issue
Block a user