OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 6 #define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/callback_list.h" | 12 #include "base/callback_list.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/translate/core/common/translate_errors.h" |
16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
18 | 19 |
19 class GURL; | 20 class GURL; |
20 struct PageTranslatedDetails; | |
21 class PrefService; | 21 class PrefService; |
22 class TranslateClient; | 22 class TranslateClient; |
23 class TranslateDriver; | 23 class TranslateDriver; |
24 struct TranslateErrorDetails; | 24 struct TranslateErrorDetails; |
25 class TranslateTabHelper; | 25 class TranslateTabHelper; |
26 | 26 |
27 namespace content { | 27 namespace content { |
28 class WebContents; | 28 class WebContents; |
29 } | 29 } |
30 | 30 |
(...skipping 30 matching lines...) Expand all Loading... |
61 static std::string GetAutoTargetLanguage(const std::string& original_language, | 61 static std::string GetAutoTargetLanguage(const std::string& original_language, |
62 PrefService* prefs); | 62 PrefService* prefs); |
63 | 63 |
64 // Translates the page contents from |source_lang| to |target_lang|. | 64 // Translates the page contents from |source_lang| to |target_lang|. |
65 // The actual translation might be performed asynchronously if the translate | 65 // The actual translation might be performed asynchronously if the translate |
66 // script is not yet available. | 66 // script is not yet available. |
67 void TranslatePage(const std::string& source_lang, | 67 void TranslatePage(const std::string& source_lang, |
68 const std::string& target_lang, | 68 const std::string& target_lang, |
69 bool triggered_from_menu); | 69 bool triggered_from_menu); |
70 | 70 |
| 71 // Starts the translation process for a page in the |page_lang| language. |
| 72 void InitiateTranslation(const std::string& page_lang); |
| 73 |
| 74 // Shows the after translate or error infobar depending on the details. |
| 75 void PageTranslated(const std::string& source_lang, |
| 76 const std::string& target_lang, |
| 77 TranslateErrors::Type error_type); |
| 78 |
71 // Reverts the contents of the page to its original language. | 79 // Reverts the contents of the page to its original language. |
72 void RevertTranslation(); | 80 void RevertTranslation(); |
73 | 81 |
74 // Reports to the Google translate server that a page language was incorrectly | 82 // Reports to the Google translate server that a page language was incorrectly |
75 // detected. This call is initiated by the user selecting the "report" menu | 83 // detected. This call is initiated by the user selecting the "report" menu |
76 // under options in the translate infobar. | 84 // under options in the translate infobar. |
77 void ReportLanguageDetectionError(); | 85 void ReportLanguageDetectionError(); |
78 | 86 |
79 // content::NotificationObserver implementation: | 87 // content::NotificationObserver implementation: |
80 virtual void Observe(int type, | 88 virtual void Observe(int type, |
81 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) OVERRIDE; | 90 const content::NotificationDetails& details) OVERRIDE; |
83 | 91 |
84 // Number of attempts before waiting for a page to be fully reloaded. | 92 // Number of attempts before waiting for a page to be fully reloaded. |
85 void set_translate_max_reload_attemps(int attempts) { | 93 void set_translate_max_reload_attemps(int attempts) { |
86 max_reload_check_attempts_ = attempts; | 94 max_reload_check_attempts_ = attempts; |
87 } | 95 } |
88 | 96 |
89 // Callback types for translate errors. | 97 // Callback types for translate errors. |
90 typedef base::Callback<void(const TranslateErrorDetails&)> | 98 typedef base::Callback<void(const TranslateErrorDetails&)> |
91 TranslateErrorCallback; | 99 TranslateErrorCallback; |
92 typedef base::CallbackList<void(const TranslateErrorDetails&)> | 100 typedef base::CallbackList<void(const TranslateErrorDetails&)> |
93 TranslateErrorCallbackList; | 101 TranslateErrorCallbackList; |
94 | 102 |
95 // Registers a callback for translate errors. | 103 // Registers a callback for translate errors. |
96 static scoped_ptr<TranslateErrorCallbackList::Subscription> | 104 static scoped_ptr<TranslateErrorCallbackList::Subscription> |
97 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); | 105 RegisterTranslateErrorCallback(const TranslateErrorCallback& callback); |
98 | 106 |
99 private: | 107 private: |
100 // Starts the translation process for a page in the |page_lang| language. | |
101 void InitiateTranslation(const std::string& page_lang); | |
102 | 108 |
103 // Initiates translation once the page is finished loading. | 109 // Initiates translation once the page is finished loading. |
104 void InitiateTranslationPosted(const std::string& page_lang, int attempt); | 110 void InitiateTranslationPosted(const std::string& page_lang, int attempt); |
105 | 111 |
106 // Sends a translation request to the RenderView. | 112 // Sends a translation request to the RenderView. |
107 void DoTranslatePage(const std::string& translate_script, | 113 void DoTranslatePage(const std::string& translate_script, |
108 const std::string& source_lang, | 114 const std::string& source_lang, |
109 const std::string& target_lang); | 115 const std::string& target_lang); |
110 | 116 |
111 // Shows the after translate or error infobar depending on the details. | |
112 void PageTranslated(PageTranslatedDetails* details); | |
113 | |
114 // Called when the Translate script has been fetched. | 117 // Called when the Translate script has been fetched. |
115 // Initiates the translation. | 118 // Initiates the translation. |
116 void OnTranslateScriptFetchComplete(int page_id, | 119 void OnTranslateScriptFetchComplete(int page_id, |
117 const std::string& source_lang, | 120 const std::string& source_lang, |
118 const std::string& target_lang, | 121 const std::string& target_lang, |
119 bool success, | 122 bool success, |
120 const std::string& data); | 123 const std::string& data); |
121 | 124 |
122 content::NotificationRegistrar notification_registrar_; | 125 content::NotificationRegistrar notification_registrar_; |
123 | 126 |
124 // Max number of attempts before checking if a page has been reloaded. | 127 // Max number of attempts before checking if a page has been reloaded. |
125 int max_reload_check_attempts_; | 128 int max_reload_check_attempts_; |
126 | 129 |
127 // Preference name for the Accept-Languages HTTP header. | 130 // Preference name for the Accept-Languages HTTP header. |
128 std::string accept_languages_pref_name_; | 131 std::string accept_languages_pref_name_; |
129 | 132 |
130 // TODO(droger): Remove all uses of |translate_tab_helper_|, use | 133 // TODO(droger): Remove all uses of |translate_tab_helper_|, use |
131 // TranslateClient and TranslateDriver instead. | 134 // TranslateClient and TranslateDriver instead. |
132 TranslateTabHelper* translate_tab_helper_; // Weak. | 135 TranslateTabHelper* translate_tab_helper_; // Weak. |
133 TranslateClient* translate_client_; // Weak. | 136 TranslateClient* translate_client_; // Weak. |
134 TranslateDriver* translate_driver_; // Weak. | 137 TranslateDriver* translate_driver_; // Weak. |
135 | 138 |
136 base::WeakPtrFactory<TranslateManager> weak_method_factory_; | 139 base::WeakPtrFactory<TranslateManager> weak_method_factory_; |
137 | 140 |
138 DISALLOW_COPY_AND_ASSIGN(TranslateManager); | 141 DISALLOW_COPY_AND_ASSIGN(TranslateManager); |
139 }; | 142 }; |
140 | 143 |
141 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ | 144 #endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_ |
OLD | NEW |