Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Web Inspector: introduce an AppController class and shared instance o…
…f it https://bugs.webkit.org/show_bug.cgi?id=177024 Reviewed by Matt Baker. WebInspectorUI currently has an app controller singleton that's distributed among many properties on the WI object, which also serves as a namespace for classes, enums, and other frontend objects. The singleton should be a proper class so that we can think more easily about what state is global. In the process of moving pieces of Main.js into AppController, I intend to move most UI related code into a view controller class for the top level view. AppController really shouldn't be doing anything to the view hierarchy or DOM. It is yet to be determined how responsibility for global DOM events, such as those for keyboard shortcuts, will be handled. This larger refactoring project will let us more easily do things like connect to multiple debuggables in the same Inspector instance, and switch between views of different debuggable targets. Even if this never comes to pass, the code will be a lot easier to reason about and maintain in the future. For the first patch, introduce {AppController, TestAppController} <: AppControllerBase. Shared code goes in the base class. In the Main.html and Test.html files, first construct the AppController and then call .initialize() to avoid cyclic dependencies on the global singleton WI.sharedApp. * UserInterface/Main.html: * UserInterface/Test.html: * UserInterface/Test/Test.js: (WI.loaded): * UserInterface/Base/Main.js: (WI.loaded): Move some shared code out of here into AppControllerBase.constructor. Eventually WI.loaded should not exist, and its code will move elsewhere. (WI.contentLoaded): Adopt global reference. * UserInterface/Controllers/AppControllerBase.js: Copied from Source/WebInspectorUI/UserInterface/Protocol/MainTarget.js. (WI.AppControllerBase): (WI.AppControllerBase.prototype.get hasExtraDomains): (WI.AppControllerBase.prototype.get debuggableType): (WI.AppControllerBase.prototype.initialize): * UserInterface/Controllers/AppController.js: New. (WI.AppController): (WI.AppController.prototype.get hasExtraDomains): (WI.AppController.prototype.get debuggableType): (WI.AppController.prototype.activateExtraDomains): * UserInterface/Test/TestAppController.js: New. (WI.TestAppController): (WI.TestAppController.prototype.get hasExtraDomains): (WI.TestAppController.prototype.get debuggableType): * UserInterface/Controllers/TimelineManager.js: (WI.TimelineManager.defaultTimelineTypes): (WI.TimelineManager.availableTimelineTypes): (WI.TimelineManager.prototype.scriptProfilerProgrammaticCaptureStarted): (WI.TimelineManager.prototype.scriptProfilerProgrammaticCaptureStopped): (WI.TimelineManager.prototype.scriptProfilerTrackingCompleted): * UserInterface/Models/TimelineRecording.js: (WI.TimelineRecording.sourceCodeTimelinesSupported): * UserInterface/Protocol/InspectorObserver.js: (WI.InspectorObserver.prototype.inspect): (WI.InspectorObserver.prototype.activateExtraDomains): (WI.InspectorObserver): * UserInterface/Protocol/MainTarget.js: (WI.MainTarget): (WI.MainTarget.prototype.get displayName): * UserInterface/Views/ResourceSidebarPanel.js: (WI.ResourceSidebarPanel): (WI.ResourceSidebarPanel.prototype.initialLayout): (WI.ResourceSidebarPanel.prototype._addScript): (WI.ResourceSidebarPanel.prototype._extraDomainsActivated): * UserInterface/Views/Toolbar.js: Use WI.sharedApp.{debuggableType, hasExtraDomains}. Canonical link: https://commits.webkit.org/193503@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222181 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
268 additions
and 46 deletions.
- +80 −0 Source/WebInspectorUI/ChangeLog
- +4 −20 Source/WebInspectorUI/UserInterface/Base/Main.js
- +59 −0 Source/WebInspectorUI/UserInterface/Controllers/AppController.js
- +66 −0 Source/WebInspectorUI/UserInterface/Controllers/AppControllerBase.js
- +5 −5 Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js
- +4 −1 Source/WebInspectorUI/UserInterface/Main.html
- +1 −1 Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js
- +2 −2 Source/WebInspectorUI/UserInterface/Protocol/InspectorObserver.js
- +3 −3 Source/WebInspectorUI/UserInterface/Protocol/MainTarget.js
- +4 −1 Source/WebInspectorUI/UserInterface/Test.html
- +0 −8 Source/WebInspectorUI/UserInterface/Test/Test.js
- +35 −0 Source/WebInspectorUI/UserInterface/Test/TestAppController.js
- +4 −4 Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js
- +1 −1 Source/WebInspectorUI/UserInterface/Views/Toolbar.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2017 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
WI.AppController = class AppController extends WI.AppControllerBase | ||
{ | ||
constructor() | ||
{ | ||
super(); | ||
|
||
this._hasExtraDomains = false; | ||
this._debuggableType = InspectorFrontendHost.debuggableType() === "web" ? WI.DebuggableType.Web : WI.DebuggableType.JavaScript; | ||
} | ||
|
||
// Properties. | ||
|
||
get hasExtraDomains() { return this._hasExtraDomains; } | ||
get debuggableType() { return this._debuggableType; } | ||
|
||
// API. | ||
|
||
activateExtraDomains(domains) | ||
{ | ||
if (this._hasExtraDomains) | ||
throw new Error("Extra domains have already been activated, cannot activate again."); | ||
|
||
this._hasExtraDomains = true; | ||
|
||
for (let domain of domains) { | ||
let agent = InspectorBackend.activateDomain(domain); | ||
if (agent.enable) | ||
agent.enable(); | ||
} | ||
|
||
// FIXME: all code within WI.activateExtraDomains should be distributed elsewhere. | ||
WI.activateExtraDomains(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2017 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
WI.DebuggableType = { | ||
Web: "web", | ||
JavaScript: "javascript" | ||
}; | ||
|
||
WI.NotImplementedError = class NotImplementedError extends Error | ||
{ | ||
constructor(message="This method is not implemented.") | ||
{ | ||
super(message); | ||
} | ||
|
||
static subclassMustOverride() | ||
{ | ||
return new WI.NotImplementedError("This method must be overridden by a subclass."); | ||
} | ||
}; | ||
|
||
WI.AppControllerBase = class AppControllerBase | ||
{ | ||
constructor() | ||
{ | ||
this._initialized = false; | ||
} | ||
|
||
get hasExtraDomains() { throw WI.NotImplementedError.subclassMustOverride(); } | ||
get debuggableType() { throw WI.NotImplementedError.subclassMustOverride(); } | ||
|
||
// Since various members of the app controller depend on the global singleton to exist, | ||
// some initialization needs to happen after the app controller has been constructed. | ||
initialize() | ||
{ | ||
if (this._initialized) | ||
throw new Error("App controller is already initialized."); | ||
|
||
this._initialized = true; | ||
|
||
// FIXME: eventually all code within WI.loaded should be distributed elsewhere. | ||
WI.loaded(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -56,7 +56,7 @@ WI.TimelineRecording = class TimelineRecording extends WI.Object | ||
|
||
static sourceCodeTimelinesSupported() | ||
{ | ||
return WI.sharedApp.debuggableType === WI.DebuggableType.Web; | ||
} | ||
|
||
// Public | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.