| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/translate/options_menu_model.h" | 5 #include "chrome/browser/translate/options_menu_model.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/infobars/infobar_tab_helper.h" | 9 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 TranslateInfoBarDelegate* translate_delegate) | 26 TranslateInfoBarDelegate* translate_delegate) |
| 27 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), | 27 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), |
| 28 translate_infobar_delegate_(translate_delegate) { | 28 translate_infobar_delegate_(translate_delegate) { |
| 29 string16 original_language = translate_delegate->GetLanguageDisplayableNameAt( | 29 string16 original_language = translate_delegate->GetLanguageDisplayableNameAt( |
| 30 translate_delegate->original_language_index()); | 30 translate_delegate->original_language_index()); |
| 31 string16 target_language = translate_delegate->GetLanguageDisplayableNameAt( | 31 string16 target_language = translate_delegate->GetLanguageDisplayableNameAt( |
| 32 translate_delegate->target_language_index()); | 32 translate_delegate->target_language_index()); |
| 33 | 33 |
| 34 // Populate the menu. | 34 // Populate the menu. |
| 35 // Incognito mode does not get any preferences related items. | 35 // Incognito mode does not get any preferences related items. |
| 36 if (!translate_delegate->owner()->web_contents()-> | 36 if (!translate_delegate->owner()->GetWebContents()-> |
| 37 GetBrowserContext()->IsOffTheRecord()) { | 37 GetBrowserContext()->IsOffTheRecord()) { |
| 38 AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS, | 38 AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS, |
| 39 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS, | 39 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS, |
| 40 original_language, target_language)); | 40 original_language, target_language)); |
| 41 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG, | 41 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG, |
| 42 l10n_util::GetStringFUTF16( | 42 l10n_util::GetStringFUTF16( |
| 43 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, | 43 IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, |
| 44 original_language)); | 44 original_language)); |
| 45 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE, | 45 AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE, |
| 46 l10n_util::GetStringUTF16( | 46 l10n_util::GetStringUTF16( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 case IDC_TRANSLATE_OPTIONS_ALWAYS : | 84 case IDC_TRANSLATE_OPTIONS_ALWAYS : |
| 85 return (!translate_infobar_delegate_->IsLanguageBlacklisted() && | 85 return (!translate_infobar_delegate_->IsLanguageBlacklisted() && |
| 86 !translate_infobar_delegate_->IsSiteBlacklisted()); | 86 !translate_infobar_delegate_->IsSiteBlacklisted()); |
| 87 | 87 |
| 88 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION : { | 88 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION : { |
| 89 // Until we have a secure URL for reporting language detection errors, | 89 // Until we have a secure URL for reporting language detection errors, |
| 90 // we don't report errors that happened on secure URLs. | 90 // we don't report errors that happened on secure URLs. |
| 91 DCHECK(translate_infobar_delegate_ != NULL); | 91 DCHECK(translate_infobar_delegate_ != NULL); |
| 92 DCHECK(translate_infobar_delegate_->owner() != NULL); | 92 DCHECK(translate_infobar_delegate_->owner() != NULL); |
| 93 DCHECK(translate_infobar_delegate_->owner()->web_contents() != NULL); | 93 DCHECK(translate_infobar_delegate_->owner()->GetWebContents() != NULL); |
| 94 NavigationEntry* entry = translate_infobar_delegate_->owner()-> | 94 NavigationEntry* entry = translate_infobar_delegate_->owner()-> |
| 95 web_contents()->GetController().GetActiveEntry(); | 95 GetWebContents()->GetController().GetActiveEntry(); |
| 96 // Delegate and tab contents should never be NULL, but active entry | 96 // Delegate and tab contents should never be NULL, but active entry |
| 97 // can be NULL when running tests. We want to return false if NULL. | 97 // can be NULL when running tests. We want to return false if NULL. |
| 98 return (entry != NULL) && !entry->GetURL().SchemeIsSecure(); | 98 return (entry != NULL) && !entry->GetURL().SchemeIsSecure(); |
| 99 } | 99 } |
| 100 default: | 100 default: |
| 101 break; | 101 break; |
| 102 } | 102 } |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 124 UMA_HISTOGRAM_COUNTS("Translate.AlwaysTranslateLang", 1); | 124 UMA_HISTOGRAM_COUNTS("Translate.AlwaysTranslateLang", 1); |
| 125 translate_infobar_delegate_->ToggleAlwaysTranslate(); | 125 translate_infobar_delegate_->ToggleAlwaysTranslate(); |
| 126 break; | 126 break; |
| 127 | 127 |
| 128 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION: | 128 case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION: |
| 129 translate_infobar_delegate_->ReportLanguageDetectionError(); | 129 translate_infobar_delegate_->ReportLanguageDetectionError(); |
| 130 break; | 130 break; |
| 131 | 131 |
| 132 case IDC_TRANSLATE_OPTIONS_ABOUT: { | 132 case IDC_TRANSLATE_OPTIONS_ABOUT: { |
| 133 WebContents* web_contents = | 133 WebContents* web_contents = |
| 134 translate_infobar_delegate_->owner()->web_contents(); | 134 translate_infobar_delegate_->owner()->GetWebContents(); |
| 135 if (web_contents) { | 135 if (web_contents) { |
| 136 OpenURLParams params( | 136 OpenURLParams params( |
| 137 GURL(chrome::kAboutGoogleTranslateURL), Referrer(), | 137 GURL(chrome::kAboutGoogleTranslateURL), Referrer(), |
| 138 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | 138 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); |
| 139 web_contents->OpenURL(params); | 139 web_contents->OpenURL(params); |
| 140 } | 140 } |
| 141 break; | 141 break; |
| 142 } | 142 } |
| 143 | 143 |
| 144 default: | 144 default: |
| 145 NOTREACHED() << "Invalid command id from menu."; | 145 NOTREACHED() << "Invalid command id from menu."; |
| 146 break; | 146 break; |
| 147 } | 147 } |
| 148 } | 148 } |
| OLD | NEW |