| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 6 #define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "chrome/common/chrome_constants.h" | |
| 15 #include "components/translate/core/common/translate_errors.h" | 14 #include "components/translate/core/common/translate_errors.h" |
| 16 | 15 |
| 16 class LanguageState; |
| 17 class TranslateClient; |
| 18 class TranslateDriver; |
| 19 class TranslateManager; |
| 17 class TranslatePrefs; | 20 class TranslatePrefs; |
| 18 | 21 |
| 19 namespace content { | |
| 20 class WebContents; | |
| 21 } // namespace content | |
| 22 | |
| 23 // The TranslateUIDelegate is a generic delegate for UI which offers Translate | 22 // The TranslateUIDelegate is a generic delegate for UI which offers Translate |
| 24 // feature to the user. | 23 // feature to the user. |
| 25 class TranslateUIDelegate { | 24 class TranslateUIDelegate { |
| 26 public: | 25 public: |
| 27 enum { | 26 enum { NO_INDEX = -1, }; |
| 28 NO_INDEX = -1, | |
| 29 }; | |
| 30 | 27 |
| 31 TranslateUIDelegate(content::WebContents* web_contents, | 28 TranslateUIDelegate(TranslateClient* translate_client, |
| 29 TranslateManager* translate_manager, |
| 32 const std::string& original_language, | 30 const std::string& original_language, |
| 33 const std::string& target_language); | 31 const std::string& target_language); |
| 34 virtual ~TranslateUIDelegate(); | 32 virtual ~TranslateUIDelegate(); |
| 35 | 33 |
| 36 content::WebContents* web_contents() { return web_contents_; } | |
| 37 | |
| 38 // Handles when an error message is shown. | 34 // Handles when an error message is shown. |
| 39 void OnErrorShown(TranslateErrors::Type error_type); | 35 void OnErrorShown(TranslateErrors::Type error_type); |
| 40 | 36 |
| 37 // Returns the LanguageState associated with this object. |
| 38 const LanguageState& GetLanguageState(); |
| 39 |
| 41 // Returns the number of languages supported. | 40 // Returns the number of languages supported. |
| 42 size_t GetNumberOfLanguages() const; | 41 size_t GetNumberOfLanguages() const; |
| 43 | 42 |
| 44 // Returns the original language index. | 43 // Returns the original language index. |
| 45 size_t GetOriginalLanguageIndex() const; | 44 size_t GetOriginalLanguageIndex() const; |
| 46 | 45 |
| 47 // Updates the original language index. | 46 // Updates the original language index. |
| 48 void UpdateOriginalLanguageIndex(size_t language_index); | 47 void UpdateOriginalLanguageIndex(size_t language_index); |
| 49 | 48 |
| 50 // Returns the target language index. | 49 // Returns the target language index. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 91 |
| 93 // Sets the value if the webpage in the current original language should be | 92 // Sets the value if the webpage in the current original language should be |
| 94 // translated into the current target language automatically. | 93 // translated into the current target language automatically. |
| 95 void SetAlwaysTranslate(bool value); | 94 void SetAlwaysTranslate(bool value); |
| 96 | 95 |
| 97 private: | 96 private: |
| 98 // Gets the host of the page being translated, or an empty string if no URL is | 97 // Gets the host of the page being translated, or an empty string if no URL is |
| 99 // associated with the current page. | 98 // associated with the current page. |
| 100 std::string GetPageHost(); | 99 std::string GetPageHost(); |
| 101 | 100 |
| 102 content::WebContents* web_contents_; | 101 TranslateClient* translate_client_; |
| 102 TranslateDriver* translate_driver_; |
| 103 TranslateManager* translate_manager_; |
| 103 | 104 |
| 104 typedef std::pair<std::string, base::string16> LanguageNamePair; | 105 typedef std::pair<std::string, base::string16> LanguageNamePair; |
| 105 | 106 |
| 106 // The list supported languages for translation. | 107 // The list supported languages for translation. |
| 107 // The pair first string is the language ISO code (ex: en, fr...), the second | 108 // The pair first string is the language ISO code (ex: en, fr...), the second |
| 108 // string is the displayable name on the current locale. | 109 // string is the displayable name on the current locale. |
| 109 // The languages are sorted alphabetically based on the displayable name. | 110 // The languages are sorted alphabetically based on the displayable name. |
| 110 std::vector<LanguageNamePair> languages_; | 111 std::vector<LanguageNamePair> languages_; |
| 111 | 112 |
| 112 // The index for language the page is originally in. | 113 // The index for language the page is originally in. |
| 113 size_t original_language_index_; | 114 size_t original_language_index_; |
| 114 | 115 |
| 115 // The index for language the page is originally in that was originally | 116 // The index for language the page is originally in that was originally |
| 116 // reported (original_language_index_ changes if the user selects a new | 117 // reported (original_language_index_ changes if the user selects a new |
| 117 // original language, but this one does not). This is necessary to report | 118 // original language, but this one does not). This is necessary to report |
| 118 // language detection errors with the right original language even if the user | 119 // language detection errors with the right original language even if the user |
| 119 // changed the original language. | 120 // changed the original language. |
| 120 size_t initial_original_language_index_; | 121 size_t initial_original_language_index_; |
| 121 | 122 |
| 122 // The index for language the page should be translated to. | 123 // The index for language the page should be translated to. |
| 123 size_t target_language_index_; | 124 size_t target_language_index_; |
| 124 | 125 |
| 125 // The translation related preferences. | 126 // The translation related preferences. |
| 126 scoped_ptr<TranslatePrefs> prefs_; | 127 scoped_ptr<TranslatePrefs> prefs_; |
| 127 | 128 |
| 128 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); | 129 DISALLOW_COPY_AND_ASSIGN(TranslateUIDelegate); |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_UI_DELEGATE_H_ | 132 #endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_UI_DELEGATE_H_ |
| OLD | NEW |