Bug 1438956 - Remove nsIDOMTimeRanges. r?bz draft
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Fri, 16 Feb 2018 19:34:28 +0100
changeset 756265 09b2a94883e8a70813d318017311a5efb1120856
parent 756125 928f0f09172fae67f6ec00e7a63969f7b28bd12e
child 756266 9daad14d4dcde5233997e6582fd3829af6ebd681
push id99450
push userbmo:adrian.wielgosik@gmail.com
push dateFri, 16 Feb 2018 18:37:10 +0000
reviewersbz
bugs1438956
milestone60.0a1
Bug 1438956 - Remove nsIDOMTimeRanges. r?bz MozReview-Commit-ID: DAgQ0OkSxkq
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
dom/html/TimeRanges.cpp
dom/html/TimeRanges.h
dom/interfaces/html/moz.build
dom/interfaces/html/nsIDOMTimeRanges.idl
xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2688,51 +2688,43 @@ HTMLMediaElement::SeekToNextFrame(ErrorR
 
 void
 HTMLMediaElement::SetCurrentTime(double aCurrentTime, ErrorResult& aRv)
 {
   RefPtr<Promise> tobeDropped = Seek(aCurrentTime, SeekTarget::Accurate, aRv);
 }
 
 /**
- * Check if aValue is inside a range of aRanges, and if so sets aIsInRanges
- * to true and put the range index in aIntervalIndex. If aValue is not
- * inside a range, aIsInRanges is set to false, and aIntervalIndex
+ * Check if aValue is inside a range of aRanges, and if so returns true
+ * and puts the range index in aIntervalIndex. If aValue is not
+ * inside a range, returns false, and aIntervalIndex
  * is set to the index of the range which ends immediately before aValue
- * (and can be -1 if aValue is before aRanges.Start(0)). Returns NS_OK
- * on success, and NS_ERROR_FAILURE on failure.
+ * (and can be -1 if aValue is before aRanges.Start(0)).
  */
-static nsresult
+static bool
 IsInRanges(TimeRanges& aRanges,
            double aValue,
-           bool& aIsInRanges,
            int32_t& aIntervalIndex)
 {
-  aIsInRanges = false;
-  uint32_t length;
-  nsresult rv = aRanges.GetLength(&length);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t length = aRanges.Length();
+
   for (uint32_t i = 0; i < length; i++) {
-    double start, end;
-    rv = aRanges.Start(i, &start);
-    NS_ENSURE_SUCCESS(rv, rv);
+    double start = aRanges.Start(i, IgnoreErrors());
     if (start > aValue) {
       aIntervalIndex = i - 1;
-      return NS_OK;
-    }
-    rv = aRanges.End(i, &end);
-    NS_ENSURE_SUCCESS(rv, rv);
+      return false;
+    }
+    double end = aRanges.End(i, IgnoreErrors());
     if (aValue <= end) {
       aIntervalIndex = i;
-      aIsInRanges = true;
-      return NS_OK;
+      return true;
     }
   }
   aIntervalIndex = length - 1;
-  return NS_OK;
+  return false;
 }
 
 already_AddRefed<Promise>
 HTMLMediaElement::Seek(double aTime,
                        SeekTarget::Type aSeekType,
                        ErrorResult& aRv)
 {
   // aTime should be non-NaN.
@@ -2786,68 +2778,53 @@ HTMLMediaElement::Seek(double aTime,
   // Clamp the seek target to inside the seekable ranges.
   media::TimeIntervals seekableIntervals = mDecoder->GetSeekable();
   if (seekableIntervals.IsInvalid()) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); // This will reject the promise.
     return promise.forget();
   }
   RefPtr<TimeRanges> seekable =
     new TimeRanges(ToSupports(OwnerDoc()), seekableIntervals);
-  uint32_t length = 0;
-  seekable->GetLength(&length);
-  if (!length) {
+  uint32_t length = seekable->Length();
+  if (length == 0) {
     promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
     return promise.forget();
   }
 
   // If the position we want to seek to is not in a seekable range, we seek
   // to the closest position in the seekable ranges instead. If two positions
   // are equally close, we seek to the closest position from the currentTime.
   // See seeking spec, point 7 :
   // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#seeking
   int32_t range = 0;
-  bool isInRange = false;
-  if (NS_FAILED(IsInRanges(*seekable, aTime, isInRange, range))) {
-    aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); // This will reject the promise.
-    return promise.forget();
-  }
+  bool isInRange = IsInRanges(*seekable, aTime, range);
   if (!isInRange) {
     if (range != -1) {
       // |range + 1| can't be negative, because the only possible negative value
       // for |range| is -1.
       if (uint32_t(range + 1) < length) {
-        double leftBound, rightBound;
-        if (NS_FAILED(seekable->End(range, &leftBound))) {
-          aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-          return promise.forget();
-        }
-        if (NS_FAILED(seekable->Start(range + 1, &rightBound))) {
-          aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-          return promise.forget();
-        }
+        double leftBound = seekable->End(range, IgnoreErrors());
+        double rightBound = seekable->Start(range + 1, IgnoreErrors());
         double distanceLeft = Abs(leftBound - aTime);
         double distanceRight = Abs(rightBound - aTime);
         if (distanceLeft == distanceRight) {
           double currentTime = CurrentTime();
           distanceLeft = Abs(leftBound - currentTime);
           distanceRight = Abs(rightBound - currentTime);
         }
         aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
       } else {
         // Seek target is after the end last range in seekable data.
         // Clamp the seek target to the end of the last seekable range.
-        if (NS_FAILED(seekable->End(length - 1, &aTime))) {
-          aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
-          return promise.forget();
-        }
+        aTime = seekable->GetEndTime();
       }
     } else {
       // aTime is before the first range in |seekable|, the closest point we can
       // seek to is the start of the first range.
-      seekable->Start(0, &aTime);
+      aTime = seekable->GetStartTime();
     }
   }
 
   // TODO: The spec requires us to update the current time to reflect the
   //       actual seek target before beginning the synchronous section, but
   //       that requires changing all MediaDecoderReaders to support telling
   //       us the fastSeek target, and it's currently not possible to get
   //       this information as we don't yet control the demuxer for all
