Bug 1267510 part 3 - Add DocumentTimeline constructor. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Wed, 29 Jun 2016 11:13:45 +0900
changeset 382149 ec92ec149a1ee6911c28a925b262d068825a6cad
parent 382142 419a6048f854d92bd9b28ad72d3de13552557154
child 382150 e56382b59888c19174ee74a006dfb79fa4fef38f
push id21637
push usermantaroh@gmail.com
push dateWed, 29 Jun 2016 02:14:31 +0000
reviewersbirtles
bugs1267510
milestone50.0a1
Bug 1267510 part 3 - Add DocumentTimeline constructor. r?birtles MozReview-Commit-ID: CqqDlHQsm0p
dom/animation/DocumentTimeline.cpp
dom/animation/DocumentTimeline.h
dom/bindings/Errors.msg
--- a/dom/animation/DocumentTimeline.cpp
+++ b/dom/animation/DocumentTimeline.cpp
@@ -31,16 +31,41 @@ NS_IMPL_ADDREF_INHERITED(DocumentTimelin
 NS_IMPL_RELEASE_INHERITED(DocumentTimeline, AnimationTimeline)
 
 JSObject*
 DocumentTimeline::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return DocumentTimelineBinding::Wrap(aCx, this, aGivenProto);
 }
 
+/* static */ already_AddRefed<DocumentTimeline>
+DocumentTimeline::Constructor(const GlobalObject& aGlobal,
+                              const DOMHighResTimeStamp& aOriginTime,
+                              ErrorResult& aRv)
+{
+  nsIDocument* doc = AnimationUtils::GetCurrentRealmDocument(aGlobal.Context());
+  if (!doc) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  TimeDuration originTime = TimeDuration::FromMilliseconds(aOriginTime);
+  if (originTime == TimeDuration::Forever() ||
+      originTime == -TimeDuration::Forever()) {
+    nsAutoString inputOriginTime;
+    inputOriginTime.AppendFloat(aOriginTime);
+    aRv.ThrowTypeError<dom::MSG_TIME_VALUE_OUT_OF_RANGE>(
+      NS_LITERAL_STRING("Origin time"));
+    return nullptr;
+  }
+  RefPtr<DocumentTimeline> timeline = new DocumentTimeline(doc, originTime);
+
+  return timeline.forget();
+}
+
 Nullable<TimeDuration>
 DocumentTimeline::GetCurrentTime() const
 {
   return ToTimelineTime(GetCurrentTimeStamp());
 }
 
 TimeStamp
 DocumentTimeline::GetCurrentTimeStamp() const
--- a/dom/animation/DocumentTimeline.h
+++ b/dom/animation/DocumentTimeline.h
@@ -5,16 +5,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_DocumentTimeline_h
 #define mozilla_dom_DocumentTimeline_h
 
 #include "mozilla/TimeStamp.h"
 #include "AnimationTimeline.h"
 #include "nsIDocument.h"
+#include "nsDOMNavigationTiming.h" // for DOMHighResTimeStamp
 #include "nsRefreshDriver.h"
 
 struct JSContext;
 
 // GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
 // GetTickCount().
 #ifdef GetCurrentTime
 #undef GetCurrentTime
@@ -46,16 +47,21 @@ protected:
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(DocumentTimeline,
                                                          AnimationTimeline)
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
 
+  static already_AddRefed<DocumentTimeline>
+  Constructor(const GlobalObject& aGlobal,
+              const DOMHighResTimeStamp& aOriginTime,
+              ErrorResult& aRv);
+
   // AnimationTimeline methods
   virtual Nullable<TimeDuration> GetCurrentTime() const override;
 
   bool TracksWallclockTime() const override
   {
     nsRefreshDriver* refreshDriver = GetRefreshDriver();
     return !refreshDriver ||
            !refreshDriver->IsTestControllingRefreshesEnabled();
--- a/dom/bindings/Errors.msg
+++ b/dom/bindings/Errors.msg
@@ -94,9 +94,10 @@ MSG_DEF(MSG_TYPEDARRAY_IS_SHARED, 1, JSE
 MSG_DEF(MSG_CACHE_ADD_FAILED_RESPONSE, 3, JSEXN_TYPEERR, "Cache got {0} response with bad status {1} while trying to add request {2}")
 MSG_DEF(MSG_SW_UPDATE_BAD_REGISTRATION, 2, JSEXN_TYPEERR, "Failed to update the ServiceWorker for scope {0] because the registration has been {1} since the update was scheduled.")
 MSG_DEF(MSG_INVALID_DURATION_ERROR, 1, JSEXN_TYPEERR, "Invalid duration '{0}'.")
 MSG_DEF(MSG_INVALID_EASING_ERROR, 1, JSEXN_TYPEERR, "Invalid easing '{0}'.")
 MSG_DEF(MSG_INVALID_SPACING_MODE_ERROR, 1, JSEXN_TYPEERR, "Invalid spacing '{0}'.")
 MSG_DEF(MSG_USELESS_SETTIMEOUT, 1, JSEXN_TYPEERR, "Useless {0} call (missing quotes around argument?)")
 MSG_DEF(MSG_TOKENLIST_NO_SUPPORTED_TOKENS, 2, JSEXN_TYPEERR, "{0} attribute of <{1}> does not define any supported tokens")
 MSG_DEF(MSG_CACHE_STREAM_CLOSED, 0, JSEXN_TYPEERR, "Response body is a cache file stream that has already been closed.")
+MSG_DEF(MSG_TIME_VALUE_OUT_OF_RANGE, 1, JSEXN_TYPEERR, "{0} is outside the supported range for time values.")
 MSG_DEF(MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN, 1, JSEXN_TYPEERR, "Request mode '{0}' was used, but request cache mode 'only-if-cached' can only be used with request mode 'same-origin'.")