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

Unified Diff: chrome/renderer/translate_helper.cc

Issue 11052002: Get the document language directly from WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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
« no previous file with comments | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/translate_helper.cc
diff --git a/chrome/renderer/translate_helper.cc b/chrome/renderer/translate_helper.cc
index fcbc3c7bd5cee7a114f82532a5b62581e5b1f55a..259d274609ee3b1198cf8a1d4188a680f52ae727 100644
--- a/chrome/renderer/translate_helper.cc
+++ b/chrome/renderer/translate_helper.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/render_messages.h"
@@ -60,9 +61,17 @@ TranslateHelper::~TranslateHelper() {
void TranslateHelper::PageCaptured(const string16& contents) {
WebDocument document = render_view()->GetWebView()->mainFrame()->document();
- // If the page explicitly specifies a language, use it, otherwise we'll
+
// determine it based on the text content using the CLD.
MAD 2012/10/02 20:15:26 determine it???
- std::string language = GetPageLanguageFromMetaTag(&document);
+ std::string language = document.contentLanguage().utf8();
+ size_t coma_index = language.find(',');
+ if (coma_index != std::string::npos) {
+ // There are more than 1 language specified, just keep the first one.
+ language = language.substr(0, coma_index);
+ }
+ TrimWhitespaceASCII(language, TRIM_ALL, &language);
+ language = StringToLowerASCII(language);
+
if (language.empty()) {
base::TimeTicks begin_time = base::TimeTicks::Now();
language = DetermineTextLanguage(contents);
@@ -105,40 +114,6 @@ bool TranslateHelper::IsPageTranslatable(WebDocument* document) {
}
// static
-std::string TranslateHelper::GetPageLanguageFromMetaTag(WebDocument* document) {
- // The META language tag looks like:
- // <meta http-equiv="content-language" content="en">
- // It can contain more than one language:
- // <meta http-equiv="content-language" content="en, fr">
- std::vector<WebElement> meta_elements;
- webkit_glue::GetMetaElementsWithAttribute(document,
- ASCIIToUTF16("http-equiv"),
- ASCIIToUTF16("content-language"),
- &meta_elements);
- if (meta_elements.empty())
- return std::string();
-
- // We don't expect more than one such tag. If there are several, just use the
- // first one.
- WebString attribute = meta_elements[0].getAttribute("content");
- if (attribute.isEmpty())
- return std::string();
-
- // The value is supposed to be ASCII.
- if (!IsStringASCII(attribute))
- return std::string();
-
- std::string language = StringToLowerASCII(UTF16ToASCII(attribute));
- size_t coma_index = language.find(',');
- if (coma_index != std::string::npos) {
- // There are more than 1 language specified, just keep the first one.
- language = language.substr(0, coma_index);
- }
- TrimWhitespaceASCII(language, TRIM_ALL, &language);
- return language;
-}
-
-// static
std::string TranslateHelper::DetermineTextLanguage(const string16& text) {
std::string language = chrome::kUnknownLanguageCode;
int num_languages = 0;
« no previous file with comments | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698