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

Side by Side Diff: chrome/browser/resources/translate_internals/translate_internals.js

Issue 15728008: Add the 'content' column to see what text is used to detect a language (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: (Rebasing) Created 7 years, 6 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 unified diff | Download patch
OLDNEW
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 (function() { 5 (function() {
6 'use strict'; 6 'use strict';
7 7
8 cr.define('cr.translateInternals', function() { 8 cr.define('cr.translateInternals', function() {
9 9
10 var detectionLogs_ = null;
11
12 function detectionLogs() {
13 if (detectionLogs_ === null)
14 detectionLogs_ = [];
15 return detectionLogs_;
16 }
17
10 /** 18 /**
11 * Initializes UI and sends a message to the browser for 19 * Initializes UI and sends a message to the browser for
12 * initialization. 20 * initialization.
13 */ 21 */
14 function initialize() { 22 function initialize() {
15 cr.ui.decorate('tabbox', cr.ui.TabBox); 23 cr.ui.decorate('tabbox', cr.ui.TabBox);
16 chrome.send('requestInfo'); 24 chrome.send('requestInfo');
25
26 var button = $('detection-logs-dump');
27 button.addEventListener('click', onDetectionLogsDump);
17 } 28 }
18 29
19 /** 30 /**
20 * Creates a new LI element with a button to dismiss the item. 31 * Creates a new LI element with a button to dismiss the item.
21 * 32 *
22 * @param {string} text The lable of the LI element. 33 * @param {string} text The lable of the LI element.
23 * @param {Function} func Callback called when the button is clicked. 34 * @param {Function} func Callback called when the button is clicked.
24 */ 35 */
25 function createLIWithDismissingButton(text, func) { 36 function createLIWithDismissingButton(text, func) {
26 var span = document.createElement('span'); 37 var span = document.createElement('span');
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 return td; 215 return td;
205 } 216 }
206 217
207 /** 218 /**
208 * Handles the message of 'languageDetectionInfoAdded' from the 219 * Handles the message of 'languageDetectionInfoAdded' from the
209 * browser. 220 * browser.
210 * 221 *
211 * @param {Object} detail The object which represents the logs. 222 * @param {Object} detail The object which represents the logs.
212 */ 223 */
213 function onLanguageDetectionInfoAdded(detail) { 224 function onLanguageDetectionInfoAdded(detail) {
225 cr.translateInternals.detectionLogs().push(detail);
226
214 var tr = document.createElement('tr'); 227 var tr = document.createElement('tr');
215 228
216 var date = new Date(detail['time']); 229 var date = new Date(detail['time']);
217 [ 230 [
218 createTD(formatDate(date), 'detection-logs-time'), 231 createTD(formatDate(date), 'detection-logs-time'),
219 createTD(detail['url'], 'detection-logs-url'), 232 createTD(detail['url'], 'detection-logs-url'),
220 createTD(formatLanguageCode(detail['content_language']), 233 createTD(formatLanguageCode(detail['content_language']),
221 'detection-logs-content-language'), 234 'detection-logs-content-language'),
222 createTD(formatLanguageCode(detail['cld_language']), 235 createTD(formatLanguageCode(detail['cld_language']),
223 'detection-logs-cld-language'), 236 'detection-logs-cld-language'),
224 createTD(detail['is_cld_reliable'], 237 createTD(detail['is_cld_reliable'],
225 'detection-logs-is-cld-reliable'), 238 'detection-logs-is-cld-reliable'),
226 createTD(formatLanguageCode(detail['language']), 239 createTD(formatLanguageCode(detail['language']),
227 'detection-logs-language'), 240 'detection-logs-language'),
241 createTD(formatLanguageCode(detail['content']),
242 'detection-logs-content'),
228 ].forEach(function(td) { 243 ].forEach(function(td) {
229 tr.appendChild(td); 244 tr.appendChild(td);
230 }); 245 });
231 246
247 // TD (and TR) can't use the CSS property 'max-height', so DIV
248 // in the content is needed.
249 var contentTD = tr.querySelector('.detection-logs-content');
250 var div = document.createElement('div');
251 div.textContent = contentTD.textContent;
252 contentTD.textContent = '';
253 contentTD.appendChild(div);
254
232 var tbody = $('detection-logs').getElementsByTagName('tbody')[0]; 255 var tbody = $('detection-logs').getElementsByTagName('tbody')[0];
233 tbody.appendChild(tr); 256 tbody.appendChild(tr);
234 } 257 }
235 258
236 /** 259 /**
237 * Handles the message of 'translateErrorDetailsAdded' from the 260 * Handles the message of 'translateErrorDetailsAdded' from the
238 * browser. 261 * browser.
239 * 262 *
240 * @param {Object} details The object which represents the logs. 263 * @param {Object} details The object which represents the logs.
241 */ 264 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 break; 297 break;
275 case 'translateErrorDetailsAdded': 298 case 'translateErrorDetailsAdded':
276 cr.translateInternals.onTranslateErrorDetailsAdded(detail); 299 cr.translateInternals.onTranslateErrorDetailsAdded(detail);
277 break; 300 break;
278 default: 301 default:
279 console.error('Unknown message:', message); 302 console.error('Unknown message:', message);
280 break; 303 break;
281 } 304 }
282 } 305 }
283 306
307 /**
308 * The callback of button#detetion-logs-dump.
309 */
310 function onDetectionLogsDump() {
311 var data = JSON.stringify(cr.translateInternals.detectionLogs());
312 var blob = new Blob([data], {'type': 'text/json'});
313 var url = webkitURL.createObjectURL(blob);
314 var filename = 'translate_internals_detect_logs_dump.json';
315
316 var a = document.createElement('a');
317 a.setAttribute('href', url);
318 a.setAttribute('download', filename);
319
320 var event = document.createEvent('MouseEvent');
321 event.initMouseEvent('click', true, true, window, 0,
322 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
323 a.dispatchEvent(event);
324 }
325
284 return { 326 return {
327 detectionLogs: detectionLogs,
285 initialize: initialize, 328 initialize: initialize,
286 messageHandler: messageHandler, 329 messageHandler: messageHandler,
287 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded, 330 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded,
288 onPrefsUpdated: onPrefsUpdated, 331 onPrefsUpdated: onPrefsUpdated,
289 onTranslateErrorDetailsAdded: onTranslateErrorDetailsAdded, 332 onTranslateErrorDetailsAdded: onTranslateErrorDetailsAdded,
290 }; 333 };
291 }); 334 });
292 335
293 /** 336 /**
294 * The entry point of the UI. 337 * The entry point of the UI.
295 */ 338 */
296 function main() { 339 function main() {
297 cr.doc.addEventListener('DOMContentLoaded', 340 cr.doc.addEventListener('DOMContentLoaded',
298 cr.translateInternals.initialize); 341 cr.translateInternals.initialize);
299 } 342 }
300 343
301 main(); 344 main();
302 })(); 345 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698