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

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: Modified the comment Created 7 years, 7 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;
Evan Stade 2013/05/23 16:48:58 docs
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return td; 189 return td;
179 } 190 }
180 191
181 /** 192 /**
182 * Handles the message of 'languageDetectionInfoAdded' from the 193 * Handles the message of 'languageDetectionInfoAdded' from the
183 * browser. 194 * browser.
184 * 195 *
185 * @param {Object} detail The object which represents the logs. 196 * @param {Object} detail The object which represents the logs.
186 */ 197 */
187 function onLanguageDetectionInfoAdded(detail) { 198 function onLanguageDetectionInfoAdded(detail) {
199 cr.translateInternals.detectionLogs().push(detail);
200
188 var tr = document.createElement('tr'); 201 var tr = document.createElement('tr');
189 202
190 var date = new Date(detail['time']); 203 var date = new Date(detail['time']);
191 [ 204 [
192 createTD(formatDate(date), 'detection-logs-time'), 205 createTD(formatDate(date), 'detection-logs-time'),
193 createTD(detail['url'], 'detection-logs-url'), 206 createTD(detail['url'], 'detection-logs-url'),
194 createTD(formatLanguageCode(detail['content_language']), 207 createTD(formatLanguageCode(detail['content_language']),
195 'detection-logs-content-language'), 208 'detection-logs-content-language'),
196 createTD(formatLanguageCode(detail['cld_language']), 209 createTD(formatLanguageCode(detail['cld_language']),
197 'detection-logs-cld-language'), 210 'detection-logs-cld-language'),
198 createTD(detail['is_cld_reliable'], 211 createTD(detail['is_cld_reliable'],
199 'detection-logs-is-cld-reliable'), 212 'detection-logs-is-cld-reliable'),
200 createTD(formatLanguageCode(detail['language']), 213 createTD(formatLanguageCode(detail['language']),
201 'detection-logs-language'), 214 'detection-logs-language'),
215 createTD(formatLanguageCode(detail['content']),
216 'detection-logs-content'),
202 ].forEach(function(td) { 217 ].forEach(function(td) {
203 tr.appendChild(td); 218 tr.appendChild(td);
204 }); 219 });
205 220
221 // TD (and TR) can't use the CSS property 'max-height', so DIV
222 // in the content is needed.
223 var contentTD = tr.querySelector('.detection-logs-content');
224 var div = document.createElement('div');
225 div.textContent = contentTD.textContent;
226 contentTD.textContent = '';
227 contentTD.appendChild(div);
228
206 var tbody = $('detection-logs').getElementsByTagName('tbody')[0]; 229 var tbody = $('detection-logs').getElementsByTagName('tbody')[0];
207 tbody.appendChild(tr); 230 tbody.appendChild(tr);
208 } 231 }
209 232
210 /** 233 /**
211 * The callback entry point from the browser. This function will be 234 * The callback entry point from the browser. This function will be
212 * called by the browser. 235 * called by the browser.
213 * 236 *
214 * @param {string} message The name of the sent message. 237 * @param {string} message The name of the sent message.
215 * @param {Object} detail The argument of the sent message. 238 * @param {Object} detail The argument of the sent message.
216 */ 239 */
217 function messageHandler(message, detail) { 240 function messageHandler(message, detail) {
218 switch (message) { 241 switch (message) {
219 case 'languageDetectionInfoAdded': 242 case 'languageDetectionInfoAdded':
220 cr.translateInternals.onLanguageDetectionInfoAdded(detail); 243 cr.translateInternals.onLanguageDetectionInfoAdded(detail);
221 break; 244 break;
222 case 'prefsUpdated': 245 case 'prefsUpdated':
223 cr.translateInternals.onPrefsUpdated(detail); 246 cr.translateInternals.onPrefsUpdated(detail);
224 break; 247 break;
225 default: 248 default:
226 console.error('Unknown message:', message); 249 console.error('Unknown message:', message);
227 break; 250 break;
228 } 251 }
229 } 252 }
230 253
254 /**
255 * The callback of button#detetion-logs-dump.
256 */
257 function onDetectionLogsDump() {
258 var data = JSON.stringify(cr.translateInternals.detectionLogs());
259 var blob = new Blob([data], {'type': 'text/json'});
260 var url = webkitURL.createObjectURL(blob);
261 var filename = 'translate_internals_detect_logs_dump.json';
262
263 var a = document.createElement('a');
264 a.setAttribute('href', url);
265 a.setAttribute('download', filename);
266
267 var event = document.createEvent('MouseEvent');
268 event.initMouseEvent('click', true, true, window, 0,
269 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
270 a.dispatchEvent(event);
271 }
272
231 return { 273 return {
274 detectionLogs: detectionLogs,
232 initialize: initialize, 275 initialize: initialize,
233 messageHandler: messageHandler, 276 messageHandler: messageHandler,
234 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded, 277 onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded,
235 onPrefsUpdated: onPrefsUpdated, 278 onPrefsUpdated: onPrefsUpdated,
236 }; 279 };
237 }); 280 });
238 281
239 /** 282 /**
240 * The entry point of the UI. 283 * The entry point of the UI.
241 */ 284 */
242 function main() { 285 function main() {
243 cr.doc.addEventListener('DOMContentLoaded', 286 cr.doc.addEventListener('DOMContentLoaded',
244 cr.translateInternals.initialize); 287 cr.translateInternals.initialize);
245 } 288 }
246 289
247 main(); 290 main();
248 })(); 291 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698