Implements the auto-translate on click: if you have translated
a page and are navigating to a new page in the same language by
clicking a link, the new page is automatically translated.
In order to do that I moved the language state from the navigation
entry to some dedicated class that each TabContents owns.
Also added some basic unit-testing for good measure.
BUG=35477
TEST=See bug steps. Run unit-tests.
Review URL: http://codereview.chromium.org/596092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38961 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 2f0dcd90..ed15084 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -269,7 +269,8 @@
is_showing_before_unload_dialog_(false),
renderer_preferences_(),
opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
- app_extension_(NULL) {
+ app_extension_(NULL),
+ language_state_(&controller_) {
ClearBlockedContentSettings();
renderer_preferences_util::UpdateFromSystemSettings(
&renderer_preferences_, profile);
@@ -811,6 +812,7 @@
NOTREACHED();
return;
}
+ language_state_.set_translation_pending(true);
render_view_host()->TranslatePage(entry->page_id(), source_lang, target_lang);
}
@@ -1503,6 +1505,9 @@
// cleaned up and covered by tests.
if (params.password_form.origin.is_valid())
GetPasswordManager()->ProvisionallySavePassword(params.password_form);
+
+ // Let the LanguageState clear its state.
+ language_state_.DidNavigate();
}
void TabContents::CloseConstrainedWindows() {
@@ -1860,11 +1865,7 @@
}
}
- NavigationEntry* entry = controller_.GetActiveEntry();
- if (GetRenderProcessHost()->id() == renderer_process_id &&
- entry && entry->page_id() == page_id) {
- entry->set_language(language);
- }
+ language_state_.LanguageDetermined(language);
std::string lang = language;
NotificationService::current()->Notify(
@@ -1876,6 +1877,8 @@
void TabContents::OnPageTranslated(int32 page_id,
const std::string& original_lang,
const std::string& translated_lang) {
+ language_state_.set_current_language(translated_lang);
+ language_state_.set_translation_pending(false);
std::pair<std::string, std::string> lang_pair =
std::make_pair(original_lang, translated_lang);
NotificationService::current()->Notify(