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 446358 a6266aced6f74cf3c643ab0e84816716ee8e0a16
parent 446357 317ad6a3e65887809451cf99a3709f6b250ff5e5
child 446359 25705af5dd38f1f5504d39896568c3eb7cd5e3f7
push id37777
push userbmo:kaku@mozilla.com
push dateThu, 01 Dec 2016 09:24:28 +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
@@ -2465,24 +2465,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()) {
@@ -7003,16 +6996,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()
 {
   nsCOMPtr<nsIRunnable> event
     = new nsResolveOrRejectPendingPlayPromisesRunner(this,
                                                      TakePendingPlayPromises());
 
   NS_DispatchToMainThread(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;