OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | |
5 /** | 4 /** |
6 * @constructor | 5 * @unrestricted |
7 * @param {!WebInspector.TargetManager} targetManager | |
8 * @param {!WebInspector.Workspace} workspace | |
9 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding | |
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping | |
11 */ | 6 */ |
12 WebInspector.NetworkMapping = function(targetManager, workspace, fileSystemWorks
paceBinding, fileSystemMapping) | 7 WebInspector.NetworkMapping = class { |
13 { | 8 /** |
| 9 * @param {!WebInspector.TargetManager} targetManager |
| 10 * @param {!WebInspector.Workspace} workspace |
| 11 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBindin
g |
| 12 * @param {!WebInspector.FileSystemMapping} fileSystemMapping |
| 13 */ |
| 14 constructor(targetManager, workspace, fileSystemWorkspaceBinding, fileSystemMa
pping) { |
14 this._targetManager = targetManager; | 15 this._targetManager = targetManager; |
15 this._workspace = workspace; | 16 this._workspace = workspace; |
16 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; | 17 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; |
17 this._fileSystemMapping = fileSystemMapping; | 18 this._fileSystemMapping = fileSystemMapping; |
18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.RevealSourceLine, this._revealSourceLine, this); | 19 InspectorFrontendHost.events.addEventListener( |
| 20 InspectorFrontendHostAPI.Events.RevealSourceLine, this._revealSourceLine
, this); |
19 | 21 |
20 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager(); | 22 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager(); |
21 this._eventListeners = [ | 23 this._eventListeners = [ |
22 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage
r.Events.FileSystemAdded, this._fileSystemAdded, this), | 24 fileSystemManager.addEventListener( |
23 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage
r.Events.FileSystemRemoved, this._fileSystemRemoved, this), | 25 WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, this._f
ileSystemAdded, this), |
| 26 fileSystemManager.addEventListener( |
| 27 WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, this.
_fileSystemRemoved, this), |
24 ]; | 28 ]; |
25 fileSystemManager.waitForFileSystems() | 29 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi
s)); |
26 .then(this._fileSystemsLoaded.bind(this)); | 30 } |
27 }; | |
28 | 31 |
29 WebInspector.NetworkMapping.prototype = { | 32 /** |
30 /** | 33 * @param {!Array<!WebInspector.IsolatedFileSystem>} fileSystems |
31 * @param {!Array<!WebInspector.IsolatedFileSystem>} fileSystems | 34 */ |
32 */ | 35 _fileSystemsLoaded(fileSystems) { |
33 _fileSystemsLoaded: function(fileSystems) | 36 for (var fileSystem of fileSystems) |
34 { | 37 this._addMappingsForFilesystem(fileSystem); |
35 for (var fileSystem of fileSystems) | 38 } |
36 this._addMappingsForFilesystem(fileSystem); | 39 |
37 }, | 40 /** |
| 41 * @param {!WebInspector.Event} event |
| 42 */ |
| 43 _fileSystemAdded(event) { |
| 44 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data
); |
| 45 this._addMappingsForFilesystem(fileSystem); |
| 46 } |
| 47 |
| 48 /** |
| 49 * @param {!WebInspector.IsolatedFileSystem} fileSystem |
| 50 */ |
| 51 _addMappingsForFilesystem(fileSystem) { |
| 52 this._addingFileSystem = true; |
| 53 this._fileSystemMapping.addFileSystem(fileSystem.path()); |
| 54 |
| 55 var mappings = fileSystem.projectProperty('mappings'); |
| 56 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) { |
| 57 var mapping = mappings[i]; |
| 58 if (!mapping || typeof mapping !== 'object') |
| 59 continue; |
| 60 var folder = mapping['folder']; |
| 61 var url = mapping['url']; |
| 62 if (typeof folder !== 'string' || typeof url !== 'string') |
| 63 continue; |
| 64 this._fileSystemMapping.addNonConfigurableFileMapping(fileSystem.path(), u
rl, folder); |
| 65 } |
| 66 this._addingFileSystem = false; |
| 67 } |
| 68 |
| 69 /** |
| 70 * @param {!WebInspector.Event} event |
| 71 */ |
| 72 _fileSystemRemoved(event) { |
| 73 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.data
); |
| 74 this._fileSystemMapping.removeFileSystem(fileSystem.path()); |
| 75 } |
| 76 |
| 77 /** |
| 78 * @param {!WebInspector.Target} target |
| 79 * @param {?WebInspector.ResourceTreeFrame} frame |
| 80 * @param {string} url |
| 81 * @return {?WebInspector.UISourceCode} |
| 82 */ |
| 83 _networkUISourceCodeForURL(target, frame, url) { |
| 84 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectId(ta
rget, frame, false), url); |
| 85 } |
| 86 |
| 87 /** |
| 88 * @param {!WebInspector.Target} target |
| 89 * @param {?WebInspector.ResourceTreeFrame} frame |
| 90 * @param {string} url |
| 91 * @return {?WebInspector.UISourceCode} |
| 92 */ |
| 93 _contentScriptUISourceCodeForURL(target, frame, url) { |
| 94 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectId(ta
rget, frame, true), url); |
| 95 } |
| 96 |
| 97 /** |
| 98 * @param {!WebInspector.Target} target |
| 99 * @param {?WebInspector.ResourceTreeFrame} frame |
| 100 * @param {string} url |
| 101 * @return {?WebInspector.UISourceCode} |
| 102 */ |
| 103 _uiSourceCodeForURL(target, frame, url) { |
| 104 return this._networkUISourceCodeForURL(target, frame, url) || |
| 105 this._contentScriptUISourceCodeForURL(target, frame, url); |
| 106 } |
| 107 |
| 108 /** |
| 109 * @param {string} url |
| 110 * @param {!WebInspector.Script} script |
| 111 * @return {?WebInspector.UISourceCode} |
| 112 */ |
| 113 uiSourceCodeForScriptURL(url, script) { |
| 114 var frame = WebInspector.ResourceTreeFrame.fromScript(script); |
| 115 return this._uiSourceCodeForURL(script.target(), frame, url); |
| 116 } |
| 117 |
| 118 /** |
| 119 * @param {string} url |
| 120 * @param {!WebInspector.CSSStyleSheetHeader} header |
| 121 * @return {?WebInspector.UISourceCode} |
| 122 */ |
| 123 uiSourceCodeForStyleURL(url, header) { |
| 124 var frame = WebInspector.ResourceTreeFrame.fromStyleSheet(header); |
| 125 return this._uiSourceCodeForURL(header.target(), frame, url); |
| 126 } |
| 127 |
| 128 /** |
| 129 * @param {string} url |
| 130 * @return {?WebInspector.UISourceCode} |
| 131 */ |
| 132 uiSourceCodeForURLForAnyTarget(url) { |
| 133 return WebInspector.workspace.uiSourceCodeForURL(url); |
| 134 } |
| 135 |
| 136 /** |
| 137 * @param {!WebInspector.UISourceCode} networkUISourceCode |
| 138 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 139 */ |
| 140 addMapping(networkUISourceCode, uiSourceCode) { |
| 141 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSystemPath(
uiSourceCode.project().id()); |
| 142 this._fileSystemMapping.addMappingForResource(networkUISourceCode.url(), fil
eSystemPath, uiSourceCode.url()); |
| 143 } |
| 144 |
| 145 /** |
| 146 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 147 */ |
| 148 removeMapping(uiSourceCode) { |
| 149 this._fileSystemMapping.removeMappingForURL(uiSourceCode.url()); |
| 150 } |
| 151 |
| 152 /** |
| 153 * @param {!WebInspector.Event} event |
| 154 */ |
| 155 _revealSourceLine(event) { |
| 156 var url = /** @type {string} */ (event.data['url']); |
| 157 var lineNumber = /** @type {number} */ (event.data['lineNumber']); |
| 158 var columnNumber = /** @type {number} */ (event.data['columnNumber']); |
| 159 |
| 160 var uiSourceCode = this.uiSourceCodeForURLForAnyTarget(url); |
| 161 if (uiSourceCode) { |
| 162 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNum
ber)); |
| 163 return; |
| 164 } |
38 | 165 |
39 /** | 166 /** |
40 * @param {!WebInspector.Event} event | 167 * @param {!WebInspector.Event} event |
| 168 * @this {WebInspector.NetworkMapping} |
41 */ | 169 */ |
42 _fileSystemAdded: function(event) | 170 function listener(event) { |
43 { | 171 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data); |
44 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.
data); | 172 if (uiSourceCode.url() === url) { |
45 this._addMappingsForFilesystem(fileSystem); | 173 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnN
umber)); |
46 }, | 174 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour
ceCodeAdded, listener, this); |
| 175 } |
| 176 } |
47 | 177 |
48 /** | 178 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA
dded, listener, this); |
49 * @param {!WebInspector.IsolatedFileSystem} fileSystem | 179 } |
50 */ | |
51 _addMappingsForFilesystem: function(fileSystem) | |
52 { | |
53 this._addingFileSystem = true; | |
54 this._fileSystemMapping.addFileSystem(fileSystem.path()); | |
55 | 180 |
56 var mappings = fileSystem.projectProperty("mappings"); | 181 dispose() { |
57 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) { | 182 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
58 var mapping = mappings[i]; | 183 } |
59 if (!mapping || typeof mapping !== "object") | |
60 continue; | |
61 var folder = mapping["folder"]; | |
62 var url = mapping["url"]; | |
63 if (typeof folder !== "string" || typeof url !== "string") | |
64 continue; | |
65 this._fileSystemMapping.addNonConfigurableFileMapping(fileSystem.pat
h(), url, folder); | |
66 } | |
67 this._addingFileSystem = false; | |
68 }, | |
69 | |
70 /** | |
71 * @param {!WebInspector.Event} event | |
72 */ | |
73 _fileSystemRemoved: function(event) | |
74 { | |
75 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event.
data); | |
76 this._fileSystemMapping.removeFileSystem(fileSystem.path()); | |
77 }, | |
78 | |
79 /** | |
80 * @param {!WebInspector.Target} target | |
81 * @param {?WebInspector.ResourceTreeFrame} frame | |
82 * @param {string} url | |
83 * @return {?WebInspector.UISourceCode} | |
84 */ | |
85 _networkUISourceCodeForURL: function(target, frame, url) | |
86 { | |
87 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI
d(target, frame, false), url); | |
88 }, | |
89 | |
90 /** | |
91 * @param {!WebInspector.Target} target | |
92 * @param {?WebInspector.ResourceTreeFrame} frame | |
93 * @param {string} url | |
94 * @return {?WebInspector.UISourceCode} | |
95 */ | |
96 _contentScriptUISourceCodeForURL: function(target, frame, url) | |
97 { | |
98 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI
d(target, frame, true), url); | |
99 }, | |
100 | |
101 /** | |
102 * @param {!WebInspector.Target} target | |
103 * @param {?WebInspector.ResourceTreeFrame} frame | |
104 * @param {string} url | |
105 * @return {?WebInspector.UISourceCode} | |
106 */ | |
107 _uiSourceCodeForURL: function(target, frame, url) | |
108 { | |
109 return this._networkUISourceCodeForURL(target, frame, url) || this._cont
entScriptUISourceCodeForURL(target, frame, url); | |
110 }, | |
111 | |
112 /** | |
113 * @param {string} url | |
114 * @param {!WebInspector.Script} script | |
115 * @return {?WebInspector.UISourceCode} | |
116 */ | |
117 uiSourceCodeForScriptURL: function(url, script) | |
118 { | |
119 var frame = WebInspector.ResourceTreeFrame.fromScript(script); | |
120 return this._uiSourceCodeForURL(script.target(), frame, url); | |
121 }, | |
122 | |
123 /** | |
124 * @param {string} url | |
125 * @param {!WebInspector.CSSStyleSheetHeader} header | |
126 * @return {?WebInspector.UISourceCode} | |
127 */ | |
128 uiSourceCodeForStyleURL: function(url, header) | |
129 { | |
130 var frame = WebInspector.ResourceTreeFrame.fromStyleSheet(header); | |
131 return this._uiSourceCodeForURL(header.target(), frame, url); | |
132 }, | |
133 | |
134 /** | |
135 * @param {string} url | |
136 * @return {?WebInspector.UISourceCode} | |
137 */ | |
138 uiSourceCodeForURLForAnyTarget: function(url) | |
139 { | |
140 return WebInspector.workspace.uiSourceCodeForURL(url); | |
141 }, | |
142 | |
143 /** | |
144 * @param {!WebInspector.UISourceCode} networkUISourceCode | |
145 * @param {!WebInspector.UISourceCode} uiSourceCode | |
146 */ | |
147 addMapping: function(networkUISourceCode, uiSourceCode) | |
148 { | |
149 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSystemP
ath(uiSourceCode.project().id()); | |
150 this._fileSystemMapping.addMappingForResource(networkUISourceCode.url(),
fileSystemPath, uiSourceCode.url()); | |
151 }, | |
152 | |
153 /** | |
154 * @param {!WebInspector.UISourceCode} uiSourceCode | |
155 */ | |
156 removeMapping: function(uiSourceCode) | |
157 { | |
158 this._fileSystemMapping.removeMappingForURL(uiSourceCode.url()); | |
159 }, | |
160 | |
161 /** | |
162 * @param {!WebInspector.Event} event | |
163 */ | |
164 _revealSourceLine: function(event) | |
165 { | |
166 var url = /** @type {string} */ (event.data["url"]); | |
167 var lineNumber = /** @type {number} */ (event.data["lineNumber"]); | |
168 var columnNumber = /** @type {number} */ (event.data["columnNumber"]); | |
169 | |
170 var uiSourceCode = this.uiSourceCodeForURLForAnyTarget(url); | |
171 if (uiSourceCode) { | |
172 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, col
umnNumber)); | |
173 return; | |
174 } | |
175 | |
176 /** | |
177 * @param {!WebInspector.Event} event | |
178 * @this {WebInspector.NetworkMapping} | |
179 */ | |
180 function listener(event) | |
181 { | |
182 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.
data); | |
183 if (uiSourceCode.url() === url) { | |
184 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber,
columnNumber)); | |
185 this._workspace.removeEventListener(WebInspector.Workspace.Event
s.UISourceCodeAdded, listener, this); | |
186 } | |
187 } | |
188 | |
189 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceC
odeAdded, listener, this); | |
190 }, | |
191 | |
192 dispose: function() | |
193 { | |
194 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | |
195 } | |
196 }; | 184 }; |
197 | 185 |
198 /** | 186 /** |
199 * @type {!WebInspector.NetworkMapping} | 187 * @type {!WebInspector.NetworkMapping} |
200 */ | 188 */ |
201 WebInspector.networkMapping; | 189 WebInspector.networkMapping; |
OLD | NEW |