@@ -2898,23 +2875,21 @@ HTMLMediaElement::Seekable() const
 
 already_AddRefed<TimeRanges>
 HTMLMediaElement::Played()
 {
   RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
 
   uint32_t timeRangeCount = 0;
   if (mPlayed) {
-    mPlayed->GetLength(&timeRangeCount);
+    timeRangeCount = mPlayed->Length();
   }
   for (uint32_t i = 0; i < timeRangeCount; i++) {
-    double begin;
-    double end;
-    mPlayed->Start(i, &begin);
-    mPlayed->End(i, &end);
+    double begin = mPlayed->Start(i, IgnoreErrors());
+    double end = mPlayed->End(i, IgnoreErrors());
     ranges->Add(begin, end);
   }
 
   if (mCurrentPlayRangeStart != -1.0) {
     double now = CurrentTime();
     if (mCurrentPlayRangeStart != now) {
       ranges->Add(mCurrentPlayRangeStart, now);
     }
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -347,24 +347,21 @@ HTMLVideoElement::IsVideoStatsEnabled()
 }
 
 double
 HTMLVideoElement::TotalPlayTime() const
 {
   double total = 0.0;
 
   if (mPlayed) {
-    uint32_t timeRangeCount = 0;
-    mPlayed->GetLength(&timeRangeCount);
+    uint32_t timeRangeCount = mPlayed->Length();
 
     for (uint32_t i = 0; i < timeRangeCount; i++) {
-      double begin;
-      double end;
-      mPlayed->Start(i, &begin);
-      mPlayed->End(i, &end);
+      double begin = mPlayed->Start(i, IgnoreErrors());
+      double end = mPlayed->End(i, IgnoreErrors());
       total += end - begin;
     }
 
     if (mCurrentPlayRangeStart != -1.0) {
       double now = CurrentTime();
       if (mCurrentPlayRangeStart != now) {
         total += now - mCurrentPlayRangeStart;
       }
--- a/dom/html/TimeRanges.cpp
+++ b/dom/html/TimeRanges.cpp
@@ -13,17 +13,16 @@
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TimeRanges, mParent)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(TimeRanges)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(TimeRanges)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TimeRanges)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsIDOMTimeRanges)
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 TimeRanges::TimeRanges()
   : mParent(nullptr)
 {
 }
 
@@ -60,61 +59,38 @@ TimeRanges::ToTimeIntervals() const
   }
   return t;
 }
 
 TimeRanges::~TimeRanges()
 {
 }
 
-NS_IMETHODIMP
-TimeRanges::GetLength(uint32_t* aLength)
-{
-  *aLength = Length();
-  return NS_OK;
-}
-
 double
 TimeRanges::Start(uint32_t aIndex, ErrorResult& aRv) const
 {
   if (aIndex >= mRanges.Length()) {
     aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
     return 0;
   }
 
   return mRanges[aIndex].mStart;
 }
 
-NS_IMETHODIMP
-TimeRanges::Start(uint32_t aIndex, double* aTime)
-{
-  ErrorResult rv;
-  *aTime = Start(aIndex, rv);
-  return rv.StealNSResult();
-}
-
 double
 TimeRanges::End(uint32_t aIndex, ErrorResult& aRv) const
 {
   if (aIndex >= mRanges.Length()) {
     aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
     return 0;
   }
 
   return mRanges[aIndex].mEnd;
 }
 
