Bug 1373888 - part6 : only release the wakelock when video is paused. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 29 Aug 2017 15:25:57 +0800
changeset 654755 73ab88c767be6926abd51d39bcfc40e41bf3bd49
parent 654754 0e9ddbb58cbab18e4d54b2f5de89359f8b37c6ce
child 654756 0cb777f01d296511fad45ee5ba5d8433b405b7da
push id76666
push useralwu@mozilla.com
push dateTue, 29 Aug 2017 07:28:48 +0000
bugs1373888
milestone57.0a1
Bug 1373888 - part6 : only release the wakelock when video is paused. Wakelock would automatically handle the lock/unlock by listening "hidden/visible", we don't need to handle it in HTMLVideoElement. MozReview-Commit-ID: AcOwR2nqm6L
dom/html/HTMLMediaElement.h
dom/html/HTMLVideoElement.cpp
dom/html/HTMLVideoElement.h
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -155,22 +155,16 @@ public:
   virtual void UnbindFromTree(bool aDeep = true,
                               bool aNullParent = true) override;
   virtual void DoneCreatingElement() override;
 
   virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable,
                                int32_t *aTabIndex) override;
   virtual int32_t TabIndexDefault() override;
 
-  /**
-   * Call this to reevaluate whether we should start/stop due to our owner
-   * document being active, inactive, visible or hidden.
-   */
-  virtual void NotifyOwnerDocumentActivityChanged();
-
   // Called by the video decoder object, on the main thread,
   // when it has read the metadata containing video dimensions,
   // etc.
   virtual void MetadataLoaded(const MediaInfo* aInfo,
                               nsAutoPtr<const MetadataTags> aTags) final override;
 
   // Called by the decoder object, on the main thread,
   // when it has read the first frame of the video or audio.
@@ -233,16 +227,22 @@ public:
 
   virtual bool IsHidden() const final override;
 
   // Called by the media decoder and the video frame to get the
   // ImageContainer containing the video data.
   virtual VideoFrameContainer* GetVideoFrameContainer() final override;
   layers::ImageContainer* GetImageContainer();
 
+  /**
+   * Call this to reevaluate whether we should start/stop due to our owner
+   * document being active, inactive, visible or hidden.
+   */
+  void NotifyOwnerDocumentActivityChanged();
+
   // From PrincipalChangeObserver<DOMMediaStream>.
   void PrincipalChanged(DOMMediaStream* aStream) override;
 
   void UpdateSrcStreamVideoPrincipal(const PrincipalHandle& aPrincipalHandle);
 
   // Called after the MediaStream we're playing rendered a frame to aContainer
   // with a different principalHandle than the previous frame.
   void PrincipalHandleChangedForVideoFrameContainer(VideoFrameContainer* aContainer,
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -230,23 +230,16 @@ bool HTMLVideoElement::MozHasAudio() con
 }
 
 JSObject*
 HTMLVideoElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return HTMLVideoElementBinding::Wrap(aCx, this, aGivenProto);
 }
 
-void
-HTMLVideoElement::NotifyOwnerDocumentActivityChanged()
-{
-  HTMLMediaElement::NotifyOwnerDocumentActivityChanged();
-  UpdateScreenWakeLock();
-}
-
 FrameStatistics*
 HTMLVideoElement::GetFrameStatistics()
 {
   return mDecoder ? &(mDecoder->GetFrameStatistics()) : nullptr;
 }
 
 already_AddRefed<VideoPlaybackQuality>
 HTMLVideoElement::GetVideoPlaybackQuality()
@@ -313,27 +306,25 @@ HTMLVideoElement::WakeLockRelease()
 {
   UpdateScreenWakeLock();
   HTMLMediaElement::WakeLockRelease();
 }
 
 void
 HTMLVideoElement::UpdateScreenWakeLock()
 {
-  bool hidden = OwnerDoc()->Hidden();
-
-  if (mScreenWakeLock && (mPaused || hidden)) {
+  if (mScreenWakeLock && mPaused) {
     ErrorResult rv;
     mScreenWakeLock->Unlock(rv);
     rv.SuppressException();
     mScreenWakeLock = nullptr;
     return;
   }
 
-  if (!mScreenWakeLock && !mPaused && !hidden && HasVideo()) {
+  if (!mScreenWakeLock && !mPaused && HasVideo()) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
     mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("video-playing"),
                                              OwnerDoc()->GetInnerWindow(),
                                              rv);
--- a/dom/html/HTMLVideoElement.h
+++ b/dom/html/HTMLVideoElement.h
@@ -124,18 +124,16 @@ public:
   uint32_t MozPresentedFrames() const;
 
   uint32_t MozPaintedFrames();
 
   double MozFrameDelay();
 
   bool MozHasAudio() const;
 
-  void NotifyOwnerDocumentActivityChanged() override;
-
   // Gives access to the decoder's frame statistics, if present.
   FrameStatistics* GetFrameStatistics();
 
   already_AddRefed<VideoPlaybackQuality> GetVideoPlaybackQuality();
 
 
   bool MozOrientationLockEnabled() const
   {