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

Unified Diff: Source/devtools/front_end/network/NetworkPanel.js

Issue 667623002: DevTools: make extension server a part of core, panels' code should depend on it. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: for review Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: Source/devtools/front_end/network/NetworkPanel.js
diff --git a/Source/devtools/front_end/network/NetworkPanel.js b/Source/devtools/front_end/network/NetworkPanel.js
index e8f3d6df911f9e1a2e261c0c262fe9434291a433..a785a757b3cbcf5c033bc885fb79b0e1cbf4e01a 100644
--- a/Source/devtools/front_end/network/NetworkPanel.js
+++ b/Source/devtools/front_end/network/NetworkPanel.js
@@ -3195,3 +3195,85 @@ WebInspector.NetworkPanelFactory.prototype = {
return WebInspector.NetworkPanel._instance();
}
}
+
+/**
+ * @constructor
+ */
+WebInspector.HARWriter = function()
+{
+}
+
+WebInspector.HARWriter.prototype = {
+ /**
+ * @param {!WebInspector.OutputStream} stream
+ * @param {!Array.<!WebInspector.NetworkRequest>} requests
+ * @param {!WebInspector.Progress} progress
+ */
+ write: function(stream, requests, progress)
+ {
+ this._stream = stream;
+ this._harLog = (new WebInspector.HARLog(requests)).build();
+ this._pendingRequests = 1; // Guard against completing resource transfer before all requests are made.
+ var entries = this._harLog.entries;
+ for (var i = 0; i < entries.length; ++i) {
+ var content = requests[i].content;
+ if (typeof content === "undefined" && requests[i].finished) {
+ ++this._pendingRequests;
+ requests[i].requestContent(this._onContentAvailable.bind(this, entries[i]));
+ } else if (content !== null)
+ entries[i].response.content.text = content;
+ }
+ var compositeProgress = new WebInspector.CompositeProgress(progress);
+ this._writeProgress = compositeProgress.createSubProgress();
+ if (--this._pendingRequests) {
+ this._requestsProgress = compositeProgress.createSubProgress();
+ this._requestsProgress.setTitle(WebInspector.UIString("Collecting content…"));
+ this._requestsProgress.setTotalWork(this._pendingRequests);
+ } else
+ this._beginWrite();
+ },
+
+ /**
+ * @param {!Object} entry
+ * @param {?string} content
+ */
+ _onContentAvailable: function(entry, content)
+ {
+ if (content !== null)
+ entry.response.content.text = content;
+ if (this._requestsProgress)
+ this._requestsProgress.worked();
+ if (!--this._pendingRequests) {
+ this._requestsProgress.done();
+ this._beginWrite();
+ }
+ },
+
+ _beginWrite: function()
+ {
+ const jsonIndent = 2;
+ this._text = JSON.stringify({log: this._harLog}, null, jsonIndent);
+ this._writeProgress.setTitle(WebInspector.UIString("Writing file…"));
+ this._writeProgress.setTotalWork(this._text.length);
+ this._bytesWritten = 0;
+ this._writeNextChunk(this._stream);
+ },
+
+ /**
+ * @param {!WebInspector.OutputStream} stream
+ * @param {string=} error
+ */
+ _writeNextChunk: function(stream, error)
+ {
+ if (this._bytesWritten >= this._text.length || error) {
+ stream.close();
+ this._writeProgress.done();
+ return;
+ }
+ const chunkSize = 100000;
+ var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize);
+ this._bytesWritten += text.length;
+ stream.write(text, this._writeNextChunk.bind(this));
+ this._writeProgress.setWorked(this._bytesWritten);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698