Web Inspector: Separate target initialization from frontend initialization
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 21:19:11 +0000 (21:19 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 31 Oct 2018 21:19:11 +0000 (21:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191052
<rdar://problem/45658384>

Reviewed by Brian Burg.

* UserInterface/Base/Main.js:
(WI.loaded):
(WI.performOneTimeFrontendInitializationsUsingTarget):
Create the targets after the rest of frontend initialization. This is a step
toward a frontend opening and being told about multiple targets instead of
knowing in advance a single target it is connected to. All backend
messages during frontend initialization now happen with an explicit target.

* UserInterface/Controllers/ApplicationCacheManager.js:
(WI.ApplicationCacheManager):
(WI.ApplicationCacheManager.prototype.initializeTarget):
(WI.ApplicationCacheManager.prototype.initialize):
* UserInterface/Controllers/CSSManager.js:
(WI.CSSManager):
(WI.CSSManager.prototype.initializeTarget):
* UserInterface/Controllers/CanvasManager.js:
(WI.CanvasManager):
(WI.CanvasManager.prototype.initializeTarget):
* UserInterface/Controllers/ConsoleManager.js:
(WI.ConsoleManager):
(WI.ConsoleManager.prototype.initializeLogChannels):
* UserInterface/Controllers/DOMManager.js:
(WI.DOMManager):
(WI.DOMManager.prototype.initializeTarget):
* UserInterface/Controllers/DOMStorageManager.js:
(WI.DOMStorageManager):
(WI.DOMStorageManager.prototype.initializeTarget):
* UserInterface/Controllers/DatabaseManager.js:
(WI.DatabaseManager):
(WI.DatabaseManager.prototype.initializeTarget):
* UserInterface/Controllers/DebuggerManager.js:
(WI.DebuggerManager):
(WI.DebuggerManager.prototype.initializeTarget):
(WI.DebuggerManager.restoreBreakpointsSoon): Deleted.
* UserInterface/Controllers/HeapManager.js:
(WI.HeapManager.prototype.initializeTarget):
* UserInterface/Controllers/IndexedDBManager.js:
(WI.IndexedDBManager):
(WI.IndexedDBManager.prototype.initializeTarget):
* UserInterface/Controllers/LayerTreeManager.js:
(WI.LayerTreeManager.prototype.initializeTarget):
* UserInterface/Controllers/MemoryManager.js:
(WI.MemoryManager.prototype.initializeTarget):
* UserInterface/Controllers/NetworkManager.js:
(WI.NetworkManager):
(WI.NetworkManager.prototype.initializeTarget):
* UserInterface/Controllers/RuntimeManager.js:
(WI.RuntimeManager):
(WI.RuntimeManager.prototype.initializeTarget):
* UserInterface/Controllers/TargetManager.js:
(WI.TargetManager):
(WI.TargetManager.prototype.initializeTargetsWithMainTarget):
* UserInterface/Controllers/TimelineManager.js:
(WI.TimelineManager):
(WI.TimelineManager.prototype.initializeTarget):
(WI.TimelineManager.prototype.set enabledTimelineTypes):
(WI.TimelineManager.prototype._updateAutoCaptureInstruments):
* UserInterface/Controllers/WorkerManager.js:
(WI.WorkerManager):
(WI.WorkerManager.prototype.initializeTarget):
Move Target initialization out of the constructor into a top level
`initializeTarget` function. This will be expected to be called
by any target that the frontend connects to.

(WI.DebuggerManager.prototype._pauseForInternalScriptsDidChange):
Drive-by fix. Update all targets if the setting changes.

(WI.WorkerManager.prototype.workerCreated):
Call initialize on the new target.

* UserInterface/Models/CSSCompletions.js:
(WI.CSSCompletions.initializeCSSCompletions):
(WI.CSSCompletions.requestCSSCompletions): Deleted.
Rename requestCSSCompletions to initializeCSSCompletions to try
and standardize on "initialize" being used for most frontend one
time initialization tasks. This being one such operation that
only needs to be performed once on a target that supports it.

* UserInterface/Protocol/Target.js:
(WI.Target):
(WI.Target.prototype.initialize):
Perform explicit target initialization, such as initializing
the state of all backend domains / agents. This is done by asking
each of the managers to do initialization work for this target.

(WI.Target.prototype.get ApplicationCacheAgent):
(WI.Target.prototype.get CSSAgent):
(WI.Target.prototype.get CanvasAgent):
(WI.Target.prototype.get ConsoleAgent):
(WI.Target.prototype.get DOMAgent):
(WI.Target.prototype.get DOMDebuggerAgent):
(WI.Target.prototype.get DOMStorageAgent):
(WI.Target.prototype.get DatabaseAgent):
(WI.Target.prototype.get DebuggerAgent):
(WI.Target.prototype.get HeapAgent):
(WI.Target.prototype.get IndexedDBAgent):
(WI.Target.prototype.get InspectorAgent):
(WI.Target.prototype.get LayerTreeAgent):
(WI.Target.prototype.get MemoryAgent):
(WI.Target.prototype.get NetworkAgent):
(WI.Target.prototype.get PageAgent):
(WI.Target.prototype.get RecordingAgent):
(WI.Target.prototype.get RuntimeAgent):
(WI.Target.prototype.get ScriptProfilerAgent):
(WI.Target.prototype.get ServiceWorkerAgent):
(WI.Target.prototype.get TargetAgent):
(WI.Target.prototype.get TimelineAgent):
(WI.Target.prototype.get WorkerAgent):
Accessors for all of the agents on a Target.

* UserInterface/Protocol/WorkerTarget.js:
(WI.WorkerTarget):
This is now automatically done in the base class.

* UserInterface/Test/Test.js:
(WI.loaded):
(WI.performOneTimeFrontendInitializationsUsingTarget):
New necessary top level hooks, and initialize more like Main.js.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237652 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Controllers/ApplicationCacheManager.js
Source/WebInspectorUI/UserInterface/Controllers/CSSManager.js
Source/WebInspectorUI/UserInterface/Controllers/CanvasManager.js
Source/WebInspectorUI/UserInterface/Controllers/ConsoleManager.js
Source/WebInspectorUI/UserInterface/Controllers/DOMManager.js
Source/WebInspectorUI/UserInterface/Controllers/DOMStorageManager.js
Source/WebInspectorUI/UserInterface/Controllers/DatabaseManager.js
Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js
Source/WebInspectorUI/UserInterface/Controllers/HeapManager.js
Source/WebInspectorUI/UserInterface/Controllers/IndexedDBManager.js
Source/WebInspectorUI/UserInterface/Controllers/LayerTreeManager.js
Source/WebInspectorUI/UserInterface/Controllers/MemoryManager.js
Source/WebInspectorUI/UserInterface/Controllers/NetworkManager.js
Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js
Source/WebInspectorUI/UserInterface/Controllers/TargetManager.js
Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js
Source/WebInspectorUI/UserInterface/Controllers/WorkerManager.js
Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js
Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js
Source/WebInspectorUI/UserInterface/Protocol/Target.js
Source/WebInspectorUI/UserInterface/Protocol/WorkerTarget.js
Source/WebInspectorUI/UserInterface/Test/Test.js

index cb0a2a0..446084e 100644 (file)
@@ -1,3 +1,130 @@
+2018-10-31  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Separate target initialization from frontend initialization
+        https://bugs.webkit.org/show_bug.cgi?id=191052
+        <rdar://problem/45658384>
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Base/Main.js:
+        (WI.loaded):
+        (WI.performOneTimeFrontendInitializationsUsingTarget):
+        Create the targets after the rest of frontend initialization. This is a step
+        toward a frontend opening and being told about multiple targets instead of
+        knowing in advance a single target it is connected to. All backend
+        messages during frontend initialization now happen with an explicit target.
+
+        * UserInterface/Controllers/ApplicationCacheManager.js:
+        (WI.ApplicationCacheManager):
+        (WI.ApplicationCacheManager.prototype.initializeTarget):
+        (WI.ApplicationCacheManager.prototype.initialize):
+        * UserInterface/Controllers/CSSManager.js:
+        (WI.CSSManager):
+        (WI.CSSManager.prototype.initializeTarget):
+        * UserInterface/Controllers/CanvasManager.js:
+        (WI.CanvasManager):
+        (WI.CanvasManager.prototype.initializeTarget):
+        * UserInterface/Controllers/ConsoleManager.js:
+        (WI.ConsoleManager):
+        (WI.ConsoleManager.prototype.initializeLogChannels):
+        * UserInterface/Controllers/DOMManager.js:
+        (WI.DOMManager):
+        (WI.DOMManager.prototype.initializeTarget):
+        * UserInterface/Controllers/DOMStorageManager.js:
+        (WI.DOMStorageManager):
+        (WI.DOMStorageManager.prototype.initializeTarget):
+        * UserInterface/Controllers/DatabaseManager.js:
+        (WI.DatabaseManager):
+        (WI.DatabaseManager.prototype.initializeTarget):
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WI.DebuggerManager):
+        (WI.DebuggerManager.prototype.initializeTarget):
+        (WI.DebuggerManager.restoreBreakpointsSoon): Deleted.
+        * UserInterface/Controllers/HeapManager.js:
+        (WI.HeapManager.prototype.initializeTarget):
+        * UserInterface/Controllers/IndexedDBManager.js:
+        (WI.IndexedDBManager):
+        (WI.IndexedDBManager.prototype.initializeTarget):
+        * UserInterface/Controllers/LayerTreeManager.js:
+        (WI.LayerTreeManager.prototype.initializeTarget):
+        * UserInterface/Controllers/MemoryManager.js:
+        (WI.MemoryManager.prototype.initializeTarget):
+        * UserInterface/Controllers/NetworkManager.js:
+        (WI.NetworkManager):
+        (WI.NetworkManager.prototype.initializeTarget):
+        * UserInterface/Controllers/RuntimeManager.js:
+        (WI.RuntimeManager):
+        (WI.RuntimeManager.prototype.initializeTarget):
+        * UserInterface/Controllers/TargetManager.js:
+        (WI.TargetManager):
+        (WI.TargetManager.prototype.initializeTargetsWithMainTarget):
+        * UserInterface/Controllers/TimelineManager.js:
+        (WI.TimelineManager):
+        (WI.TimelineManager.prototype.initializeTarget):
+        (WI.TimelineManager.prototype.set enabledTimelineTypes):
+        (WI.TimelineManager.prototype._updateAutoCaptureInstruments):
+        * UserInterface/Controllers/WorkerManager.js:
+        (WI.WorkerManager):
+        (WI.WorkerManager.prototype.initializeTarget):
+        Move Target initialization out of the constructor into a top level
+        `initializeTarget` function. This will be expected to be called
+        by any target that the frontend connects to.
+
+        (WI.DebuggerManager.prototype._pauseForInternalScriptsDidChange):
+        Drive-by fix. Update all targets if the setting changes.
+
+        (WI.WorkerManager.prototype.workerCreated):
+        Call initialize on the new target.
+
+        * UserInterface/Models/CSSCompletions.js:
+        (WI.CSSCompletions.initializeCSSCompletions):
+        (WI.CSSCompletions.requestCSSCompletions): Deleted.
+        Rename requestCSSCompletions to initializeCSSCompletions to try
+        and standardize on "initialize" being used for most frontend one
+        time initialization tasks. This being one such operation that
+        only needs to be performed once on a target that supports it.
+
+        * UserInterface/Protocol/Target.js:
+        (WI.Target):
+        (WI.Target.prototype.initialize):
+        Perform explicit target initialization, such as initializing
+        the state of all backend domains / agents. This is done by asking
+        each of the managers to do initialization work for this target.
+
+        (WI.Target.prototype.get ApplicationCacheAgent):
+        (WI.Target.prototype.get CSSAgent):
+        (WI.Target.prototype.get CanvasAgent):
+        (WI.Target.prototype.get ConsoleAgent):
+        (WI.Target.prototype.get DOMAgent):
+        (WI.Target.prototype.get DOMDebuggerAgent):
+        (WI.Target.prototype.get DOMStorageAgent):
+        (WI.Target.prototype.get DatabaseAgent):
+        (WI.Target.prototype.get DebuggerAgent):
+        (WI.Target.prototype.get HeapAgent):
+        (WI.Target.prototype.get IndexedDBAgent):
+        (WI.Target.prototype.get InspectorAgent):
+        (WI.Target.prototype.get LayerTreeAgent):
+        (WI.Target.prototype.get MemoryAgent):
+        (WI.Target.prototype.get NetworkAgent):
+        (WI.Target.prototype.get PageAgent):
+        (WI.Target.prototype.get RecordingAgent):
+        (WI.Target.prototype.get RuntimeAgent):
+        (WI.Target.prototype.get ScriptProfilerAgent):
+        (WI.Target.prototype.get ServiceWorkerAgent):
+        (WI.Target.prototype.get TargetAgent):
+        (WI.Target.prototype.get TimelineAgent):
+        (WI.Target.prototype.get WorkerAgent):
+        Accessors for all of the agents on a Target.
+
+        * UserInterface/Protocol/WorkerTarget.js:
+        (WI.WorkerTarget):
+        This is now automatically done in the base class.
+
+        * UserInterface/Test/Test.js:
+        (WI.loaded):
+        (WI.performOneTimeFrontendInitializationsUsingTarget):
+        New necessary top level hooks, and initialize more like Main.js.
+
 2018-10-31  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: Audit: show metadata for results
index fcb0e4f..d250edf 100644 (file)
@@ -88,17 +88,6 @@ WI.loaded = function()
     if (InspectorBackend.registerCanvasDispatcher)
         InspectorBackend.registerCanvasDispatcher(new WI.CanvasObserver);
 
-    // Main backend target.
-    WI.mainTarget = new WI.MainTarget;
-    WI.pageTarget = WI.sharedApp.debuggableType === WI.DebuggableType.Web ? WI.mainTarget : null;
-
-    // Enable agents.
-    if (window.InspectorAgent)
-        InspectorAgent.enable();
-
-    // Perform one-time tasks.
-    WI.CSSCompletions.requestCSSCompletions();
-
     // Listen for the ProvisionalLoadStarted event before registering for events so our code gets called before any managers or sidebars.
     // This lets us save a state cookie before any managers or sidebars do any resets that would affect state (namely TimelineManager).
     WI.Frame.addEventListener(WI.Frame.Event.ProvisionalLoadStarted, this._provisionalLoadStarted, this);
@@ -108,46 +97,38 @@ WI.loaded = function()
 
     // Create the singleton managers next, before the user interface elements, so the user interface can register
     // as event listeners on these managers.
-    this.targetManager = new WI.TargetManager;
-    this.branchManager = new WI.BranchManager;
-    this.networkManager = new WI.NetworkManager;
-    this.domStorageManager = new WI.DOMStorageManager;
-    this.databaseManager = new WI.DatabaseManager;
-    this.indexedDBManager = new WI.IndexedDBManager;
-    this.domManager = new WI.DOMManager;
-    this.cssManager = new WI.CSSManager;
-    this.consoleManager = new WI.ConsoleManager;
-    this.runtimeManager = new WI.RuntimeManager;
-    this.heapManager = new WI.HeapManager;
-    this.memoryManager = new WI.MemoryManager;
-    this.applicationCacheManager = new WI.ApplicationCacheManager;
-    this.timelineManager = new WI.TimelineManager;
-    this.debuggerManager = new WI.DebuggerManager;
-    this.layerTreeManager = new WI.LayerTreeManager;
-    this.workerManager = new WI.WorkerManager;
-    this.domDebuggerManager = new WI.DOMDebuggerManager;
-    this.canvasManager = new WI.CanvasManager;
-    this.auditManager = new WI.AuditManager;
-
-    // Enable the Console Agent after creating the singleton managers.
-    ConsoleAgent.enable();
-
-    // Tell the backend we are initialized after all our initialization messages have been sent.
-    setTimeout(function() {
-        // COMPATIBILITY (iOS 8): Inspector.initialized did not exist yet.
-        if (window.InspectorAgent && InspectorAgent.initialized)
-            InspectorAgent.initialized();
-    }, 0);
+    WI.managers = [
+        WI.targetManager = new WI.TargetManager,
+        WI.branchManager = new WI.BranchManager,
+        WI.networkManager = new WI.NetworkManager,
+        WI.domStorageManager = new WI.DOMStorageManager,
+        WI.databaseManager = new WI.DatabaseManager,
+        WI.indexedDBManager = new WI.IndexedDBManager,
+        WI.domManager = new WI.DOMManager,
+        WI.cssManager = new WI.CSSManager,
+        WI.consoleManager = new WI.ConsoleManager,
+        WI.runtimeManager = new WI.RuntimeManager,
+        WI.heapManager = new WI.HeapManager,
+        WI.memoryManager = new WI.MemoryManager,
+        WI.applicationCacheManager = new WI.ApplicationCacheManager,
+        WI.timelineManager = new WI.TimelineManager,
+        WI.debuggerManager = new WI.DebuggerManager,
+        WI.layerTreeManager = new WI.LayerTreeManager,
+        WI.workerManager = new WI.WorkerManager,
+        WI.domDebuggerManager = new WI.DOMDebuggerManager,
+        WI.canvasManager = new WI.CanvasManager,
+        WI.auditManager = new WI.AuditManager,
+    ];
 
     // Register for events.
-    this.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, this._debuggerDidPause, this);
-    this.debuggerManager.addEventListener(WI.DebuggerManager.Event.Resumed, this._debuggerDidResume, this);
-    this.domManager.addEventListener(WI.DOMManager.Event.InspectModeStateChanged, this._inspectModeStateChanged, this);
-    this.domManager.addEventListener(WI.DOMManager.Event.DOMNodeWasInspected, this._domNodeWasInspected, this);
-    this.domStorageManager.addEventListener(WI.DOMStorageManager.Event.DOMStorageObjectWasInspected, this._domStorageWasInspected, this);
-    this.databaseManager.addEventListener(WI.DatabaseManager.Event.DatabaseWasInspected, this._databaseWasInspected, this);
-    this.networkManager.addEventListener(WI.NetworkManager.Event.MainFrameDidChange, this._mainFrameDidChange, this);
-    this.networkManager.addEventListener(WI.NetworkManager.Event.FrameWasAdded, this._frameWasAdded, this);
+    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Paused, this._debuggerDidPause, this);
+    WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.Resumed, this._debuggerDidResume, this);
+    WI.domManager.addEventListener(WI.DOMManager.Event.InspectModeStateChanged, this._inspectModeStateChanged, this);
+    WI.domManager.addEventListener(WI.DOMManager.Event.DOMNodeWasInspected, this._domNodeWasInspected, this);
+    WI.domStorageManager.addEventListener(WI.DOMStorageManager.Event.DOMStorageObjectWasInspected, this._domStorageWasInspected, this);
+    WI.databaseManager.addEventListener(WI.DatabaseManager.Event.DatabaseWasInspected, this._databaseWasInspected, this);
+    WI.networkManager.addEventListener(WI.NetworkManager.Event.MainFrameDidChange, this._mainFrameDidChange, this);
+    WI.networkManager.addEventListener(WI.NetworkManager.Event.FrameWasAdded, this._frameWasAdded, this);
 
     WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
 
