Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/FileContentView.js

Issue 1609973002: DevTools: promisify ContentProvider.requestContent and all its clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaseline Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 */ 62 */
63 _metadataReceived: function(errorCode, metadata) 63 _metadataReceived: function(errorCode, metadata)
64 { 64 {
65 if (errorCode || !metadata) 65 if (errorCode || !metadata)
66 return; 66 return;
67 67
68 if (this._content) { 68 if (this._content) {
69 if (!this._content.updateMetadata(metadata)) 69 if (!this._content.updateMetadata(metadata))
70 return; 70 return;
71 var sourceFrame = /** @type {!WebInspector.SourceFrame} */ (this._in nerView); 71 var sourceFrame = /** @type {!WebInspector.SourceFrame} */ (this._in nerView);
72 this._content.requestContent(sourceFrame.setContent.bind(sourceFrame )); 72 this._content.requestContent().then(sourceFrame.setContent.bind(sour ceFrame));
73 } else { 73 } else {
74 this._innerView.detach(); 74 this._innerView.detach();
75 this._content = new WebInspector.FileContentView.FileContentProvider (this._file, metadata); 75 this._content = new WebInspector.FileContentView.FileContentProvider (this._file, metadata);
76 var sourceFrame = new WebInspector.SourceFrame(this._content); 76 var sourceFrame = new WebInspector.SourceFrame(this._content);
77 sourceFrame.setHighlighterType(this._file.resourceType.canonicalMime Type()); 77 sourceFrame.setHighlighterType(this._file.resourceType.canonicalMime Type());
78 this._innerView = sourceFrame; 78 this._innerView = sourceFrame;
79 this._innerView.show(this.element); 79 this._innerView.show(this.element);
80 } 80 }
81 }, 81 },
82 82
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 * @override 118 * @override
119 * @return {!WebInspector.ResourceType} 119 * @return {!WebInspector.ResourceType}
120 */ 120 */
121 contentType: function() 121 contentType: function()
122 { 122 {
123 return this._file.resourceType; 123 return this._file.resourceType;
124 }, 124 },
125 125
126 /** 126 /**
127 * @override 127 * @override
128 * @param {function(?string)} callback 128 * @return {!Promise<?string>}
129 */ 129 */
130 requestContent: function(callback) 130 requestContent: function()
131 { 131 {
132 var callback;
133 var promise = new Promise(fulfill => callback = fulfill);
132 var size = /** @type {number} */ (this._metadata.size); 134 var size = /** @type {number} */ (this._metadata.size);
133 this._file.requestFileContent(true, 0, size, this._charset || "", this._ fileContentReceived.bind(this, callback)); 135 this._file.requestFileContent(true, 0, size, this._charset || "", this._ fileContentReceived.bind(this, callback));
136 return promise;
134 }, 137 },
135 138
136 /** 139 /**
137 * @param {function(?string)} callback 140 * @param {function(?string)} callback
138 * @param {number} errorCode 141 * @param {number} errorCode
139 * @param {string=} content 142 * @param {string=} content
140 * @param {boolean=} base64Encoded 143 * @param {boolean=} base64Encoded
141 * @param {string=} charset 144 * @param {string=} charset
142 */ 145 */
143 _fileContentReceived: function(callback, errorCode, content, base64Encoded, charset) 146 _fileContentReceived: function(callback, errorCode, content, base64Encoded, charset)
(...skipping 24 matching lines...) Expand all
168 * @return {boolean} 171 * @return {boolean}
169 */ 172 */
170 updateMetadata: function(metadata) 173 updateMetadata: function(metadata)
171 { 174 {
172 if (this._metadata.modificationTime >= metadata.modificationTime) 175 if (this._metadata.modificationTime >= metadata.modificationTime)
173 return false; 176 return false;
174 this._metadata = metadata.modificationTime; 177 this._metadata = metadata.modificationTime;
175 return true; 178 return true;
176 } 179 }
177 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698