~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebInspectorUI/UserInterface/Views/BlackboxSettingsView.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.BlackboxSettingsView = class BlackboxSettingsView extends WI.SettingsView
 
27
{
 
28
    constructor()
 
29
    {
 
30
        super("blackbox", WI.UIString("Blackbox"));
 
31
 
 
32
        this._blackboxPatternCodeMirrorMap = new Map;
 
33
    }
 
34
 
 
35
    // Public
 
36
 
 
37
    selectBlackboxPattern(regex)
 
38
    {
 
39
        console.assert(regex instanceof RegExp);
 
40
        console.assert(this.didInitialLayout);
 
41
 
 
42
        let codeMirror = this._blackboxPatternCodeMirrorMap.get(regex);
 
43
        console.assert(codeMirror);
 
44
        if (!codeMirror)
 
45
            return;
 
46
 
 
47
        codeMirror.focus();
 
48
    }
 
49
 
 
50
    // Protected
 
51
 
 
52
    initialLayout()
 
53
    {
 
54
        super.initialLayout();
 
55
 
 
56
        let patternBlackboxExplanationElement = this.element.insertBefore(document.createElement("p"), this.element.lastChild);
 
57
        patternBlackboxExplanationElement.textContent = WI.UIString("If the URL of any script matches one of the regular expression patterns below, any pauses that would have happened in that script will be deferred until execution has continued to outside of that script.");
 
58
 
 
59
        let table = this.element.insertBefore(document.createElement("table"), this.element.lastChild);
 
60
 
 
61
        let tableHead = table.appendChild(document.createElement("thead"));
 
62
 
 
63
        let tableHeadRow = tableHead.appendChild(document.createElement("tr"));
 
64
 
 
65
        let urlHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
 
66
        urlHeaderCell.classList.add("url");
 
67
        urlHeaderCell.textContent = WI.UIString("URL Pattern");
 
68
 
 
69
        let caseSensitiveHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
 
70
        caseSensitiveHeaderCell.classList.add("case-sensitive");
 
71
        caseSensitiveHeaderCell.textContent = WI.UIString("Case Sensitive");
 
72
 
 
73
        let removeBlackboxHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
 
74
        removeBlackboxHeaderCell.classList.add("remove-blackbox");
 
75
 
 
76
        this._tableBody = table.appendChild(document.createElement("tbody"));
 
77
 
 
78
        for (let regex of WI.debuggerManager.blackboxPatterns)
 
79
            this._addRow(regex);
 
80
 
 
81
        if (!this._tableBody.children.length)
 
82
            this._addRow(null);
 
83
 
 
84
        let tableFoot = table.appendChild(document.createElement("tfoot"));
 
85
 
 
86
        let tableFooterRow = tableFoot.appendChild(document.createElement("tr"));
 
87
 
 
88
        let addBlackboxCell = tableFooterRow.appendChild(document.createElement("td"));
 
89
 
 
90
        let addBlackboxButton = addBlackboxCell.appendChild(document.createElement("button"));
 
91
        addBlackboxButton.textContent = WI.UIString("Add Pattern");
 
92
        addBlackboxButton.addEventListener("click", (event) => {
 
93
            for (let [regex, codeMirror] of this._blackboxPatternCodeMirrorMap) {
 
94
                if (!regex) {
 
95
                    codeMirror.focus();
 
96
                    return;
 
97
                }
 
98
            }
 
99
 
 
100
            this._addRow(null);
 
101
        });
 
102
 
 
103
        let individualBlackboxExplanationElement = this.element.insertBefore(document.createElement("p"), this.element.lastChild);
 
104
        let blackboxIconElement = WI.ImageUtilities.useSVGSymbol("Images/Hide.svg#currentColor", "toggle-script-blackbox", WI.UIString("Ignore script when debugging"));
 
105
        String.format(WI.UIString("Scripts can also be individually blackboxed by clicking on the %s icon that is shown on hover."), [blackboxIconElement], String.standardFormatters, individualBlackboxExplanationElement, (a, b) => {
 
106
            a.append(b);
 
107
            return a;
 
108
        });
 
109
    }
 
110
 
 
111
    // Private
 
112
 
 
113
    _addRow(regex)
 
114
    {
 
115
        let tableBodyRow = this._tableBody.appendChild(document.createElement("tr"));
 
116
 
 
117
        let urlBodyCell = tableBodyRow.appendChild(document.createElement("td"));
 
118
        urlBodyCell.classList.add("url");
 
119
 
 
120
        let urlCodeMirror = WI.CodeMirrorEditor.create(urlBodyCell, {
 
121
            extraKeys: {"Tab": false, "Shift-Tab": false},
 
122
            lineWrapping: false,
 
123
            matchBrackets: false,
 
124
            mode: "text/x-regex",
 
125
            placeholder: WI.UIString("Regular Expression"),
 
126
            scrollbarStyle: null,
 
127
            value: regex ? regex.source : "",
 
128
        });
 
129
        this._blackboxPatternCodeMirrorMap.set(regex, urlCodeMirror);
 
130
 
 
131
        this.needsLayout();
 
132
 
 
133
        let caseSensitiveBodyCell = tableBodyRow.appendChild(document.createElement("td"));
 
134
        caseSensitiveBodyCell.classList.add("case-sensitive");
 
135
 
 
136
        let caseSensitiveCheckbox = caseSensitiveBodyCell.appendChild(document.createElement("input"));
 
137
        caseSensitiveCheckbox.type = "checkbox";
 
138
        caseSensitiveCheckbox.checked = regex ? !regex.ignoreCase : true;
 
139
 
 
140
        let removeBlackboxBodyCell = tableBodyRow.appendChild(document.createElement("td"));
 
141
        removeBlackboxBodyCell.classList.add("remove-blackbox");
 
142
 
 
143
        let removeBlackboxButton = removeBlackboxBodyCell.appendChild(WI.ImageUtilities.useSVGSymbol("Images/NavigationItemTrash.svg", "remove-blackbox-button", WI.UIString("Delete Blackbox")));
 
144
        removeBlackboxButton.addEventListener("click", (event) => {
 
145
            if (regex)
 
146
                WI.debuggerManager.setShouldBlackboxPattern(regex, false);
 
147
            regex = null;
 
148
 
 
149
            this._blackboxPatternCodeMirrorMap.delete(regex);
 
150
 
 
151
            tableBodyRow.remove();
 
152
 
 
153
            if (!this._tableBody.children.length)
 
154
                this._addRow(null);
 
155
        });
 
156
 
 
157
        let update = () => {
 
158
            let url = urlCodeMirror.getValue();
 
159
 
 
160
            if (regex) {
 
161
                if (regex.source === url && regex.ignoreCase !== caseSensitiveCheckbox.checked)
 
162
                    return;
 
163
 
 
164
                WI.debuggerManager.setShouldBlackboxPattern(regex, false);
 
165
            }
 
166
 
 
167
            this._blackboxPatternCodeMirrorMap.delete(regex);
 
168
 
 
169
            regex = url ? new RegExp(url, !caseSensitiveCheckbox.checked ? "i" : "") : null;
 
170
            if (regex)
 
171
                WI.debuggerManager.setShouldBlackboxPattern(regex, true);
 
172
 
 
173
            console.assert(regex || !this._blackboxPatternCodeMirrorMap.has(regex));
 
174
            this._blackboxPatternCodeMirrorMap.set(regex, urlCodeMirror);
 
175
        };
 
176
        urlCodeMirror.addKeyMap({
 
177
            "Enter": update,
 
178
            "Esc": update,
 
179
        });
 
180
        urlCodeMirror.on("blur", update);
 
181
        caseSensitiveCheckbox.addEventListener("change", update);
 
182
 
 
183
        if (!regex)
 
184
            urlCodeMirror.focus();
 
185
    }
 
186
};