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

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

Issue 15881006: Added 'error logs' tab to chrome://translte-internals. (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 /** 10 /**
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 var key = 'language-' + langCode; 51 var key = 'language-' + langCode;
52 if (key in templateData) { 52 if (key in templateData) {
53 var langName = templateData[key]; 53 var langName = templateData[key];
54 return langCode + ' (' + langName + ')'; 54 return langCode + ' (' + langName + ')';
55 } 55 }
56 56
57 return langCode; 57 return langCode;
58 } 58 }
59 59
60 /** 60 /**
61 * Formats the error type to a human-readable text.
62 *
63 * @param {string} error Translation error type from the browser.
64 * @return {string} The formatted string.
65 */
66 function formatTranslateErrorsType(error) {
67 // This list is from chrome/common/translate_errors.h. If this header
68 // file is updated, the below list also should be updated.
69 var errorStrs = {
70 0: 'None',
71 1: 'Network',
72 2: 'Initialization Error',
73 3: 'Unknown Language',
74 4: 'Unsupported Language',
75 5: 'Identical Languages',
76 6: 'Translation Error',
77 };
78
79 if (error < 0 || errorStrs.length <= error) {
80 console.error('Invalid error code:', error);
81 return 'Invalid Error Code';
82 }
83 return errorStrs[error];
84 }
85
86 /**
61 * Handles the message of 'prefsUpdated' from the browser. 87 * Handles the message of 'prefsUpdated' from the browser.
62 * 88 *
63 * @param {Object} detail the object which represents pref values. 89 * @param {Object} detail the object which represents pref values.
64 */ 90 */
65 function onPrefsUpdated(detail) { 91 function onPrefsUpdated(detail) {
66 var ul; 92 var ul;
67 ul = document.querySelector('#prefs-language-blacklist ul'); 93 ul = document.querySelector('#prefs-language-blacklist ul');
68 ul.innerHTML = ''; 94 ul.innerHTML = '';
69 95
70 if ('translate_language_blacklist' in detail) { 96 if ('translate_language_blacklist' in detail) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 'detection-logs-language'), 227 'detection-logs-language'),
202 ].forEach(function(td) { 228 ].forEach(function(td) {
203 tr.appendChild(td); 229 tr.appendChild(td);
204 }); 230 });
205 231
206 var tbody = $('detection-logs').getElementsByTagName('tbody')[0]; 232 var tbody = $('detection-logs').getElementsByTagName('tbody')[0];
207 tbody.appendChild(tr); 233 tbody.appendChild(tr);
208 } 234 }
209 235
210 /** 236 /**
237 * Handles the message of 'translateErrorDetailsAdded' from the
238 * browser.
239 *
240 * @param {Object} details The object which represents the logs.
241 */
242 function onTranslateErrorDetailsAdded(details) {
243 var tr = document.createElement('tr');
244
245 var errorStr = details['error'] + ': ' +
246 formatTranslateErrorsType(details['error']);
247 [
248 createTD(formatDate(new Date(details['time'])),
249 'error-logs-time'),
250 createTD(details['url'], 'error-logs-url'),
251 createTD(errorStr, 'error-logs-error'),
252 ].forEach(function(td) {
253 tr.appendChild(td);
254 });
255
256 var tbody = $('error-logs').getElementsByTagName('tbody')[0];
257 tbody.appendChild(tr);
258 }
259
260 /**
211 * The callback entry point from the browser. This function will be 261 * The callback entry point from the browser. This function will be
212 * called by the browser. 262 * called by the browser.
213 * 263 *
214 * @param {string} message The name of the sent message. 264 * @param {string} message The name of the sent message.
215 * @param {Object} detail The argument of the sent message. 265 * @param {Object} detail The argument of the sent message.
216 */ 266 */
217 function messageHandler(message, detail) { 267 function messageHandler(message, detail) {
218 switch (message) { 268 switch (message) {
219 case 'languageDetectionInfoAdded': 269 case 'languageDetectionInfoAdded':
220 cr.translateInternals.onLanguageDetectionInfoAdded(detail); 270 cr.translateInternals.onLanguageDetectionInfoAdded(detail);
221 break; 271 break;
222 case 'prefsUpdated': 272 case 'prefsUpdated':
223 cr.translateInternals.onPrefsUpdated(detail); 273 cr.translateInternals.onPrefsUpdated(detail);
224 break; 274 break;
275 case 'translateErrorDetailsAdded':
276 cr.translateInternals.onTranslateErrorDetailsAdded(detail);
277 break;
225 default: 278 default:
226 console.error('Unknown message:', message); 279 console.error('Unknown message:', message);
227 break; 280 break;
228 } 281 }
229 } 282 }
230 283
231 return { 284 return {
232 initialize: initialize, 285 initialize: initialize,
233 messageHandler: messageHandler, 286 messageHandler: messageHandler,
234 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded, 287 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded,
235 onPrefsUpdated: onPrefsUpdated, 288 onPrefsUpdated: onPrefsUpdated,
289 onTranslateErrorDetailsAdded: onTranslateErrorDetailsAdded,
236 }; 290 };
237 }); 291 });
238 292
239 /** 293 /**
240 * The entry point of the UI. 294 * The entry point of the UI.
241 */ 295 */
242 function main() { 296 function main() {
243 cr.doc.addEventListener('DOMContentLoaded', 297 cr.doc.addEventListener('DOMContentLoaded',
244 cr.translateInternals.initialize); 298 cr.translateInternals.initialize);
245 } 299 }
246 300
247 main(); 301 main();
248 })(); 302 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698