summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd2
-rw-r--r--chrome/browser/browser.cc1
-rw-r--r--chrome/browser/translate/translate_manager.cc3
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc30
-rw-r--r--chrome/browser/views/options/advanced_contents_view.cc73
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
7 files changed, 109 insertions, 4 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index c3567ca..081b78a 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -5808,7 +5808,7 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_OPTIONS_ADVANCED_SECTION_TITLE_NETWORK">
Network
</message>
- <message name="IDS_OPTIONS_ADVANCED_SECTION_TRANSLATE">
+ <message name="IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE">
Translate
</message>
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 93ebc68..7246061 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1431,6 +1431,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kWebAppCreateInAppsMenu, true);
prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true);
prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, true);
+ prefs->RegisterBooleanPref(prefs::kEnableTranslate, true);
}
// static
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index d1ee940..8c90bdf 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -134,6 +134,9 @@ TranslateManager::TranslateManager()
void TranslateManager::InitiateTranslation(TabContents* tab,
const std::string& page_lang) {
PrefService* prefs = tab->profile()->GetPrefs();
+ if (!prefs->GetBoolean(prefs::kEnableTranslate))
+ return;
+
NavigationEntry* entry = tab->controller().GetActiveEntry();
if (!entry) {
NOTREACHED();
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 5480fb4..eb63416 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -10,6 +10,7 @@
#include "chrome/common/ipc_test_sink.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
class TestTranslateManager : public TranslateManager {
@@ -360,3 +361,32 @@ TEST_F(TranslateManagerTest, TranslateInPageNavigation) {
// And there is a new one.
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
+
+// Tests that the translate preference is honored.
+TEST_F(TranslateManagerTest, TranslatePref) {
+ // Make sure the pref allows translate.
+ PrefService* prefs = contents()->profile()->GetPrefs();
+ prefs->SetBoolean(prefs::kEnableTranslate, true);
+
+ // Simulate navigating to a page and gettings its language.
+ SimulateNavigation(GURL("http://www.google.fr"), 0, L"Le Google", "fr");
+
+ // An infobar should be shown.
+ TranslateInfoBarDelegate* infobar = GetTranslateInfoBar();
+ EXPECT_TRUE(infobar != NULL);
+
+ // Disable translate.
+ prefs->SetBoolean(prefs::kEnableTranslate, false);
+
+ // Navigate to a new page, that should close the previous infobar.
+ GURL url("http://www.youtube.fr");
+ NavigateAndCommit(url);
+ infobar = GetTranslateInfoBar();
+ EXPECT_TRUE(infobar == NULL);
+
+ // Simulate getting the page contents and language, that should not trigger
+ // a translate infobar.
+ SimulateOnPageContents(url, 1, L"Le YouTube", "fr");
+ infobar = GetTranslateInfoBar();
+ EXPECT_TRUE(infobar == NULL);
+}
diff --git a/chrome/browser/views/options/advanced_contents_view.cc b/chrome/browser/views/options/advanced_contents_view.cc
index 61f93ab..756396e 100644
--- a/chrome/browser/views/options/advanced_contents_view.cc
+++ b/chrome/browser/views/options/advanced_contents_view.cc
@@ -243,9 +243,9 @@ class AdvancedSection : public OptionsPageView {
// Convenience helpers for adding controls to specific layouts in an
// aesthetically pleasing way.
void AddWrappingCheckboxRow(views::GridLayout* layout,
- views::Checkbox* checkbox,
- int id,
- bool related_follows);
+ views::Checkbox* checkbox,
+ int id,
+ bool related_follows);
void AddWrappingLabelRow(views::GridLayout* layout,
views::Label* label,
int id,
@@ -1228,6 +1228,71 @@ void DownloadSection::UpdateDownloadDirectoryDisplay() {
}
////////////////////////////////////////////////////////////////////////////////
+// TranslateSection
+
+class TranslateSection : public AdvancedSection,
+ public views::ButtonListener {
+ public:
+ explicit TranslateSection(Profile* profile);
+ virtual ~TranslateSection() {}
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
+ protected:
+ // OptionsPageView overrides:
+ virtual void InitControlLayout();
+ virtual void NotifyPrefChanged(const std::wstring* pref_name);
+
+ private:
+ // Control for this section:
+ views::Checkbox* enable_translate_checkbox_;
+
+ // Preferences for this section:
+ BooleanPrefMember enable_translate_;
+
+ DISALLOW_COPY_AND_ASSIGN(TranslateSection );
+};
+
+TranslateSection::TranslateSection(Profile* profile)
+ : enable_translate_checkbox_(NULL),
+ AdvancedSection(profile,
+ l10n_util::GetString(IDS_OPTIONS_ADVANCED_SECTION_TITLE_TRANSLATE)) {
+}
+
+void TranslateSection::ButtonPressed(
+ views::Button* sender, const views::Event& event) {
+ DCHECK(sender == enable_translate_checkbox_);
+ bool enabled = enable_translate_checkbox_->checked();
+ UserMetricsRecordAction(enabled ? "Options_Translate_Enable" :
+ "Options_Translate_Disable",
+ profile()->GetPrefs());
+ enable_translate_.SetValue(enabled);
+}
+
+void TranslateSection::InitControlLayout() {
+ AdvancedSection::InitControlLayout();
+
+ GridLayout* layout = new GridLayout(contents_);
+ contents_->SetLayoutManager(layout);
+
+ AddIndentedColumnSet(layout, 0);
+
+ enable_translate_checkbox_ = new views::Checkbox(
+ l10n_util::GetString(IDS_OPTIONS_TRANSLATE_ENABLE_TRANSLATE));
+ enable_translate_checkbox_->set_listener(this);
+ AddWrappingCheckboxRow(layout, enable_translate_checkbox_, 0, false);
+
+ // Init member pref so we can update the controls if prefs change.
+ enable_translate_.Init(prefs::kEnableTranslate, profile()->GetPrefs(), this);
+}
+
+void TranslateSection::NotifyPrefChanged(const std::wstring* pref_name) {
+ if (!pref_name || *pref_name == prefs::kEnableTranslate)
+ enable_translate_checkbox_->SetChecked(enable_translate_.GetValue());
+}
+
+////////////////////////////////////////////////////////////////////////////////
// AdvancedContentsView
class AdvancedContentsView : public OptionsPageView {
@@ -1317,6 +1382,8 @@ void AdvancedContentsView::InitControlLayout() {
layout->StartRow(0, single_column_view_set_id);
layout->AddView(new NetworkSection(profile()));
layout->StartRow(0, single_column_view_set_id);
+ layout->AddView(new TranslateSection(profile()));
+ layout->StartRow(0, single_column_view_set_id);
layout->AddView(new DownloadSection(profile()));
layout->StartRow(0, single_column_view_set_id);
layout->AddView(new WebContentSection(profile()));
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 7d70df9..7c9ca69 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -337,6 +337,9 @@ const wchar_t kPrivacyFilterRules[] = L"profile.privacy_filter_rules";
// side of the browser window.
const wchar_t kUseVerticalTabs[] = L"tabs.use_vertical_tabs";
+// Boolean that is true when the translate feature is enabled.
+const wchar_t kEnableTranslate[] = L"translate.enabled";
+
// *************** LOCAL STATE ***************
// These are attached to the machine/installation
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index bcefd48..5659995 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -129,6 +129,7 @@ extern const wchar_t kAutoFillEnabled[];
extern const wchar_t kAutoFillDialogPlacement[];
extern const wchar_t kPrivacyFilterRules[];
extern const wchar_t kUseVerticalTabs[];
+extern const wchar_t kEnableTranslate[];
// Local state
extern const wchar_t kMetricsClientID[];