@@ -155,48 +136,32 @@ WI.loaded = function()
 
     // Create settings.
     this._showingSplitConsoleSetting = new WI.Setting("showing-split-console", false);
-
     this._openTabsSetting = new WI.Setting("open-tab-types", ["elements", "network", "debugger", "resources", "timeline", "storage", "canvas", "console"]);
     this._selectedTabIndexSetting = new WI.Setting("selected-tab-index", 0);
-
     this.showShadowDOMSetting = new WI.Setting("show-shadow-dom", false);
-
-    // COMPATIBILITY (iOS 8): Page.enableTypeProfiler did not exist.
     this.showJavaScriptTypeInformationSetting = new WI.Setting("show-javascript-type-information", false);
     this.showJavaScriptTypeInformationSetting.addEventListener(WI.Setting.Event.Changed, this._showJavaScriptTypeInformationSettingChanged, this);
-    if (this.showJavaScriptTypeInformationSetting.value && window.RuntimeAgent && RuntimeAgent.enableTypeProfiler)
-        RuntimeAgent.enableTypeProfiler();
-
     this.enableControlFlowProfilerSetting = new WI.Setting("enable-control-flow-profiler", false);
     this.enableControlFlowProfilerSetting.addEventListener(WI.Setting.Event.Changed, this._enableControlFlowProfilerSettingChanged, this);
