Bug 1244768 part 8 - extract the HTMLMediaElement::CreateDOMPromise() utility; r?jwwang
MozReview-Commit-ID: 28NopfA8lgV
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2491,24 +2491,17 @@ IsInRanges(dom::TimeRanges& aRanges,
already_AddRefed<Promise>
HTMLMediaElement::Seek(double aTime,
SeekTarget::Type aSeekType,
ErrorResult& aRv)
{
// aTime should be non-NaN.
MOZ_ASSERT(!mozilla::IsNaN(aTime));
- nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(OwnerDoc()->GetInnerWindow());
-
- if (!global) {
- aRv.Throw(NS_ERROR_UNEXPECTED);
- return nullptr;
- }
-
- RefPtr<Promise> promise = Promise::Create(global, aRv);
+ RefPtr<Promise> promise = CreateDOMPromise(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// Detect if user has interacted with element by seeking so that
// play will not be blocked when initiated by a script.
if (EventStateManager::IsHandlingUserInput()) {
@@ -7036,16 +7029,29 @@ HTMLMediaElement::TakePendingPlayPromise
void
HTMLMediaElement::NotifyAboutPlaying()
{
// Stick to the DispatchAsyncEvent() call path for now because we want to
// trigger some telemetry-related codes in the DispatchAsyncEvent() method.
DispatchAsyncEvent(NS_LITERAL_STRING("playing"));
}
+already_AddRefed<Promise>
+HTMLMediaElement::CreateDOMPromise(ErrorResult& aRv) const
+{
+ nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(OwnerDoc()->GetInnerWindow());
+
+ if (!global) {
+ aRv.Throw(NS_ERROR_UNEXPECTED);
+ return nullptr;
+ }
+
+ return Promise::Create(global, aRv);
+}
+
void
HTMLMediaElement::AsyncResolvePendingPlayPromises()
{
if (mShuttingDown) {
return;
}
nsCOMPtr<nsIRunnable> event
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1254,16 +1254,18 @@ protected:
// This method snapshots the mPendingPlayPromises by TakePendingPlayPromises()
// and queues a task to reject them.
void AsyncRejectPendingPlayPromises(nsresult aError);
// This method snapshots the mPendingPlayPromises by TakePendingPlayPromises()
// and queues a task to resolve them also to dispatch a "playing" event.
void NotifyAboutPlaying();
+ already_AddRefed<Promise> CreateDOMPromise(ErrorResult& aRv) const;
+
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;
// Observers listening to changes to the mDecoder principal.
// Used by streams captured from this element.
nsTArray<DecoderPrincipalChangeObserver*> mDecoderPrincipalChangeObservers;