LayoutTest inspector/worker/debugger-pause.html sometimes times out
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Protocol / Target.js
index fc38a1b..92d13fc 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.Target = class Target extends WebInspector.Object
+WI.Target = class Target extends WI.Object
 {
-    constructor(name, type, connection)
+    constructor(identifier, name, type, connection)
     {
         super();
 
+        this._identifier = identifier;
         this._name = name;
         this._type = type;
         this._connection = connection;
         this._executionContext = null;
+        this._mainResource = null;
+        this._resourceCollection = new WI.ResourceCollection;
+        this._extraScriptCollection = new WI.ScriptCollection;
 
         this._connection.target = this;
-
-        this.initialize();
     }
 
     // Agents
 
     get RuntimeAgent() { return this._connection._agents.Runtime; }
+    get ConsoleAgent() { return this._connection._agents.Console; }
+    get DebuggerAgent() { return this._connection._agents.Debugger; }
+    get HeapAgent() { return this._connection._agents.Heap; }
 
     // Public
 
+    get identifier() { return this._identifier; }
+    set identifier(identifier) { this._identifier = identifier; }
+
     get name() { return this._name; }
+    set name(name) { this._name = name; }
+
     get type() { return this._type; }
     get connection() { return this._connection; }
     get executionContext() { return this._executionContext; }
-};
-
-WebInspector.Target.Type = {
-    Main: Symbol("main"),
-    Worker: Symbol("worker"),
-};
 
-WebInspector.MainTarget = class MainTarget extends WebInspector.Target
-{
-    constructor(connection)
-    {
-        super("", WebInspector.Target.Type.Main, InspectorBackend.mainConnection);
-    }
+    get resourceCollection() { return this._resourceCollection; }
+    get extraScriptCollection() { return this._extraScriptCollection; }
 
-    // Protected (Target)
+    get displayName() { return this._name; }
 
-    get displayName()
+    get mainResource()
     {
-        if (WebInspector.debuggableType === WebInspector.DebuggableType.Web)
-            return WebInspector.UIString("Main Frame");
-        return WebInspector.UIString("Main Context");
+        return this._mainResource;
     }
 
-    initialize()
+    set mainResource(resource)
     {
-        this._executionContext = new WebInspector.ExecutionContext(this, WebInspector.RuntimeManager.TopLevelContextExecutionIdentifier, this.displayName, true, null);
+        console.assert(!this._mainResource);
+
+        this._mainResource = resource;
+
+        this.dispatchEventToListeners(WI.Target.Event.MainResourceAdded, {resource});
     }
-}
 
-WebInspector.WorkerTarget = class WorkerTarget extends WebInspector.Target
-{
-    constructor(name, connection)
+    addResource(resource)
     {
-        super(name, WebInspector.Target.Type.Worker, connection);
-    }
+        this._resourceCollection.add(resource);
 
-    // Protected (Target)
+        this.dispatchEventToListeners(WI.Target.Event.ResourceAdded, {resource});
+    }
 
-    get displayName()
+    adoptResource(resource)
     {
-        return WebInspector.displayNameForURL(this._name);
+        resource._target = this;
+
+        this.addResource(resource);
     }
 
-    initialize()
+    addScript(script)
     {
-        if (this.RuntimeAgent) {
-            this.RuntimeAgent.enable();
-            this._executionContext = new WebInspector.ExecutionContext(this, WebInspector.RuntimeManager.TopLevelContextExecutionIdentifier, this.displayName, false, null);
-        }
+        this._extraScriptCollection.add(script);
+
+        this.dispatchEventToListeners(WI.Target.Event.ScriptAdded, {script});
     }
-}
+};
+
+WI.Target.Type = {
+    Page: Symbol("page"),
+    JSContext: Symbol("jscontext"),
+    ServiceWorker: Symbol("service-worker"),
+    Worker: Symbol("worker"),
+};
+
+WI.Target.Event = {
+    MainResourceAdded: "target-main-resource-added",
+    ResourceAdded: "target-resource-added",
+    ScriptAdded: "target-script-added",
+};