-    if (this.enableControlFlowProfilerSetting.value && window.RuntimeAgent && RuntimeAgent.enableControlFlowProfiler)
-        RuntimeAgent.enableControlFlowProfiler();
-
-    // COMPATIBILITY (iOS 8): Page.setShowPaintRects did not exist.
     this.showPaintRectsSetting = new WI.Setting("show-paint-rects", false);
-    if (this.showPaintRectsSetting.value && window.PageAgent && PageAgent.setShowPaintRects)
-        PageAgent.setShowPaintRects(true);
-
-    this.printStylesEnabled = false;
-
-    // COMPATIBILITY (iOS 10.3): Network.setDisableResourceCaching did not exist.
     this.resourceCachingDisabledSetting = new WI.Setting("disable-resource-caching", false);
-    if (window.NetworkAgent && NetworkAgent.setResourceCachingDisabled) {
-        if (this.resourceCachingDisabledSetting.value)
-            NetworkAgent.setResourceCachingDisabled(true);
-        this.resourceCachingDisabledSetting.addEventListener(WI.Setting.Event.Changed, this._resourceCachingDisabledSettingChanged, this);
-    }
+    this.resourceCachingDisabledSetting.addEventListener(WI.Setting.Event.Changed, this._resourceCachingDisabledSettingChanged, this);
 
