2014-07-17 20:40:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-17 20:40:54 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "IDBFileRequest.h"
|
|
|
|
|
|
|
|
#include "IDBFileHandle.h"
|
|
|
|
#include "js/RootingAPI.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/dom/IDBFileRequestBinding.h"
|
|
|
|
#include "mozilla/dom/ProgressEvent.h"
|
2015-09-09 14:15:05 +03:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-07-17 20:40:54 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsLiteralString.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2016-02-17 00:46:08 +03:00
|
|
|
|
|
|
|
using namespace mozilla::dom::indexedDB;
|
2014-07-17 20:40:54 +04:00
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
IDBFileRequest::IDBFileRequest(IDBFileHandle* aFileHandle,
|
2015-09-09 14:15:05 +03:00
|
|
|
bool aWrapAsDOMRequest)
|
2019-03-29 21:05:11 +03:00
|
|
|
: DOMRequest(aFileHandle->GetOwnerGlobal()),
|
2015-09-09 14:15:05 +03:00
|
|
|
mFileHandle(aFileHandle),
|
|
|
|
mWrapAsDOMRequest(aWrapAsDOMRequest),
|
2017-06-07 13:36:42 +03:00
|
|
|
mHasEncoding(false) {
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
aFileHandle->AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IDBFileRequest::~IDBFileRequest() { AssertIsOnOwningThread(); }
|
|
|
|
|
|
|
|
// static
|
2019-12-16 17:35:59 +03:00
|
|
|
RefPtr<IDBFileRequest> IDBFileRequest::Create(IDBFileHandle* aFileHandle,
|
|
|
|
bool aWrapAsDOMRequest) {
|
2015-09-09 14:15:05 +03:00
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
aFileHandle->AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
|
2019-12-16 17:35:59 +03:00
|
|
|
return new IDBFileRequest(aFileHandle, aWrapAsDOMRequest);
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
void IDBFileRequest::FireProgressEvent(uint64_t aLoaded, uint64_t aTotal) {
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2019-04-01 19:46:46 +03:00
|
|
|
if (NS_FAILED(CheckCurrentGlobalCorrectness())) {
|
2017-06-07 13:36:42 +03:00
|
|
|
return;
|
2015-09-09 14:15:05 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
ProgressEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mLengthComputable = false;
|
|
|
|
init.mLoaded = aLoaded;
|
|
|
|
init.mTotal = aTotal;
|
2015-09-09 14:15:05 +03:00
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
RefPtr<ProgressEvent> event =
|
2020-07-01 11:29:29 +03:00
|
|
|
ProgressEvent::Constructor(this, u"progress"_ns, init);
|
2017-06-07 13:36:42 +03:00
|
|
|
DispatchTrustedEvent(event);
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBFileRequest, DOMRequest)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBFileRequest, DOMRequest)
|
|
|
|
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBFileRequest)
|
2017-06-07 13:36:42 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMRequest)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(IDBFileRequest, DOMRequest, mFileHandle)
|
|
|
|
|
|
|
|
void IDBFileRequest::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
aVisitor.mCanHandle = true;
|
2017-12-18 19:07:36 +03:00
|
|
|
aVisitor.SetParentTarget(mFileHandle, false);
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
// virtual
|
|
|
|
JSObject* IDBFileRequest::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2017-06-07 13:36:42 +03:00
|
|
|
if (mWrapAsDOMRequest) {
|
|
|
|
return DOMRequest::WrapObject(aCx, aGivenProto);
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
2018-06-26 00:20:54 +03:00
|
|
|
return IDBFileRequest_Binding::Wrap(aCx, this, aGivenProto);
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|