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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 * @param {?string} content | 87 * @param {?string} content |
88 */ | 88 */ |
89 function onResourceContent(content) | 89 function onResourceContent(content) |
90 { | 90 { |
91 var imageSrc = WebInspector.Resource.contentAsDataURL(content, mimeType, true); | 91 var imageSrc = WebInspector.Resource.contentAsDataURL(content, mimeType, true); |
92 if (imageSrc === null) | 92 if (imageSrc === null) |
93 imageSrc = url; | 93 imageSrc = url; |
94 image.src = imageSrc; | 94 image.src = imageSrc; |
95 } | 95 } |
96 | 96 |
97 contentProvider.requestContent(onResourceContent); | 97 contentProvider.requestContent().then(onResourceContent); |
98 } | 98 } |
99 | 99 |
100 WebInspector.Resource.prototype = { | 100 WebInspector.Resource.prototype = { |
101 /** | 101 /** |
102 * @return {?WebInspector.NetworkRequest} | 102 * @return {?WebInspector.NetworkRequest} |
103 */ | 103 */ |
104 get request() | 104 get request() |
105 { | 105 { |
106 return this._request; | 106 return this._request; |
107 }, | 107 }, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 */ | 204 */ |
205 contentType: function() | 205 contentType: function() |
206 { | 206 { |
207 if (this.resourceType() === WebInspector.resourceTypes.Document && this. mimeType.indexOf("javascript") !== -1) | 207 if (this.resourceType() === WebInspector.resourceTypes.Document && this. mimeType.indexOf("javascript") !== -1) |
208 return WebInspector.resourceTypes.Script; | 208 return WebInspector.resourceTypes.Script; |
209 return this.resourceType(); | 209 return this.resourceType(); |
210 }, | 210 }, |
211 | 211 |
212 /** | 212 /** |
213 * @override | 213 * @override |
214 * @param {function(?string)} callback | 214 * @return {!Promise<?string>} |
215 */ | 215 */ |
216 requestContent: function(callback) | 216 requestContent: function() |
217 { | 217 { |
218 if (typeof this._content !== "undefined") { | 218 if (typeof this._content !== "undefined") |
219 callback(this._content); | 219 return Promise.resolve(this._content); |
220 return; | |
221 } | |
222 | 220 |
221 var callback; | |
222 var promise = new Promise(fulfill => callback = fulfill); | |
pfeldman
2016/01/20 19:23:51
cache promise
| |
223 this._pendingContentCallbacks.push(callback); | 223 this._pendingContentCallbacks.push(callback); |
224 if (!this._request || this._request.finished) | 224 if (!this._request || this._request.finished) |
225 this._innerRequestContent(); | 225 this._innerRequestContent(); |
226 return promise; | |
226 }, | 227 }, |
227 | 228 |
228 /** | 229 /** |
229 * @return {string} | 230 * @return {string} |
230 */ | 231 */ |
231 canonicalMimeType: function() | 232 canonicalMimeType: function() |
232 { | 233 { |
233 return this.contentType().canonicalMimeType() || this.mimeType; | 234 return this.contentType().canonicalMimeType() || this.mimeType; |
234 }, | 235 }, |
235 | 236 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 * @param {string} content | 316 * @param {string} content |
316 * @param {boolean} contentEncoded | 317 * @param {boolean} contentEncoded |
317 * @this {WebInspector.Resource} | 318 * @this {WebInspector.Resource} |
318 */ | 319 */ |
319 function resourceContentLoaded(error, content, contentEncoded) | 320 function resourceContentLoaded(error, content, contentEncoded) |
320 { | 321 { |
321 contentLoaded.call(this, error, content, contentEncoded); | 322 contentLoaded.call(this, error, content, contentEncoded); |
322 } | 323 } |
323 | 324 |
324 if (this.request) { | 325 if (this.request) { |
325 this.request.requestContent(requestContentLoaded.bind(this)); | 326 this.request.requestContent().then(requestContentLoaded.bind(this)); |
326 return; | 327 return; |
327 } | 328 } |
328 | 329 |
329 /** | 330 /** |
330 * @param {?string} content | 331 * @param {?string} content |
331 * @this {WebInspector.Resource} | 332 * @this {WebInspector.Resource} |
332 */ | 333 */ |
333 function requestContentLoaded(content) | 334 function requestContentLoaded(content) |
334 { | 335 { |
335 contentLoaded.call(this, null, content, this.request.contentEncoded) ; | 336 contentLoaded.call(this, null, content, this.request.contentEncoded) ; |
(...skipping 19 matching lines...) Expand all Loading... | |
355 if (this._type.isTextType()) | 356 if (this._type.isTextType()) |
356 return true; | 357 return true; |
357 if (this._type === WebInspector.resourceTypes.Other) | 358 if (this._type === WebInspector.resourceTypes.Other) |
358 return !!this._content && !this._contentEncoded; | 359 return !!this._content && !this._contentEncoded; |
359 return false; | 360 return false; |
360 }, | 361 }, |
361 | 362 |
362 __proto__: WebInspector.SDKObject.prototype | 363 __proto__: WebInspector.SDKObject.prototype |
363 } | 364 } |
364 | 365 |
OLD | NEW |