Changeset 222181 in webkit
- Timestamp:
- Sep 18, 2017 2:33:41 PM (7 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 11 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r222174 r222181 1 2017-09-18 Brian Burg <bburg@apple.com> 2 3 Web Inspector: introduce an AppController class and shared instance of it 4 https://bugs.webkit.org/show_bug.cgi?id=177024 5 6 Reviewed by Matt Baker. 7 8 WebInspectorUI currently has an app controller singleton that's distributed 9 among many properties on the WI object, which also serves as a namespace for 10 classes, enums, and other frontend objects. The singleton should be a proper 11 class so that we can think more easily about what state is global. 12 13 In the process of moving pieces of Main.js into AppController, I intend to move 14 most UI related code into a view controller class for the top level view. 15 AppController really shouldn't be doing anything to the view hierarchy or DOM. 16 It is yet to be determined how responsibility for global DOM events, such as 17 those for keyboard shortcuts, will be handled. 18 19 This larger refactoring project will let us more easily do things like connect 20 to multiple debuggables in the same Inspector instance, and switch between views 21 of different debuggable targets. Even if this never comes to pass, the code will 22 be a lot easier to reason about and maintain in the future. 23 24 For the first patch, introduce {AppController, TestAppController} <: AppControllerBase. 25 Shared code goes in the base class. In the Main.html and Test.html files, first 26 construct the AppController and then call .initialize() to avoid cyclic dependencies 27 on the global singleton WI.sharedApp. 28 29 * UserInterface/Main.html: 30 * UserInterface/Test.html: 31 * UserInterface/Test/Test.js: 32 (WI.loaded): 33 * UserInterface/Base/Main.js: 34 (WI.loaded): 35 Move some shared code out of here into AppControllerBase.constructor. 36 Eventually WI.loaded should not exist, and its code will move elsewhere. 37 38 (WI.contentLoaded): 39 Adopt global reference. 40 41 * UserInterface/Controllers/AppControllerBase.js: Copied from Source/WebInspectorUI/UserInterface/Protocol/MainTarget.js. 42 (WI.AppControllerBase): 43 (WI.AppControllerBase.prototype.get hasExtraDomains): 44 (WI.AppControllerBase.prototype.get debuggableType): 45 (WI.AppControllerBase.prototype.initialize): 46 47 * UserInterface/Controllers/AppController.js: New. 48 (WI.AppController): 49 (WI.AppController.prototype.get hasExtraDomains): 50 (WI.AppController.prototype.get debuggableType): 51 (WI.AppController.prototype.activateExtraDomains): 52 53 * UserInterface/Test/TestAppController.js: New. 54 (WI.TestAppController): 55 (WI.TestAppController.prototype.get hasExtraDomains): 56 (WI.TestAppController.prototype.get debuggableType): 57 58 * UserInterface/Controllers/TimelineManager.js: 59 (WI.TimelineManager.defaultTimelineTypes): 60 (WI.TimelineManager.availableTimelineTypes): 61 (WI.TimelineManager.prototype.scriptProfilerProgrammaticCaptureStarted): 62 (WI.TimelineManager.prototype.scriptProfilerProgrammaticCaptureStopped): 63 (WI.TimelineManager.prototype.scriptProfilerTrackingCompleted): 64 * UserInterface/Models/TimelineRecording.js: 65 (WI.TimelineRecording.sourceCodeTimelinesSupported): 66 * UserInterface/Protocol/InspectorObserver.js: 67 (WI.InspectorObserver.prototype.inspect): 68 (WI.InspectorObserver.prototype.activateExtraDomains): 69 (WI.InspectorObserver): 70 * UserInterface/Protocol/MainTarget.js: 71 (WI.MainTarget): 72 (WI.MainTarget.prototype.get displayName): 73 * UserInterface/Views/ResourceSidebarPanel.js: 74 (WI.ResourceSidebarPanel): 75 (WI.ResourceSidebarPanel.prototype.initialLayout): 76 (WI.ResourceSidebarPanel.prototype._addScript): 77 (WI.ResourceSidebarPanel.prototype._extraDomainsActivated): 78 * UserInterface/Views/Toolbar.js: 79 Use WI.sharedApp.{debuggableType, hasExtraDomains}. 80 1 81 2017-09-18 Matt Baker <mattbaker@apple.com> 2 82 -
trunk/Source/WebInspectorUI/UserInterface/Base/Main.js
r221943 r222181 34 34 }; 35 35 36 WI.DebuggableType = {37 Web: "web",38 JavaScript: "javascript"39 };40 41 36 WI.SelectedSidebarPanelCookieKey = "selected-sidebar-panel"; 42 37 WI.TypeIdentifierCookieKey = "represented-object-type"; … … 56 51 WI.loaded = function() 57 52 { 58 this.debuggableType = InspectorFrontendHost.debuggableType() === "web" ? WI.DebuggableType.Web : WI.DebuggableType.JavaScript;59 this.hasExtraDomains = false;60 61 53 // Register observers for events from the InspectorBackend. 62 54 if (InspectorBackend.registerInspectorDispatcher) … … 248 240 } 249 241 250 document.body.classList.add( this.debuggableType);242 document.body.classList.add(WI.sharedApp.debuggableType); 251 243 document.body.setAttribute("dir", this.resolvedLayoutDirection()); 252 244 … … 379 371 380 372 var toolTip; 381 if (WI. debuggableType === WI.DebuggableType.JavaScript)373 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) 382 374 toolTip = WI.UIString("Restart (%s)").format(this._reloadPageKeyboardShortcut.displayName); 383 375 else … … 705 697 WI.activateExtraDomains = function(domains) 706 698 { 707 this.hasExtraDomains = true;708 709 for (var domain of domains) {710 var agent = InspectorBackend.activateDomain(domain);711 if (agent.enable)712 agent.enable();713 }714 715 699 this.notifications.dispatchEventToListeners(WI.Notification.ExtraDomainsActivated, {"domains": domains}); 716 700 … … 1860 1844 { 1861 1845 // COMPATIBILITY (iOS 7): Page.archive did not exist yet. 1862 if (!window.PageAgent || !PageAgent.archive || this. debuggableType !== WI.DebuggableType.Web) {1846 if (!window.PageAgent || !PageAgent.archive || this.sharedApp.debuggableType !== WI.DebuggableType.Web) { 1863 1847 this._downloadToolbarButton.hidden = true; 1864 1848 return; … … 2590 2574 { 2591 2575 // COMPATIBILITY (iOS 7): Page.archive did not exist yet. 2592 if (!PageAgent.archive || this. debuggableType !== WI.DebuggableType.Web)2576 if (!PageAgent.archive || this.sharedApp.debuggableType !== WI.DebuggableType.Web) 2593 2577 return false; 2594 2578 -
trunk/Source/WebInspectorUI/UserInterface/Controllers/AppController.js
r222180 r222181 1 1 /* 2 * Copyright (C) 201 6Apple Inc. All rights reserved.2 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 WI. MainTarget = class MainTarget extends WI.Target26 WI.AppController = class AppController extends WI.AppControllerBase 27 27 { 28 constructor( connection)28 constructor() 29 29 { 30 super( "main", "", WI.Target.Type.Main, InspectorBackend.mainConnection);30 super(); 31 31 32 let displayName = WI.debuggableType === WI.DebuggableType.Web ? WI.UIString("Main Frame") : this.displayName;33 this._ executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, displayName, true, null);32 this._hasExtraDomains = false; 33 this._debuggableType = InspectorFrontendHost.debuggableType() === "web" ? WI.DebuggableType.Web : WI.DebuggableType.JavaScript; 34 34 } 35 35 36 // Pro tected (Target)36 // Properties. 37 37 38 get displayName() 38 get hasExtraDomains() { return this._hasExtraDomains; } 39 get debuggableType() { return this._debuggableType; } 40 41 // API. 42 43 activateExtraDomains(domains) 39 44 { 40 switch (WI.debuggableType) { 41 case WI.DebuggableType.Web: 42 return WI.UIString("Page"); 43 case WI.DebuggableType.JavaScript: 44 return WI.UIString("JavaScript Context"); 45 default: 46 console.error("Unexpected debuggable type: ", WI.debuggableType); 47 return WI.UIString("Main"); 45 if (this._hasExtraDomains) 46 throw new Error("Extra domains have already been activated, cannot activate again."); 47 48 this._hasExtraDomains = true; 49 50 for (let domain of domains) { 51 let agent = InspectorBackend.activateDomain(domain); 52 if (agent.enable) 53 agent.enable(); 48 54 } 49 }50 55 51 get mainResource() 52 { 53 let mainFrame = WI.frameResourceManager.mainFrame; 54 return mainFrame ? mainFrame.mainResource : null; 56 // FIXME: all code within WI.activateExtraDomains should be distributed elsewhere. 57 WI.activateExtraDomains(); 55 58 } 56 59 }; -
trunk/Source/WebInspectorUI/UserInterface/Controllers/AppControllerBase.js
r222180 r222181 1 1 /* 2 * Copyright (C) 201 6Apple Inc. All rights reserved.2 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 WI.MainTarget = class MainTarget extends WI.Target 26 WI.DebuggableType = { 27 Web: "web", 28 JavaScript: "javascript" 29 }; 30 31 WI.NotImplementedError = class NotImplementedError extends Error 27 32 { 28 constructor( connection)33 constructor(message="This method is not implemented.") 29 34 { 30 super("main", "", WI.Target.Type.Main, InspectorBackend.mainConnection); 31 32 let displayName = WI.debuggableType === WI.DebuggableType.Web ? WI.UIString("Main Frame") : this.displayName; 33 this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, displayName, true, null); 35 super(message); 34 36 } 35 37 36 // Protected (Target) 38 static subclassMustOverride() 39 { 40 return new WI.NotImplementedError("This method must be overridden by a subclass."); 41 } 42 }; 37 43 38 get displayName() 44 WI.AppControllerBase = class AppControllerBase 45 { 46 constructor() 39 47 { 40 switch (WI.debuggableType) { 41 case WI.DebuggableType.Web: 42 return WI.UIString("Page"); 43 case WI.DebuggableType.JavaScript: 44 return WI.UIString("JavaScript Context"); 45 default: 46 console.error("Unexpected debuggable type: ", WI.debuggableType); 47 return WI.UIString("Main"); 48 } 48 this._initialized = false; 49 49 } 50 50 51 get mainResource() 51 get hasExtraDomains() { throw WI.NotImplementedError.subclassMustOverride(); } 52 get debuggableType() { throw WI.NotImplementedError.subclassMustOverride(); } 53 54 // Since various members of the app controller depend on the global singleton to exist, 55 // some initialization needs to happen after the app controller has been constructed. 56 initialize() 52 57 { 53 let mainFrame = WI.frameResourceManager.mainFrame; 54 return mainFrame ? mainFrame.mainResource : null; 58 if (this._initialized) 59 throw new Error("App controller is already initialized."); 60 61 this._initialized = true; 62 63 // FIXME: eventually all code within WI.loaded should be distributed elsewhere. 64 WI.loaded(); 55 65 } 56 66 }; -
trunk/Source/WebInspectorUI/UserInterface/Controllers/TimelineManager.js
r222064 r222181 67 67 static defaultTimelineTypes() 68 68 { 69 if (WI. debuggableType === WI.DebuggableType.JavaScript) {69 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) { 70 70 let defaultTypes = [WI.TimelineRecord.Type.Script]; 71 71 if (WI.HeapAllocationsInstrument.supported()) … … 89 89 { 90 90 let types = WI.TimelineManager.defaultTimelineTypes(); 91 if (WI. debuggableType === WI.DebuggableType.JavaScript)91 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) 92 92 return types; 93 93 … … 879 879 { 880 880 // FIXME: <https://webkit.org/b/158753> Generalize the concept of Instruments on the backend to work equally for JSContext and Web inspection 881 console.assert(WI. debuggableType === WI.DebuggableType.JavaScript);881 console.assert(WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript); 882 882 console.assert(!this._isCapturing); 883 883 … … 888 888 { 889 889 // FIXME: <https://webkit.org/b/158753> Generalize the concept of Instruments on the backend to work equally for JSContext and Web inspection 890 console.assert(WI. debuggableType === WI.DebuggableType.JavaScript);890 console.assert(WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript); 891 891 console.assert(this._isCapturing); 892 892 … … 978 978 // Associate the ScriptProfiler created records with Web Timeline records. 979 979 // Filter out the already added ScriptProfiler events which should not have been wrapped. 980 if (WI. debuggableType !== WI.DebuggableType.JavaScript) {980 if (WI.sharedApp.debuggableType !== WI.DebuggableType.JavaScript) { 981 981 this._scriptProfilerRecords = this._scriptProfilerRecords.filter((x) => x.__scriptProfilerType === ScriptProfilerAgent.EventType.Other); 982 982 this._mergeScriptProfileRecords(); -
trunk/Source/WebInspectorUI/UserInterface/Main.html
r221943 r222181 818 818 819 819 <script src="Base/Main.js"></script> 820 <script src="Controllers/AppControllerBase.js"></script> 821 <script src="Controllers/AppController.js"></script> 820 822 821 823 <script src="Debug/Bootstrap.js"></script> … … 825 827 826 828 <script> 827 WI.loaded(); 829 WI.sharedApp = new WI.AppController; 830 WI.sharedApp.initialize(); 828 831 </script> 829 832 </head> -
trunk/Source/WebInspectorUI/UserInterface/Models/TimelineRecording.js
r220119 r222181 57 57 static sourceCodeTimelinesSupported() 58 58 { 59 return WI. debuggableType === WI.DebuggableType.Web;59 return WI.sharedApp.debuggableType === WI.DebuggableType.Web; 60 60 } 61 61 -
trunk/Source/WebInspectorUI/UserInterface/Protocol/InspectorObserver.js
r220119 r222181 56 56 }); 57 57 remoteObject.release(); 58 return; 58 return; 59 59 } 60 60 … … 69 69 activateExtraDomains(domains) 70 70 { 71 WI. activateExtraDomains(domains);71 WI.sharedApp.activateExtraDomains(domains); 72 72 } 73 73 }; -
trunk/Source/WebInspectorUI/UserInterface/Protocol/MainTarget.js
r220119 r222181 30 30 super("main", "", WI.Target.Type.Main, InspectorBackend.mainConnection); 31 31 32 let displayName = WI. debuggableType === WI.DebuggableType.Web ? WI.UIString("Main Frame") : this.displayName;32 let displayName = WI.sharedApp.debuggableType === WI.DebuggableType.Web ? WI.UIString("Main Frame") : this.displayName; 33 33 this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, displayName, true, null); 34 34 } … … 38 38 get displayName() 39 39 { 40 switch (WI. debuggableType) {40 switch (WI.sharedApp.debuggableType) { 41 41 case WI.DebuggableType.Web: 42 42 return WI.UIString("Page"); … … 44 44 return WI.UIString("JavaScript Context"); 45 45 default: 46 console.error("Unexpected debuggable type: ", WI. debuggableType);46 console.error("Unexpected debuggable type: ", WI.sharedApp.debuggableType); 47 47 return WI.UIString("Main"); 48 48 } -
trunk/Source/WebInspectorUI/UserInterface/Test.html
r222052 r222181 47 47 48 48 <script src="Test/Test.js"></script> 49 <script src="Controllers/AppControllerBase.js"></script> 50 <script src="Test/TestAppController.js"></script> 49 51 50 52 <script src="Base/DOMUtilities.js"></script> … … 217 219 218 220 <script type="text/javascript"> 219 WI.loaded(); 221 WI.sharedApp = new WI.TestAppController; 222 WI.sharedApp.initialize(); 220 223 221 224 // Debug logging is synchronous on the test page. -
trunk/Source/WebInspectorUI/UserInterface/Test/Test.js
r222052 r222181 24 24 */ 25 25 26 WI.DebuggableType = {27 Web: "web",28 JavaScript: "javascript"29 };30 31 26 WI.loaded = function() 32 27 { 33 this.debuggableType = WI.DebuggableType.Web;34 this.hasExtraDomains = false;35 36 28 // Register observers for events from the InspectorBackend. 37 29 // The initialization order should match the same in Main.js. -
trunk/Source/WebInspectorUI/UserInterface/Test/TestAppController.js
r222180 r222181 1 1 /* 2 * Copyright (C) 201 6Apple Inc. All rights reserved.2 * Copyright (C) 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 WI. MainTarget = class MainTarget extends WI.Target26 WI.TestAppController = class TestAppController extends WI.AppControllerBase 27 27 { 28 constructor( connection)28 constructor() 29 29 { 30 super("main", "", WI.Target.Type.Main, InspectorBackend.mainConnection); 31 32 let displayName = WI.debuggableType === WI.DebuggableType.Web ? WI.UIString("Main Frame") : this.displayName; 33 this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, displayName, true, null); 30 super(); 34 31 } 35 32 36 // Protected (Target) 37 38 get displayName() 39 { 40 switch (WI.debuggableType) { 41 case WI.DebuggableType.Web: 42 return WI.UIString("Page"); 43 case WI.DebuggableType.JavaScript: 44 return WI.UIString("JavaScript Context"); 45 default: 46 console.error("Unexpected debuggable type: ", WI.debuggableType); 47 return WI.UIString("Main"); 48 } 49 } 50 51 get mainResource() 52 { 53 let mainFrame = WI.frameResourceManager.mainFrame; 54 return mainFrame ? mainFrame.mainResource : null; 55 } 33 get hasExtraDomains() { return false; } 34 get debuggableType() { return WI.DebuggableType.Web; } 56 35 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/ResourceSidebarPanel.js
r220609 r222181 77 77 this.contentTreeOutline.includeSourceMapResourceChildren = true; 78 78 79 if (WI. debuggableType === WI.DebuggableType.JavaScript) {79 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) { 80 80 this.contentTreeOutline.disclosureButtons = false; 81 81 WI.SourceCode.addEventListener(WI.SourceCode.Event.SourceMapAdded, () => { this.contentTreeOutline.disclosureButtons = true; }, this); … … 204 204 this._addScript(script); 205 205 206 if (script.sourceMaps.length && WI. debuggableType === WI.DebuggableType.JavaScript)206 if (script.sourceMaps.length && WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) 207 207 this.contentTreeOutline.disclosureButtons = true; 208 208 } … … 336 336 parentFolderTreeElement = this._extensionScriptsFolderTreeElement; 337 337 } else { 338 if (WI. debuggableType === WI.DebuggableType.JavaScript && !WI.hasExtraDomains)338 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript && !WI.sharedApp.hasExtraDomains) 339 339 insertIntoTopLevel = true; 340 340 else { … … 497 497 _extraDomainsActivated() 498 498 { 499 if (WI. debuggableType === WI.DebuggableType.JavaScript)499 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) 500 500 this.contentTreeOutline.disclosureButtons = true; 501 501 } -
trunk/Source/WebInspectorUI/UserInterface/Views/Toolbar.js
r220119 r222181 102 102 103 103 // Force collapsed style for JavaScript debuggables. 104 if (WI. debuggableType === WI.DebuggableType.JavaScript) {104 if (WI.sharedApp.debuggableType === WI.DebuggableType.JavaScript) { 105 105 this.element.classList.add(WI.NavigationBar.CollapsedStyleClassName); 106 106 return;
Note: See TracChangeset
for help on using the changeset viewer.