summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/net_internals
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-12 18:29:50 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-12 18:29:50 +0000
commit2c9be01dc74d1b0edff9c9288abcb66516083af0 (patch)
tree431bbfd66b0da88b1f1e487b5888746c361d63db /chrome/browser/resources/net_internals
parent893290ab807f68b3968d8437076901bf9bba4567 (diff)
downloadchromium_src-2c9be01dc74d1b0edff9c9288abcb66516083af0.zip
chromium_src-2c9be01dc74d1b0edff9c9288abcb66516083af0.tar.gz
chromium_src-2c9be01dc74d1b0edff9c9288abcb66516083af0.tar.bz2
Cleanup: extract common code between two functions.
Review URL: http://codereview.chromium.org/1992014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/net_internals')
-rw-r--r--chrome/browser/resources/net_internals/logviewpainter.js44
1 files changed, 16 insertions, 28 deletions
diff --git a/chrome/browser/resources/net_internals/logviewpainter.js b/chrome/browser/resources/net_internals/logviewpainter.js
index dd1e3d4..2f8d916 100644
--- a/chrome/browser/resources/net_internals/logviewpainter.js
+++ b/chrome/browser/resources/net_internals/logviewpainter.js
@@ -123,43 +123,31 @@ function getTextForExtraParams(entry) {
}
}
+/**
+ * Indent |lines| by |start|.
+ *
+ * For example, if |start| = ' -> ' and |lines| = ['line1', 'line2', 'line3']
+ * the output will be:
+ *
+ * " -> line1\n" +
+ * " line2\n" +
+ * " line3"
+ */
+function indentLines(start, lines) {
+ return start + lines.join('\n' + makeRepeatedString(' ', start.length));
+}
+
function getTextForRequestHeadersExtraParam(entry) {
var params = entry.extra_parameters;
- // We prepend spaces to each line to make it line up with the arrow.
- var firstLinePrefix = " --> "
- var prefix = " ";
-
- var out = [];
-
// Strip the trailing CRLF that params.line contains.
var lineWithoutCRLF = params.line.replace(/\r\n$/g, '');
- out.push(firstLinePrefix + lineWithoutCRLF);
- // Concatenate all of the header lines.
- for (var i = 0; i < params.headers.length; ++i)
- out.push(prefix + params.headers[i]);
-
- return out.join("\n");
+ return indentLines(' --> ', [lineWithoutCRLF].concat(params.headers));
}
function getTextForResponseHeadersExtraParam(entry) {
- var headers = entry.extra_parameters.headers;
-
- // We prepend spaces to each line to make it line up with the arrow.
- var firstLinePrefix = " --> "
- var prefix = " ";
-
- var out = [];
-
- if (headers.length > 0)
- out.push(firstLinePrefix + headers[0])
-
- // Concatenate all the rest of the header lines.
- for (var i = 1; i < headers.length; ++i)
- out.push(prefix + headers[i]);
-
- return out.join("\n");
+ return indentLines(' --> ', entry.extra_parameters.headers);
}
function getTextForEvent(entry) {