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