+    // State.
+    this.printStylesEnabled = false;
     this.setZoomFactor(WI.settings.zoomFactor.value);
-
-    this.mouseCoords = {
-        x: 0,
-        y: 0
-    };
-
+    this.mouseCoords = {x: 0, y: 0};
     this.visible = false;
-
     this._windowKeydownListeners = [];
+
+    // Targets.
+    WI.mainTarget = new WI.MainTarget;
+    WI.mainTarget.initialize();
+    WI.pageTarget = WI.sharedApp.debuggableType === WI.DebuggableType.Web ? WI.mainTarget : null;
+
+    // Post-target initialization.
+    WI.targetManager.initializeMainTarget();
+    WI.runtimeManager.activeExecutionContext = WI.mainTarget.executionContext;
 };
 
 WI.contentLoaded = function()
@@ -519,6 +484,19 @@ WI.contentLoaded = function()
         this.runBootstrapOperations();
 };
 
+WI.performOneTimeFrontendInitializationsUsingTarget = function(target)
+{
+    if (!WI.__didPerformConsoleInitialization && target.ConsoleAgent) {
+        WI.__didPerformConsoleInitialization = true;
+        WI.consoleManager.initializeLogChannels(target);
+    }
+
+    if (!WI.__didPerformCSSInitialization && target.CSSAgent) {
+        WI.__didPerformCSSInitialization = true;
+        WI.CSSCompletions.initializeCSSCompletions(target);
+    }
+};
+
 WI.isTabTypeAllowed = function(tabType)
 {
     let tabClass = this._knownTabClassesByType.get(tabType);
@@ -682,7 +660,8 @@ WI.activateExtraDomains = function(domains)
 {
     this.notifications.dispatchEventToListeners(WI.Notification.ExtraDomainsActivated, {domains});
 
-    WI.CSSCompletions.requestCSSCompletions();
+    if (WI.mainTarget && WI.mainTarget.CSSAgent)
+        WI.CSSCompletions.initializeCSSCompletions(WI.assumingMainTarget());
 
     this._updateReloadToolbarButton();
     this._updateDownloadToolbarButton();
@@ -2703,7 +2682,7 @@ WI.reportInternalError = function(errorOrString, details = {})
 
 Object.defineProperty(WI, "targets",
 {
-    get() { return this.targetManager.targets; }
+    get() { return WI.targetManager.targets; }
 });
 
 // Many places assume the main target because they cannot yet be
index f1341b2..20f6918 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: ApplicationCacheManager lacks advanced multi-target support. (ApplciationCache objects per-target)
+
 WI.ApplicationCacheManager = class ApplicationCacheManager extends WI.Object
 {
     constructor()
     {
         super();
 
-        if (window.ApplicationCacheAgent)
-            ApplicationCacheAgent.enable();
-
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
         WI.Frame.addEventListener(WI.Frame.Event.ChildFrameWasRemoved, this._childFrameWasRemoved, this);
 
@@ -40,14 +39,21 @@ WI.ApplicationCacheManager = class ApplicationCacheManager extends WI.Object
         this.initialize();
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.ApplicationCacheAgent) {
+            target.ApplicationCacheAgent.enable();
+            target.ApplicationCacheAgent.getFramesWithManifests(this._framesWithManifestsLoaded.bind(this));
+        }
+    }
+
     // Public
 
     initialize()
     {
         this._applicationCacheObjects = {};
-
-        if (window.ApplicationCacheAgent)
-            ApplicationCacheAgent.getFramesWithManifests(this._framesWithManifestsLoaded.bind(this));
     }
 
     get applicationCacheObjects()
index c792a23..b28b442 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: CSSManager lacks advanced multi-target support. (Stylesheets per-target)
+
 WI.CSSManager = class CSSManager extends WI.Object
 {
     constructor()
     {
         super();
 
-        if (window.CSSAgent)
-            CSSAgent.enable();
-
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
         WI.Frame.addEventListener(WI.Frame.Event.ResourceWasAdded, this._resourceAdded, this);
         WI.Resource.addEventListener(WI.SourceCode.Event.ContentDidChange, this._resourceContentDidChange, this);
@@ -52,6 +51,14 @@ WI.CSSManager = class CSSManager extends WI.Object
         this._fetchedInitialStyleSheets = window.CSSAgent && window.CSSAgent.hasEvent("styleSheetAdded");
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.CSSAgent)
+            target.CSSAgent.enable();
+    }
+
     // Static
 
     static protocolStyleSheetOriginToEnum(origin)
index ad5f2e9..1f50da3 100644 (file)
@@ -23,6 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: CanvasManager lacks advanced multi-target support. (Canvases per-target)
+
 WI.CanvasManager = class CanvasManager extends WI.Object
 {
     constructor()
@@ -34,9 +36,14 @@ WI.CanvasManager = class CanvasManager extends WI.Object
         this._canvasIdentifierMap = new Map;
         this._shaderProgramIdentifierMap = new Map;
         this._importedRecordings = new Set;
+    }
 
-        if (window.CanvasAgent)
-            CanvasAgent.enable();
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.CanvasAgent)
+            target.CanvasAgent.enable();
     }
 
     // Public
index bf4a117..bc56eb1 100644 (file)
@@ -39,20 +39,6 @@ WI.ConsoleManager = class ConsoleManager extends WI.Object
 
         this._customLoggingChannels = [];
         this._loggingChannelSources = [];
-
-        if (WI.ConsoleManager.supportsLogChannels()) {
-            this._loggingChannelSources = [WI.ConsoleMessage.MessageSource.Media, WI.ConsoleMessage.MessageSource.WebRTC];
-            ConsoleAgent.getLoggingChannels((error, channels) => {
-                if (error)
-                    return;
-
-                for (let channel of channels) {
-                    console.assert(this._loggingChannelSources.includes(channel.source));
-                }
-
-                this._customLoggingChannels = channels.map(WI.LoggingChannel.fromPayload);
-            });
-        }
     }
 
     // Static
@@ -164,6 +150,28 @@ WI.ConsoleManager = class ConsoleManager extends WI.Object
             target.ConsoleAgent.clearMessages();
     }
 
+    initializeLogChannels(target)
+    {
+        console.assert(target.ConsoleAgent);
+
+        if (!WI.ConsoleManager.supportsLogChannels())
+            return;
+
+        if (this._loggingChannelSources.length)
+            return;
+
+        this._loggingChannelSources = [WI.ConsoleMessage.MessageSource.Media, WI.ConsoleMessage.MessageSource.WebRTC];
+
+        target.ConsoleAgent.getLoggingChannels((error, channels) => {
+            if (error)
+                return;
+
+            console.assert(channels.every((channel) => this._loggingChannelSources.includes(channel.source)));
+
+            this._customLoggingChannels = channels.map(WI.LoggingChannel.fromPayload);
+        });
+    }
+
     // Private
 
     _mainResourceDidChange(event)
index 35a2f08..5081a6b 100644 (file)
@@ -30,6 +30,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: DOMManager lacks advanced multi-target support. (DOMNodes per-target)
+
 WI.DOMManager = class DOMManager extends WI.Object
 {
     constructor()
@@ -46,8 +48,21 @@ WI.DOMManager = class DOMManager extends WI.Object
         this._breakpointsForEventListeners = new Map;
 
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
+    }
 
