summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 20:36:00 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-03 20:36:00 +0000
commit1b4c9f4539a4b62ac82dda83e097e25f83e87c50 (patch)
tree259cf68dfd3afae2ea86d6cbf2f08555a82c7a97
parent64909e688bc9ad982acc764f69b7e27e89caba7f (diff)
downloadchromium_src-1b4c9f4539a4b62ac82dda83e097e25f83e87c50.zip
chromium_src-1b4c9f4539a4b62ac82dda83e097e25f83e87c50.tar.gz
chromium_src-1b4c9f4539a4b62ac82dda83e097e25f83e87c50.tar.bz2
Don't show a translate infobar when the page is in a language
not supported by the translation server. BUG=34365 TEST=Visit http://www.breizh.net/brezhoneg/, no translation infobar should be shown. Review URL: http://codereview.chromium.org/568028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38010 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/translation_service.cc15
-rw-r--r--chrome/browser/renderer_host/translation_service.h8
-rw-r--r--chrome/browser/translate/translate_manager.cc3
3 files changed, 25 insertions, 1 deletions
diff --git a/chrome/browser/renderer_host/translation_service.cc b/chrome/browser/renderer_host/translation_service.cc
index 38f11c3..095802d 100644
--- a/chrome/browser/renderer_host/translation_service.cc
+++ b/chrome/browser/renderer_host/translation_service.cc
@@ -103,7 +103,6 @@ const char* kSupportedLanguages[] = {
"yi", // Yiddish
};
-
// The maximum size in bytes after which the server will refuse the request.
const size_t kTextRequestMaxSize = 1024 * 30;
@@ -134,6 +133,10 @@ class SendTranslationRequestTask : public CancelableTask {
} // namespace
+// static
+base::LazyInstance<std::set<std::string> >
+ TranslationService::supported_languages_(base::LINKER_INITIALIZED);
+
// Contains the information necessary to send a request to the translation
// server. It is used to group several renderer queries, as to limit the
// load sent to the translation server.
@@ -410,6 +413,16 @@ std::string TranslationService::GetLanguageCode(
return chrome_locale;
}
+// static
+bool TranslationService::IsSupportedLanguage(const std::string& page_language) {
+ if (supported_languages_.Pointer()->empty()) {
+ for (size_t i = 0; i < arraysize(kSupportedLanguages); ++i)
+ supported_languages_.Pointer()->insert(kSupportedLanguages[i]);
+ }
+ return supported_languages_.Pointer()->find(page_language) !=
+ supported_languages_.Pointer()->end();
+}
+
////////////////////////////////////////////////////////////////////////////////
// TranslationService, protected:
diff --git a/chrome/browser/renderer_host/translation_service.h b/chrome/browser/renderer_host/translation_service.h
index e77c7cb..dc84b24 100644
--- a/chrome/browser/renderer_host/translation_service.h
+++ b/chrome/browser/renderer_host/translation_service.h
@@ -6,9 +6,11 @@
#define CHROME_BROWSER_RENDERER_HOST_TRANSLATION_SERVICE_H_
#include <map>
+#include <set>
#include <string>
#include <vector>
+#include "base/lazy_instance.h"
#include "base/scoped_ptr.h"
#include "base/string16.h"
#include "chrome/browser/net/url_fetcher.h"
@@ -70,6 +72,9 @@ class TranslationService : public URLFetcher::Delegate {
// specified |chrome_locale|.
static std::string GetLanguageCode(const std::string& chrome_locale);
+ // Returns true if |page_language| is supported by the translation server.
+ static bool IsSupportedLanguage(const std::string& page_language);
+
protected:
// The amount of time in ms after which a pending request is sent if no other
// translation request has been received.
@@ -155,6 +160,9 @@ class TranslationService : public URLFetcher::Delegate {
TranslationRequestMap pending_translation_requests_;
TranslationRequestMap pending_secure_translation_requests_;
+ // The language supported by the translation server.
+ static base::LazyInstance<std::set<std::string> > supported_languages_;
+
DISALLOW_COPY_AND_ASSIGN(TranslationService);
};
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 6de7bf2..4022187 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -79,6 +79,9 @@ void TranslateManager::InitiateTranslation(TabContents* tab,
return;
}
+ if (!TranslationService::IsSupportedLanguage(page_lang))
+ return; // Nothing to do, we don't support that language.
+
std::string ui_lang = TranslationService::GetLanguageCode(
g_browser_process->GetApplicationLocale());