summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate/translate_infobars_delegates.cc
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 16:41:53 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-29 16:41:53 +0000
commit8db841ac0528a7eba71e89260526da9ba33dbb54 (patch)
tree79501d52aa828b2bbaf87e91064f978851d702d2 /chrome/browser/translate/translate_infobars_delegates.cc
parent89e29d25efa776ed1f564e576d764fd3e9ddecfc (diff)
downloadchromium_src-8db841ac0528a7eba71e89260526da9ba33dbb54.zip
chromium_src-8db841ac0528a7eba71e89260526da9ba33dbb54.tar.gz
chromium_src-8db841ac0528a7eba71e89260526da9ba33dbb54.tar.bz2
implement error state for translate infobar
- this cl implements the UI on Windows and the partial backend of IPC messaging to include error type - implement error state - add translate error types - use a structure as details for IPC messaging between render view and browser so as to include error type (was using std::pair) - translate delegate handles error state and provides mapping to error messages - infobar handles visual error states - modify background painting to handle normal and error backgrounds, and animation of cross-fading between the 2 backgrounds - infobar now stores state (and translation_pending flag) that it's currently displaying to user, instead of just relying on TransateInfoBarDelegate's - if infobar receives PAGE_TRANSLAED notification before delegate does (possible because order is not fixed), delegate's state won't be updated to be used by infobar. - after all the observers have received the notification, both infobar and delegate will end up with matching states, so there's no worries of out-of-sync. - update unittests accordingly - update mac and linux code accordingly to make build pass - jay will implement the remaining backend to pass actual translate error types to the IPC message (tracked by bug 37778) BUG=38548 TEST=none yet, until bug 37778 is also fixed. Review URL: http://codereview.chromium.org/1321003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42953 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate/translate_infobars_delegates.cc')
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.cc42
1 files changed, 34 insertions, 8 deletions
diff --git a/chrome/browser/translate/translate_infobars_delegates.cc b/chrome/browser/translate/translate_infobars_delegates.cc
index e13be6a..5caff33 100644
--- a/chrome/browser/translate/translate_infobars_delegates.cc
+++ b/chrome/browser/translate/translate_infobars_delegates.cc
@@ -48,8 +48,10 @@ string16 TranslateInfoBarDelegate::GetDisplayNameForLocale(
language_code, g_browser_process->GetApplicationLocale(), true);
}
-void TranslateInfoBarDelegate::UpdateState(TranslateState new_state) {
+void TranslateInfoBarDelegate::UpdateState(TranslateState new_state,
+ TranslateErrors::Type error_type) {
translation_pending_ = false;
+ error_type_ = error_type;
if (state_ != new_state)
state_ = new_state;
}
@@ -137,14 +139,15 @@ void TranslateInfoBarDelegate::ToggleAlwaysTranslate() {
target_lang_code());
}
-void TranslateInfoBarDelegate::GetMessageText(string16 *message_text,
- std::vector<size_t> *offsets, bool *swapped_language_placeholders) {
+void TranslateInfoBarDelegate::GetMessageText(
+ TranslateInfoBarDelegate::TranslateState state, string16 *message_text,
+ std::vector<size_t> *offsets, bool *swapped_language_placeholders) {
*swapped_language_placeholders = false;
offsets->clear();
std::vector<size_t> offsets_tmp;
int message_resource_id = IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE;
- if (state() == kAfterTranslate)
+ if (state == kAfterTranslate)
message_resource_id = IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE;
*message_text = l10n_util::GetStringFUTF16(message_resource_id,
string16(), string16(), &offsets_tmp);
@@ -165,13 +168,33 @@ void TranslateInfoBarDelegate::GetMessageText(string16 *message_text,
*offsets = offsets_tmp;
}
+string16 TranslateInfoBarDelegate::GetErrorMessage(
+ TranslateErrors::Type error_type) {
+ int message_id = 0;
+ switch (error_type) {
+ case TranslateErrors::NONE:
+ return string16();
+ case TranslateErrors::NETWORK:
+ message_id = IDS_TRANSLATE_INFOBAR_ERROR_CANT_CONNECT;
+ break;
+ case TranslateErrors::SERVER:
+ message_id = IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE;
+ break;
+ default:
+ NOTREACHED() << "Invalid translate error type";
+ break;
+ }
+ return l10n_util::GetStringUTF16(message_id);
+}
+
// TranslateInfoBarDelegate: static: -------------------------------------------
TranslateInfoBarDelegate* TranslateInfoBarDelegate::Create(
TabContents* tab_contents, PrefService* user_prefs, TranslateState state,
const GURL& url,
const std::string& original_lang_code,
- const std::string& target_lang_code) {
+ const std::string& target_lang_code,
+ TranslateErrors::Type error_type) {
std::vector<std::string> supported_languages;
TranslationService::GetSupportedLanguages(&supported_languages);
@@ -196,14 +219,16 @@ TranslateInfoBarDelegate* TranslateInfoBarDelegate::Create(
return NULL;
return new TranslateInfoBarDelegate(tab_contents, user_prefs, state, url,
- original_lang_index, target_lang_index);
+ original_lang_index, target_lang_index,
+ error_type);
}
// TranslateInfoBarDelegate: private: ------------------------------------------
TranslateInfoBarDelegate::TranslateInfoBarDelegate(TabContents* tab_contents,
PrefService* user_prefs, TranslateState state, const GURL& url,
- int original_lang_index, int target_lang_index)
+ int original_lang_index, int target_lang_index,
+ TranslateErrors::Type error_type)
: InfoBarDelegate(tab_contents),
tab_contents_(tab_contents),
prefs_(new TranslatePrefs(user_prefs)),
@@ -214,7 +239,8 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate(TabContents* tab_contents,
target_lang_index_(target_lang_index),
never_translate_language_(false),
never_translate_site_(false),
- always_translate_(false) {
+ always_translate_(false),
+ error_type_(error_type) {
TranslationService::GetSupportedLanguages(&supported_languages_);
DCHECK(original_lang_index_ > -1);
DCHECK(target_lang_index_ > -1);