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
3 // found in the LICENSE file.
7 * @param {!WebInspector.Workspace} workspace
8 * @param {!WebInspector.FileSystemMapping} fileSystemMapping
10 WebInspector.NetworkMapping = function(workspace, fileSystemMapping)
12 this._workspace = workspace;
13 this._fileSystemMapping = fileSystemMapping;
14 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.RevealSourceLine, this._revealSourceLine, this);
17 WebInspector.NetworkMapping.prototype = {
19 * @param {!WebInspector.UISourceCode} uiSourceCode
22 networkURL: function(uiSourceCode)
24 // FIXME: This should use fileSystemMapping to determine url.
25 return uiSourceCode.networkURL();
32 hasMappingForURL: function(url)
34 return this._fileSystemMapping.hasMappingForURL(url);
39 * @param {!WebInspector.Target} target
40 * @return {?WebInspector.UISourceCode}
42 _networkUISourceCodeForURL: function(url, target)
44 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
45 var projectId = WebInspector.NetworkProject.projectId(target, splitURL[0], false);
46 var project = this._workspace.project(projectId);
47 return project ? project.uiSourceCode(splitURL.slice(1).join("/")) : null;
52 * @param {!WebInspector.Target} target
53 * @return {?WebInspector.UISourceCode}
55 _contentScriptUISourceCodeForURL: function(url, target)
57 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
58 var projectId = WebInspector.NetworkProject.projectId(target, splitURL[0], true);
59 var project = this._workspace.project(projectId);
60 return project ? project.uiSourceCode(splitURL.slice(1).join("/")) : null;
65 * @param {!WebInspector.Target} target
66 * @return {?WebInspector.UISourceCode}
68 uiSourceCodeForURL: function(url, target)
70 var file = this._fileSystemMapping.fileForURL(url);
72 var projectId = WebInspector.FileSystemWorkspaceBinding.projectId(file.fileSystemPath);
73 var project = this._workspace.project(projectId);
74 return project ? project.uiSourceCode(file.filePath) : null;
77 return this._networkUISourceCodeForURL(url, target) || this._contentScriptUISourceCodeForURL(url, target);
82 * @return {?WebInspector.UISourceCode}
84 uiSourceCodeForURLForAnyTarget: function(url)
86 for (var target of WebInspector.targetManager.targets()) {
87 var result = this.uiSourceCodeForURL(url, target);
95 * @param {string} fileSystemPath
96 * @param {string} filePath
99 urlForPath: function(fileSystemPath, filePath)
101 return this._fileSystemMapping.urlForPath(fileSystemPath, filePath);
105 * @param {!WebInspector.UISourceCode} networkUISourceCode
106 * @param {!WebInspector.UISourceCode} uiSourceCode
107 * @param {!WebInspector.FileSystemWorkspaceBinding} fileSystemWorkspaceBinding
109 addMapping: function(networkUISourceCode, uiSourceCode, fileSystemWorkspaceBinding)
111 var url = this.networkURL(networkUISourceCode);
112 var path = uiSourceCode.path();
113 var fileSystemPath = fileSystemWorkspaceBinding.fileSystemPath(uiSourceCode.project().id());
114 this._fileSystemMapping.addMappingForResource(url, fileSystemPath, path);
118 * @param {!WebInspector.UISourceCode} uiSourceCode
120 removeMapping: function(uiSourceCode)
122 var networkURL = this.networkURL(uiSourceCode);
123 this._fileSystemMapping.removeMappingForURL(networkURL);
127 * @param {!WebInspector.Event} event
129 _revealSourceLine: function(event)
131 var url = /** @type {string} */ (event.data["url"]);
132 var lineNumber = /** @type {number} */ (event.data["lineNumber"]);
133 var columnNumber = /** @type {number} */ (event.data["columnNumber"]);
135 var uiSourceCode = this.uiSourceCodeForURLForAnyTarget(url);
137 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
142 * @param {!WebInspector.Event} event
143 * @this {WebInspector.NetworkMapping}
145 function listener(event)
147 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
148 if (this.networkURL(uiSourceCode) === url) {
149 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
150 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener, this);
154 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener, this);
159 * @type {!WebInspector.NetworkMapping}
161 WebInspector.networkMapping;