| OLD | NEW |
| 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 * @implements {WebInspector.ContentProvider} | 5 * @implements {Common.ContentProvider} |
| 6 * @unrestricted | 6 * @unrestricted |
| 7 */ | 7 */ |
| 8 WebInspector.CSSStyleSheetHeader = class { | 8 SDK.CSSStyleSheetHeader = class { |
| 9 /** | 9 /** |
| 10 * @param {!WebInspector.CSSModel} cssModel | 10 * @param {!SDK.CSSModel} cssModel |
| 11 * @param {!Protocol.CSS.CSSStyleSheetHeader} payload | 11 * @param {!Protocol.CSS.CSSStyleSheetHeader} payload |
| 12 */ | 12 */ |
| 13 constructor(cssModel, payload) { | 13 constructor(cssModel, payload) { |
| 14 this._cssModel = cssModel; | 14 this._cssModel = cssModel; |
| 15 this.id = payload.styleSheetId; | 15 this.id = payload.styleSheetId; |
| 16 this.frameId = payload.frameId; | 16 this.frameId = payload.frameId; |
| 17 this.sourceURL = payload.sourceURL; | 17 this.sourceURL = payload.sourceURL; |
| 18 this.hasSourceURL = !!payload.hasSourceURL; | 18 this.hasSourceURL = !!payload.hasSourceURL; |
| 19 this.origin = payload.origin; | 19 this.origin = payload.origin; |
| 20 this.title = payload.title; | 20 this.title = payload.title; |
| 21 this.disabled = payload.disabled; | 21 this.disabled = payload.disabled; |
| 22 this.isInline = payload.isInline; | 22 this.isInline = payload.isInline; |
| 23 this.startLine = payload.startLine; | 23 this.startLine = payload.startLine; |
| 24 this.startColumn = payload.startColumn; | 24 this.startColumn = payload.startColumn; |
| 25 if (payload.ownerNode) | 25 if (payload.ownerNode) |
| 26 this.ownerNode = new WebInspector.DeferredDOMNode(cssModel.target(), paylo
ad.ownerNode); | 26 this.ownerNode = new SDK.DeferredDOMNode(cssModel.target(), payload.ownerN
ode); |
| 27 this.setSourceMapURL(payload.sourceMapURL); | 27 this.setSourceMapURL(payload.sourceMapURL); |
| 28 } | 28 } |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * @return {!WebInspector.ContentProvider} | 31 * @return {!Common.ContentProvider} |
| 32 */ | 32 */ |
| 33 originalContentProvider() { | 33 originalContentProvider() { |
| 34 if (!this._originalContentProvider) { | 34 if (!this._originalContentProvider) { |
| 35 var lazyContent = this._cssModel.originalStyleSheetText.bind(this._cssMode
l, this); | 35 var lazyContent = this._cssModel.originalStyleSheetText.bind(this._cssMode
l, this); |
| 36 this._originalContentProvider = | 36 this._originalContentProvider = |
| 37 new WebInspector.StaticContentProvider(this.contentURL(), this.content
Type(), lazyContent); | 37 new Common.StaticContentProvider(this.contentURL(), this.contentType()
, lazyContent); |
| 38 } | 38 } |
| 39 return this._originalContentProvider; | 39 return this._originalContentProvider; |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * @param {string=} sourceMapURL | 43 * @param {string=} sourceMapURL |
| 44 */ | 44 */ |
| 45 setSourceMapURL(sourceMapURL) { | 45 setSourceMapURL(sourceMapURL) { |
| 46 var completeSourceMapURL = this.sourceURL && sourceMapURL ? | 46 var completeSourceMapURL = this.sourceURL && sourceMapURL ? |
| 47 WebInspector.ParsedURL.completeURL(this.sourceURL, sourceMapURL) : | 47 Common.ParsedURL.completeURL(this.sourceURL, sourceMapURL) : |
| 48 sourceMapURL; | 48 sourceMapURL; |
| 49 this.sourceMapURL = completeSourceMapURL; | 49 this.sourceMapURL = completeSourceMapURL; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @return {!WebInspector.Target} | 53 * @return {!SDK.Target} |
| 54 */ | 54 */ |
| 55 target() { | 55 target() { |
| 56 return this._cssModel.target(); | 56 return this._cssModel.target(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * @return {!WebInspector.CSSModel} | 60 * @return {!SDK.CSSModel} |
| 61 */ | 61 */ |
| 62 cssModel() { | 62 cssModel() { |
| 63 return this._cssModel; | 63 return this._cssModel; |
| 64 } | 64 } |
| 65 | 65 |
| 66 /** | 66 /** |
| 67 * @return {string} | 67 * @return {string} |
| 68 */ | 68 */ |
| 69 resourceURL() { | 69 resourceURL() { |
| 70 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.source
URL; | 70 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.source
URL; |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @return {string} | 74 * @return {string} |
| 75 */ | 75 */ |
| 76 _viaInspectorResourceURL() { | 76 _viaInspectorResourceURL() { |
| 77 var resourceTreeModel = WebInspector.ResourceTreeModel.fromTarget(this.targe
t()); | 77 var resourceTreeModel = SDK.ResourceTreeModel.fromTarget(this.target()); |
| 78 var frame = resourceTreeModel.frameForId(this.frameId); | 78 var frame = resourceTreeModel.frameForId(this.frameId); |
| 79 console.assert(frame); | 79 console.assert(frame); |
| 80 var parsedURL = new WebInspector.ParsedURL(frame.url); | 80 var parsedURL = new Common.ParsedURL(frame.url); |
| 81 var fakeURL = 'inspector://' + parsedURL.host + parsedURL.folderPathComponen
ts; | 81 var fakeURL = 'inspector://' + parsedURL.host + parsedURL.folderPathComponen
ts; |
| 82 if (!fakeURL.endsWith('/')) | 82 if (!fakeURL.endsWith('/')) |
| 83 fakeURL += '/'; | 83 fakeURL += '/'; |
| 84 fakeURL += 'inspector-stylesheet'; | 84 fakeURL += 'inspector-stylesheet'; |
| 85 return fakeURL; | 85 return fakeURL; |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * @param {number} lineNumberInStyleSheet | 89 * @param {number} lineNumberInStyleSheet |
| 90 * @return {number} | 90 * @return {number} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 /** | 105 /** |
| 106 * @override | 106 * @override |
| 107 * @return {string} | 107 * @return {string} |
| 108 */ | 108 */ |
| 109 contentURL() { | 109 contentURL() { |
| 110 return this.resourceURL(); | 110 return this.resourceURL(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * @override | 114 * @override |
| 115 * @return {!WebInspector.ResourceType} | 115 * @return {!Common.ResourceType} |
| 116 */ | 116 */ |
| 117 contentType() { | 117 contentType() { |
| 118 return WebInspector.resourceTypes.Stylesheet; | 118 return Common.resourceTypes.Stylesheet; |
| 119 } | 119 } |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * @override | 122 * @override |
| 123 * @return {!Promise<?string>} | 123 * @return {!Promise<?string>} |
| 124 */ | 124 */ |
| 125 requestContent() { | 125 requestContent() { |
| 126 return /** @type {!Promise<?string>} */ (this._cssModel.getStyleSheetText(th
is.id)); | 126 return /** @type {!Promise<?string>} */ (this._cssModel.getStyleSheetText(th
is.id)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * @override | 130 * @override |
| 131 * @param {string} query | 131 * @param {string} query |
| 132 * @param {boolean} caseSensitive | 132 * @param {boolean} caseSensitive |
| 133 * @param {boolean} isRegex | 133 * @param {boolean} isRegex |
| 134 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack | 134 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback |
| 135 */ | 135 */ |
| 136 searchInContent(query, caseSensitive, isRegex, callback) { | 136 searchInContent(query, caseSensitive, isRegex, callback) { |
| 137 function performSearch(content) { | 137 function performSearch(content) { |
| 138 callback(WebInspector.ContentProvider.performSearchInContent(content, quer
y, caseSensitive, isRegex)); | 138 callback(Common.ContentProvider.performSearchInContent(content, query, cas
eSensitive, isRegex)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // searchInContent should call back later. | 141 // searchInContent should call back later. |
| 142 this.requestContent().then(performSearch); | 142 this.requestContent().then(performSearch); |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * @return {boolean} | 146 * @return {boolean} |
| 147 */ | 147 */ |
| 148 isViaInspector() { | 148 isViaInspector() { |
| 149 return this.origin === 'inspector'; | 149 return this.origin === 'inspector'; |
| 150 } | 150 } |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * @implements {WebInspector.ContentProvider} | 154 * @implements {Common.ContentProvider} |
| 155 * @unrestricted | 155 * @unrestricted |
| 156 */ | 156 */ |
| 157 WebInspector.CSSStyleSheetHeader.OriginalContentProvider = class { | 157 SDK.CSSStyleSheetHeader.OriginalContentProvider = class { |
| 158 /** | 158 /** |
| 159 * @param {!WebInspector.CSSStyleSheetHeader} header | 159 * @param {!SDK.CSSStyleSheetHeader} header |
| 160 */ | 160 */ |
| 161 constructor(header) { | 161 constructor(header) { |
| 162 this._header = header; | 162 this._header = header; |
| 163 } | 163 } |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * @override | 166 * @override |
| 167 * @return {string} | 167 * @return {string} |
| 168 */ | 168 */ |
| 169 contentURL() { | 169 contentURL() { |
| 170 return this._header.contentURL(); | 170 return this._header.contentURL(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * @override | 174 * @override |
| 175 * @return {!WebInspector.ResourceType} | 175 * @return {!Common.ResourceType} |
| 176 */ | 176 */ |
| 177 contentType() { | 177 contentType() { |
| 178 return this._header.contentType(); | 178 return this._header.contentType(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * @override | 182 * @override |
| 183 * @return {!Promise<?string>} | 183 * @return {!Promise<?string>} |
| 184 */ | 184 */ |
| 185 requestContent() { | 185 requestContent() { |
| 186 return /** @type {!Promise<?string>} */ (this._header.cssModel().originalSty
leSheetText(this._header)); | 186 return /** @type {!Promise<?string>} */ (this._header.cssModel().originalSty
leSheetText(this._header)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 /** | 189 /** |
| 190 * @override | 190 * @override |
| 191 * @param {string} query | 191 * @param {string} query |
| 192 * @param {boolean} caseSensitive | 192 * @param {boolean} caseSensitive |
| 193 * @param {boolean} isRegex | 193 * @param {boolean} isRegex |
| 194 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack | 194 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback |
| 195 */ | 195 */ |
| 196 searchInContent(query, caseSensitive, isRegex, callback) { | 196 searchInContent(query, caseSensitive, isRegex, callback) { |
| 197 /** | 197 /** |
| 198 * @param {?string} content | 198 * @param {?string} content |
| 199 */ | 199 */ |
| 200 function performSearch(content) { | 200 function performSearch(content) { |
| 201 var searchResults = | 201 var searchResults = |
| 202 content ? WebInspector.ContentProvider.performSearchInContent(content,
query, caseSensitive, isRegex) : []; | 202 content ? Common.ContentProvider.performSearchInContent(content, query
, caseSensitive, isRegex) : []; |
| 203 callback(searchResults); | 203 callback(searchResults); |
| 204 } | 204 } |
| 205 | 205 |
| 206 this.requestContent().then(performSearch); | 206 this.requestContent().then(performSearch); |
| 207 } | 207 } |
| 208 }; | 208 }; |
| OLD | NEW |