summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-30 16:59:03 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-30 16:59:03 +0000
commit7838c2502799cbfe33ba16575b0e7d0b03740dd1 (patch)
tree17e926b6917b11264605ca01c7c9c1bfb3125d55
parent5179b0eb8c7f0399157d747f8bce1838cdeb89d7 (diff)
downloadchromium_src-7838c2502799cbfe33ba16575b0e7d0b03740dd1.zip
chromium_src-7838c2502799cbfe33ba16575b0e7d0b03740dd1.tar.gz
chromium_src-7838c2502799cbfe33ba16575b0e7d0b03740dd1.tar.bz2
Revert 51263 (breaks the Linux views build)
Adds support for language detection on the server side. The CLD can sometimes fail to detect the language of a page, in which case the translate server might be able to. This CL ensures the browser deals with the server side language detection properly. Also added a new factory method to create error translate infobar delegates that does not assert when the language code is incorrect. Also changed the enums in TranslateInfoBarDelegate2 to use the constant name style, as it is the preferred naming for enums according to the style guide. Original review: http://codereview.chromium.org/2859013/show BUG=40857 TEST=Visit http://www.saanconf.org/saanday.htm, use the context menu to translate the page. You should get an error mentioning the page is already in English. Review URL: http://codereview.chromium.org/2860037 TBR=jcivelli@chromium.org Review URL: http://codereview.chromium.org/2873035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51265 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_base.mm14
-rw-r--r--chrome/browser/cocoa/translate/translate_infobar_unittest.mm14
-rw-r--r--chrome/browser/cocoa/translate/translate_message_infobar_controller.mm6
-rw-r--r--chrome/browser/gtk/translate/translate_infobar_base_gtk.cc14
-rw-r--r--chrome/browser/translate/translate_infobar_delegate2.cc65
-rw-r--r--chrome/browser/translate/translate_infobar_delegate2.h29
-rw-r--r--chrome/browser/translate/translate_manager2.cc31
-rw-r--r--chrome/browser/translate/translate_manager2_unittest.cc76
-rw-r--r--chrome/browser/views/infobars/translate_infobar_base.cc14
-rw-r--r--chrome/common/translate_errors.h6
-rw-r--r--chrome/renderer/translate_helper.cc5
12 files changed, 88 insertions, 192 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index a1854d7..483426a 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -7042,12 +7042,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE" desc="Error message to show for translate infobar when translate server is unable to translate page">
The translation failed because of a server error.
</message>
- <message name="IDS_TRANSLATE_INFOBAR_UNKNOWN_PAGE_LANGUAGE" desc="Error message to show for translate infobar when the page language could not be determined.">
- The translation failed because the page's language could not be determined.
- </message>
- <message name="IDS_TRANSLATE_INFOBAR_ERROR_SAME_LANGUAGE" desc="Error message to show for translate infobar when the original and target languages are identical">
- The translation failed because the page is already in <ph name="language">$1<ex>English</ex></ph>.
- </message>
<!-- Desktop notifications -->
<message name="IDS_NOTIFICATION_BALLOON_DISMISS_LABEL" desc="Text on the button which dismisses the balloon.">
diff --git a/chrome/browser/cocoa/translate/translate_infobar_base.mm b/chrome/browser/cocoa/translate/translate_infobar_base.mm
index 7daf09a..f93a733 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_base.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_base.mm
@@ -114,16 +114,16 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() {
TranslateInfoBarControllerBase* infobar_controller = NULL;
switch (type_) {
- case kBeforeTranslate:
+ case BEFORE_TRANSLATE:
infobar_controller =
[[BeforeTranslateInfobarController alloc] initWithDelegate:this];
break;
- case kAfterTranslate:
+ case AFTER_TRANSLATE:
infobar_controller =
[[AfterTranslateInfobarController alloc] initWithDelegate:this];
break;
- case kTranslating:
- case kTranslationError:
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
infobar_controller =
[[TranslateMessageInfobarController alloc] initWithDelegate:this];
break;
@@ -456,8 +456,8 @@ InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() {
- (IBAction)ok:(id)sender {
TranslateInfoBarDelegate2* delegate = [self delegate];
TranslateInfoBarDelegate2::Type state = delegate->type();
- DCHECK(state == TranslateInfoBarDelegate2::kBeforeTranslate ||
- state == TranslateInfoBarDelegate2::kTranslationError);
+ DCHECK(state == TranslateInfoBarDelegate2::BEFORE_TRANSLATE ||
+ state == TranslateInfoBarDelegate2::TRANSLATION_ERROR);
delegate->Translate();
UMA_HISTOGRAM_COUNTS("Translate.Translate", 1);
}
@@ -465,7 +465,7 @@ InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() {
// Called when someone clicks on the "Nope" button.
- (IBAction)cancel:(id)sender {
DCHECK(
- [self delegate]->type() == TranslateInfoBarDelegate2::kBeforeTranslate);
+ [self delegate]->type() == TranslateInfoBarDelegate2::BEFORE_TRANSLATE);
[self delegate]->TranslationDeclined();
UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslate", 1);
[super dismiss:nil];
diff --git a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
index dd3410e..38eb1ac 100644
--- a/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
+++ b/chrome/browser/cocoa/translate/translate_infobar_unittest.mm
@@ -26,10 +26,10 @@ namespace {
// All states the translate toolbar can assume.
TranslateInfoBarDelegate2::Type kTranslateToolbarStates[] = {
- TranslateInfoBarDelegate2::kBeforeTranslate,
- TranslateInfoBarDelegate2::kAfterTranslate,
- TranslateInfoBarDelegate2::kTranslating,
- TranslateInfoBarDelegate2::kTranslationError
+ TranslateInfoBarDelegate2::BEFORE_TRANSLATE,
+ TranslateInfoBarDelegate2::AFTER_TRANSLATE,
+ TranslateInfoBarDelegate2::TRANSLATING,
+ TranslateInfoBarDelegate2::TRANSLATION_ERROR
};
class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate2 {
@@ -82,7 +82,7 @@ class TranslationInfoBarTest : public CocoaTest {
}
void CreateInfoBar() {
- CreateInfoBar(TranslateInfoBarDelegate2::kBeforeTranslate);
+ CreateInfoBar(TranslateInfoBarDelegate2::BEFORE_TRANSLATE);
}
void CreateInfoBar(TranslateInfoBarDelegate2::Type type) {
@@ -94,7 +94,7 @@ class TranslationInfoBarTest : public CocoaTest {
MSG_ROUTING_NONE,
NULL));
TranslateErrors::Type error = TranslateErrors::NONE;
- if (type == TranslateInfoBarDelegate2::kTranslationError)
+ if (type == TranslateInfoBarDelegate2::TRANSLATION_ERROR)
error = TranslateErrors::NETWORK;
infobar_delegate.reset(
new MockTranslateInfoBarDelegate(type, error, tab_contents.get()));
@@ -125,7 +125,7 @@ TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) {
// Check that clicking the "Retry" button calls Translate() when we're
// in the error mode - http://crbug.com/41315 .
TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) {
- CreateInfoBar(TranslateInfoBarDelegate2::kTranslationError);
+ CreateInfoBar(TranslateInfoBarDelegate2::TRANSLATION_ERROR);
EXPECT_CALL(*infobar_delegate, Translate()).Times(1);
diff --git a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
index 3288cea..1087820 100644
--- a/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
+++ b/chrome/browser/cocoa/translate/translate_message_infobar_controller.mm
@@ -14,9 +14,9 @@ using TranslateInfoBarUtilities::MoveControl;
if ((self = [super initWithDelegate:delegate])) {
TranslateInfoBarDelegate2* delegate = [self delegate];
if (delegate->IsError())
- state_ = TranslateInfoBarDelegate2::kTranslationError;
+ state_ = TranslateInfoBarDelegate2::TRANSLATION_ERROR;
else
- state_ = TranslateInfoBarDelegate2::kTranslating;
+ state_ = TranslateInfoBarDelegate2::TRANSLATING;
}
return self;
}
@@ -33,7 +33,7 @@ using TranslateInfoBarUtilities::MoveControl;
- (NSArray*)visibleControls {
NSMutableArray* visibleControls =
[NSMutableArray arrayWithObjects:label1_.get(), nil];
- if (state_ == TranslateInfoBarDelegate2::kTranslationError)
+ if (state_ == TranslateInfoBarDelegate2::TRANSLATION_ERROR)
[visibleControls addObject:tryAgainButton_];
return visibleControls;
}
diff --git a/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc b/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
index 80ee803..a2d46e0 100644
--- a/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
+++ b/chrome/browser/gtk/translate/translate_infobar_base_gtk.cc
@@ -36,14 +36,14 @@ TranslateInfoBarBase::TranslateInfoBarBase(TranslateInfoBarDelegate2* delegate)
: InfoBar(delegate) {
TranslateInfoBarDelegate2::BackgroundAnimationType animation =
delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate2::kNone) {
+ if (animation != TranslateInfoBarDelegate2::NONE) {
background_color_animation_.reset(new SlideAnimation(this));
background_color_animation_->SetTweenType(Tween::LINEAR);
background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate2::kNormalToError) {
+ if (animation == TranslateInfoBarDelegate2::NORMAL_TO_ERROR) {
background_color_animation_->Show();
} else {
- DCHECK_EQ(TranslateInfoBarDelegate2::kErrorToNormal, animation);
+ DCHECK_EQ(TranslateInfoBarDelegate2::ERROR_TO_NORMAL, animation);
// Hide() runs the animation in reverse.
background_color_animation_->Reset(1.0);
background_color_animation_->Hide();
@@ -216,14 +216,14 @@ void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) {
InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() {
TranslateInfoBarBase* infobar = NULL;
switch (type_) {
- case kBeforeTranslate:
+ case BEFORE_TRANSLATE:
infobar = new BeforeTranslateInfoBar(this);
break;
- case kAfterTranslate:
+ case AFTER_TRANSLATE:
infobar = new AfterTranslateInfoBar(this);
break;
- case kTranslating:
- case kTranslationError:
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
infobar = new TranslateMessageInfoBar(this);
break;
default:
diff --git a/chrome/browser/translate/translate_infobar_delegate2.cc b/chrome/browser/translate/translate_infobar_delegate2.cc
index 8172a0d..7733b5f 100644
--- a/chrome/browser/translate/translate_infobar_delegate2.cc
+++ b/chrome/browser/translate/translate_infobar_delegate2.cc
@@ -17,31 +17,17 @@
#include "grit/theme_resources.h"
// static
-TranslateInfoBarDelegate2* TranslateInfoBarDelegate2::CreateDelegate(
+TranslateInfoBarDelegate2* TranslateInfoBarDelegate2::CreateInstance(
Type type,
+ TranslateErrors::Type error,
TabContents* tab_contents,
const std::string& original_language,
const std::string& target_language) {
- DCHECK(type != kTranslationError);
if (!TranslateManager2::IsSupportedLanguage(original_language) ||
!TranslateManager2::IsSupportedLanguage(target_language)) {
return NULL;
}
- TranslateInfoBarDelegate2* delegate =
- new TranslateInfoBarDelegate2(type, TranslateErrors::NONE,
- tab_contents,
- original_language, target_language);
- DCHECK(delegate->original_language_index() != -1);
- DCHECK(delegate->target_language_index() != -1);
- return delegate;
-}
-
-TranslateInfoBarDelegate2* TranslateInfoBarDelegate2::CreateErrorDelegate(
- TranslateErrors::Type error,
- TabContents* tab_contents,
- const std::string& original_language,
- const std::string& target_language) {
- return new TranslateInfoBarDelegate2(kTranslationError, error, tab_contents,
+ return new TranslateInfoBarDelegate2(type, error, tab_contents,
original_language, target_language);
}
@@ -53,15 +39,15 @@ TranslateInfoBarDelegate2::TranslateInfoBarDelegate2(
const std::string& target_language)
: InfoBarDelegate(tab_contents),
type_(type),
- background_animation_(kNone),
+ background_animation_(NONE),
tab_contents_(tab_contents),
original_language_index_(-1),
target_language_index_(-1),
error_(error),
infobar_view_(NULL),
prefs_(tab_contents_->profile()->GetPrefs()) {
- DCHECK((type_ != kTranslationError && error == TranslateErrors::NONE) ||
- (type_ == kTranslationError && error != TranslateErrors::NONE));
+ DCHECK((type_ != TRANSLATION_ERROR && error == TranslateErrors::NONE) ||
+ (type_ == TRANSLATION_ERROR && error != TranslateErrors::NONE));
std::vector<std::string> language_codes;
TranslateManager2::GetSupportedLanguages(&language_codes);
@@ -85,9 +71,12 @@ TranslateInfoBarDelegate2::TranslateInfoBarDelegate2(
std::string language_code = iter->first;
if (language_code == original_language)
original_language_index_ = iter - languages_.begin();
- if (language_code == target_language)
+ else if (language_code == target_language)
target_language_index_ = iter - languages_.begin();
}
+
+ DCHECK(original_language_index_ != -1);
+ DCHECK(target_language_index_ != -1);
}
int TranslateInfoBarDelegate2::GetLanguageCount() const {
@@ -119,7 +108,7 @@ void TranslateInfoBarDelegate2::SetOriginalLanguage(int language_index) {
original_language_index_ = language_index;
if (infobar_view_)
infobar_view_->OriginalLanguageChanged();
- if (type_ == kAfterTranslate)
+ if (type_ == AFTER_TRANSLATE)
Translate();
}
@@ -128,12 +117,12 @@ void TranslateInfoBarDelegate2::SetTargetLanguage(int language_index) {
target_language_index_ = language_index;
if (infobar_view_)
infobar_view_->TargetLanguageChanged();
- if (type_ == kAfterTranslate)
+ if (type_ == AFTER_TRANSLATE)
Translate();
}
bool TranslateInfoBarDelegate2::IsError() {
- return type_ == kTranslationError;
+ return type_ == TRANSLATION_ERROR;
}
void TranslateInfoBarDelegate2::Translate() {
@@ -166,7 +155,7 @@ void TranslateInfoBarDelegate2::TranslationDeclined() {
}
void TranslateInfoBarDelegate2::InfoBarDismissed() {
- if (type_ != kBeforeTranslate)
+ if (type_ != BEFORE_TRANSLATE)
return;
// The user closed the infobar without clicking the translate button.
@@ -250,11 +239,11 @@ void TranslateInfoBarDelegate2::NeverTranslatePageLanguage() {
string16 TranslateInfoBarDelegate2::GetMessageInfoBarText() {
switch (type_) {
- case kTranslating:
+ case TRANSLATING:
return l10n_util::GetStringFUTF16(
IDS_TRANSLATE_INFOBAR_TRANSLATING_TO,
GetLanguageDisplayableNameAt(target_language_index_));
- case kTranslationError:
+ case TRANSLATION_ERROR:
switch (error_) {
case TranslateErrors::NETWORK:
return l10n_util::GetStringUTF16(
@@ -263,13 +252,6 @@ string16 TranslateInfoBarDelegate2::GetMessageInfoBarText() {
case TranslateErrors::TRANSLATION_ERROR:
return l10n_util::GetStringUTF16(
IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE);
- case TranslateErrors::UNKNOWN_LANGUAGE:
- return l10n_util::GetStringUTF16(
- IDS_TRANSLATE_INFOBAR_UNKNOWN_PAGE_LANGUAGE);
- case TranslateErrors::IDENTICAL_LANGUAGES:
- return l10n_util::GetStringFUTF16(
- IDS_TRANSLATE_INFOBAR_ERROR_SAME_LANGUAGE,
- GetLanguageDisplayableNameAt(target_language_index_));
default:
NOTREACHED();
return string16();
@@ -282,14 +264,9 @@ string16 TranslateInfoBarDelegate2::GetMessageInfoBarText() {
string16 TranslateInfoBarDelegate2::GetMessageInfoBarButtonText() {
switch (type_) {
- case kTranslating:
+ case TRANSLATING:
return string16();
- case kTranslationError:
- if (error_ == TranslateErrors::IDENTICAL_LANGUAGES ||
- error_ == TranslateErrors::UNKNOWN_LANGUAGE) {
- // No retry button, we would fail again with the same error.
- return string16();
- }
+ case TRANSLATION_ERROR:
return l10n_util::GetStringUTF16(IDS_TRANSLATE_INFOBAR_RETRY);
default:
NOTREACHED();
@@ -298,7 +275,7 @@ string16 TranslateInfoBarDelegate2::GetMessageInfoBarButtonText() {
}
void TranslateInfoBarDelegate2::MessageInfoBarButtonPressed() {
- DCHECK(type_ == kTranslationError);
+ DCHECK(type_ == TRANSLATION_ERROR);
Singleton<TranslateManager2>::get()->TranslatePage(
tab_contents_, GetOriginalLanguageCode(), GetTargetLanguageCode());
}
@@ -316,10 +293,10 @@ bool TranslateInfoBarDelegate2::ShouldShowAlwaysTranslateButton() {
void TranslateInfoBarDelegate2::UpdateBackgroundAnimation(
TranslateInfoBarDelegate2* previous_infobar) {
if (!previous_infobar || previous_infobar->IsError() == IsError()) {
- background_animation_ = kNone;
+ background_animation_ = NONE;
return;
}
- background_animation_ = IsError() ? kNormalToError: kErrorToNormal;
+ background_animation_ = IsError() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL;
}
std::string TranslateInfoBarDelegate2::GetPageHost() {
diff --git a/chrome/browser/translate/translate_infobar_delegate2.h b/chrome/browser/translate/translate_infobar_delegate2.h
index 7b5f691..14c683a 100644
--- a/chrome/browser/translate/translate_infobar_delegate2.h
+++ b/chrome/browser/translate/translate_infobar_delegate2.h
@@ -19,33 +19,28 @@ class TranslateInfoBarDelegate2 : public InfoBarDelegate {
public:
// The different types of infobars that can be shown for translation.
enum Type {
- kBeforeTranslate,
- kTranslating,
- kAfterTranslate,
- kTranslationError
+ BEFORE_TRANSLATE,
+ TRANSLATING,
+ AFTER_TRANSLATE,
+ TRANSLATION_ERROR
};
// The types of background color animations.
enum BackgroundAnimationType {
- kNone,
- kNormalToError,
- kErrorToNormal
+ NONE,
+ NORMAL_TO_ERROR,
+ ERROR_TO_NORMAL
};
- // Factory method to create a non-error translate infobar.
+ // Factory method.
// The original and target language specified are the ASCII language codes
// (ex: en, fr...).
// Returns NULL if it failed, typically if |original_language| or
// |target_language| is not a supported language.
- static TranslateInfoBarDelegate2* CreateDelegate(
+ // |error| should be set to NONE if |infobar_type| is not TRANSLATION_ERROR.
+ static TranslateInfoBarDelegate2* CreateInstance(
Type infobar_type,
- TabContents* tab_contents,
- const std::string& original_language,
- const std::string& target_language);
-
- // Factory method to create an error translate infobar.
- static TranslateInfoBarDelegate2* CreateErrorDelegate(
- TranslateErrors::Type error_type,
+ TranslateErrors::Type error,
TabContents* tab_contents,
const std::string& original_language,
const std::string& target_language);
@@ -63,8 +58,6 @@ class TranslateInfoBarDelegate2 : public InfoBarDelegate {
Type type() const { return type_; }
- TranslateErrors::Type error() const { return error_; }
-
int original_language_index() const { return original_language_index_; }
int target_language_index() const { return target_language_index_; }
diff --git a/chrome/browser/translate/translate_manager2.cc b/chrome/browser/translate/translate_manager2.cc
index e7f70f0..7f8cfa9 100644
--- a/chrome/browser/translate/translate_manager2.cc
+++ b/chrome/browser/translate/translate_manager2.cc
@@ -275,9 +275,11 @@ void TranslateManager2::OnURLFetchComplete(const URLFetcher* source,
}
if (error) {
- ShowInfoBar(tab, TranslateInfoBarDelegate2::CreateErrorDelegate(
- TranslateErrors::NETWORK, tab,
- request.source_lang, request.target_lang));
+ ShowInfoBar(tab,
+ TranslateInfoBarDelegate2::CreateInstance(
+ TranslateInfoBarDelegate2::TRANSLATION_ERROR,
+ TranslateErrors::NETWORK,
+ tab, request.source_lang, request.target_lang));
} else {
// Translate the page.
DoTranslatePage(tab, translate_script_,
@@ -357,9 +359,9 @@ void TranslateManager2::InitiateTranslation(TabContents* tab,
}
// Prompts the user if he/she wants the page translated.
- tab->AddInfoBar(TranslateInfoBarDelegate2::CreateDelegate(
- TranslateInfoBarDelegate2::kBeforeTranslate, tab,
- page_lang, target_lang));
+ tab->AddInfoBar(TranslateInfoBarDelegate2::CreateInstance(
+ TranslateInfoBarDelegate2::BEFORE_TRANSLATE,
+ TranslateErrors::NONE, tab, page_lang, target_lang));
}
void TranslateManager2::InitiateTranslationPosted(
@@ -424,8 +426,9 @@ void TranslateManager2::DoTranslatePage(TabContents* tab,
// We don't show the translating infobar if no translate infobar is already
// showing (that is the case when the translation was triggered by the
// "always translate" for example).
- infobar = TranslateInfoBarDelegate2::CreateDelegate(
- TranslateInfoBarDelegate2::kTranslating, tab, source_lang, target_lang);
+ infobar = TranslateInfoBarDelegate2::CreateInstance(
+ TranslateInfoBarDelegate2::TRANSLATING, TranslateErrors::NONE,
+ tab, source_lang, target_lang);
ShowInfoBar(tab, infobar);
}
tab->language_state().set_translation_pending(true);
@@ -438,13 +441,13 @@ void TranslateManager2::PageTranslated(TabContents* tab,
// Create the new infobar to display.
TranslateInfoBarDelegate2* infobar;
if (details->error_type != TranslateErrors::NONE) {
- infobar = TranslateInfoBarDelegate2::CreateErrorDelegate(
- details->error_type, tab,
- details->source_language, details->target_language);
+ infobar = TranslateInfoBarDelegate2::CreateInstance(
+ TranslateInfoBarDelegate2::TRANSLATION_ERROR, details->error_type,
+ tab, details->source_language, details->target_language);
} else {
- infobar = TranslateInfoBarDelegate2::CreateDelegate(
- TranslateInfoBarDelegate2::kAfterTranslate, tab,
- details->source_language, details->target_language);
+ infobar = TranslateInfoBarDelegate2::CreateInstance(
+ TranslateInfoBarDelegate2::AFTER_TRANSLATE, TranslateErrors::NONE,
+ tab, details->source_language, details->target_language);
}
ShowInfoBar(tab, infobar);
}
diff --git a/chrome/browser/translate/translate_manager2_unittest.cc b/chrome/browser/translate/translate_manager2_unittest.cc
index bf72b52..4030b2a 100644
--- a/chrome/browser/translate/translate_manager2_unittest.cc
+++ b/chrome/browser/translate/translate_manager2_unittest.cc
@@ -152,8 +152,6 @@ class TranslateManager2Test : public RenderViewHostTestHarness,
}
virtual void TearDown() {
- process()->sink().ClearMessages();
-
notification_registrar_.Remove(
this,
NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
@@ -273,7 +271,7 @@ TEST_F(TranslateManager2Test, NormalTranslate) {
// We should have an infobar.
TranslateInfoBarDelegate2* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate2::BEFORE_TRANSLATE, infobar->type());
// Simulate clicking translate.
process()->sink().ClearMessages();
@@ -294,7 +292,7 @@ TEST_F(TranslateManager2Test, NormalTranslate) {
// The "Translating..." infobar should be showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kTranslating, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate2::TRANSLATING, infobar->type());
// Simulate the render notifying the translation has been done.
rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en",
@@ -303,7 +301,7 @@ TEST_F(TranslateManager2Test, NormalTranslate) {
// The after translate infobar should be showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kAfterTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate2::AFTER_TRANSLATE, infobar->type());
// Simulate changing the original language, this should trigger a translation.
process()->sink().ClearMessages();
@@ -344,7 +342,7 @@ TEST_F(TranslateManager2Test, TranslateScriptNotAvailable) {
// We should have an infobar.
TranslateInfoBarDelegate2* infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kBeforeTranslate, infobar->type());
+ EXPECT_EQ(TranslateInfoBarDelegate2::BEFORE_TRANSLATE, infobar->type());
// Simulate clicking translate.
process()->sink().ClearMessages();
@@ -358,63 +356,7 @@ TEST_F(TranslateManager2Test, TranslateScriptNotAvailable) {
// And we should have an error infobar showing.
infobar = GetTranslateInfoBar();
ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kTranslationError, infobar->type());
-}
-
-// Ensures we deal correctly with pages for which the browser does not recognize
-// the language (the translate server may or not detect the language).
-TEST_F(TranslateManager2Test, TranslateUnknownLanguage) {
- // Simulate navigating to a page ("und" is the string returned by the CLD for
- // languages it does not recognize).
- SimulateNavigation(GURL("http://www.google.mys"), 0, "G00g1e", "und");
-
- // We should not have an infobar as we don't know the language.
- ASSERT_TRUE(GetTranslateInfoBar() == NULL);
-
- // Translate the page anyway throught the context menu.
- scoped_ptr<TestRenderViewContextMenu> menu(
- TestRenderViewContextMenu::CreateContextMenu(contents()));
- menu->Init();
- menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
- SimulateURLFetch(true); // Simulare receiving the translate script.
-
- // Simulate the render notifying the translation has been done, the server
- // having detected the page was in a known and supported language.
- rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(0, 0, "fr", "en",
- TranslateErrors::NONE));
-
- // The after translate infobar should be showing.
- TranslateInfoBarDelegate2* infobar = GetTranslateInfoBar();
- ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kAfterTranslate, infobar->type());
- EXPECT_EQ("fr", infobar->GetOriginalLanguageCode());
- EXPECT_EQ("en", infobar->GetTargetLanguageCode());
-
- // Let's run the same steps but this time the server detects the page is
- // already in English.
- SimulateNavigation(GURL("http://www.google.com"), 1, "The Google", "und");
- menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
- menu->Init();
- menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
- rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(1, 0, "en", "en",
- TranslateErrors::IDENTICAL_LANGUAGES));
- infobar = GetTranslateInfoBar();
- ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kTranslationError, infobar->type());
- EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error());
-
- // Let's run the same steps again but this time the server fails to detect the
- // page's language (it returns an empty string).
- SimulateNavigation(GURL("http://www.google.com"), 2, "The Google", "und");
- menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
- menu->Init();
- menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE);
- rvh()->TestOnMessageReceived(ViewHostMsg_PageTranslated(2, 0, "", "en",
- TranslateErrors::UNKNOWN_LANGUAGE));
- infobar = GetTranslateInfoBar();
- ASSERT_TRUE(infobar != NULL);
- EXPECT_EQ(TranslateInfoBarDelegate2::kTranslationError, infobar->type());
- EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error());
+ EXPECT_EQ(TranslateInfoBarDelegate2::TRANSLATION_ERROR, infobar->type());
}
// Tests that we show/don't show an info-bar for all languages the CLD can
@@ -983,14 +925,6 @@ TEST_F(TranslateManager2Test, FAILS_ContextMenu) {
menu->Init();
EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
-
- // Test that the translate context menu is enabled when the page is in an
- // unknown language as the UI.
- SimulateNavigation(url, 0, "G00g1e", "und");
- menu.reset(TestRenderViewContextMenu::CreateContextMenu(contents()));
- menu->Init();
- EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE));
- EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE));
}
// Tests that an extra always/never translate button is shown on the "before
diff --git a/chrome/browser/views/infobars/translate_infobar_base.cc b/chrome/browser/views/infobars/translate_infobar_base.cc
index 4347f0d..b62a3ef 100644
--- a/chrome/browser/views/infobars/translate_infobar_base.cc
+++ b/chrome/browser/views/infobars/translate_infobar_base.cc
@@ -30,14 +30,14 @@ TranslateInfoBarBase::TranslateInfoBarBase(
TranslateInfoBarDelegate2::BackgroundAnimationType animation =
delegate->background_animation_type();
- if (animation != TranslateInfoBarDelegate2::kNone) {
+ if (animation != TranslateInfoBarDelegate2::NONE) {
background_color_animation_.reset(new SlideAnimation(this));
background_color_animation_->SetTweenType(Tween::LINEAR);
background_color_animation_->SetSlideDuration(500);
- if (animation == TranslateInfoBarDelegate2::kNormalToError) {
+ if (animation == TranslateInfoBarDelegate2::NORMAL_TO_ERROR) {
background_color_animation_->Show();
} else {
- DCHECK_EQ(TranslateInfoBarDelegate2::kErrorToNormal, animation);
+ DCHECK_EQ(TranslateInfoBarDelegate2::ERROR_TO_NORMAL, animation);
// Hide() runs the animation in reverse.
background_color_animation_->Reset(1.0);
background_color_animation_->Hide();
@@ -158,14 +158,14 @@ void TranslateInfoBarBase::FadeBackground(gfx::Canvas* canvas,
InfoBar* TranslateInfoBarDelegate2::CreateInfoBar() {
TranslateInfoBarBase* infobar = NULL;
switch (type_) {
- case kBeforeTranslate:
+ case BEFORE_TRANSLATE:
infobar = new BeforeTranslateInfoBar(this);
break;
- case kAfterTranslate:
+ case AFTER_TRANSLATE:
infobar = new AfterTranslateInfoBar(this);
break;
- case kTranslating:
- case kTranslationError:
+ case TRANSLATING:
+ case TRANSLATION_ERROR:
infobar = new TranslateMessageInfoBar(this);
break;
default:
diff --git a/chrome/common/translate_errors.h b/chrome/common/translate_errors.h
index 56a104c..c8f4225 100644
--- a/chrome/common/translate_errors.h
+++ b/chrome/common/translate_errors.h
@@ -13,10 +13,8 @@ class TranslateErrors {
NONE = 0,
NETWORK, // No connectivity.
INITIALIZATION_ERROR, // The translation script failed to initialize.
- UNKNOWN_LANGUAGE, // The page's language could not be detected.
- IDENTICAL_LANGUAGES, // The original and target languages are the same.
- TRANSLATION_ERROR, // An error was reported by the translation script
- // during translation.
+ TRANSLATION_ERROR, // An error was reported by the translation script
+ // during translation.
};
private:
diff --git a/chrome/renderer/translate_helper.cc b/chrome/renderer/translate_helper.cc
index 5075917..7caeec4 100644
--- a/chrome/renderer/translate_helper.cc
+++ b/chrome/renderer/translate_helper.cc
@@ -182,10 +182,7 @@ void TranslateHelper::CheckTranslateStatus() {
if (source_lang_ == kAutoDetectionLanguage) {
actual_source_lang = GetOriginalPageLanguage();
if (actual_source_lang.empty()) {
- NotifyBrowserTranslationFailed(TranslateErrors::UNKNOWN_LANGUAGE);
- return;
- } else if (actual_source_lang == target_lang_) {
- NotifyBrowserTranslationFailed(TranslateErrors::IDENTICAL_LANGUAGES);
+ NotifyBrowserTranslationFailed(TranslateErrors::TRANSLATION_ERROR);
return;
}
} else {