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 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> | 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> |
4 * Copyright (C) 2011 Google Inc. All rights reserved. | 4 * Copyright (C) 2011 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 3177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3188 | 3188 |
3189 WebInspector.NetworkPanelFactory.prototype = { | 3189 WebInspector.NetworkPanelFactory.prototype = { |
3190 /** | 3190 /** |
3191 * @return {!WebInspector.Panel} | 3191 * @return {!WebInspector.Panel} |
3192 */ | 3192 */ |
3193 createPanel: function() | 3193 createPanel: function() |
3194 { | 3194 { |
3195 return WebInspector.NetworkPanel._instance(); | 3195 return WebInspector.NetworkPanel._instance(); |
3196 } | 3196 } |
3197 } | 3197 } |
| 3198 |
| 3199 /** |
| 3200 * @constructor |
| 3201 */ |
| 3202 WebInspector.HARWriter = function() |
| 3203 { |
| 3204 } |
| 3205 |
| 3206 WebInspector.HARWriter.prototype = { |
| 3207 /** |
| 3208 * @param {!WebInspector.OutputStream} stream |
| 3209 * @param {!Array.<!WebInspector.NetworkRequest>} requests |
| 3210 * @param {!WebInspector.Progress} progress |
| 3211 */ |
| 3212 write: function(stream, requests, progress) |
| 3213 { |
| 3214 this._stream = stream; |
| 3215 this._harLog = (new WebInspector.HARLog(requests)).build(); |
| 3216 this._pendingRequests = 1; // Guard against completing resource transfer
before all requests are made. |
| 3217 var entries = this._harLog.entries; |
| 3218 for (var i = 0; i < entries.length; ++i) { |
| 3219 var content = requests[i].content; |
| 3220 if (typeof content === "undefined" && requests[i].finished) { |
| 3221 ++this._pendingRequests; |
| 3222 requests[i].requestContent(this._onContentAvailable.bind(this, e
ntries[i])); |
| 3223 } else if (content !== null) |
| 3224 entries[i].response.content.text = content; |
| 3225 } |
| 3226 var compositeProgress = new WebInspector.CompositeProgress(progress); |
| 3227 this._writeProgress = compositeProgress.createSubProgress(); |
| 3228 if (--this._pendingRequests) { |
| 3229 this._requestsProgress = compositeProgress.createSubProgress(); |
| 3230 this._requestsProgress.setTitle(WebInspector.UIString("Collecting co
ntent…")); |
| 3231 this._requestsProgress.setTotalWork(this._pendingRequests); |
| 3232 } else |
| 3233 this._beginWrite(); |
| 3234 }, |
| 3235 |
| 3236 /** |
| 3237 * @param {!Object} entry |
| 3238 * @param {?string} content |
| 3239 */ |
| 3240 _onContentAvailable: function(entry, content) |
| 3241 { |
| 3242 if (content !== null) |
| 3243 entry.response.content.text = content; |
| 3244 if (this._requestsProgress) |
| 3245 this._requestsProgress.worked(); |
| 3246 if (!--this._pendingRequests) { |
| 3247 this._requestsProgress.done(); |
| 3248 this._beginWrite(); |
| 3249 } |
| 3250 }, |
| 3251 |
| 3252 _beginWrite: function() |
| 3253 { |
| 3254 const jsonIndent = 2; |
| 3255 this._text = JSON.stringify({log: this._harLog}, null, jsonIndent); |
| 3256 this._writeProgress.setTitle(WebInspector.UIString("Writing file…")); |
| 3257 this._writeProgress.setTotalWork(this._text.length); |
| 3258 this._bytesWritten = 0; |
| 3259 this._writeNextChunk(this._stream); |
| 3260 }, |
| 3261 |
| 3262 /** |
| 3263 * @param {!WebInspector.OutputStream} stream |
| 3264 * @param {string=} error |
| 3265 */ |
| 3266 _writeNextChunk: function(stream, error) |
| 3267 { |
| 3268 if (this._bytesWritten >= this._text.length || error) { |
| 3269 stream.close(); |
| 3270 this._writeProgress.done(); |
| 3271 return; |
| 3272 } |
| 3273 const chunkSize = 100000; |
| 3274 var text = this._text.substring(this._bytesWritten, this._bytesWritten +
chunkSize); |
| 3275 this._bytesWritten += text.length; |
| 3276 stream.write(text, this._writeNextChunk.bind(this)); |
| 3277 this._writeProgress.setWorked(this._bytesWritten); |
| 3278 } |
| 3279 } |
OLD | NEW |