-        this.ensureDocument();
+    // Target
+
+    initializeTarget(target)
+    {
+        // FIXME: This should be improved when adding better DOM multi-target support since it is really per-target.
+        // This currently uses a setTimeout since it doesn't need to happen immediately, and DOMManager uses the
+        // global DOMAgent to request the document, so we want to make sure we've transitioned the global agents
+        // to this target if necessary.
+        if (target.DOMAgent) {
+            setTimeout(() => {
+                this.ensureDocument();
+            });
+        }
     }
 
     // Public
@@ -71,19 +86,17 @@ WI.DOMManager = class DOMManager extends WI.Object
 
         this._pendingDocumentRequestCallbacks = [callback];
 
-        function onDocumentAvailable(error, root)
-        {
-            if (!error)
-                this._setDocument(root);
+        if (window.DOMAgent) {
+            DOMAgent.getDocument((error, root) => {
+                if (!error)
+                    this._setDocument(root);
 
-            for (let callback of this._pendingDocumentRequestCallbacks)
-                callback(this._document);
+                for (let callback of this._pendingDocumentRequestCallbacks)
+                    callback(this._document);
 
-            this._pendingDocumentRequestCallbacks = null;
+                this._pendingDocumentRequestCallbacks = null;
+            });
         }
-
-        if (window.DOMAgent)
-            DOMAgent.getDocument(onDocumentAvailable.bind(this));
     }
 
     ensureDocument()
index 4a3f540..eab97f4 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: DOMStorageManager lacks advanced multi-target support. (DOMStorage per-target)
+
 WI.DOMStorageManager = class DOMStorageManager extends WI.Object
 {
     constructor()
     {
         super();
 
-        if (window.DOMStorageAgent)
-            DOMStorageAgent.enable();
-
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
         WI.Frame.addEventListener(WI.Frame.Event.SecurityOriginDidChange, this._securityOriginDidChange, this);
 
         this.initialize();
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.DOMStorageAgent)
+            target.DOMStorageAgent.enable();
+    }
+
     // Public
 
     initialize()
index 9d84e1a..9c0d583 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: DatabaseManager lacks advanced multi-target support. (DataBase per-target)
+
 WI.DatabaseManager = class DatabaseManager extends WI.Object
 {
     constructor()
     {
         super();
 
-        if (window.DatabaseAgent)
-            DatabaseAgent.enable();
-
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
 
         this.initialize();
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.DatabaseAgent)
+            target.DatabaseAgent.enable();
+    }
+
     // Public
 
     initialize()
index 9a7a671..2836268 100644 (file)
@@ -29,8 +29,6 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
     {
         super();
 
-        DebuggerAgent.enable();
-
         WI.notifications.addEventListener(WI.Notification.DebugUIEnabledDidChange, this._debugUIEnabledDidChange, this);
 
         WI.Breakpoint.addEventListener(WI.Breakpoint.Event.DisplayLocationDidChange, this._breakpointDisplayLocationDidChange, this);
@@ -45,6 +43,8 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
 
         WI.targetManager.addEventListener(WI.TargetManager.Event.TargetRemoved, this._targetRemoved, this);
 
+        WI.settings.pauseForInternalScripts.addEventListener(WI.Setting.Event.Changed, this._pauseForInternalScriptsDidChange);
+
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
 
         this._breakpointsSetting = new WI.Setting("breakpoints", []);
@@ -78,7 +78,6 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
 
         this._internalWebKitScripts = [];
         this._targetDebuggerDataMap = new Map;
-        this._targetDebuggerDataMap.set(WI.mainTarget, new WI.DebuggerData(WI.mainTarget));
 
         // Used to detect deleted probe actions.
         this._knownProbeIdentifiersForBreakpoint = new Map;
@@ -95,37 +94,54 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
             this._temporarilyDisabledBreakpointsRestoreSetting.value = null;
         }
 
-        DebuggerAgent.setBreakpointsActive(this._breakpointsEnabledSetting.value);
-        DebuggerAgent.setPauseOnExceptions(this._breakOnExceptionsState);
+        this._ignoreBreakpointDisplayLocationDidChangeEvent = false;
+
+        // Ensure that all managers learn about restored breakpoints,
+        // regardless of their initialization order.
+        setTimeout(() => {
+            this._restoringBreakpoints = true;
+            for (let cookie of this._breakpointsSetting.value)
+                this.addBreakpoint(new WI.Breakpoint(cookie));
+            this._restoringBreakpoints = false;
+        });
+    }
+
+    // Target
+
+    initializeTarget(target)
+    {
+        let targetData = this.dataForTarget(target);
+
+        // Initialize global state.
+        target.DebuggerAgent.enable();
+        target.DebuggerAgent.setBreakpointsActive(this._breakpointsEnabledSetting.value);
+        target.DebuggerAgent.setPauseOnExceptions(this._breakOnExceptionsState);
 
         // COMPATIBILITY (iOS 10): DebuggerAgent.setPauseOnAssertions did not exist yet.
         if (DebuggerAgent.setPauseOnAssertions)
-            DebuggerAgent.setPauseOnAssertions(this._assertionFailuresBreakpointEnabledSetting.value);
+            target.DebuggerAgent.setPauseOnAssertions(this._assertionFailuresBreakpointEnabledSetting.value);
 
         // COMPATIBILITY (iOS 10): Debugger.setAsyncStackTraceDepth did not exist yet.
         if (DebuggerAgent.setAsyncStackTraceDepth)
-            DebuggerAgent.setAsyncStackTraceDepth(this._asyncStackTraceDepthSetting.value);
+            target.DebuggerAgent.setAsyncStackTraceDepth(this._asyncStackTraceDepthSetting.value);
 
         // COMPATIBILITY (iOS 12): DebuggerAgent.setPauseForInternalScripts did not exist yet.
-        if (DebuggerAgent.setPauseForInternalScripts) {
-            let updateBackendSetting = () => { DebuggerAgent.setPauseForInternalScripts(WI.settings.pauseForInternalScripts.value); };
-            WI.settings.pauseForInternalScripts.addEventListener(WI.Setting.Event.Changed, updateBackendSetting);
-
-            updateBackendSetting();
-        }
+        if (DebuggerAgent.setPauseForInternalScripts)
+            target.DebuggerAgent.setPauseForInternalScripts(WI.settings.pauseForInternalScripts.value);
 
-        this._ignoreBreakpointDisplayLocationDidChangeEvent = false;
+        if (this.paused)
+            targetData.pauseIfNeeded();
 
-        function restoreBreakpointsSoon() {
-            this._restoringBreakpoints = true;
-            for (let cookie of this._breakpointsSetting.value)
-                this.addBreakpoint(new WI.Breakpoint(cookie));
-            this._restoringBreakpoints = false;
+        // Initialize breakpoints.
+        this._restoringBreakpoints = true;
+        for (let breakpoint of this._breakpoints) {
+            if (breakpoint.disabled)
+                continue;
+            if (!breakpoint.contentIdentifier)
+                continue;
+            this._setBreakpoint(breakpoint, target);
         }
-
-        // Ensure that all managers learn about restored breakpoints,
-        // regardless of their initialization order.
-        setTimeout(restoreBreakpointsSoon.bind(this), 0);
+        this._restoringBreakpoints = false;
     }
 
     // Public
@@ -539,33 +555,6 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
         return this._nextBreakpointActionIdentifier++;
     }
 
