Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/persistence/DefaultMapping.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.DefaultMapping = class { 7 Persistence.DefaultMapping = class {
8 /** 8 /**
9 * @param {!WebInspector.Workspace} workspace 9 * @param {!Workspace.Workspace} workspace
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping 10 * @param {!Workspace.FileSystemMapping} fileSystemMapping
11 * @param {function(!WebInspector.PersistenceBinding)} onBindingCreated 11 * @param {function(!Persistence.PersistenceBinding)} onBindingCreated
12 * @param {function(!WebInspector.PersistenceBinding)} onBindingRemoved 12 * @param {function(!Persistence.PersistenceBinding)} onBindingRemoved
13 */ 13 */
14 constructor(workspace, fileSystemMapping, onBindingCreated, onBindingRemoved) { 14 constructor(workspace, fileSystemMapping, onBindingCreated, onBindingRemoved) {
15 this._workspace = workspace; 15 this._workspace = workspace;
16 this._fileSystemMapping = fileSystemMapping; 16 this._fileSystemMapping = fileSystemMapping;
17 /** @type {!Set<!WebInspector.PersistenceBinding>} */ 17 /** @type {!Set<!Persistence.PersistenceBinding>} */
18 this._bindings = new Set(); 18 this._bindings = new Set();
19 this._onBindingCreated = onBindingCreated; 19 this._onBindingCreated = onBindingCreated;
20 this._onBindingRemoved = onBindingRemoved; 20 this._onBindingRemoved = onBindingRemoved;
21 21
22 this._eventListeners = [ 22 this._eventListeners = [
23 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded , this._onUISourceCodeAdded, this), 23 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, t his._onUISourceCodeAdded, this),
24 workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemov ed, this._onUISourceCodeRemoved, this), 24 workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeRemoved, this._onUISourceCodeRemoved, this),
25 workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemoved, t his._onProjectRemoved, this), 25 workspace.addEventListener(Workspace.Workspace.Events.ProjectRemoved, this ._onProjectRemoved, this),
26 this._fileSystemMapping.addEventListener( 26 this._fileSystemMapping.addEventListener(
27 WebInspector.FileSystemMapping.Events.FileMappingAdded, this._remap, t his), 27 Workspace.FileSystemMapping.Events.FileMappingAdded, this._remap, this ),
28 this._fileSystemMapping.addEventListener( 28 this._fileSystemMapping.addEventListener(
29 WebInspector.FileSystemMapping.Events.FileMappingRemoved, this._remap, this) 29 Workspace.FileSystemMapping.Events.FileMappingRemoved, this._remap, th is)
30 ]; 30 ];
31 this._remap(); 31 this._remap();
32 } 32 }
33 33
34 _remap() { 34 _remap() {
35 for (var binding of this._bindings.valuesArray()) 35 for (var binding of this._bindings.valuesArray())
36 this._unbind(binding.network); 36 this._unbind(binding.network);
37 var networkProjects = this._workspace.projectsForType(WebInspector.projectTy pes.Network); 37 var networkProjects = this._workspace.projectsForType(Workspace.projectTypes .Network);
38 for (var networkProject of networkProjects) { 38 for (var networkProject of networkProjects) {
39 for (var uiSourceCode of networkProject.uiSourceCodes()) 39 for (var uiSourceCode of networkProject.uiSourceCodes())
40 this._bind(uiSourceCode); 40 this._bind(uiSourceCode);
41 } 41 }
42 } 42 }
43 43
44 /** 44 /**
45 * @param {!WebInspector.Event} event 45 * @param {!Common.Event} event
46 */ 46 */
47 _onUISourceCodeAdded(event) { 47 _onUISourceCodeAdded(event) {
48 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); 48 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
49 this._bind(uiSourceCode); 49 this._bind(uiSourceCode);
50 } 50 }
51 51
52 /** 52 /**
53 * @param {!WebInspector.Event} event 53 * @param {!Common.Event} event
54 */ 54 */
55 _onUISourceCodeRemoved(event) { 55 _onUISourceCodeRemoved(event) {
56 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); 56 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
57 this._unbind(uiSourceCode); 57 this._unbind(uiSourceCode);
58 } 58 }
59 59
60 /** 60 /**
61 * @param {!WebInspector.Event} event 61 * @param {!Common.Event} event
62 */ 62 */
63 _onProjectRemoved(event) { 63 _onProjectRemoved(event) {
64 var project = /** @type {!WebInspector.Project} */ (event.data); 64 var project = /** @type {!Workspace.Project} */ (event.data);
65 for (var uiSourceCode of project.uiSourceCodes()) 65 for (var uiSourceCode of project.uiSourceCodes())
66 this._unbind(uiSourceCode); 66 this._unbind(uiSourceCode);
67 } 67 }
68 68
69 /** 69 /**
70 * @param {!WebInspector.UISourceCode} uiSourceCode 70 * @param {!Workspace.UISourceCode} uiSourceCode
71 * @return {?WebInspector.PersistenceBinding} 71 * @return {?Persistence.PersistenceBinding}
72 */ 72 */
73 _createBinding(uiSourceCode) { 73 _createBinding(uiSourceCode) {
74 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem) { 74 if (uiSourceCode.project().type() === Workspace.projectTypes.FileSystem) {
75 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSystemPat h(uiSourceCode.project().id()); 75 var fileSystemPath = Bindings.FileSystemWorkspaceBinding.fileSystemPath(ui SourceCode.project().id());
76 var networkURL = this._fileSystemMapping.networkURLForFileSystemURL(fileSy stemPath, uiSourceCode.url()); 76 var networkURL = this._fileSystemMapping.networkURLForFileSystemURL(fileSy stemPath, uiSourceCode.url());
77 var networkSourceCode = networkURL ? this._workspace.uiSourceCodeForURL(ne tworkURL) : null; 77 var networkSourceCode = networkURL ? this._workspace.uiSourceCodeForURL(ne tworkURL) : null;
78 return networkSourceCode ? new WebInspector.PersistenceBinding(networkSour ceCode, uiSourceCode, false) : null; 78 return networkSourceCode ? new Persistence.PersistenceBinding(networkSourc eCode, uiSourceCode, false) : null;
79 } 79 }
80 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network) { 80 if (uiSourceCode.project().type() === Workspace.projectTypes.Network) {
81 var file = this._fileSystemMapping.fileForURL(uiSourceCode.url()); 81 var file = this._fileSystemMapping.fileForURL(uiSourceCode.url());
82 var projectId = file ? WebInspector.FileSystemWorkspaceBinding.projectId(f ile.fileSystemPath) : null; 82 var projectId = file ? Bindings.FileSystemWorkspaceBinding.projectId(file. fileSystemPath) : null;
83 var fileSourceCode = file && projectId ? this._workspace.uiSourceCode(proj ectId, file.fileURL) : null; 83 var fileSourceCode = file && projectId ? this._workspace.uiSourceCode(proj ectId, file.fileURL) : null;
84 return fileSourceCode ? new WebInspector.PersistenceBinding(uiSourceCode, fileSourceCode, false) : null; 84 return fileSourceCode ? new Persistence.PersistenceBinding(uiSourceCode, f ileSourceCode, false) : null;
85 } 85 }
86 return null; 86 return null;
87 } 87 }
88 88
89 /** 89 /**
90 * @param {!WebInspector.UISourceCode} uiSourceCode 90 * @param {!Workspace.UISourceCode} uiSourceCode
91 */ 91 */
92 _bind(uiSourceCode) { 92 _bind(uiSourceCode) {
93 console.assert(!uiSourceCode[WebInspector.DefaultMapping._binding], 'Cannot bind already bound UISourceCode!'); 93 console.assert(!uiSourceCode[Persistence.DefaultMapping._binding], 'Cannot b ind already bound UISourceCode!');
94 var binding = this._createBinding(uiSourceCode); 94 var binding = this._createBinding(uiSourceCode);
95 if (!binding) 95 if (!binding)
96 return; 96 return;
97 this._bindings.add(binding); 97 this._bindings.add(binding);
98 binding.network[WebInspector.DefaultMapping._binding] = binding; 98 binding.network[Persistence.DefaultMapping._binding] = binding;
99 binding.fileSystem[WebInspector.DefaultMapping._binding] = binding; 99 binding.fileSystem[Persistence.DefaultMapping._binding] = binding;
100 100
101 binding.fileSystem.addEventListener( 101 binding.fileSystem.addEventListener(
102 WebInspector.UISourceCode.Events.TitleChanged, this._onFileSystemUISourc eCodeRenamed, this); 102 Workspace.UISourceCode.Events.TitleChanged, this._onFileSystemUISourceCo deRenamed, this);
103 103
104 this._onBindingCreated.call(null, binding); 104 this._onBindingCreated.call(null, binding);
105 } 105 }
106 106
107 /** 107 /**
108 * @param {!WebInspector.UISourceCode} uiSourceCode 108 * @param {!Workspace.UISourceCode} uiSourceCode
109 */ 109 */
110 _unbind(uiSourceCode) { 110 _unbind(uiSourceCode) {
111 var binding = uiSourceCode[WebInspector.DefaultMapping._binding]; 111 var binding = uiSourceCode[Persistence.DefaultMapping._binding];
112 if (!binding) 112 if (!binding)
113 return; 113 return;
114 this._bindings.delete(binding); 114 this._bindings.delete(binding);
115 binding.network[WebInspector.DefaultMapping._binding] = null; 115 binding.network[Persistence.DefaultMapping._binding] = null;
116 binding.fileSystem[WebInspector.DefaultMapping._binding] = null; 116 binding.fileSystem[Persistence.DefaultMapping._binding] = null;
117 117
118 binding.fileSystem.removeEventListener( 118 binding.fileSystem.removeEventListener(
119 WebInspector.UISourceCode.Events.TitleChanged, this._onFileSystemUISourc eCodeRenamed, this); 119 Workspace.UISourceCode.Events.TitleChanged, this._onFileSystemUISourceCo deRenamed, this);
120 120
121 this._onBindingRemoved.call(null, binding); 121 this._onBindingRemoved.call(null, binding);
122 } 122 }
123 123
124 /** 124 /**
125 * @param {!WebInspector.Event} event 125 * @param {!Common.Event} event
126 */ 126 */
127 _onFileSystemUISourceCodeRenamed(event) { 127 _onFileSystemUISourceCodeRenamed(event) {
128 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.target); 128 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.target);
129 var binding = uiSourceCode[WebInspector.DefaultMapping._binding]; 129 var binding = uiSourceCode[Persistence.DefaultMapping._binding];
130 this._unbind(binding.network); 130 this._unbind(binding.network);
131 this._bind(binding.network); 131 this._bind(binding.network);
132 } 132 }
133 133
134 dispose() { 134 dispose() {
135 WebInspector.EventTarget.removeEventListeners(this._eventListeners); 135 Common.EventTarget.removeEventListeners(this._eventListeners);
136 } 136 }
137 }; 137 };
138 138
139 WebInspector.DefaultMapping._binding = Symbol('DefaultMapping.Binding'); 139 Persistence.DefaultMapping._binding = Symbol('DefaultMapping.Binding');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698