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

Unified Diff: trunk/src/chrome/renderer/translate/translate_helper.cc

Issue 16045007: Revert 202427 "Translate: adopt html lang attribute if valid val..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/renderer/translate/translate_helper.cc
===================================================================
--- trunk/src/chrome/renderer/translate/translate_helper.cc (revision 202442)
+++ trunk/src/chrome/renderer/translate/translate_helper.cc (working copy)
@@ -93,24 +93,18 @@
// language of the intended audience (a distinction really only
// relevant for things like langauge textbooks). This distinction
// shouldn't affect translation.
- WebFrame* main_frame = GetMainFrame();
- if (!main_frame)
- return;
- WebDocument document = main_frame->document();
+ WebDocument document = GetMainFrame()->document();
std::string content_language = document.contentLanguage().utf8();
- std::string html_lang =
- document.documentElement().getAttribute("lang").utf8();
std::string cld_language;
bool is_cld_reliable;
std::string language = DeterminePageLanguage(
- content_language, html_lang, contents, &cld_language, &is_cld_reliable);
+ content_language, contents, &cld_language, &is_cld_reliable);
if (language.empty())
return;
language_determined_time_ = base::TimeTicks::Now();
- // TODO(toyoshim): Add |html_lang| to LanguageDetectionDetails.
GURL url(document.url());
LanguageDetectionDetails details;
details.time = base::Time::Now();
@@ -325,20 +319,7 @@
}
// static
-void TranslateHelper::ApplyLanguageCodeCorrection(std::string* code) {
- // Correct well-known format errors.
- CorrectLanguageCodeTypo(code);
-
- // Convert language code synonym firstly because sometime synonym code is in
- // invalid format, e.g. 'fil'. After validation, such a 3 characters language
- // gets converted to an empty string.
- ConvertLanguageCodeSynonym(code);
- ResetInvalidLanguageCode(code);
-}
-
-// static
std::string TranslateHelper::DeterminePageLanguage(const std::string& code,
- const std::string& html_lang,
const string16& contents,
std::string* cld_language_p,
bool* is_cld_reliable_p) {
@@ -356,27 +337,17 @@
ConvertLanguageCodeSynonym(&cld_language);
#endif // defined(ENABLE_LANGUAGE_DETECTION)
- // Check if html lang attribute is valid.
- std::string modified_html_lang;
- if (!html_lang.empty()) {
- modified_html_lang = html_lang;
- ApplyLanguageCodeCorrection(&modified_html_lang);
- TranslateHelperMetrics::ReportHtmlLang(html_lang, modified_html_lang);
- VLOG(9) << "html lang based language code: " << modified_html_lang;
- }
+ // Correct well-known format errors.
+ std::string language = code;
+ CorrectLanguageCodeTypo(&language);
- // Check if Content-Language is valid.
- std::string modified_code;
- if (!code.empty()) {
- modified_code = code;
- ApplyLanguageCodeCorrection(&modified_code);
- TranslateHelperMetrics::ReportContentLanguage(code, modified_code);
- }
+ // Convert language code synonym firstly because sometime synonym code is in
+ // invalid format, e.g. 'fil'. After validation, such a 3 characters language
+ // gets converted to an empty string.
+ ConvertLanguageCodeSynonym(&language);
+ ResetInvalidLanguageCode(&language);
- // Adopt |modified_html_lang| if it is valid. Otherwise, adopt
- // |modified_code|.
- std::string language = modified_html_lang.empty() ? modified_code :
- modified_html_lang;
+ TranslateHelperMetrics::ReportContentLanguage(code, language);
#if defined(ENABLE_LANGUAGE_DETECTION)
// If |language| is empty, just use CLD result even though it might be
@@ -462,8 +433,7 @@
const std::string& translate_script,
const std::string& source_lang,
const std::string& target_lang) {
- WebFrame* main_frame = GetMainFrame();
- if (!main_frame || render_view()->GetPageId() != page_id)
+ if (render_view()->GetPageId() != page_id)
return; // We navigated away, nothing to do.
if (translation_pending_ && page_id == page_id_ &&
@@ -487,7 +457,7 @@
TranslateHelperMetrics::ReportUserActionDuration(language_determined_time_,
base::TimeTicks::Now());
- GURL url(main_frame->document().url());
+ GURL url(GetMainFrame()->document().url());
TranslateHelperMetrics::ReportPageScheme(url.scheme());
if (!IsTranslateLibAvailable()) {
@@ -620,10 +590,12 @@
WebFrame* TranslateHelper::GetMainFrame() {
WebView* web_view = render_view()->GetWebView();
-
- // When the tab is going to be closed, the web_view can be NULL.
- if (!web_view)
+ if (!web_view) {
+ // When the WebView is going away, the render view should have called
+ // CancelPendingTranslation() which should have stopped any pending work, so
+ // that case should not happen.
+ NOTREACHED();
return NULL;
-
+ }
return web_view->mainFrame();
}
« no previous file with comments | « trunk/src/chrome/renderer/translate/translate_helper.h ('k') | trunk/src/chrome/renderer/translate/translate_helper_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698