[DFG] Convert ValueAdd(Int32, String) => MakeRope(ToString(Int32), String)
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Controllers / XHRBreakpointTreeController.js
1 /*
2  * Copyright (C) 2017 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.XHRBreakpointTreeController = class XHRBreakpointsTreeController extends WebInspector.Object
27 {
28     constructor(treeOutline)
29     {
30         super();
31
32         this._treeOutline = treeOutline;
33
34         WebInspector.Frame.addEventListener(WebInspector.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
35
36         WebInspector.domDebuggerManager.addEventListener(WebInspector.DOMDebuggerManager.Event.XHRBreakpointAdded, this._xhrBreakpointAdded, this);
37         WebInspector.domDebuggerManager.addEventListener(WebInspector.DOMDebuggerManager.Event.XHRBreakpointRemoved, this._xhrBreakpointRemoved, this);
38
39         this._allReqestsBreakpointTreeElement = new WebInspector.XHRBreakpointTreeElement(WebInspector.domDebuggerManager.allRequestsBreakpoint, WebInspector.DebuggerSidebarPanel.AssertionIconStyleClassName, WebInspector.UIString("All Requests"));
40
41         this._treeOutline.appendChild(this._allReqestsBreakpointTreeElement);
42
43         for (let breakpoint of WebInspector.domDebuggerManager.xhrBreakpoints)
44             this._addTreeElement(breakpoint);
45     }
46
47     // Public
48
49     revealAndSelect(breakpoint)
50     {
51         let treeElement = this._treeOutline.findTreeElement(breakpoint);
52         if (!treeElement)
53             return;
54
55         treeElement.revealAndSelect();
56     }
57
58     disconnect()
59     {
60         WebInspector.Frame.removeEventListener(null, null, this);
61         WebInspector.domDebuggerManager.removeEventListener(null, null, this);
62     }
63
64     // Private
65
66     _xhrBreakpointAdded(event)
67     {
68         this._addTreeElement(event.data.breakpoint);
69     }
70
71     _xhrBreakpointRemoved(event)
72     {
73         let breakpoint = event.data.breakpoint;
74         let treeElement = this._treeOutline.findTreeElement(breakpoint);
75         if (!treeElement)
76             return;
77
78         this._treeOutline.removeChild(treeElement);
79     }
80
81     _mainResourceDidChange(event)
82     {
83         if (!event.target.isMainFrame())
84             return;
85
86         while (this._treeOutline.children.length > 1)
87             this._treeOutline.removeChild(this._treeOutline.children.lastValue);
88     }
89
90     _addTreeElement(breakpoint)
91     {
92         let treeElement = this._treeOutline.findTreeElement(breakpoint);
93         console.assert(!treeElement);
94         if (treeElement)
95             return;
96
97         this._treeOutline.appendChild(new WebInspector.XHRBreakpointTreeElement(breakpoint));
98     }
99 };