LayoutTest inspector/worker/debugger-pause.html sometimes times out
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Protocol / Target.js
1 /*
2  * Copyright (C) 2016 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.Target = class Target extends WI.Object
27 {
28     constructor(identifier, name, type, connection)
29     {
30         super();
31
32         this._identifier = identifier;
33         this._name = name;
34         this._type = type;
35         this._connection = connection;
36         this._executionContext = null;
37         this._mainResource = null;
38         this._resourceCollection = new WI.ResourceCollection;
39         this._extraScriptCollection = new WI.ScriptCollection;
40
41         this._connection.target = this;
42     }
43
44     // Agents
45
46     get RuntimeAgent() { return this._connection._agents.Runtime; }
47     get ConsoleAgent() { return this._connection._agents.Console; }
48     get DebuggerAgent() { return this._connection._agents.Debugger; }
49     get HeapAgent() { return this._connection._agents.Heap; }
50
51     // Public
52
53     get identifier() { return this._identifier; }
54     set identifier(identifier) { this._identifier = identifier; }
55
56     get name() { return this._name; }
57     set name(name) { this._name = name; }
58
59     get type() { return this._type; }
60     get connection() { return this._connection; }
61     get executionContext() { return this._executionContext; }
62
63     get resourceCollection() { return this._resourceCollection; }
64     get extraScriptCollection() { return this._extraScriptCollection; }
65
66     get displayName() { return this._name; }
67
68     get mainResource()
69     {
70         return this._mainResource;
71     }
72
73     set mainResource(resource)
74     {
75         console.assert(!this._mainResource);
76
77         this._mainResource = resource;
78
79         this.dispatchEventToListeners(WI.Target.Event.MainResourceAdded, {resource});
80     }
81
82     addResource(resource)
83     {
84         this._resourceCollection.add(resource);
85
86         this.dispatchEventToListeners(WI.Target.Event.ResourceAdded, {resource});
87     }
88
89     adoptResource(resource)
90     {
91         resource._target = this;
92
93         this.addResource(resource);
94     }
95
96     addScript(script)
97     {
98         this._extraScriptCollection.add(script);
99
100         this.dispatchEventToListeners(WI.Target.Event.ScriptAdded, {script});
101     }
102 };
103
104 WI.Target.Type = {
105     Page: Symbol("page"),
106     JSContext: Symbol("jscontext"),
107     ServiceWorker: Symbol("service-worker"),
108     Worker: Symbol("worker"),
109 };
110
111 WI.Target.Event = {
112     MainResourceAdded: "target-main-resource-added",
113     ResourceAdded: "target-resource-added",
114     ScriptAdded: "target-script-added",
115 };