| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | |
| 5 /** | 4 /** |
| 6 * @constructor | |
| 7 * @implements {WebInspector.ContentProvider} | 5 * @implements {WebInspector.ContentProvider} |
| 8 * @param {string} contentURL | 6 * @unrestricted |
| 9 * @param {!WebInspector.ResourceType} contentType | |
| 10 * @param {function():!Promise<string>} lazyContent | |
| 11 */ | 7 */ |
| 12 WebInspector.StaticContentProvider = function(contentURL, contentType, lazyConte
nt) | 8 WebInspector.StaticContentProvider = class { |
| 13 { | 9 /** |
| 10 * @param {string} contentURL |
| 11 * @param {!WebInspector.ResourceType} contentType |
| 12 * @param {function():!Promise<string>} lazyContent |
| 13 */ |
| 14 constructor(contentURL, contentType, lazyContent) { |
| 14 this._contentURL = contentURL; | 15 this._contentURL = contentURL; |
| 15 this._contentType = contentType; | 16 this._contentType = contentType; |
| 16 this._lazyContent = lazyContent; | 17 this._lazyContent = lazyContent; |
| 18 } |
| 19 |
| 20 /** |
| 21 * @param {string} contentURL |
| 22 * @param {!WebInspector.ResourceType} contentType |
| 23 * @param {string} content |
| 24 * @return {!WebInspector.StaticContentProvider} |
| 25 */ |
| 26 static fromString(contentURL, contentType, content) { |
| 27 var lazyContent = () => Promise.resolve(content); |
| 28 return new WebInspector.StaticContentProvider(contentURL, contentType, lazyC
ontent); |
| 29 } |
| 30 |
| 31 /** |
| 32 * @override |
| 33 * @return {string} |
| 34 */ |
| 35 contentURL() { |
| 36 return this._contentURL; |
| 37 } |
| 38 |
| 39 /** |
| 40 * @override |
| 41 * @return {!WebInspector.ResourceType} |
| 42 */ |
| 43 contentType() { |
| 44 return this._contentType; |
| 45 } |
| 46 |
| 47 /** |
| 48 * @override |
| 49 * @return {!Promise<?string>} |
| 50 */ |
| 51 requestContent() { |
| 52 return /** @type {!Promise<?string>} */ (this._lazyContent()); |
| 53 } |
| 54 |
| 55 /** |
| 56 * @override |
| 57 * @param {string} query |
| 58 * @param {boolean} caseSensitive |
| 59 * @param {boolean} isRegex |
| 60 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 61 */ |
| 62 searchInContent(query, caseSensitive, isRegex, callback) { |
| 63 /** |
| 64 * @param {string} content |
| 65 */ |
| 66 function performSearch(content) { |
| 67 callback(WebInspector.ContentProvider.performSearchInContent(content, quer
y, caseSensitive, isRegex)); |
| 68 } |
| 69 |
| 70 this._lazyContent().then(performSearch); |
| 71 } |
| 17 }; | 72 }; |
| 18 | 73 |
| 19 /** | |
| 20 * @param {string} contentURL | |
| 21 * @param {!WebInspector.ResourceType} contentType | |
| 22 * @param {string} content | |
| 23 * @return {!WebInspector.StaticContentProvider} | |
| 24 */ | |
| 25 WebInspector.StaticContentProvider.fromString = function(contentURL, contentType
, content) | |
| 26 { | |
| 27 var lazyContent = () => Promise.resolve(content); | |
| 28 return new WebInspector.StaticContentProvider(contentURL, contentType, lazyC
ontent); | |
| 29 }; | |
| 30 | 74 |
| 31 WebInspector.StaticContentProvider.prototype = { | |
| 32 /** | |
| 33 * @override | |
| 34 * @return {string} | |
| 35 */ | |
| 36 contentURL: function() | |
| 37 { | |
| 38 return this._contentURL; | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * @override | |
| 43 * @return {!WebInspector.ResourceType} | |
| 44 */ | |
| 45 contentType: function() | |
| 46 { | |
| 47 return this._contentType; | |
| 48 }, | |
| 49 | |
| 50 /** | |
| 51 * @override | |
| 52 * @return {!Promise<?string>} | |
| 53 */ | |
| 54 requestContent: function() | |
| 55 { | |
| 56 return /** @type {!Promise<?string>} */(this._lazyContent()); | |
| 57 }, | |
| 58 | |
| 59 /** | |
| 60 * @override | |
| 61 * @param {string} query | |
| 62 * @param {boolean} caseSensitive | |
| 63 * @param {boolean} isRegex | |
| 64 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | |
| 65 */ | |
| 66 searchInContent: function(query, caseSensitive, isRegex, callback) | |
| 67 { | |
| 68 /** | |
| 69 * @param {string} content | |
| 70 */ | |
| 71 function performSearch(content) | |
| 72 { | |
| 73 callback(WebInspector.ContentProvider.performSearchInContent(content
, query, caseSensitive, isRegex)); | |
| 74 } | |
| 75 | |
| 76 this._lazyContent().then(performSearch); | |
| 77 } | |
| 78 }; | |
| OLD | NEW |