2
* Copyright (C) 2019 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
26
WI.BlackboxSettingsView = class BlackboxSettingsView extends WI.SettingsView
30
super("blackbox", WI.UIString("Blackbox"));
32
this._blackboxPatternCodeMirrorMap = new Map;
37
selectBlackboxPattern(regex)
39
console.assert(regex instanceof RegExp);
40
console.assert(this.didInitialLayout);
42
let codeMirror = this._blackboxPatternCodeMirrorMap.get(regex);
43
console.assert(codeMirror);
54
super.initialLayout();
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.");
59
let table = this.element.insertBefore(document.createElement("table"), this.element.lastChild);
61
let tableHead = table.appendChild(document.createElement("thead"));
63
let tableHeadRow = tableHead.appendChild(document.createElement("tr"));
65
let urlHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
66
urlHeaderCell.classList.add("url");
67
urlHeaderCell.textContent = WI.UIString("URL Pattern");
69
let caseSensitiveHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
70
caseSensitiveHeaderCell.classList.add("case-sensitive");
71
caseSensitiveHeaderCell.textContent = WI.UIString("Case Sensitive");
73
let removeBlackboxHeaderCell = tableHeadRow.appendChild(document.createElement("th"));
74
removeBlackboxHeaderCell.classList.add("remove-blackbox");
76
this._tableBody = table.appendChild(document.createElement("tbody"));
78
for (let regex of WI.debuggerManager.blackboxPatterns)
81
if (!this._tableBody.children.length)
84
let tableFoot = table.appendChild(document.createElement("tfoot"));
86
let tableFooterRow = tableFoot.appendChild(document.createElement("tr"));
88
let addBlackboxCell = tableFooterRow.appendChild(document.createElement("td"));
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) {
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) => {
115
let tableBodyRow = this._tableBody.appendChild(document.createElement("tr"));
117
let urlBodyCell = tableBodyRow.appendChild(document.createElement("td"));
118
urlBodyCell.classList.add("url");
120
let urlCodeMirror = WI.CodeMirrorEditor.create(urlBodyCell, {
121
extraKeys: {"Tab": false, "Shift-Tab": false},
123
matchBrackets: false,
124
mode: "text/x-regex",
125
placeholder: WI.UIString("Regular Expression"),
126
scrollbarStyle: null,
127
value: regex ? regex.source : "",
129
this._blackboxPatternCodeMirrorMap.set(regex, urlCodeMirror);
133
let caseSensitiveBodyCell = tableBodyRow.appendChild(document.createElement("td"));
134
caseSensitiveBodyCell.classList.add("case-sensitive");
136
let caseSensitiveCheckbox = caseSensitiveBodyCell.appendChild(document.createElement("input"));
137
caseSensitiveCheckbox.type = "checkbox";
138
caseSensitiveCheckbox.checked = regex ? !regex.ignoreCase : true;
140
let removeBlackboxBodyCell = tableBodyRow.appendChild(document.createElement("td"));
141
removeBlackboxBodyCell.classList.add("remove-blackbox");
143
let removeBlackboxButton = removeBlackboxBodyCell.appendChild(WI.ImageUtilities.useSVGSymbol("Images/NavigationItemTrash.svg", "remove-blackbox-button", WI.UIString("Delete Blackbox")));
144
removeBlackboxButton.addEventListener("click", (event) => {
146
WI.debuggerManager.setShouldBlackboxPattern(regex, false);
149
this._blackboxPatternCodeMirrorMap.delete(regex);
151
tableBodyRow.remove();
153
if (!this._tableBody.children.length)
158
let url = urlCodeMirror.getValue();
161
if (regex.source === url && regex.ignoreCase !== caseSensitiveCheckbox.checked)
164
WI.debuggerManager.setShouldBlackboxPattern(regex, false);
167
this._blackboxPatternCodeMirrorMap.delete(regex);
169
regex = url ? new RegExp(url, !caseSensitiveCheckbox.checked ? "i" : "") : null;
171
WI.debuggerManager.setShouldBlackboxPattern(regex, true);
173
console.assert(regex || !this._blackboxPatternCodeMirrorMap.has(regex));
174
this._blackboxPatternCodeMirrorMap.set(regex, urlCodeMirror);
176
urlCodeMirror.addKeyMap({
180
urlCodeMirror.on("blur", update);
181
caseSensitiveCheckbox.addEventListener("change", update);
184
urlCodeMirror.focus();