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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/NetworkMapping.js

Issue 2349343002: DevTools: introduce persistence/ module (Closed)
Patch Set: DevTools: add persistence/ module Created 4 years, 3 months 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 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 4
5 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {!WebInspector.TargetManager} targetManager 7 * @param {!WebInspector.TargetManager} targetManager
8 * @param {!WebInspector.Workspace} workspace 8 * @param {!WebInspector.Workspace} workspace
9 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding 9 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping 10 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
11 */ 11 */
12 WebInspector.NetworkMapping = function(targetManager, workspace, fileSystemWorks paceBinding, fileSystemMapping) 12 WebInspector.NetworkMapping = function(targetManager, workspace, fileSystemWorks paceBinding, fileSystemMapping)
13 { 13 {
14 this._targetManager = targetManager; 14 this._targetManager = targetManager;
15 this._workspace = workspace; 15 this._workspace = workspace;
16 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding; 16 this._fileSystemWorkspaceBinding = fileSystemWorkspaceBinding;
17 this._fileSystemMapping = fileSystemMapping; 17 this._fileSystemMapping = fileSystemMapping;
18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.RevealSourceLine, this._revealSourceLine, this); 18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.RevealSourceLine, this._revealSourceLine, this);
19 19
20 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager(); 20 var fileSystemManager = fileSystemWorkspaceBinding.fileSystemManager();
21 this._eventListeners = [
22 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage r.Events.FileSystemAdded, this._fileSystemAdded, this),
23 fileSystemManager.addEventListener(WebInspector.IsolatedFileSystemManage r.Events.FileSystemRemoved, this._fileSystemRemoved, this),
24 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingAdded, this._fileSystemMappingChanged, this),
25 this._fileSystemMapping.addEventListener(WebInspector.FileSystemMapping. Events.FileMappingRemoved, this._fileSystemMappingChanged, this)
26 ];
27
28 fileSystemManager.waitForFileSystems() 21 fileSystemManager.waitForFileSystems()
dgozman 2016/09/22 19:55:53 We either don't do waitForFileSystems or we listen
lushnikov 2016/09/23 21:56:12 Done.
29 .then(this._fileSystemsLoaded.bind(this)); 22 .then(this._fileSystemsLoaded.bind(this));
30 } 23 }
31 24
32 WebInspector.NetworkMapping.prototype = { 25 WebInspector.NetworkMapping.prototype = {
33 /** 26 /**
34 * @param {!Array<!WebInspector.IsolatedFileSystem>} fileSystems 27 * @param {!Array<!WebInspector.IsolatedFileSystem>} fileSystems
35 */ 28 */
36 _fileSystemsLoaded: function(fileSystems) 29 _fileSystemsLoaded: function(fileSystems)
37 { 30 {
38 for (var fileSystem of fileSystems) 31 for (var fileSystem of fileSystems)
39 this._addMappingsForFilesystem(fileSystem); 32 this._addMappingsForFilesystem(fileSystem);
40 }, 33 },
41 34
42 /** 35 /**
43 * @param {!WebInspector.Event} event
44 */
45 _fileSystemAdded: function(event)
46 {
47 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event. data);
48 this._addMappingsForFilesystem(fileSystem);
49 this._fileSystemMappingChanged();
50 },
51
52 /**
53 * @param {!WebInspector.IsolatedFileSystem} fileSystem 36 * @param {!WebInspector.IsolatedFileSystem} fileSystem
54 */ 37 */
55 _addMappingsForFilesystem: function(fileSystem) 38 _addMappingsForFilesystem: function(fileSystem)
56 { 39 {
57 this._addingFileSystem = true; 40 this._addingFileSystem = true;
58 this._fileSystemMapping.addFileSystem(fileSystem.path()); 41 this._fileSystemMapping.addFileSystem(fileSystem.path());
59 42
60 var mappings = fileSystem.projectProperty("mappings"); 43 var mappings = fileSystem.projectProperty("mappings");
61 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) { 44 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) {
62 var mapping = mappings[i]; 45 var mapping = mappings[i];
63 if (!mapping || typeof mapping !== "object") 46 if (!mapping || typeof mapping !== "object")
64 continue; 47 continue;
65 var folder = mapping["folder"]; 48 var folder = mapping["folder"];
66 var url = mapping["url"]; 49 var url = mapping["url"];
67 if (typeof folder !== "string" || typeof url !== "string") 50 if (typeof folder !== "string" || typeof url !== "string")
68 continue; 51 continue;
69 this._fileSystemMapping.addNonConfigurableFileMapping(fileSystem.pat h(), url, folder); 52 this._fileSystemMapping.addNonConfigurableFileMapping(fileSystem.pat h(), url, folder);
70 } 53 }
71 this._addingFileSystem = false; 54 this._addingFileSystem = false;
72 }, 55 },
73 56
74 /** 57 /**
75 * @param {!WebInspector.Event} event
76 */
77 _fileSystemRemoved: function(event)
78 {
79 var fileSystem = /** @type {!WebInspector.IsolatedFileSystem} */ (event. data);
80 this._fileSystemMapping.removeFileSystem(fileSystem.path());
81 this._fileSystemMappingChanged();
82 },
83
84 /**
85 * @param {!WebInspector.UISourceCode} uiSourceCode 58 * @param {!WebInspector.UISourceCode} uiSourceCode
86 * @return {string} 59 * @return {string}
87 */ 60 */
88 networkURL: function(uiSourceCode) 61 networkURL: function(uiSourceCode)
89 { 62 {
90 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) { 63 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em)
91 var fileSystemPath = this._fileSystemWorkspaceBinding.fileSystemPath (uiSourceCode.project().id()); 64 return "";
92 return this._networkURLForFileSystemURL(fileSystemPath, uiSourceCode .url());
93 }
94 return uiSourceCode.url(); 65 return uiSourceCode.url();
95 }, 66 },
96 67
97 /** 68 /**
98 * @param {string} url
99 * @return {boolean}
100 */
101 hasMappingForNetworkURL: function(url)
102 {
103 return this._fileSystemMapping.hasMappingForNetworkURL(url);
104 },
105
106 /**
107 * @param {!WebInspector.Target} target 69 * @param {!WebInspector.Target} target
108 * @param {?WebInspector.ResourceTreeFrame} frame 70 * @param {?WebInspector.ResourceTreeFrame} frame
109 * @param {string} url 71 * @param {string} url
110 * @return {?WebInspector.UISourceCode} 72 * @return {?WebInspector.UISourceCode}
111 */ 73 */
112 _networkUISourceCodeForURL: function(target, frame, url) 74 _networkUISourceCodeForURL: function(target, frame, url)
113 { 75 {
114 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI d(target, frame, false), url); 76 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI d(target, frame, false), url);
115 }, 77 },
116 78
117 /** 79 /**
118 * @param {!WebInspector.Target} target 80 * @param {!WebInspector.Target} target
119 * @param {?WebInspector.ResourceTreeFrame} frame 81 * @param {?WebInspector.ResourceTreeFrame} frame
120 * @param {string} url 82 * @param {string} url
121 * @return {?WebInspector.UISourceCode} 83 * @return {?WebInspector.UISourceCode}
122 */ 84 */
123 _contentScriptUISourceCodeForURL: function(target, frame, url) 85 _contentScriptUISourceCodeForURL: function(target, frame, url)
124 { 86 {
125 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI d(target, frame, true), url); 87 return this._workspace.uiSourceCode(WebInspector.NetworkProject.projectI d(target, frame, true), url);
126 }, 88 },
127 89
128 /** 90 /**
129 * @param {string} url
130 * @return {?WebInspector.UISourceCode}
131 */
132 _fileSystemUISourceCodeForURL: function(url)
133 {
134 var file = this._fileSystemMapping.fileForURL(url);
135 if (file) {
136 var projectId = WebInspector.FileSystemWorkspaceBinding.projectId(fi le.fileSystemPath);
137 return this._workspace.uiSourceCode(projectId, file.fileURL);
138 }
139 return null;
140 },
141
142 /**
143 * @param {!WebInspector.Target} target 91 * @param {!WebInspector.Target} target
144 * @param {?WebInspector.ResourceTreeFrame} frame 92 * @param {?WebInspector.ResourceTreeFrame} frame
145 * @param {string} url 93 * @param {string} url
146 * @return {?WebInspector.UISourceCode} 94 * @return {?WebInspector.UISourceCode}
147 */ 95 */
148 _uiSourceCodeForURL: function(target, frame, url) 96 _uiSourceCodeForURL: function(target, frame, url)
149 { 97 {
150 return this._fileSystemUISourceCodeForURL(url) || this._networkUISourceC odeForURL(target, frame, url) || this._contentScriptUISourceCodeForURL(target, f rame, url); 98 return this._networkUISourceCodeForURL(target, frame, url) || this._cont entScriptUISourceCodeForURL(target, frame, url);
151 }, 99 },
152 100
153 /** 101 /**
154 * @param {string} url 102 * @param {string} url
155 * @param {!WebInspector.Script} script 103 * @param {!WebInspector.Script} script
156 * @return {?WebInspector.UISourceCode} 104 * @return {?WebInspector.UISourceCode}
157 */ 105 */
158 uiSourceCodeForScriptURL: function(url, script) 106 uiSourceCodeForScriptURL: function(url, script)
159 { 107 {
160 var frame = WebInspector.ResourceTreeFrame.fromScript(script); 108 var frame = WebInspector.ResourceTreeFrame.fromScript(script);
(...skipping 10 matching lines...) Expand all
171 var frame = WebInspector.ResourceTreeFrame.fromStyleSheet(header); 119 var frame = WebInspector.ResourceTreeFrame.fromStyleSheet(header);
172 return this._uiSourceCodeForURL(header.target(), frame, url); 120 return this._uiSourceCodeForURL(header.target(), frame, url);
173 }, 121 },
174 122
175 /** 123 /**
176 * @param {string} url 124 * @param {string} url
177 * @return {?WebInspector.UISourceCode} 125 * @return {?WebInspector.UISourceCode}
178 */ 126 */
179 uiSourceCodeForURLForAnyTarget: function(url) 127 uiSourceCodeForURLForAnyTarget: function(url)
180 { 128 {
181 return this._fileSystemUISourceCodeForURL(url) || WebInspector.workspace .uiSourceCodeForURL(url); 129 return WebInspector.workspace.uiSourceCodeForURL(url);
182 }, 130 },
183 131
184 /** 132 /**
185 * @param {string} fileSystemPath
186 * @param {string} filePath
187 * @return {string}
188 */
189 _networkURLForFileSystemURL: function(fileSystemPath, filePath)
190 {
191 return this._fileSystemMapping.networkURLForFileSystemURL(fileSystemPath , filePath);
192 },
193
194 /**
195 * @param {!WebInspector.UISourceCode} networkUISourceCode 133 * @param {!WebInspector.UISourceCode} networkUISourceCode
196 * @param {!WebInspector.UISourceCode} uiSourceCode 134 * @param {!WebInspector.UISourceCode} uiSourceCode
197 */ 135 */
198 addMapping: function(networkUISourceCode, uiSourceCode) 136 addMapping: function(networkUISourceCode, uiSourceCode)
199 { 137 {
200 var url = this.networkURL(networkUISourceCode); 138 var url = this.networkURL(networkUISourceCode);
201 var path = uiSourceCode.url(); 139 var path = uiSourceCode.url();
202 var fileSystemPath = this._fileSystemWorkspaceBinding.fileSystemPath(uiS ourceCode.project().id()); 140 var fileSystemPath = WebInspector.FileSystemWorkspaceBinding.fileSystemP ath(uiSourceCode.project().id());
203 this._fileSystemMapping.addMappingForResource(url, fileSystemPath, path) ; 141 this._fileSystemMapping.addMappingForResource(url, fileSystemPath, path) ;
204 }, 142 },
205 143
206 /** 144 /**
207 * @param {!WebInspector.UISourceCode} uiSourceCode 145 * @param {!WebInspector.UISourceCode} uiSourceCode
208 */ 146 */
209 removeMapping: function(uiSourceCode) 147 removeMapping: function(uiSourceCode)
210 { 148 {
211 var networkURL = this.networkURL(uiSourceCode); 149 var networkURL = this.networkURL(uiSourceCode);
212 this._fileSystemMapping.removeMappingForURL(networkURL); 150 this._fileSystemMapping.removeMappingForURL(networkURL);
(...skipping 23 matching lines...) Expand all
236 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event. data); 174 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event. data);
237 if (this.networkURL(uiSourceCode) === url) { 175 if (this.networkURL(uiSourceCode) === url) {
238 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber)); 176 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
239 this._workspace.removeEventListener(WebInspector.Workspace.Event s.UISourceCodeAdded, listener, this); 177 this._workspace.removeEventListener(WebInspector.Workspace.Event s.UISourceCodeAdded, listener, this);
240 } 178 }
241 } 179 }
242 180
243 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceC odeAdded, listener, this); 181 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceC odeAdded, listener, this);
244 }, 182 },
245 183
246 _fileSystemMappingChanged: function()
247 {
248 if (this._addingFileSystem)
249 return;
250 this._targetManager.suspendAndResumeAllTargets();
251 },
252
253 dispose: function() 184 dispose: function()
254 { 185 {
255 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
256 } 186 }
257 } 187 }
258 188
259 /** 189 /**
260 * @type {!WebInspector.NetworkMapping} 190 * @type {!WebInspector.NetworkMapping}
261 */ 191 */
262 WebInspector.networkMapping; 192 WebInspector.networkMapping;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698