-NS_IMETHODIMP
-TimeRanges::End(uint32_t aIndex, double* aTime)
-{
-  ErrorResult rv;
-  *aTime = End(aIndex, rv);
-  return rv.StealNSResult();
-}
-
 void
 TimeRanges::Add(double aStart, double aEnd)
 {
   if (aStart > aEnd) {
     NS_WARNING("Can't add a range if the end is older that the start.");
     return;
   }
   mRanges.AppendElement(TimeRange(aStart,aEnd));
--- a/dom/html/TimeRanges.h
+++ b/dom/html/TimeRanges.h
@@ -3,40 +3,38 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_TimeRanges_h_
 #define mozilla_dom_TimeRanges_h_
 
 #include "nsCOMPtr.h"
-#include "nsIDOMTimeRanges.h"
 #include "nsISupports.h"
 #include "nsTArray.h"
 #include "nsWrapperCache.h"
 #include "mozilla/ErrorResult.h"
 #include "TimeUnits.h"
 
 namespace mozilla {
 
 namespace dom {
 class TimeRanges;
 } // namespace dom
 
 namespace dom {
 
 // Implements media TimeRanges:
 // http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#timeranges
-class TimeRanges final : public nsIDOMTimeRanges,
+class TimeRanges final : public nsISupports,
                          public nsWrapperCache
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TimeRanges)
-  NS_DECL_NSIDOMTIMERANGES
 
   TimeRanges();
   explicit TimeRanges(nsISupports* aParent);
   explicit TimeRanges(const media::TimeIntervals& aTimeIntervals);
   TimeRanges(nsISupports* aParent, const media::TimeIntervals& aTimeIntervals);
 
   media::TimeIntervals ToTimeIntervals() const;
 
--- a/dom/interfaces/html/moz.build
+++ b/dom/interfaces/html/moz.build
@@ -6,14 +6,13 @@
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "DOM")
 
 XPIDL_SOURCES += [
     'nsIDOMHTMLFormElement.idl',
     'nsIDOMHTMLInputElement.idl',
     'nsIDOMMozBrowserFrame.idl',
-    'nsIDOMTimeRanges.idl',
     'nsIMozBrowserFrame.idl',
 ]
 
 XPIDL_MODULE = 'dom_html'
 
deleted file mode 100644
--- a/dom/interfaces/html/nsIDOMTimeRanges.idl
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "domstubs.idl"
-
-[uuid(c43448db-0bab-461d-b648-1ca14a967f7e)]
-interface nsIDOMTimeRanges : nsISupports
-{
-  /* The number of ranges represented by the time range object */
-  readonly attribute unsigned long length;
-
-  /* The position of the start of the index'd range, in seconds measured
-     from the start of the timeline that this object represents */
-  double start(in unsigned long index);
-
-  /* The position of the end of the index'd range, in seconds measured
-     from the start of the timeline that this object represents */
-  double end(in unsigned long index);
-};
--- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
@@ -43,17 +43,16 @@
 #include "nsIDOMOfflineResourceList.h"
 #include "nsIDOMParser.h"
 #include "nsIDOMProcessingInstruction.h"
 #include "nsIDOMRange.h"
 #include "nsIDOMScreen.h"
 #include "nsIDOMScrollAreaEvent.h"
 #include "nsIDOMSerializer.h"
 #include "nsIDOMText.h"
-#include "nsIDOMTimeRanges.h"
 #include "nsIDOMUIEvent.h"
 #include "nsIDOMWheelEvent.h"
 #include "nsIDOMXMLDocument.h"
 #include "nsIDOMXULCommandEvent.h"
 #include "nsIDOMXULElement.h"
 #include "nsIFrameLoader.h"
 #include "nsIListBoxObject.h"
 #include "nsISelection.h"
@@ -117,17 +116,16 @@
 #include "mozilla/dom/SelectionBinding.h"
 #include "mozilla/dom/ScrollAreaEventBinding.h"
 #include "mozilla/dom/StorageEventBinding.h"
 #include "mozilla/dom/StyleSheetBinding.h"
 #include "mozilla/dom/StyleSheetListBinding.h"
 #include "mozilla/dom/SVGElementBinding.h"
 #include "mozilla/dom/TextBinding.h"
 #include "mozilla/dom/TimeEventBinding.h"
-#include "mozilla/dom/TimeRangesBinding.h"
 #include "mozilla/dom/TreeBoxObjectBinding.h"
 #include "mozilla/dom/UIEventBinding.h"
 #include "mozilla/dom/WheelEventBinding.h"
 #include "mozilla/dom/XMLDocumentBinding.h"
 #include "mozilla/dom/XMLHttpRequestEventTargetBinding.h"
 #include "mozilla/dom/XMLHttpRequestUploadBinding.h"
 #include "mozilla/dom/XMLSerializerBinding.h"
 #include "mozilla/dom/XULCommandEventBinding.h"
@@ -227,17 +225,16 @@ const ComponentsInterfaceShimEntry kComp
   DEFINE_SHIM(Range),
 #ifdef MOZ_WEBRTC
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMDataChannel, RTCDataChannel),
 #endif
   DEFINE_SHIM(Screen),
   DEFINE_SHIM(ScrollAreaEvent),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIDOMSerializer, XMLSerializer),
   DEFINE_SHIM(Text),
-  DEFINE_SHIM(TimeRanges),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsITreeBoxObject, TreeBoxObject),
   DEFINE_SHIM(UIEvent),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIWebBrowserPersistable, FrameLoader),
   DEFINE_SHIM(WheelEvent),
   DEFINE_SHIM(XMLDocument),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestEventTarget, XMLHttpRequestEventTarget),
   DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIXMLHttpRequestUpload, XMLHttpRequestUpload),
   DEFINE_SHIM(XULCommandEvent),