| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 14 * its contributors may be used to endorse or promote products derived | 14 * its contributors may be used to endorse or promote products derived |
| 15 * from this software without specific prior written permission. | 15 * from this software without specific prior written permission. |
| 16 * | 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 /** | 28 /** |
| 29 * @implements {WebInspector.ContentProvider} | 29 * @implements {Common.ContentProvider} |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.Resource = class extends WebInspector.SDKObject { | 32 SDK.Resource = class extends SDK.SDKObject { |
| 33 /** | 33 /** |
| 34 * @param {!WebInspector.Target} target | 34 * @param {!SDK.Target} target |
| 35 * @param {?WebInspector.NetworkRequest} request | 35 * @param {?SDK.NetworkRequest} request |
| 36 * @param {string} url | 36 * @param {string} url |
| 37 * @param {string} documentURL | 37 * @param {string} documentURL |
| 38 * @param {!Protocol.Page.FrameId} frameId | 38 * @param {!Protocol.Page.FrameId} frameId |
| 39 * @param {!Protocol.Network.LoaderId} loaderId | 39 * @param {!Protocol.Network.LoaderId} loaderId |
| 40 * @param {!WebInspector.ResourceType} type | 40 * @param {!Common.ResourceType} type |
| 41 * @param {string} mimeType | 41 * @param {string} mimeType |
| 42 * @param {?Date} lastModified | 42 * @param {?Date} lastModified |
| 43 * @param {?number} contentSize | 43 * @param {?number} contentSize |
| 44 */ | 44 */ |
| 45 constructor(target, request, url, documentURL, frameId, loaderId, type, mimeTy
pe, lastModified, contentSize) { | 45 constructor(target, request, url, documentURL, frameId, loaderId, type, mimeTy
pe, lastModified, contentSize) { |
| 46 super(target); | 46 super(target); |
| 47 this._request = request; | 47 this._request = request; |
| 48 this.url = url; | 48 this.url = url; |
| 49 this._documentURL = documentURL; | 49 this._documentURL = documentURL; |
| 50 this._frameId = frameId; | 50 this._frameId = frameId; |
| 51 this._loaderId = loaderId; | 51 this._loaderId = loaderId; |
| 52 this._type = type || WebInspector.resourceTypes.Other; | 52 this._type = type || Common.resourceTypes.Other; |
| 53 this._mimeType = mimeType; | 53 this._mimeType = mimeType; |
| 54 | 54 |
| 55 this._lastModified = lastModified && lastModified.isValid() ? lastModified :
null; | 55 this._lastModified = lastModified && lastModified.isValid() ? lastModified :
null; |
| 56 this._contentSize = contentSize; | 56 this._contentSize = contentSize; |
| 57 | 57 |
| 58 /** @type {?string} */ this._content; | 58 /** @type {?string} */ this._content; |
| 59 /** @type {boolean} */ this._contentEncoded; | 59 /** @type {boolean} */ this._contentEncoded; |
| 60 this._pendingContentCallbacks = []; | 60 this._pendingContentCallbacks = []; |
| 61 if (this._request && !this._request.finished) | 61 if (this._request && !this._request.finished) |
| 62 this._request.addEventListener(WebInspector.NetworkRequest.Events.Finished
Loading, this._requestFinished, this); | 62 this._request.addEventListener(SDK.NetworkRequest.Events.FinishedLoading,
this._requestFinished, this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * @return {?Date} | 66 * @return {?Date} |
| 67 */ | 67 */ |
| 68 lastModified() { | 68 lastModified() { |
| 69 if (this._lastModified || !this._request) | 69 if (this._lastModified || !this._request) |
| 70 return this._lastModified; | 70 return this._lastModified; |
| 71 var lastModifiedHeader = this._request.responseLastModified(); | 71 var lastModifiedHeader = this._request.responseLastModified(); |
| 72 var date = lastModifiedHeader ? new Date(lastModifiedHeader) : null; | 72 var date = lastModifiedHeader ? new Date(lastModifiedHeader) : null; |
| 73 this._lastModified = date && date.isValid() ? date : null; | 73 this._lastModified = date && date.isValid() ? date : null; |
| 74 return this._lastModified; | 74 return this._lastModified; |
| 75 } | 75 } |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * @return {?number} | 78 * @return {?number} |
| 79 */ | 79 */ |
| 80 contentSize() { | 80 contentSize() { |
| 81 if (typeof this._contentSize === 'number' || !this._request) | 81 if (typeof this._contentSize === 'number' || !this._request) |
| 82 return this._contentSize; | 82 return this._contentSize; |
| 83 return this._request.resourceSize; | 83 return this._request.resourceSize; |
| 84 } | 84 } |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * @return {?WebInspector.NetworkRequest} | 87 * @return {?SDK.NetworkRequest} |
| 88 */ | 88 */ |
| 89 get request() { | 89 get request() { |
| 90 return this._request; | 90 return this._request; |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * @return {string} | 94 * @return {string} |
| 95 */ | 95 */ |
| 96 get url() { | 96 get url() { |
| 97 return this._url; | 97 return this._url; |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * @param {string} x | 101 * @param {string} x |
| 102 */ | 102 */ |
| 103 set url(x) { | 103 set url(x) { |
| 104 this._url = x; | 104 this._url = x; |
| 105 this._parsedURL = new WebInspector.ParsedURL(x); | 105 this._parsedURL = new Common.ParsedURL(x); |
| 106 } | 106 } |
| 107 | 107 |
| 108 get parsedURL() { | 108 get parsedURL() { |
| 109 return this._parsedURL; | 109 return this._parsedURL; |
| 110 } | 110 } |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * @return {string} | 113 * @return {string} |
| 114 */ | 114 */ |
| 115 get documentURL() { | 115 get documentURL() { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 131 } | 131 } |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * @return {string} | 134 * @return {string} |
| 135 */ | 135 */ |
| 136 get displayName() { | 136 get displayName() { |
| 137 return this._parsedURL.displayName; | 137 return this._parsedURL.displayName; |
| 138 } | 138 } |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * @return {!WebInspector.ResourceType} | 141 * @return {!Common.ResourceType} |
| 142 */ | 142 */ |
| 143 resourceType() { | 143 resourceType() { |
| 144 return this._request ? this._request.resourceType() : this._type; | 144 return this._request ? this._request.resourceType() : this._type; |
| 145 } | 145 } |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * @return {string} | 148 * @return {string} |
| 149 */ | 149 */ |
| 150 get mimeType() { | 150 get mimeType() { |
| 151 return this._request ? this._request.mimeType : this._mimeType; | 151 return this._request ? this._request.mimeType : this._mimeType; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 /** | 168 /** |
| 169 * @override | 169 * @override |
| 170 * @return {string} | 170 * @return {string} |
| 171 */ | 171 */ |
| 172 contentURL() { | 172 contentURL() { |
| 173 return this._url; | 173 return this._url; |
| 174 } | 174 } |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * @override | 177 * @override |
| 178 * @return {!WebInspector.ResourceType} | 178 * @return {!Common.ResourceType} |
| 179 */ | 179 */ |
| 180 contentType() { | 180 contentType() { |
| 181 if (this.resourceType() === WebInspector.resourceTypes.Document && this.mime
Type.indexOf('javascript') !== -1) | 181 if (this.resourceType() === Common.resourceTypes.Document && this.mimeType.i
ndexOf('javascript') !== -1) |
| 182 return WebInspector.resourceTypes.Script; | 182 return Common.resourceTypes.Script; |
| 183 return this.resourceType(); | 183 return this.resourceType(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * @override | 187 * @override |
| 188 * @return {!Promise<?string>} | 188 * @return {!Promise<?string>} |
| 189 */ | 189 */ |
| 190 requestContent() { | 190 requestContent() { |
| 191 if (typeof this._content !== 'undefined') | 191 if (typeof this._content !== 'undefined') |
| 192 return Promise.resolve(this._content); | 192 return Promise.resolve(this._content); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 204 */ | 204 */ |
| 205 canonicalMimeType() { | 205 canonicalMimeType() { |
| 206 return this.contentType().canonicalMimeType() || this.mimeType; | 206 return this.contentType().canonicalMimeType() || this.mimeType; |
| 207 } | 207 } |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @override | 210 * @override |
| 211 * @param {string} query | 211 * @param {string} query |
| 212 * @param {boolean} caseSensitive | 212 * @param {boolean} caseSensitive |
| 213 * @param {boolean} isRegex | 213 * @param {boolean} isRegex |
| 214 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack | 214 * @param {function(!Array.<!Common.ContentProvider.SearchMatch>)} callback |
| 215 */ | 215 */ |
| 216 searchInContent(query, caseSensitive, isRegex, callback) { | 216 searchInContent(query, caseSensitive, isRegex, callback) { |
| 217 /** | 217 /** |
| 218 * @param {?Protocol.Error} error | 218 * @param {?Protocol.Error} error |
| 219 * @param {!Array.<!Protocol.Debugger.SearchMatch>} searchMatches | 219 * @param {!Array.<!Protocol.Debugger.SearchMatch>} searchMatches |
| 220 */ | 220 */ |
| 221 function callbackWrapper(error, searchMatches) { | 221 function callbackWrapper(error, searchMatches) { |
| 222 callback(searchMatches || []); | 222 callback(searchMatches || []); |
| 223 } | 223 } |
| 224 | 224 |
| 225 if (this.frameId) | 225 if (this.frameId) |
| 226 this.target().pageAgent().searchInResource( | 226 this.target().pageAgent().searchInResource( |
| 227 this.frameId, this.url, query, caseSensitive, isRegex, callbackWrapper
); | 227 this.frameId, this.url, query, caseSensitive, isRegex, callbackWrapper
); |
| 228 else | 228 else |
| 229 callback([]); | 229 callback([]); |
| 230 } | 230 } |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * @param {!Element} image | 233 * @param {!Element} image |
| 234 */ | 234 */ |
| 235 populateImageSource(image) { | 235 populateImageSource(image) { |
| 236 /** | 236 /** |
| 237 * @param {?string} content | 237 * @param {?string} content |
| 238 * @this {WebInspector.Resource} | 238 * @this {SDK.Resource} |
| 239 */ | 239 */ |
| 240 function onResourceContent(content) { | 240 function onResourceContent(content) { |
| 241 var imageSrc = WebInspector.ContentProvider.contentAsDataURL(content, this
._mimeType, true); | 241 var imageSrc = Common.ContentProvider.contentAsDataURL(content, this._mime
Type, true); |
| 242 if (imageSrc === null) | 242 if (imageSrc === null) |
| 243 imageSrc = this._url; | 243 imageSrc = this._url; |
| 244 image.src = imageSrc; | 244 image.src = imageSrc; |
| 245 } | 245 } |
| 246 | 246 |
| 247 this.requestContent().then(onResourceContent.bind(this)); | 247 this.requestContent().then(onResourceContent.bind(this)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 _requestFinished() { | 250 _requestFinished() { |
| 251 this._request.removeEventListener(WebInspector.NetworkRequest.Events.Finishe
dLoading, this._requestFinished, this); | 251 this._request.removeEventListener(SDK.NetworkRequest.Events.FinishedLoading,
this._requestFinished, this); |
| 252 if (this._pendingContentCallbacks.length) | 252 if (this._pendingContentCallbacks.length) |
| 253 this._innerRequestContent(); | 253 this._innerRequestContent(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 _innerRequestContent() { | 256 _innerRequestContent() { |
| 257 if (this._contentRequested) | 257 if (this._contentRequested) |
| 258 return; | 258 return; |
| 259 this._contentRequested = true; | 259 this._contentRequested = true; |
| 260 | 260 |
| 261 /** | 261 /** |
| 262 * @param {?Protocol.Error} error | 262 * @param {?Protocol.Error} error |
| 263 * @param {?string} content | 263 * @param {?string} content |
| 264 * @param {boolean} contentEncoded | 264 * @param {boolean} contentEncoded |
| 265 * @this {WebInspector.Resource} | 265 * @this {SDK.Resource} |
| 266 */ | 266 */ |
| 267 function contentLoaded(error, content, contentEncoded) { | 267 function contentLoaded(error, content, contentEncoded) { |
| 268 if (error || content === null) { | 268 if (error || content === null) { |
| 269 replyWithContent.call(this, null, false); | 269 replyWithContent.call(this, null, false); |
| 270 return; | 270 return; |
| 271 } | 271 } |
| 272 replyWithContent.call(this, content, contentEncoded); | 272 replyWithContent.call(this, content, contentEncoded); |
| 273 } | 273 } |
| 274 | 274 |
| 275 /** | 275 /** |
| 276 * @param {?string} content | 276 * @param {?string} content |
| 277 * @param {boolean} contentEncoded | 277 * @param {boolean} contentEncoded |
| 278 * @this {WebInspector.Resource} | 278 * @this {SDK.Resource} |
| 279 */ | 279 */ |
| 280 function replyWithContent(content, contentEncoded) { | 280 function replyWithContent(content, contentEncoded) { |
| 281 this._content = content; | 281 this._content = content; |
| 282 this._contentEncoded = contentEncoded; | 282 this._contentEncoded = contentEncoded; |
| 283 var callbacks = this._pendingContentCallbacks.slice(); | 283 var callbacks = this._pendingContentCallbacks.slice(); |
| 284 for (var i = 0; i < callbacks.length; ++i) | 284 for (var i = 0; i < callbacks.length; ++i) |
| 285 callbacks[i](this._content); | 285 callbacks[i](this._content); |
| 286 this._pendingContentCallbacks.length = 0; | 286 this._pendingContentCallbacks.length = 0; |
| 287 delete this._contentRequested; | 287 delete this._contentRequested; |
| 288 } | 288 } |
| 289 | 289 |
| 290 /** | 290 /** |
| 291 * @param {?Protocol.Error} error | 291 * @param {?Protocol.Error} error |
| 292 * @param {string} content | 292 * @param {string} content |
| 293 * @param {boolean} contentEncoded | 293 * @param {boolean} contentEncoded |
| 294 * @this {WebInspector.Resource} | 294 * @this {SDK.Resource} |
| 295 */ | 295 */ |
| 296 function resourceContentLoaded(error, content, contentEncoded) { | 296 function resourceContentLoaded(error, content, contentEncoded) { |
| 297 contentLoaded.call(this, error, content, contentEncoded); | 297 contentLoaded.call(this, error, content, contentEncoded); |
| 298 } | 298 } |
| 299 | 299 |
| 300 if (this.request) { | 300 if (this.request) { |
| 301 this.request.requestContent().then(requestContentLoaded.bind(this)); | 301 this.request.requestContent().then(requestContentLoaded.bind(this)); |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 | 304 |
| 305 /** | 305 /** |
| 306 * @param {?string} content | 306 * @param {?string} content |
| 307 * @this {WebInspector.Resource} | 307 * @this {SDK.Resource} |
| 308 */ | 308 */ |
| 309 function requestContentLoaded(content) { | 309 function requestContentLoaded(content) { |
| 310 contentLoaded.call(this, null, content, this.request.contentEncoded); | 310 contentLoaded.call(this, null, content, this.request.contentEncoded); |
| 311 } | 311 } |
| 312 | 312 |
| 313 this.target().pageAgent().getResourceContent(this.frameId, this.url, resourc
eContentLoaded.bind(this)); | 313 this.target().pageAgent().getResourceContent(this.frameId, this.url, resourc
eContentLoaded.bind(this)); |
| 314 } | 314 } |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * @return {boolean} | 317 * @return {boolean} |
| 318 */ | 318 */ |
| 319 hasTextContent() { | 319 hasTextContent() { |
| 320 if (this._type.isTextType()) | 320 if (this._type.isTextType()) |
| 321 return true; | 321 return true; |
| 322 if (this._type === WebInspector.resourceTypes.Other) | 322 if (this._type === Common.resourceTypes.Other) |
| 323 return !!this._content && !this._contentEncoded; | 323 return !!this._content && !this._contentEncoded; |
| 324 return false; | 324 return false; |
| 325 } | 325 } |
| 326 }; | 326 }; |
| OLD | NEW |