~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebInspectorUI/UserInterface/Controllers/InspectedTargetTypesDiagnosticEventRecorder.js

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2019 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.InspectedTargetTypesDiagnosticEventRecorder = class InspectedTargetTypesDiagnosticEventRecorder extends WI.DiagnosticEventRecorder
 
27
{
 
28
    constructor(controller)
 
29
    {
 
30
        super("InspectedTargetTypes", controller);
 
31
 
 
32
        this._initialDelayBeforeSamplingTimerIdentifier = undefined;
 
33
    }
 
34
 
 
35
    // Static
 
36
 
 
37
    static get initialDelayBeforeSamplingInterval()
 
38
    {
 
39
        return 5 * 1000; // In milliseconds.
 
40
    }
 
41
 
 
42
    // Protected
 
43
 
 
44
    setup()
 
45
    {
 
46
        // If it's been less than 5 seconds since the frontend loaded, wait a bit.
 
47
        if (performance.now() - WI.frontendCompletedLoadTimestamp < InspectedTargetTypesDiagnosticEventRecorder.initialDelayBeforeSamplingInterval)
 
48
            this._startInitialDelayBeforeSamplingTimer();
 
49
        else
 
50
            this._sampleInspectedTarget();
 
51
 
 
52
    }
 
53
 
 
54
    teardown()
 
55
    {
 
56
        this._stopInitialDelayBeforeSamplingTimer();
 
57
    }
 
58
 
 
59
    // Private
 
60
 
 
61
    _startInitialDelayBeforeSamplingTimer()
 
62
    {
 
63
        if (this._initialDelayBeforeSamplingTimerIdentifier) {
 
64
            clearTimeout(this._initialDelayBeforeSamplingTimerIdentifier);
 
65
            this._initialDelayBeforeSamplingTimerIdentifier = undefined;
 
66
        }
 
67
 
 
68
        // All intervals are in milliseconds.
 
69
        let maximumInitialDelay = InspectedTargetTypesDiagnosticEventRecorder.initialDelayBeforeSamplingInterval;
 
70
        let elapsedTime = performance.now() - WI.frontendCompletedLoadTimestamp;
 
71
        let remainingTime = maximumInitialDelay - elapsedTime;
 
72
        let initialDelay = Number.constrain(remainingTime, 0, maximumInitialDelay);
 
73
        this._initialDelayBeforeSamplingTimerIdentifier = setTimeout(this._sampleInspectedTarget.bind(this), initialDelay);
 
74
    }
 
75
 
 
76
    _stopInitialDelayBeforeSamplingTimer()
 
77
    {
 
78
        if (this._initialDelayBeforeSamplingTimerIdentifier) {
 
79
            clearTimeout(this._initialDelayBeforeSamplingTimerIdentifier);
 
80
            this._initialDelayBeforeSamplingTimerIdentifier = undefined;
 
81
        }
 
82
    }
 
83
 
 
84
    _sampleInspectedTarget()
 
85
    {
 
86
        this._stopInitialDelayBeforeSamplingTimer();
 
87
 
 
88
        this.logDiagnosticEvent(this.name, {
 
89
            debuggableType: this._determineDebuggableType(),
 
90
            targetPlatformName: this._determineTargetPlatformName(),
 
91
            targetBuildVersion: this._determineTargetBuildVersion(),
 
92
            targetProductVersion: this._determineTargetProductVersion(),
 
93
            targetIsSimulator: this._determineTargetIsSimulator(),
 
94
        });
 
95
    }
 
96
 
 
97
    _determineDebuggableType()
 
98
    {
 
99
        this._ensureCachedDebuggableInfo();
 
100
 
 
101
        return this._cachedDebuggableInfo.debuggableType;
 
102
    }
 
103
 
 
104
    _determineTargetPlatformName()
 
105
    {
 
106
        this._ensureCachedDebuggableInfo();
 
107
 
 
108
        return this._cachedDebuggableInfo.targetPlatformName;
 
109
    }
 
110
 
 
111
    _determineTargetBuildVersion()
 
112
    {
 
113
        this._ensureCachedDebuggableInfo();
 
114
 
 
115
        return this._cachedDebuggableInfo.targetBuildVersion;
 
116
    }
 
117
 
 
118
    _determineTargetProductVersion()
 
119
    {
 
120
        this._ensureCachedDebuggableInfo();
 
121
 
 
122
        return this._cachedDebuggableInfo.targetProductVersion;
 
123
    }
 
124
 
 
125
    _determineTargetIsSimulator()
 
126
    {
 
127
        this._ensureCachedDebuggableInfo();
 
128
 
 
129
        return !!this._cachedDebuggableInfo.targetIsSimulator;
 
130
    }
 
131
 
 
132
    _ensureCachedDebuggableInfo()
 
133
    {
 
134
        if (this._cachedDebuggableInfo)
 
135
            return;
 
136
 
 
137
        let debuggableInfo = InspectorFrontendHost.debuggableInfo;
 
138
        this._cachedDebuggableInfo = {
 
139
            debuggableType: WI.DebuggableType.fromString(debuggableInfo.debuggableType) || WI.DebuggableType.JavaScript,
 
140
            targetPlatformName: debuggableInfo.targetPlatformName || "Unknown",
 
141
            targetBuildVersion: debuggableInfo.targetBuildVersion || "Unknown",
 
142
            targetProductVersion: debuggableInfo.targetProductVersion || "Unknown",
 
143
            targetIsSimulator: debuggableInfo.targetIsSimulator,
 
144
        };
 
145
    }
 
146
};