-    initializeTarget(target)
-    {
-        let DebuggerAgent = target.DebuggerAgent;
-        let targetData = this.dataForTarget(target);
-
-        // Initialize global state.
-        DebuggerAgent.enable();
-        DebuggerAgent.setBreakpointsActive(this._breakpointsEnabledSetting.value);
-        DebuggerAgent.setPauseOnAssertions(this._assertionFailuresBreakpointEnabledSetting.value);
-        DebuggerAgent.setPauseOnExceptions(this._breakOnExceptionsState);
-        DebuggerAgent.setAsyncStackTraceDepth(this._asyncStackTraceDepthSetting.value);
-
-        if (this.paused)
-            targetData.pauseIfNeeded();
-
-        // Initialize breakpoints.
-        this._restoringBreakpoints = true;
-        for (let breakpoint of this._breakpoints) {
-            if (breakpoint.disabled)
-                continue;
-            if (!breakpoint.contentIdentifier)
-                continue;
-            this._setBreakpoint(breakpoint, target);
-        }
-        this._restoringBreakpoints = false;
-    }
-
     // Protected (Called from WI.DebuggerObserver)
 
     breakpointResolved(target, breakpointIdentifier, location)
@@ -1165,6 +1154,15 @@ WI.DebuggerManager = class DebuggerManager extends WI.Object
             this.dispatchEventToListeners(WI.DebuggerManager.Event.Resumed);
     }
 
+    _pauseForInternalScriptsDidChange(event)
+    {
+        // COMPATIBILITY (iOS 12): DebuggerAgent.setPauseForInternalScripts did not exist yet.
+        console.assert(DebuggerAgent.setPauseForInternalScripts);
+
+        for (let target of WI.targets)
+            target.DebuggerAgent.setPauseForInternalScripts(WI.settings.pauseForInternalScripts.value);
+    }
+
     _mainResourceDidChange(event)
     {
         if (!event.target.isMainFrame())
index 888c4b9..361e04b 100644 (file)
 
 WI.HeapManager = class HeapManager extends WI.Object
 {
-    constructor()
-    {
-        super();
+    // Target
 
-        if (window.HeapAgent)
-            HeapAgent.enable();
+    initializeTarget(target)
+    {
+        if (target.HeapAgent)
+            target.HeapAgent.enable();
     }
 
     // Public
index d272b0e..a3849fb 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: IndexedDBManager lacks advanced multi-target support. (IndexedDatabase per-target)
+
 WI.IndexedDBManager = class IndexedDBManager extends WI.Object
 {
     constructor()
     {
         super();
 
-        if (window.IndexedDBAgent)
-            IndexedDBAgent.enable();
-
         WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._mainResourceDidChange, this);
         WI.Frame.addEventListener(WI.Frame.Event.SecurityOriginDidChange, this._securityOriginDidChange, this);
 
         this.initialize();
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.IndexedDBAgent)
+            target.IndexedDBAgent.enable();
+    }
+
     // Public
 
     initialize()
index 6b8d317..17e1ad5 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: LayerTreeManager lacks advanced multi-target support. (Layers per-target)
+
 WI.LayerTreeManager = class LayerTreeManager extends WI.Object
 {
-    constructor()
-    {
-        super();
+    // Target
 
-        if (window.LayerTreeAgent)
-            LayerTreeAgent.enable();
+    initializeTarget(target)
+    {
+        if (target.LayerTreeAgent)
+            target.LayerTreeAgent.enable();
     }
 
     // Public
index ec71950..76e67a6 100644 (file)
 
 WI.MemoryManager = class MemoryManager extends WI.Object
 {
-    constructor()
-    {
-        super();
+    // Target
 
-        if (window.MemoryAgent)
-            MemoryAgent.enable();
+    initializeTarget(target)
+    {
+        if (target.MemoryAgent)
+            target.MemoryAgent.enable();
     }
 
     // Public
index 44d0b1c..4a8b307 100644 (file)
@@ -23,6 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: NetworkManager lacks advanced multi-target support. (Network.loadResource invocations per-target)
+
 WI.NetworkManager = class NetworkManager extends WI.Object
 {
     constructor()
@@ -40,19 +42,37 @@ WI.NetworkManager = class NetworkManager extends WI.Object
         this._sourceMapURLMap = new Map;
         this._downloadingSourceMaps = new Set;
 
-        if (window.PageAgent) {
-            PageAgent.enable();
-            PageAgent.getResourceTree(this._processMainFrameResourceTreePayload.bind(this));
+        WI.notifications.addEventListener(WI.Notification.ExtraDomainsActivated, this._extraDomainsActivated, this);
+        WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._handleFrameMainResourceDidChange, this);
+    }
+
+    // Target
+
+    initializeTarget(target)
+    {
+        if (target.PageAgent) {
+            target.PageAgent.enable();
+            target.PageAgent.getResourceTree(this._processMainFrameResourceTreePayload.bind(this));
         }
 
-        if (window.ServiceWorkerAgent)
-            ServiceWorkerAgent.getInitializationInfo(this._processServiceWorkerConfiguration.bind(this));
+        // FIXME: ServiceWorkerAgent should only be exposed in the "serviceworker" target type.
+        // Currently it is exposed to "web" targets. Work around this by only using the
+        // ServiceWorker domain if there is no Page domain.
+        if (target.ServiceWorkerAgent && !target.PageAgent)
+            target.ServiceWorkerAgent.getInitializationInfo(this._processServiceWorkerConfiguration.bind(this));
 
-        if (window.NetworkAgent)
-            NetworkAgent.enable();
+        if (target.NetworkAgent) {
+            target.NetworkAgent.enable();
 
-        WI.notifications.addEventListener(WI.Notification.ExtraDomainsActivated, this._extraDomainsActivated, this);
-        WI.Frame.addEventListener(WI.Frame.Event.MainResourceDidChange, this._handleFrameMainResourceDidChange, this);
+            // COMPATIBILITY (iOS 10.3): Network.setDisableResourceCaching did not exist.
+            if (NetworkAgent.setResourceCachingDisabled) {
+                if (WI.resourceCachingDisabledSetting && WI.resourceCachingDisabledSetting.value)
+                    target.NetworkAgent.setResourceCachingDisabled(true);
+            }
+        }
+
+        if (target.type === WI.Target.Type.Worker)
+            this.adoptOrphanedResourcesForTarget(target);
     }
 
     // Public
index 6c51516..73b6af5 100644 (file)
@@ -29,14 +29,26 @@ WI.RuntimeManager = class RuntimeManager extends WI.Object
     {
         super();
 
-        // Enable the RuntimeAgent to receive notification of execution contexts.
-        RuntimeAgent.enable();
-
-        this._activeExecutionContext = WI.mainTarget.executionContext;
+        this._activeExecutionContext = null;
 
         WI.Frame.addEventListener(WI.Frame.Event.ExecutionContextsCleared, this._frameExecutionContextsCleared, this);
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        target.RuntimeAgent.enable();
+
+        // COMPATIBILITY (iOS 8): Runtime.enableTypeProfiler did not exist.
+        if (WI.showJavaScriptTypeInformationSetting && WI.showJavaScriptTypeInformationSetting.value && RuntimeAgent.enableTypeProfiler)
+            target.RuntimeAgent.enableTypeProfiler();
+
+        // COMPATIBILITY (iOS 10): Runtime.enableControlFlowProfiler did not exist
+        if (WI.enableControlFlowProfilerSetting && WI.enableControlFlowProfilerSetting.value && RuntimeAgent.enableControlFlowProfiler)
+            target.RuntimeAgent.enableControlFlowProfiler();
+    }
+
     // Public
 
     get activeExecutionContext()
index 9590fb4..c757cb6 100644 (file)
@@ -29,9 +29,7 @@ WI.TargetManager = class TargetManager extends WI.Object
     {
         super();
 
-        console.assert(WI.mainTarget);
-
-        this._targets = new Set([WI.mainTarget]);
+        this._targets = new Set;
     }
 
     // Public
@@ -70,6 +68,12 @@ WI.TargetManager = class TargetManager extends WI.Object
 
         this.dispatchEventToListeners(WI.TargetManager.Event.TargetRemoved, {target});
     }
+
+    initializeMainTarget()
+    {
+        console.assert(WI.mainTarget);
+        this._targets.add(WI.mainTarget);
+    }
 };
 
 WI.TargetManager.Event = {
index 226f399..9eae45b 100644 (file)
@@ -23,6 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: TimelineManager lacks advanced multi-target support. (Instruments/Profilers per-target)
+
 WI.TimelineManager = class TimelineManager extends WI.Object
 {
     constructor()
@@ -38,7 +40,6 @@ WI.TimelineManager = class TimelineManager extends WI.Object
         WI.memoryManager.addEventListener(WI.MemoryManager.Event.MemoryPressure, this._memoryPressure, this);
 
         this._enabledTimelineTypesSetting = new WI.Setting("enabled-instrument-types", WI.TimelineManager.defaultTimelineTypes());
-        this._updateAutoCaptureInstruments();
 
         this._persistentNetworkTimeline = new WI.NetworkTimeline;
 
@@ -62,6 +63,13 @@ WI.TimelineManager = class TimelineManager extends WI.Object
         this.reset();
     }
 
+    // Target
+
+    initializeTarget(target)
+    {
+        this._updateAutoCaptureInstruments([target]);
+    }
+
     // Static
 
     static defaultTimelineTypes()
@@ -167,7 +175,7 @@ WI.TimelineManager = class TimelineManager extends WI.Object
     {
         this._enabledTimelineTypesSetting.value = x || [];
 
-        this._updateAutoCaptureInstruments();
+        this._updateAutoCaptureInstruments(WI.targets);
     }
 
     isCapturing()
@@ -1052,11 +1060,8 @@ WI.TimelineManager = class TimelineManager extends WI.Object
         // FIXME: <https://webkit.org/b/152904> Web Inspector: Timeline UI should keep up with processing all incoming records
     }
 
-    _updateAutoCaptureInstruments()
+    _updateAutoCaptureInstruments(targets)
     {
-        if (!window.TimelineAgent)
-            return;
-
         if (!TimelineAgent.setInstruments)
             return;
 
@@ -1082,7 +1087,10 @@ WI.TimelineManager = class TimelineManager extends WI.Object
             }
         }
 
-        TimelineAgent.setInstruments([...instrumentSet]);
+        for (let target of targets) {
+            if (target.TimelineAgent)
+                target.TimelineAgent.setInstruments([...instrumentSet]);
+        }
     }
 };
 
index 029eb54..537354b 100644 (file)
@@ -30,9 +30,14 @@ WI.WorkerManager = class WorkerManager extends WI.Object
         super();
 
         this._connections = new Map;
+    }
+
+    // Target
 
