f8c8951414c5f543322ab95dec9dcc37e5ce84e2
[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.domDebuggerManager.addEventListener(WebInspector.DOMDebuggerManager.Event.XHRBreakpointAdded, this._xhrBreakpointAdded, this);
35         WebInspector.domDebuggerManager.addEventListener(WebInspector.DOMDebuggerManager.Event.XHRBreakpointRemoved, this._xhrBreakpointRemoved, this);
36
37         this._allReqestsBreakpointTreeElement = new WebInspector.XHRBreakpointTreeElement(WebInspector.domDebuggerManager.allRequestsBreakpoint, WebInspector.DebuggerSidebarPanel.AssertionIconStyleClassName, WebInspector.UIString("All Requests"));
38
39         this._treeOutline.appendChild(this._allReqestsBreakpointTreeElement);
40
41         for (let breakpoint of WebInspector.domDebuggerManager.xhrBreakpoints)
42             this._addTreeElement(breakpoint);
43     }
44
45     // Public
46
47     revealAndSelect(breakpoint)
48     {
49         let treeElement = this._treeOutline.findTreeElement(breakpoint);
50         if (!treeElement)
51             return;
52
53         treeElement.revealAndSelect();
54     }
55
56     disconnect()
57     {
58         WebInspector.Frame.removeEventListener(null, null, this);
59         WebInspector.domDebuggerManager.removeEventListener(null, null, this);
60     }
61
62     // Private
63
64     _xhrBreakpointAdded(event)
65     {
66         this._addTreeElement(event.data.breakpoint);
67     }
68
69     _xhrBreakpointRemoved(event)
70     {
71         let breakpoint = event.data.breakpoint;
72         let treeElement = this._treeOutline.findTreeElement(breakpoint);
73         if (!treeElement)
74             return;
75
76         this._treeOutline.removeChild(treeElement);
77     }
78
79     _addTreeElement(breakpoint)
80     {
81         let treeElement = this._treeOutline.findTreeElement(breakpoint);
82         console.assert(!treeElement);
83         if (treeElement)
84             return;
85
86         this._treeOutline.appendChild(new WebInspector.XHRBreakpointTreeElement(breakpoint));
87     }
88 };