| 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 13 matching lines...) Expand all Loading... |
| 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.HARWriter = class { | 34 Network.HARWriter = class { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.OutputStream} stream | 36 * @param {!Common.OutputStream} stream |
| 37 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 37 * @param {!Array.<!SDK.NetworkRequest>} requests |
| 38 * @param {!WebInspector.Progress} progress | 38 * @param {!Common.Progress} progress |
| 39 */ | 39 */ |
| 40 write(stream, requests, progress) { | 40 write(stream, requests, progress) { |
| 41 this._stream = stream; | 41 this._stream = stream; |
| 42 this._harLog = (new WebInspector.HARLog(requests)).build(); | 42 this._harLog = (new SDK.HARLog(requests)).build(); |
| 43 this._pendingRequests = 1; // Guard against completing resource transfer be
fore all requests are made. | 43 this._pendingRequests = 1; // Guard against completing resource transfer be
fore all requests are made. |
| 44 var entries = this._harLog.entries; | 44 var entries = this._harLog.entries; |
| 45 for (var i = 0; i < entries.length; ++i) { | 45 for (var i = 0; i < entries.length; ++i) { |
| 46 var content = requests[i].content; | 46 var content = requests[i].content; |
| 47 if (typeof content === 'undefined' && requests[i].finished) { | 47 if (typeof content === 'undefined' && requests[i].finished) { |
| 48 ++this._pendingRequests; | 48 ++this._pendingRequests; |
| 49 requests[i].requestContent().then(this._onContentAvailable.bind(this, en
tries[i], requests[i])); | 49 requests[i].requestContent().then(this._onContentAvailable.bind(this, en
tries[i], requests[i])); |
| 50 } else if (content !== null) | 50 } else if (content !== null) |
| 51 this._setEntryContent(entries[i], requests[i]); | 51 this._setEntryContent(entries[i], requests[i]); |
| 52 } | 52 } |
| 53 var compositeProgress = new WebInspector.CompositeProgress(progress); | 53 var compositeProgress = new Common.CompositeProgress(progress); |
| 54 this._writeProgress = compositeProgress.createSubProgress(); | 54 this._writeProgress = compositeProgress.createSubProgress(); |
| 55 if (--this._pendingRequests) { | 55 if (--this._pendingRequests) { |
| 56 this._requestsProgress = compositeProgress.createSubProgress(); | 56 this._requestsProgress = compositeProgress.createSubProgress(); |
| 57 this._requestsProgress.setTitle(WebInspector.UIString('Collecting content…
')); | 57 this._requestsProgress.setTitle(Common.UIString('Collecting content…')); |
| 58 this._requestsProgress.setTotalWork(this._pendingRequests); | 58 this._requestsProgress.setTotalWork(this._pendingRequests); |
| 59 } else | 59 } else |
| 60 this._beginWrite(); | 60 this._beginWrite(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * @param {!Object} entry | 64 * @param {!Object} entry |
| 65 * @param {!WebInspector.NetworkRequest} request | 65 * @param {!SDK.NetworkRequest} request |
| 66 */ | 66 */ |
| 67 _setEntryContent(entry, request) { | 67 _setEntryContent(entry, request) { |
| 68 if (request.content !== null) | 68 if (request.content !== null) |
| 69 entry.response.content.text = request.content; | 69 entry.response.content.text = request.content; |
| 70 if (request.contentEncoded) | 70 if (request.contentEncoded) |
| 71 entry.response.content.encoding = 'base64'; | 71 entry.response.content.encoding = 'base64'; |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {!Object} entry | 75 * @param {!Object} entry |
| 76 * @param {!WebInspector.NetworkRequest} request | 76 * @param {!SDK.NetworkRequest} request |
| 77 * @param {?string} content | 77 * @param {?string} content |
| 78 */ | 78 */ |
| 79 _onContentAvailable(entry, request, content) { | 79 _onContentAvailable(entry, request, content) { |
| 80 this._setEntryContent(entry, request); | 80 this._setEntryContent(entry, request); |
| 81 if (this._requestsProgress) | 81 if (this._requestsProgress) |
| 82 this._requestsProgress.worked(); | 82 this._requestsProgress.worked(); |
| 83 if (!--this._pendingRequests) { | 83 if (!--this._pendingRequests) { |
| 84 this._requestsProgress.done(); | 84 this._requestsProgress.done(); |
| 85 this._beginWrite(); | 85 this._beginWrite(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 _beginWrite() { | 89 _beginWrite() { |
| 90 const jsonIndent = 2; | 90 const jsonIndent = 2; |
| 91 this._text = JSON.stringify({log: this._harLog}, null, jsonIndent); | 91 this._text = JSON.stringify({log: this._harLog}, null, jsonIndent); |
| 92 this._writeProgress.setTitle(WebInspector.UIString('Writing file…')); | 92 this._writeProgress.setTitle(Common.UIString('Writing file…')); |
| 93 this._writeProgress.setTotalWork(this._text.length); | 93 this._writeProgress.setTotalWork(this._text.length); |
| 94 this._bytesWritten = 0; | 94 this._bytesWritten = 0; |
| 95 this._writeNextChunk(this._stream); | 95 this._writeNextChunk(this._stream); |
| 96 } | 96 } |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * @param {!WebInspector.OutputStream} stream | 99 * @param {!Common.OutputStream} stream |
| 100 * @param {string=} error | 100 * @param {string=} error |
| 101 */ | 101 */ |
| 102 _writeNextChunk(stream, error) { | 102 _writeNextChunk(stream, error) { |
| 103 if (this._bytesWritten >= this._text.length || error) { | 103 if (this._bytesWritten >= this._text.length || error) { |
| 104 stream.close(); | 104 stream.close(); |
| 105 this._writeProgress.done(); | 105 this._writeProgress.done(); |
| 106 return; | 106 return; |
| 107 } | 107 } |
| 108 const chunkSize = 100000; | 108 const chunkSize = 100000; |
| 109 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chu
nkSize); | 109 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chu
nkSize); |
| 110 this._bytesWritten += text.length; | 110 this._bytesWritten += text.length; |
| 111 stream.write(text, this._writeNextChunk.bind(this)); | 111 stream.write(text, this._writeNextChunk.bind(this)); |
| 112 this._writeProgress.setWorked(this._bytesWritten); | 112 this._writeProgress.setWorked(this._bytesWritten); |
| 113 } | 113 } |
| 114 }; | 114 }; |
| OLD | NEW |