-        if (window.WorkerAgent)
-            WorkerAgent.enable();
+    initializeTarget(target)
+    {
+        if (target.WorkerAgent)
+            target.WorkerAgent.enable();
     }
 
     // Public
@@ -41,6 +46,8 @@ WI.WorkerManager = class WorkerManager extends WI.Object
     {
         let connection = new InspectorBackend.WorkerConnection(workerId);
         let workerTarget = new WI.WorkerTarget(workerId, url, connection);
+        workerTarget.initialize();
+
         WI.targetManager.addTarget(workerTarget);
 
         this._connections.set(workerId, connection);
index bb51ef3..05fb4fd 100644 (file)
@@ -78,8 +78,10 @@ WI.CSSCompletions = class CSSCompletions
 
     // Static
 
-    static requestCSSCompletions()
+    static initializeCSSCompletions(target)
     {
+        console.assert(target.CSSAgent);
+
         if (WI.CSSCompletions.cssNameCompletions)
             return;
 
@@ -162,13 +164,11 @@ WI.CSSCompletions = class CSSCompletions
             WI.CSSKeywordCompletions.addPropertyCompletionValues("font", fontFamilyNames);
         }
 
-        if (window.CSSAgent) {
-            CSSAgent.getSupportedCSSProperties(propertyNamesCallback);
+        target.CSSAgent.getSupportedCSSProperties(propertyNamesCallback);
 
-            // COMPATIBILITY (iOS 9): CSS.getSupportedSystemFontFamilyNames did not exist.
-            if (CSSAgent.getSupportedSystemFontFamilyNames)
-                CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback);
-        }
+        // COMPATIBILITY (iOS 9): CSS.getSupportedSystemFontFamilyNames did not exist.
+        if (CSSAgent.getSupportedSystemFontFamilyNames)
+            target.CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback);
     }
 
     // Public
index c8813db..46a1210 100644 (file)
@@ -70,6 +70,7 @@ InspectorBackendClass = class InspectorBackendClass
 
     get dumpInspectorProtocolMessages()
     {
+        return true;
         return WI.settings.autoLogProtocolMessages.value;
     }
 
index 92d13fc..0f6c335 100644 (file)
@@ -33,20 +33,88 @@ WI.Target = class Target extends WI.Object
         this._name = name;
         this._type = type;
         this._connection = connection;
+        this._agents = connection._agents;
         this._executionContext = null;
         this._mainResource = null;
         this._resourceCollection = new WI.ResourceCollection;
         this._extraScriptCollection = new WI.ScriptCollection;
 
         this._connection.target = this;
+
+        // Agents we always expect in every target.
+        console.assert(this.RuntimeAgent);
+        console.assert(this.DebuggerAgent);
+        console.assert(this.ConsoleAgent);
+    }
+
+    // Target
+
+    initialize()
+    {
+        // Intentionally initialize InspectorAgent first if it is available.
+        // This may not be strictly necessary anymore, but is historical.
+        if (this.InspectorAgent)
+            this.InspectorAgent.enable();
+
+        // Initialize agents.
+        for (let manager of WI.managers) {
+            if (manager.initializeTarget)
+                manager.initializeTarget(this);
+        }
+
+        // Non-manager specific initialization.
+        // COMPATIBILITY (iOS 8): Page.setShowPaintRects did not exist.
+        if (this.PageAgent) {
+            if (PageAgent.setShowPaintRects && WI.showPaintRectsSetting && WI.showPaintRectsSetting.value)
+                this.PageAgent.setShowPaintRects(true);
+        }
+
+        // Intentionally defer ConsoleAgent initialization to the end. We do this so that any
+        // previous initialization messages will have their responses arrive before a stream
+        // of console message added events come in after enabling Console.
+        this.ConsoleAgent.enable();
+
+        setTimeout(() => {
+            // Use this opportunity to run any one time frontend initialization
+            // now that we have a target with potentially new capabilities.
+            WI.performOneTimeFrontendInitializationsUsingTarget(this);
+        });
+
+        setTimeout(() => {
+            // Tell the backend we are initialized after all our initialization messages have been sent.
+            // This allows an automatically paused backend to resume execution, but we want to ensure
+            // our breakpoints were already sent to that backend.
+            // COMPATIBILITY (iOS 8): Inspector.initialized did not exist yet.
+            if (this.InspectorAgent && InspectorAgent.initialized)
+                this.InspectorAgent.initialized();
+        });
     }
 
     // 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; }
