already_AddRefed<Promise> MediaDevices::GetDisplayMedia( const DisplayMediaStreamConstraints& aConstraints, CallerType aCallerType, ErrorResult& aRv) { RefPtr<Promise> p = Promise::Create(GetParentObject(), aRv); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } RefPtr<MediaDevices> self(this); MediaManager::Get() ->GetDisplayMedia(GetOwner(), aConstraints, aCallerType) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [this, self, p](RefPtr<DOMMediaStream>&& aStream) { if (!GetWindowIfCurrent()) { return; // leave promise pending after navigation. } p->MaybeResolve(std::move(aStream)); }, [this, self, p](RefPtr<MediaMgrError>&& error) { nsPIDOMWindowInner* window = GetWindowIfCurrent(); if (!window) { return; // leave promise pending after navigation. } p->MaybeReject(MakeRefPtr<MediaStreamError>(window, *error)); }); return p.forget(); }
IPCBlobInputStreamChild::IPCBlobInputStreamChild(const nsID& aID, uint64_t aSize) : mMutex("IPCBlobInputStreamChild::mMutex") , mID(aID) , mSize(aSize) , mState(eActive) , mOwningEventTarget(GetCurrentThreadSerialEventTarget()) { // If we are running in a worker, we need to send a Close() to the parent side // before the thread is released. if (!NS_IsMainThread()) { WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); if (!workerPrivate) { return; } RefPtr<StrongWorkerRef> workerRef = StrongWorkerRef::Create(workerPrivate, "IPCBlobInputStreamChild"); if (!workerRef) { return; } // We must keep the worker alive until the migration is completed. mWorkerRef = new ThreadSafeWorkerRef(workerRef); } }
void IPCBlobInputStreamChild::Migrated() { MutexAutoLock lock(mMutex); MOZ_ASSERT(mState == eInactiveMigrating); mWorkerRef = nullptr; mOwningEventTarget = GetCurrentThreadSerialEventTarget(); MOZ_ASSERT(IPCBlobInputStreamThread::IsOnFileEventTarget(mOwningEventTarget)); // Maybe we have no reasons to keep this actor alive. if (mStreams.IsEmpty()) { mState = eInactive; SendClose(); return; } mState = eActive; // Let's processing the pending operations. We need a stream for each pending // operation. for (uint32_t i = 0; i < mPendingOperations.Length(); ++i) { if (mPendingOperations[i].mOp == PendingOperation::eStreamNeeded) { SendStreamNeeded(); } else { MOZ_ASSERT(mPendingOperations[i].mOp == PendingOperation::eLengthNeeded); SendLengthNeeded(); } } }
FileReader::FileReader(nsIGlobalObject* aGlobal, WeakWorkerRef* aWorkerRef) : DOMEventTargetHelper(aGlobal) , mFileData(nullptr) , mDataLen(0) , mDataFormat(FILE_AS_BINARY) , mResultArrayBuffer(nullptr) , mProgressEventWasDelayed(false) , mTimerIsActive(false) , mReadyState(EMPTY) , mTotal(0) , mTransferred(0) , mBusyCount(0) , mWeakWorkerRef(aWorkerRef) { MOZ_ASSERT(aGlobal); MOZ_ASSERT_IF(NS_IsMainThread(), !mWeakWorkerRef); if (NS_IsMainThread()) { mTarget = aGlobal->EventTargetFor(TaskCategory::Other); } else { mTarget = GetCurrentThreadSerialEventTarget(); } SetDOMStringToNull(mResult); }
void U2FTokenManager::Sign(PWebAuthnTransactionParent* aTransactionParent, const uint64_t& aTransactionId, const WebAuthnGetAssertionInfo& aTransactionInfo) { MOZ_LOG(gU2FTokenManagerLog, LogLevel::Debug, ("U2FAuthSign")); ClearTransaction(); mTransactionParent = aTransactionParent; mTokenManagerImpl = GetTokenManagerImpl(); if (!mTokenManagerImpl) { AbortTransaction(aTransactionId, NS_ERROR_DOM_NOT_ALLOWED_ERR); return; } if ((aTransactionInfo.RpIdHash().Length() != SHA256_LENGTH) || (aTransactionInfo.ClientDataHash().Length() != SHA256_LENGTH)) { AbortTransaction(aTransactionId, NS_ERROR_DOM_UNKNOWN_ERR); return; } // Show a prompt that lets the user cancel the ongoing transaction. NS_ConvertUTF16toUTF8 origin(aTransactionInfo.Origin()); SendPromptNotification(kSignPromptNotifcation, aTransactionId, origin.get()); uint64_t tid = mLastTransactionId = aTransactionId; mozilla::TimeStamp startTime = mozilla::TimeStamp::Now(); mTokenManagerImpl ->Sign(aTransactionInfo) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [tid, startTime](WebAuthnGetAssertionResult&& aResult) { U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeConfirmSign(tid, aResult); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FSignFinish"), 1); Telemetry::AccumulateTimeDelta( Telemetry::WEBAUTHN_GET_ASSERTION_MS, startTime); }, [tid](nsresult rv) { MOZ_ASSERT(NS_FAILED(rv)); U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeAbortSign(tid, rv); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FSignAbort"), 1); }) ->Track(mSignPromise); }
void U2FTokenManager::Register(PWebAuthnTransactionParent* aTransactionParent, const uint64_t& aTransactionId, const WebAuthnMakeCredentialInfo& aTransactionInfo) { MOZ_LOG(gU2FTokenManagerLog, LogLevel::Debug, ("U2FAuthRegister")); ClearTransaction(); mTransactionParent = aTransactionParent; mTokenManagerImpl = GetTokenManagerImpl(); if (!mTokenManagerImpl) { AbortTransaction(aTransactionId, NS_ERROR_DOM_NOT_ALLOWED_ERR); return; } // Check if all the supplied parameters are syntactically well-formed and // of the correct length. If not, return an error code equivalent to // UnknownError and terminate the operation. if ((aTransactionInfo.RpIdHash().Length() != SHA256_LENGTH) || (aTransactionInfo.ClientDataHash().Length() != SHA256_LENGTH)) { AbortTransaction(aTransactionId, NS_ERROR_DOM_UNKNOWN_ERR); return; } uint64_t tid = mLastTransactionId = aTransactionId; mozilla::TimeStamp startTime = mozilla::TimeStamp::Now(); mTokenManagerImpl->Register(aTransactionInfo.ExcludeList(), aTransactionInfo.AuthenticatorSelection(), aTransactionInfo.RpIdHash(), aTransactionInfo.ClientDataHash(), aTransactionInfo.TimeoutMS()) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [tid, startTime](U2FRegisterResult&& aResult) { U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeConfirmRegister(tid, aResult); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FRegisterFinish"), 1); Telemetry::AccumulateTimeDelta( Telemetry::WEBAUTHN_CREATE_CREDENTIAL_MS, startTime); }, [tid](nsresult rv) { MOZ_ASSERT(NS_FAILED(rv)); U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeAbortRegister(tid, rv); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FRegisterAbort"), 1); }) ->Track(mRegisterPromise); }
void U2FTokenManager::DoRegister(const WebAuthnMakeCredentialInfo& aInfo) { mozilla::ipc::AssertIsOnBackgroundThread(); MOZ_ASSERT(mLastTransactionId > 0); // Show a prompt that lets the user cancel the ongoing transaction. NS_ConvertUTF16toUTF8 origin(aInfo.Origin()); SendPromptNotification(kRegisterPromptNotifcation, mLastTransactionId, origin.get()); uint64_t tid = mLastTransactionId; mozilla::TimeStamp startTime = mozilla::TimeStamp::Now(); bool requestDirectAttestation = aInfo.RequestDirectAttestation(); mTokenManagerImpl ->Register(aInfo) ->Then(GetCurrentThreadSerialEventTarget(), __func__, [tid, startTime, requestDirectAttestation](WebAuthnMakeCredentialResult&& aResult) { U2FTokenManager* mgr = U2FTokenManager::Get(); // The token manager implementations set DirectAttestationPermitted // to false by default. Override this here with information from // the JS prompt. aResult.DirectAttestationPermitted() = requestDirectAttestation; mgr->MaybeConfirmRegister(tid, aResult); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FRegisterFinish"), 1); Telemetry::AccumulateTimeDelta( Telemetry::WEBAUTHN_CREATE_CREDENTIAL_MS, startTime); }, [tid](nsresult rv) { MOZ_ASSERT(NS_FAILED(rv)); U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeAbortRegister(tid, rv); Telemetry::ScalarAdd( Telemetry::ScalarID::SECURITY_WEBAUTHN_USED, NS_LITERAL_STRING("U2FRegisterAbort"), 1); }) ->Track(mRegisterPromise); }
ServiceWorkerCloneData::ServiceWorkerCloneData() : mEventTarget(GetCurrentThreadSerialEventTarget()) { MOZ_DIAGNOSTIC_ASSERT(mEventTarget); }