summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-13 20:10:58 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-13 20:10:58 +0000
commit80fc611572f3495e774811acd4d7925e06bf50ec (patch)
treec39805df0ce860b708d815d042c4d4d0530697c6 /chrome
parent9ed45b61504bf62f10ff5b3c0cc4d8f3ff8f8ba7 (diff)
downloadchromium_src-80fc611572f3495e774811acd4d7925e06bf50ec.zip
chromium_src-80fc611572f3495e774811acd4d7925e06bf50ec.tar.gz
chromium_src-80fc611572f3495e774811acd4d7925e06bf50ec.tar.bz2
Sites like Google Maps may trigger navigations when the user interacts with the page.
In such cases, we shouldn't show a new translate infobar offering to translate the page if the user already declined translation on that page. BUG=48215 TEST=See bug for URL and steps. Review URL: http://codereview.chromium.org/3183001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56072 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/tab_contents/language_state.cc9
-rw-r--r--chrome/browser/tab_contents/language_state.h5
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc4
-rw-r--r--chrome/browser/translate/translate_manager.cc7
-rw-r--r--chrome/browser/translate/translate_manager_unittest.cc29
5 files changed, 44 insertions, 10 deletions
diff --git a/chrome/browser/tab_contents/language_state.cc b/chrome/browser/tab_contents/language_state.cc
index 2808b2a..5f78876 100644
--- a/chrome/browser/tab_contents/language_state.cc
+++ b/chrome/browser/tab_contents/language_state.cc
@@ -18,11 +18,14 @@ LanguageState::LanguageState(NavigationController* nav_controller)
LanguageState::~LanguageState() {
}
-void LanguageState::DidNavigate(bool reload, bool in_page) {
- in_page_navigation_ = in_page;
- if (in_page)
+void LanguageState::DidNavigate(
+ const NavigationController::LoadCommittedDetails& details) {
+ in_page_navigation_ = details.is_in_page;
+ if (in_page_navigation_ || !details.is_main_frame)
return; // Don't reset our states, the page has not changed.
+ bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
+ details.type == NavigationType::SAME_PAGE;
if (reload) {
// We might not get a LanguageDetermined notifications on reloads. Make sure
// to keep the original language and to set current_lang_ so
diff --git a/chrome/browser/tab_contents/language_state.h b/chrome/browser/tab_contents/language_state.h
index 630727d..b3728a3 100644
--- a/chrome/browser/tab_contents/language_state.h
+++ b/chrome/browser/tab_contents/language_state.h
@@ -9,8 +9,7 @@
#include <string>
#include "base/basictypes.h"
-
-class NavigationController;
+#include "chrome/browser/tab_contents/navigation_controller.h"
// This class holds the language state of the current page.
// There is one LanguageState instance per TabContents.
@@ -28,7 +27,7 @@ class LanguageState {
// Should be called when the page did a new navigation (whether it is a main
// frame or sub-frame navigation).
- void DidNavigate(bool reload, bool in_page_navigation);
+ void DidNavigate(const NavigationController::LoadCommittedDetails& details);
// Should be called when the language of the page has been determined.
// |page_translatable| when false indicates that the browser should not offer
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 9ab1020..3b12242 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -1662,9 +1662,7 @@ void TabContents::DidNavigateAnyFramePostCommit(
GetPasswordManager()->ProvisionallySavePassword(params.password_form);
// Let the LanguageState clear its state.
- bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
- details.type == NavigationType::SAME_PAGE;
- language_state_.DidNavigate(reload, details.is_in_page);
+ language_state_.DidNavigate(details);
}
void TabContents::CloseConstrainedWindows() {
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 23bfc2f..64d029e 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -187,6 +187,13 @@ void TranslateManager::Observe(NotificationType type,
NOTREACHED();
return;
}
+ if (!load_details->is_main_frame &&
+ controller->tab_contents()->language_state().translation_declined()) {
+ // Some sites (such as Google map) may trigger sub-frame navigations
+ // when the user interacts with the page. We don't want to show a new
+ // infobar if the user already dismissed one in that case.
+ return;
+ }
if (entry->transition_type() != PageTransition::RELOAD &&
load_details->type != NavigationType::SAME_PAGE) {
return;
diff --git a/chrome/browser/translate/translate_manager_unittest.cc b/chrome/browser/translate/translate_manager_unittest.cc
index 302aae01..08a2994 100644
--- a/chrome/browser/translate/translate_manager_unittest.cc
+++ b/chrome/browser/translate/translate_manager_unittest.cc
@@ -618,7 +618,7 @@ TEST_F(TranslateManagerTest, ReloadFromLocationBar) {
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
-// Tests that a close translate infobar does not reappear when navigating
+// Tests that a closed translate infobar does not reappear when navigating
// in-page.
TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) {
// Simulate navigating to a page and getting its language.
@@ -638,6 +638,33 @@ TEST_F(TranslateManagerTest, CloseInfoBarInPageNavigation) {
EXPECT_TRUE(GetTranslateInfoBar() != NULL);
}
+// Tests that a closed translate infobar does not reappear when navigating
+// in a subframe. (http://crbug.com/48215)
+TEST_F(TranslateManagerTest, CloseInfoBarInSubframeNavigation) {
+ // Simulate navigating to a page and getting its language.
+ SimulateNavigation(GURL("http://www.google.fr"), 0, "Le Google", "fr", true);
+
+ // Close the infobar.
+ EXPECT_TRUE(CloseTranslateInfoBar());
+
+ // Simulate a sub-frame auto-navigating.
+ rvh()->SendNavigateWithTransition(1, GURL("http://pub.com"),
+ PageTransition::AUTO_SUBFRAME);
+ EXPECT_TRUE(GetTranslateInfoBar() == NULL);
+
+ // Simulate the user navigating in a sub-frame.
+ rvh()->SendNavigateWithTransition(2, GURL("http://pub.com"),
+ PageTransition::MANUAL_SUBFRAME);
+ EXPECT_TRUE(GetTranslateInfoBar() == NULL);
+
+ // Navigate out of page, a new infobar should show.
+ SimulateNavigation(GURL("http://www.google.fr/foot"), 3, "Le Google", "fr",
+ true);
+ EXPECT_TRUE(GetTranslateInfoBar() != NULL);
+}
+
+
+
// Tests that denying translation is sticky when navigating in page.
TEST_F(TranslateManagerTest, DenyTranslateInPageNavigation) {
// Simulate navigating to a page and getting its language.