+    get ApplicationCacheAgent() { return this._agents.ApplicationCache; }
+    get CSSAgent() { return this._agents.CSS; }
+    get CanvasAgent() { return this._agents.Canvas; }
+    get ConsoleAgent() { return this._agents.Console; }
+    get DOMAgent() { return this._agents.DOM; }
+    get DOMDebuggerAgent() { return this._agents.DOMDebugger; }
+    get DOMStorageAgent() { return this._agents.DOMStorage; }
+    get DatabaseAgent() { return this._agents.Database; }
+    get DebuggerAgent() { return this._agents.Debugger; }
+    get HeapAgent() { return this._agents.Heap; }
+    get IndexedDBAgent() { return this._agents.IndexedDB; }
+    get InspectorAgent() { return this._agents.Inspector; }
+    get LayerTreeAgent() { return this._agents.LayerTree; }
+    get MemoryAgent() { return this._agents.Memory; }
+    get NetworkAgent() { return this._agents.Network; }
+    get PageAgent() { return this._agents.Page; }
+    get RecordingAgent() { return this._agents.Recording; }
+    get RuntimeAgent() { return this._agents.Runtime; }
+    get ScriptProfilerAgent() { return this._agents.ScriptProfiler; }
+    get ServiceWorkerAgent() { return this._agents.ServiceWorker; }
+    get TargetAgent() { return this._agents.Target; }
+    get TimelineAgent() { return this._agents.Timeline; }
+    get WorkerAgent() { return this._agents.Worker; }
 
     // Public
 
index de4e349..bb0be69 100644 (file)
@@ -29,25 +29,7 @@ WI.WorkerTarget = class WorkerTarget extends WI.Target
     {
         super(workerId, name, WI.Target.Type.Worker, connection);
 
-        WI.networkManager.adoptOrphanedResourcesForTarget(this);
-
-        if (this.RuntimeAgent) {
-            this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelExecutionContextIdentifier, this.displayName, false, null);
-            this.RuntimeAgent.enable();
-            if (WI.showJavaScriptTypeInformationSetting && WI.showJavaScriptTypeInformationSetting.value)
-                this.RuntimeAgent.enableTypeProfiler();
-            if (WI.enableControlFlowProfilerSetting && WI.enableControlFlowProfilerSetting.value)
-                this.RuntimeAgent.enableControlFlowProfiler();
-        }
-
-        if (this.DebuggerAgent)
-            WI.debuggerManager.initializeTarget(this);
-
-        if (this.ConsoleAgent)
-            this.ConsoleAgent.enable();
-
-        if (this.HeapAgent)
-            this.HeapAgent.enable();
+        this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, this.displayName, false, null);
     }
 
     // Protected (Target)
index e012c1d..744afe7 100644 (file)
@@ -44,38 +44,40 @@ WI.loaded = function()
     InspectorBackend.registerWorkerDispatcher(new WI.WorkerObserver);
     InspectorBackend.registerCanvasDispatcher(new WI.CanvasObserver);
 
-    WI.mainTarget = new WI.MainTarget;
-    WI.pageTarget = WI.sharedApp.debuggableType === WI.DebuggableType.Web ? WI.mainTarget : null;
-
     // Instantiate controllers used by tests.
-    this.targetManager = new WI.TargetManager;
-    this.networkManager = new WI.NetworkManager;
-    this.domStorageManager = new WI.DOMStorageManager;
-    this.domManager = new WI.DOMManager;
-    this.cssManager = new WI.CSSManager;
-    this.consoleManager = new WI.ConsoleManager;
-    this.runtimeManager = new WI.RuntimeManager;
-    this.heapManager = new WI.HeapManager;
-    this.memoryManager = new WI.MemoryManager;
-    this.timelineManager = new WI.TimelineManager;
-    this.debuggerManager = new WI.DebuggerManager;
-    this.layerTreeManager = new WI.LayerTreeManager;
-    this.workerManager = new WI.WorkerManager;
-    this.domDebuggerManager = new WI.DOMDebuggerManager;
-    this.canvasManager = new WI.CanvasManager;
-    this.auditManager = new WI.AuditManager;
-
+    WI.managers = [
+        WI.targetManager = new WI.TargetManager,
+        WI.networkManager = new WI.NetworkManager,
+        WI.domStorageManager = new WI.DOMStorageManager,
+        WI.domManager = new WI.DOMManager,
+        WI.cssManager = new WI.CSSManager,
+        WI.consoleManager = new WI.ConsoleManager,
+        WI.runtimeManager = new WI.RuntimeManager,
+        WI.heapManager = new WI.HeapManager,
+        WI.memoryManager = new WI.MemoryManager,
+        WI.timelineManager = new WI.TimelineManager,
+        WI.debuggerManager = new WI.DebuggerManager,
+        WI.layerTreeManager = new WI.LayerTreeManager,
+        WI.workerManager = new WI.WorkerManager,
+        WI.domDebuggerManager = new WI.DOMDebuggerManager,
+        WI.canvasManager = new WI.CanvasManager,
+        WI.auditManager = new WI.AuditManager,
+    ];
+
+    // Register for events.
     document.addEventListener("DOMContentLoaded", this.contentLoaded);
 
-    // Enable agents.
-    InspectorAgent.enable();
-    ConsoleAgent.enable();
-
-    // Perform one-time tasks.
-    WI.CSSCompletions.requestCSSCompletions();
-
     // Global settings.
     this.showShadowDOMSetting = new WI.Setting("show-shadow-dom", true);
+
+    // Targets.
+    WI.mainTarget = new WI.MainTarget;
+    WI.mainTarget.initialize();
+    WI.pageTarget = WI.sharedApp.debuggableType === WI.DebuggableType.Web ? WI.mainTarget : null;
+
+    // Post-target initialization.
+    WI.targetManager.initializeMainTarget();
+    WI.runtimeManager.activeExecutionContext = WI.mainTarget.executionContext;
 };
 
 WI.contentLoaded = function()
@@ -88,9 +90,22 @@ WI.contentLoaded = function()
     InspectorFrontendHost.loaded();
 };
 
+WI.performOneTimeFrontendInitializationsUsingTarget = function(target)
+{
+    if (!WI.__didPerformConsoleInitialization && target.ConsoleAgent) {
+        WI.__didPerformConsoleInitialization = true;
+        WI.consoleManager.initializeLogChannels(target);
+    }
+
+    if (!WI.__didPerformCSSInitialization && target.CSSAgent) {
+        WI.__didPerformCSSInitialization = true;
+        WI.CSSCompletions.initializeCSSCompletions(target);
+    }
+};
+
 Object.defineProperty(WI, "targets",
 {
-    get() { return this.targetManager.targets; }
+    get() { return WI.targetManager.targets; }
 });
 
 WI.assumingMainTarget = () => WI.mainTarget;