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