Bug 1244768 part 8 - extract the HTMLMediaElement::CreateDOMPromise() utility; r?jwwang draft
authorKaku Kuo <tkuo@mozilla.com>
Mon, 08 Aug 2016 16:53:20 +0800
changeset 448117 55a1917f730b460bbe16f17a3296a2887c21551e
parent 448116 8ee66b17f9a4059b956659f5aa20c0b2da8df308
child 448118 ce933def6ca5f343773a487bfd6305ff89ba19b0
push id38268
push userbmo:kaku@mozilla.com
push dateFri, 09 Dec 2016 07:03:42 +0000
reviewersjwwang
bugs1244768
milestone53.0a1
Bug 1244768 part 8 - extract the HTMLMediaElement::CreateDOMPromise() utility; r?jwwang MozReview-Commit-ID: 28NopfA8lgV
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
--- 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;