Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @implements {WebInspector.CSSSourceMapping} | |
| 34 * @param {!WebInspector.CSSModel} cssModel | 33 * @param {!WebInspector.CSSModel} cssModel |
| 35 * @param {!WebInspector.Workspace} workspace | 34 * @param {!WebInspector.Workspace} workspace |
| 36 * @param {!WebInspector.NetworkMapping} networkMapping | 35 * @param {!WebInspector.NetworkMapping} networkMapping |
| 37 */ | 36 */ |
| 38 WebInspector.StylesSourceMapping = function(cssModel, workspace, networkMapping) | 37 WebInspector.StylesSourceMapping = function(cssModel, workspace, networkMapping) |
| 39 { | 38 { |
| 40 this._cssModel = cssModel; | 39 this._cssModel = cssModel; |
| 41 this._workspace = workspace; | 40 this._workspace = workspace; |
| 42 this._networkMapping = networkMapping; | 41 this._networkMapping = networkMapping; |
| 43 | 42 |
| 44 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee tHeader>>>} */ | 43 /** @type {!Map<string, !Map<string, !Map<string, !WebInspector.CSSStyleShee tHeader>>>} */ |
| 45 this._urlToHeadersByFrameId = new Map(); | 44 this._urlToHeadersByFrameId = new Map(); |
| 46 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */ | 45 /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.StyleFile>} */ |
| 47 this._styleFiles = new Map(); | 46 this._styleFiles = new Map(); |
| 48 | 47 |
| 49 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this); | 48 this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectRemove d, this._projectRemoved, this); |
| 50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAddedToWorkspace, this); | 49 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeA dded, this._uiSourceCodeAddedToWorkspace, this); |
| 51 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); | 50 this._workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeR emoved, this._uiSourceCodeRemoved, this); |
| 52 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChang ed, this._styleSheetChanged, this); | 51 this._cssModel.addEventListener(WebInspector.CSSModel.Events.StyleSheetChang ed, this._styleSheetChanged, this); |
| 53 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventListene r( | 52 WebInspector.ResourceTreeModel.fromTarget(cssModel.target()).addEventListene r( |
| 54 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbindAl lUISourceCodes, this); | 53 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._unbindAl lUISourceCodes, this); |
| 55 } | 54 } |
| 56 | 55 |
| 57 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; | 56 WebInspector.StylesSourceMapping.ChangeUpdateTimeoutMs = 200; |
| 58 | 57 |
| 59 WebInspector.StylesSourceMapping.prototype = { | 58 WebInspector.StylesSourceMapping.prototype = { |
| 60 /** | 59 /** |
| 61 * @override | |
| 62 * @param {!WebInspector.CSSLocation} rawLocation | 60 * @param {!WebInspector.CSSLocation} rawLocation |
| 63 * @return {?WebInspector.UILocation} | 61 * @return {?WebInspector.UILocation} |
| 64 */ | 62 */ |
| 65 rawLocationToUILocation: function(rawLocation) | 63 rawLocationToUILocation: function(rawLocation) |
| 66 { | 64 { |
| 67 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat ion.url, rawLocation.header()); | 65 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(rawLocat ion.url, rawLocation.header()); |
| 68 if (!uiSourceCode) | 66 if (!uiSourceCode) |
| 69 return null; | 67 return null; |
| 70 var lineNumber = rawLocation.lineNumber; | 68 var lineNumber = rawLocation.lineNumber; |
| 71 var columnNumber = rawLocation.columnNumber; | 69 var columnNumber = rawLocation.columnNumber; |
| 72 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet Id); | 70 var header = this._cssModel.styleSheetHeaderForId(rawLocation.styleSheet Id); |
| 73 if (header && header.isInline && header.hasSourceURL) { | 71 if (header && header.isInline && header.hasSourceURL) { |
| 74 lineNumber -= header.lineNumberInSource(0); | 72 lineNumber -= header.lineNumberInSource(0); |
| 75 columnNumber -= header.columnNumberInSource(lineNumber, 0); | 73 columnNumber -= header.columnNumberInSource(lineNumber, 0); |
| 76 } | 74 } |
| 77 return uiSourceCode.uiLocation(lineNumber, columnNumber); | 75 return uiSourceCode.uiLocation(lineNumber, columnNumber); |
| 78 }, | 76 }, |
| 79 | 77 |
| 80 /** | 78 /** |
| 81 * @override | |
| 82 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 83 * @param {number} lineNumber | |
| 84 * @param {number} columnNumber | |
| 85 * @return {?WebInspector.CSSLocation} | |
| 86 */ | |
| 87 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) | |
| 88 { | |
| 89 return null; | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * @override | |
| 94 * @return {boolean} | |
| 95 */ | |
| 96 isIdentity: function() | |
| 97 { | |
| 98 return true; | |
| 99 }, | |
| 100 | |
| 101 /** | |
| 102 * @override | |
| 103 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 104 * @param {number} lineNumber | |
| 105 * @return {boolean} | |
| 106 */ | |
| 107 uiLineHasMapping: function(uiSourceCode, lineNumber) | |
| 108 { | |
| 109 return true; | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * @return {!WebInspector.Target} | |
| 114 */ | |
| 115 target: function() | |
| 116 { | |
| 117 return this._cssModel.target(); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * @param {!WebInspector.CSSStyleSheetHeader} header | 79 * @param {!WebInspector.CSSStyleSheetHeader} header |
| 122 */ | 80 */ |
| 123 addHeader: function(header) | 81 addHeader: function(header) |
| 124 { | 82 { |
| 125 var url = header.resourceURL(); | 83 var url = header.resourceURL(); |
| 126 if (!url) | 84 if (!url) |
| 127 return; | 85 return; |
| 128 | 86 |
| 129 WebInspector.cssWorkspaceBinding.pushSourceMapping(header, this); | |
| 130 var map = this._urlToHeadersByFrameId.get(url); | 87 var map = this._urlToHeadersByFrameId.get(url); |
| 131 if (!map) { | 88 if (!map) { |
| 132 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS heetHeader>>} */ (new Map()); | 89 map = /** @type {!Map.<string, !Map.<string, !WebInspector.CSSStyleS heetHeader>>} */ (new Map()); |
| 133 this._urlToHeadersByFrameId.set(url, map); | 90 this._urlToHeadersByFrameId.set(url, map); |
| 134 } | 91 } |
| 135 var headersById = map.get(header.frameId); | 92 var headersById = map.get(header.frameId); |
| 136 if (!headersById) { | 93 if (!headersById) { |
| 137 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe ader>} */ (new Map()); | 94 headersById = /** @type {!Map.<string, !WebInspector.CSSStyleSheetHe ader>} */ (new Map()); |
| 138 map.set(header.frameId, headersById); | 95 map.set(header.frameId, headersById); |
| 139 } | 96 } |
| 140 headersById.set(header.id, header); | 97 headersById.set(header.id, header); |
| 141 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, hea der); | 98 var uiSourceCode = this._networkMapping.uiSourceCodeForStyleURL(url, hea der); |
| 142 if (uiSourceCode) | 99 if (uiSourceCode) |
| 143 this._bindUISourceCode(uiSourceCode, header); | 100 this._bindUISourceCode(uiSourceCode, header); |
| 101 WebInspector.cssWorkspaceBinding.updateLocations(header); | |
|
dgozman
2016/09/02 19:13:01
Remove.
lushnikov
2016/09/08 00:20:26
Done.
| |
| 144 }, | 102 }, |
| 145 | 103 |
| 146 /** | 104 /** |
| 147 * @param {!WebInspector.CSSStyleSheetHeader} header | 105 * @param {!WebInspector.CSSStyleSheetHeader} header |
| 148 */ | 106 */ |
| 149 removeHeader: function(header) | 107 removeHeader: function(header) |
| 150 { | 108 { |
| 151 var url = header.resourceURL(); | 109 var url = header.resourceURL(); |
| 152 if (!url) | 110 if (!url) |
| 153 return; | 111 return; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 179 return; | 137 return; |
| 180 styleFile.dispose(); | 138 styleFile.dispose(); |
| 181 this._styleFiles.delete(uiSourceCode); | 139 this._styleFiles.delete(uiSourceCode); |
| 182 }, | 140 }, |
| 183 | 141 |
| 184 /** | 142 /** |
| 185 * @param {!WebInspector.Event} event | 143 * @param {!WebInspector.Event} event |
| 186 */ | 144 */ |
| 187 _unbindAllUISourceCodes: function(event) | 145 _unbindAllUISourceCodes: function(event) |
| 188 { | 146 { |
| 189 if (event.data.target() !== this.target()) | 147 if (event.data.target() !== this._cssModel.target()) |
| 190 return; | 148 return; |
| 191 for (var styleFile of this._styleFiles.values()) | 149 for (var styleFile of this._styleFiles.values()) |
| 192 styleFile.dispose(); | 150 styleFile.dispose(); |
| 193 this._styleFiles.clear(); | 151 this._styleFiles.clear(); |
| 194 this._urlToHeadersByFrameId = new Map(); | 152 this._urlToHeadersByFrameId = new Map(); |
| 195 }, | 153 }, |
| 196 | 154 |
| 197 /** | 155 /** |
| 198 * @param {!WebInspector.Event} event | 156 * @param {!WebInspector.Event} event |
| 199 */ | 157 */ |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 }, | 360 }, |
| 403 | 361 |
| 404 dispose: function() | 362 dispose: function() |
| 405 { | 363 { |
| 406 if (this._terminated) | 364 if (this._terminated) |
| 407 return; | 365 return; |
| 408 this._terminated = true; | 366 this._terminated = true; |
| 409 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 367 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
| 410 } | 368 } |
| 411 } | 369 } |
| OLD | NEW |