Modern IDB: Add -private.html variants of crypto/subtle IndexedDB tests.
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Models / Timeline.js
1 /*
2  * Copyright (C) 2013 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 WebInspector.Timeline = class Timeline extends WebInspector.Object
27 {
28     constructor(type)
29     {
30         super();
31
32         this._type = type;
33
34         this.reset(true);
35     }
36
37     // Static
38
39     static create(type)
40     {
41         if (type === WebInspector.TimelineRecord.Type.Network)
42             return new WebInspector.NetworkTimeline(type);
43
44         if (type === WebInspector.TimelineRecord.Type.Memory)
45             return new WebInspector.MemoryTimeline(type);
46
47         return new WebInspector.Timeline(type);
48     }
49
50     // Public
51
52     get type()
53     {
54         return this._type;
55     }
56
57     get startTime()
58     {
59         return this._startTime;
60     }
61
62     get endTime()
63     {
64         return this._endTime;
65     }
66
67     get records()
68     {
69         return this._records;
70     }
71
72     reset(suppressEvents)
73     {
74         this._records = [];
75         this._startTime = NaN;
76         this._endTime = NaN;
77
78         if (!suppressEvents) {
79             this.dispatchEventToListeners(WebInspector.Timeline.Event.TimesUpdated);
80             this.dispatchEventToListeners(WebInspector.Timeline.Event.Reset);
81         }
82     }
83
84     addRecord(record)
85     {
86         if (record.updatesDynamically)
87             record.addEventListener(WebInspector.TimelineRecord.Event.Updated, this._recordUpdated, this);
88
89         this._records.push(record);
90
91         this._updateTimesIfNeeded(record);
92
93         this.dispatchEventToListeners(WebInspector.Timeline.Event.RecordAdded, {record});
94     }
95
96     saveIdentityToCookie(cookie)
97     {
98         cookie[WebInspector.Timeline.TimelineTypeCookieKey] = this._type;
99     }
100
101     refresh()
102     {
103         this.dispatchEventToListeners(WebInspector.Timeline.Event.Refreshed);
104     }
105
106     // Private
107
108     _updateTimesIfNeeded(record)
109     {
110         var changed = false;
111
112         if (isNaN(this._startTime) || record.startTime < this._startTime) {
113             this._startTime = record.startTime;
114             changed = true;
115         }
116
117         if (isNaN(this._endTime) || this._endTime < record.endTime) {
118             this._endTime = record.endTime;
119             changed = true;
120         }
121
122         if (changed)
123             this.dispatchEventToListeners(WebInspector.Timeline.Event.TimesUpdated);
124     }
125
126     _recordUpdated(event)
127     {
128         this._updateTimesIfNeeded(event.target);
129     }
130 };
131
132 WebInspector.Timeline.Event = {
133     Reset: "timeline-reset",
134     RecordAdded: "timeline-record-added",
135     TimesUpdated: "timeline-times-updated",
136     Refreshed: "timeline-refreshed",
137 };
138
139 WebInspector.Timeline.TimelineTypeCookieKey = "timeline-type";