wpt/css/css-images/gradient/color-stops-parsing.html fails
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Models / MediaTimelineRecord.js
1 /*
2  * Copyright (C) 2018 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 WI.MediaTimelineRecord = class MediaTimelineRecord extends WI.TimelineRecord
27 {
28     constructor(eventType, timestamp, {domNode, domEvent, isPowerEfficient} = {})
29     {
30         console.assert(Object.values(WI.MediaTimelineRecord.EventType).includes(eventType));
31
32         super(WI.TimelineRecord.Type.Media, timestamp, timestamp);
33
34         this._eventType = eventType;
35         this._domNode = domNode || null;
36         this._domEvent = domEvent || null;
37         this._isPowerEfficient = isPowerEfficient || false;
38     }
39
40     // Import / Export
41
42     static fromJSON(json)
43     {
44         let {eventType, timestamp} = json;
45
46         // COMPATIBILITY (iOS 12.2): isLowPower was renamed to isPowerEfficient.
47         if ("isLowPower" in json && !("isPowerEfficient" in json))
48             json.isPowerEfficient = json.isLowPower;
49
50         return new WI.MediaTimelineRecord(eventType, timestamp, json);
51     }
52
53     toJSON()
54     {
55         // FIXME: DOMNode
56
57         // Don't include the DOMEvent's originator.
58         let domEvent = this._domEvent;
59         if (domEvent && domEvent.originator) {
60             domEvent = Object.shallowCopy(domEvent);
61             domEvent.originator = undefined;
62         }
63
64         return {
65             type: this.type,
66             eventType: this._eventType,
67             timestamp: this.startTime,
68             domEvent,
69             isPowerEfficient: this._isPowerEfficient,
70         };
71     }
72
73     // Public
74
75     get eventType() { return this._eventType; }
76     get domNode() { return this._domNode; }
77     get domEvent() { return this._domEvent; }
78     get isPowerEfficient() { return this._isPowerEfficient; }
79
80     get displayName()
81     {
82         if (this._eventType === WI.MediaTimelineRecord.EventType.DOMEvent && this._domEvent) {
83             let eventName = this._domEvent.eventName;
84             if (eventName === "webkitfullscreenchange" && this._domEvent.data)
85                 return this._domEvent.data.enabled ? WI.UIString("Entered Full-Screen Mode") : WI.UIString("Exited Full-Screen Mode");
86             return eventName;
87         }
88
89         if (this._eventType === MediaTimelineRecord.EventType.PowerEfficientPlaybackStateChanged)
90             return this._isPowerEfficient ? WI.UIString("Power Efficient Playback Started") : WI.UIString("Power Efficient Playback Stopped");
91
92         if (this._domNode)
93             return this._domNode.displayName;
94
95         console.error("Unknown media record event type: ", this._eventType, this);
96         return WI.UIString("Media Event");
97     }
98
99     saveIdentityToCookie(cookie)
100     {
101         super.saveIdentityToCookie(cookie);
102
103         cookie["media-timeline-record-event-type"] = this._eventType;
104         if (this._eventType === MediaTimelineRecord.EventType.PowerEfficientPlaybackStateChanged)
105             cookie["media-timeline-record-power-efficient-playback"] = this._isPowerEfficient;
106         if (this._domNode)
107             cookie["media-timeline-record-dom-node"] = this._domNode.path();
108         if (this._domEvent) {
109             cookie["media-timeline-record-dom-event"] = this._domEvent.eventName;
110             if (this._domEvent.data && this._domEvent.data.enabled)
111                 cookie["media-timeline-record-dom-event-active"] = true;
112         }
113     }
114 };
115
116 WI.MediaTimelineRecord.EventType = {
117     DOMEvent: "dom-event",
118     PowerEfficientPlaybackStateChanged: "power-efficient-playback-state-changed",
119 };