OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Contents of lines that act as delimiters for multi-line values. | 5 // Contents of lines that act as delimiters for multi-line values. |
6 var DELIM_START = '---------- START ----------'; | 6 var DELIM_START = '---------- START ----------'; |
7 var DELIM_END = '---------- END ----------'; | 7 var DELIM_END = '---------- END ----------'; |
8 | 8 |
9 // Limit file size to 10 MiB to prevent hanging on accidental upload. | 9 // Limit file size to 10 MiB to prevent hanging on accidental upload. |
10 var MAX_FILE_SIZE = 10485760; | 10 var MAX_FILE_SIZE = 10485760; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 * Read in a log asynchronously, calling parseSystemLog if successful. | 100 * Read in a log asynchronously, calling parseSystemLog if successful. |
101 * @param {File} file The file to read. | 101 * @param {File} file The file to read. |
102 */ | 102 */ |
103 function importLog(file) { | 103 function importLog(file) { |
104 if (file && file.size <= MAX_FILE_SIZE) { | 104 if (file && file.size <= MAX_FILE_SIZE) { |
105 var reader = new FileReader(); | 105 var reader = new FileReader(); |
106 reader.onload = function() { | 106 reader.onload = function() { |
107 if (parseSystemLog(this.result)) { | 107 if (parseSystemLog(this.result)) { |
108 // Reset table title and status | 108 // Reset table title and status |
109 $('tableTitle').textContent = | 109 $('tableTitle').textContent = |
110 loadTimeData.getStringF('logFileTableTitle', file.name); | 110 loadTimeData.getStringF('logFileTableTitle', file.name); |
111 $('status').textContent = ''; | 111 $('status').textContent = ''; |
112 } else { | 112 } else { |
113 showError(file.name); | 113 showError(file.name); |
114 } | 114 } |
115 }; | 115 }; |
116 reader.readAsText(file); | 116 reader.readAsText(file); |
117 } else if (file) { | 117 } else if (file) { |
118 showError(file.name); | 118 showError(file.name); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 /** | 122 /** |
123 * Convert text-based log into list of name-value pairs. | 123 * Convert text-based log into list of name-value pairs. |
124 * @param {string} text The raw text of a log. | 124 * @param {string} text The raw text of a log. |
125 * @return {boolean} True if the log was parsed successfully. | 125 * @return {boolean} True if the log was parsed successfully. |
126 */ | 126 */ |
127 function parseSystemLog(text) { | 127 function parseSystemLog(text) { |
128 var details = []; | 128 var details = []; |
129 var lines = text.split('\n'); | 129 var lines = text.split('\n'); |
130 for (var i = 0, len = lines.length; i < len; i++) { | 130 for (var i = 0, len = lines.length; i < len; i++) { |
131 // Skip empty lines. | 131 // Skip empty lines. |
132 if (!lines[i]) | 132 if (!lines[i]) |
133 continue; | 133 continue; |
134 | 134 |
135 var delimiter = lines[i].indexOf('='); | 135 var delimiter = lines[i].indexOf('='); |
136 if (delimiter <= 0) { | 136 if (delimiter <= 0) { |
137 if (i == lines.length - 1) | 137 if (i == lines.length - 1) |
138 break; | 138 break; |
139 // If '=' is missing here, format is wrong. | 139 // If '=' is missing here, format is wrong. |
140 return false; | 140 return false; |
141 } | 141 } |
142 | 142 |
143 var name = lines[i].substring(0, delimiter); | 143 var name = lines[i].substring(0, delimiter); |
144 var value = ''; | 144 var value = ''; |
145 // Set value if non-empty | 145 // Set value if non-empty |
146 if (lines[i].length > delimiter + 1) | 146 if (lines[i].length > delimiter + 1) |
147 value = lines[i].substring(delimiter + 1); | 147 value = lines[i].substring(delimiter + 1); |
148 | 148 |
149 // Delimiters are based on kMultilineIndicatorString, kMultilineStartString, | 149 // Delimiters are based on kMultilineIndicatorString, kMultilineStartString, |
150 // and kMultilineEndString in components/feedback/feedback_data.cc. | 150 // and kMultilineEndString in components/feedback/feedback_data.cc. |
151 // If these change, we should check for both the old and new versions. | 151 // If these change, we should check for both the old and new versions. |
152 if (value == '<multiline>') { | 152 if (value == '<multiline>') { |
153 // Skip start delimiter. | 153 // Skip start delimiter. |
154 if (i == len - 1 || | 154 if (i == len - 1 || lines[++i].indexOf(DELIM_START) == -1) |
155 lines[++i].indexOf(DELIM_START) == -1) | |
156 return false; | 155 return false; |
157 | 156 |
158 ++i; | 157 ++i; |
159 value = ''; | 158 value = ''; |
160 // Append lines between start and end delimiters. | 159 // Append lines between start and end delimiters. |
161 while (i < len && lines[i] != DELIM_END) | 160 while (i < len && lines[i] != DELIM_END) |
162 value += lines[i++] + '\n'; | 161 value += lines[i++] + '\n'; |
163 | 162 |
164 // Remove trailing newline. | 163 // Remove trailing newline. |
165 if (value) | 164 if (value) |
(...skipping 14 matching lines...) Expand all Loading... |
180 | 179 |
181 $('collapseAll').onclick = collapseAll; | 180 $('collapseAll').onclick = collapseAll; |
182 $('expandAll').onclick = expandAll; | 181 $('expandAll').onclick = expandAll; |
183 | 182 |
184 var tp = $('t'); | 183 var tp = $('t'); |
185 tp.addEventListener('dragover', handleDragOver, false); | 184 tp.addEventListener('dragover', handleDragOver, false); |
186 tp.addEventListener('drop', handleDrop, false); | 185 tp.addEventListener('drop', handleDrop, false); |
187 | 186 |
188 collapseMultiLineStrings(); | 187 collapseMultiLineStrings(); |
189 }); | 188 }); |
OLD | NEW |