Add the 'content' column to chrome://translate-internals/

This column allows us to see what text is used to detect a language.  The text is generated from the web page seen by the user, and doesn't include HTML tags.  The text is sent from the renderer process to the browser process each time when detecting.

This feature will help us to solve the problems, for example, the problem where the translation infobar indicates the web page language we don't expect.

For now, with this CL, the text is always sent even though the translate-internals tab page doesn't exist.

BUG=175967

Review URL: https://chromiumcodereview.appspot.com/15728008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203093 0039d316-1c4b-4281-b951-d872f2087c98
parent 8cadffe6
......@@ -4,7 +4,7 @@ Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<div>
<h2>Detection Logs</h2>
<h2>Detection Logs <button id="detection-logs-dump">Dump</button></h2>
<table>
<thead>
<tr>
......@@ -20,6 +20,7 @@ found in the LICENSE file.
Is CLD reliable?
</th>
<th class="detection-logs-language">Adopted language</th>
<th class="detection-logs-content">Content</th>
</tr>
</thead>
<tbody></tbody>
......
......@@ -38,7 +38,6 @@ tabpanel > div > div {
.dump {
font-family: monospace;
text-wrap: unrestricted;
white-space: pre-wrap;
}
......@@ -62,11 +61,11 @@ tabpanel > div > div {
}
.detection-logs-time {
width: 20%;
width: 15%;
}
.detection-logs-url {
width: 40%;
width: 20%;
}
td.detection-logs-url {
......@@ -89,6 +88,18 @@ td.detection-logs-url {
width: 10%;
}
.detection-logs-content {
width: 25%;
}
td.detection-logs-content div {
font-family: monospace;
max-height: 250px;
overflow: auto;
white-space: pre-wrap;
word-wrap: break-word;
}
.error-logs-time {
width: 20%;
}
......
......@@ -7,6 +7,14 @@
cr.define('cr.translateInternals', function() {
var detectionLogs_ = null;
function detectionLogs() {
if (detectionLogs_ === null)
detectionLogs_ = [];
return detectionLogs_;
}
/**
* Initializes UI and sends a message to the browser for
* initialization.
......@@ -14,6 +22,9 @@
function initialize() {
cr.ui.decorate('tabbox', cr.ui.TabBox);
chrome.send('requestInfo');
var button = $('detection-logs-dump');
button.addEventListener('click', onDetectionLogsDump);
}
/**
......@@ -211,6 +222,8 @@
* @param {Object} detail The object which represents the logs.
*/
function onLanguageDetectionInfoAdded(detail) {
cr.translateInternals.detectionLogs().push(detail);
var tr = document.createElement('tr');
var date = new Date(detail['time']);
......@@ -225,10 +238,20 @@
'detection-logs-is-cld-reliable'),
createTD(formatLanguageCode(detail['language']),
'detection-logs-language'),
createTD(formatLanguageCode(detail['content']),
'detection-logs-content'),
].forEach(function(td) {
tr.appendChild(td);
});
// TD (and TR) can't use the CSS property 'max-height', so DIV
// in the content is needed.
var contentTD = tr.querySelector('.detection-logs-content');
var div = document.createElement('div');
div.textContent = contentTD.textContent;
contentTD.textContent = '';
contentTD.appendChild(div);
var tbody = $('detection-logs').getElementsByTagName('tbody')[0];
tbody.appendChild(tr);
}
......@@ -281,7 +304,27 @@
}
}
/**
* The callback of button#detetion-logs-dump.
*/
function onDetectionLogsDump() {
var data = JSON.stringify(cr.translateInternals.detectionLogs());
var blob = new Blob([data], {'type': 'text/json'});
var url = webkitURL.createObjectURL(blob);
var filename = 'translate_internals_detect_logs_dump.json';
var a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('download', filename);
var event = document.createEvent('MouseEvent');
event.initMouseEvent('click', true, true, window, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, null);
a.dispatchEvent(event);
}
return {
detectionLogs: detectionLogs,
initialize: initialize,
messageHandler: messageHandler,
onLanguageDetectionInfoAdded: onLanguageDetectionInfoAdded,
......
......@@ -48,6 +48,7 @@ void TranslateInternalsHandler::OnLanguageDetection(
dict.Set("is_cld_reliable",
new base::FundamentalValue(details.is_cld_reliable));
dict.Set("language", new base::StringValue(details.adopted_language));
dict.Set("content", new base::StringValue(details.contents));
SendMessageToJs("languageDetectionInfoAdded", dict);
}
......
......@@ -7,6 +7,7 @@
#include <string>
#include "base/string16.h"
#include "base/time.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message_macros.h"
......@@ -32,6 +33,9 @@ struct LanguageDetectionDetails {
// The adopted language
std::string adopted_language;
// The contents which is used for detection
string16 contents;
};
#endif // CHROME_COMMON_LANGUAGE_DETECTION_DETAILS_H_
......@@ -252,6 +252,7 @@ IPC_STRUCT_TRAITS_BEGIN(LanguageDetectionDetails)
IPC_STRUCT_TRAITS_MEMBER(cld_language)
IPC_STRUCT_TRAITS_MEMBER(is_cld_reliable)
IPC_STRUCT_TRAITS_MEMBER(adopted_language)
IPC_STRUCT_TRAITS_MEMBER(contents)
IPC_STRUCT_TRAITS_END()
//-----------------------------------------------------------------------------
......
......@@ -124,6 +124,10 @@ void TranslateHelper::PageCaptured(const string16& contents) {
details.is_cld_reliable = is_cld_reliable;
details.adopted_language = language;
// TODO(hajimehoshi): If this affects performance, it should be set only if
// translate-internals tab exists.
details.contents = contents;
Send(new ChromeViewHostMsg_TranslateLanguageDetermined(
routing_id(),
details,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment