OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ | 5 #ifndef CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ |
6 #define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ | 6 #define CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/common/translate/translate_errors.h" | 13 #include "chrome/common/translate/translate_errors.h" |
14 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
15 | 15 |
16 namespace WebKit { | 16 namespace blink { |
17 class WebDocument; | 17 class WebDocument; |
18 class WebFrame; | 18 class WebFrame; |
19 } | 19 } |
20 | 20 |
21 // This class deals with page translation. | 21 // This class deals with page translation. |
22 // There is one TranslateHelper per RenderView. | 22 // There is one TranslateHelper per RenderView. |
23 | 23 |
24 class TranslateHelper : public content::RenderViewObserver { | 24 class TranslateHelper : public content::RenderViewObserver { |
25 public: | 25 public: |
26 explicit TranslateHelper(content::RenderView* render_view); | 26 explicit TranslateHelper(content::RenderView* render_view); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, ResetInvalidLanguageCode); | 99 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, ResetInvalidLanguageCode); |
100 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, SimilarLanguageCode); | 100 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, SimilarLanguageCode); |
101 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, WellKnownWrongConfiguration); | 101 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, WellKnownWrongConfiguration); |
102 | 102 |
103 // Converts language code to the one used in server supporting list. | 103 // Converts language code to the one used in server supporting list. |
104 static void ConvertLanguageCodeSynonym(std::string* code); | 104 static void ConvertLanguageCodeSynonym(std::string* code); |
105 | 105 |
106 // Returns whether the page associated with |document| is a candidate for | 106 // Returns whether the page associated with |document| is a candidate for |
107 // translation. Some pages can explictly specify (via a meta-tag) that they | 107 // translation. Some pages can explictly specify (via a meta-tag) that they |
108 // should not be translated. | 108 // should not be translated. |
109 static bool IsTranslationAllowed(WebKit::WebDocument* document); | 109 static bool IsTranslationAllowed(blink::WebDocument* document); |
110 | 110 |
111 // RenderViewObserver implementation. | 111 // RenderViewObserver implementation. |
112 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 112 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
113 | 113 |
114 // Cancels any translation that is currently being performed. This does not | 114 // Cancels any translation that is currently being performed. This does not |
115 // revert existing translations. | 115 // revert existing translations. |
116 void CancelPendingTranslation(); | 116 void CancelPendingTranslation(); |
117 | 117 |
118 // Checks if the current running page translation is finished or errored and | 118 // Checks if the current running page translation is finished or errored and |
119 // notifies the browser accordingly. If the translation has not terminated, | 119 // notifies the browser accordingly. If the translation has not terminated, |
120 // posts a task to check again later. | 120 // posts a task to check again later. |
121 void CheckTranslateStatus(); | 121 void CheckTranslateStatus(); |
122 | 122 |
123 // Called by TranslatePage to do the actual translation. |count| is used to | 123 // Called by TranslatePage to do the actual translation. |count| is used to |
124 // limit the number of retries. | 124 // limit the number of retries. |
125 void TranslatePageImpl(int count); | 125 void TranslatePageImpl(int count); |
126 | 126 |
127 // Sends a message to the browser to notify it that the translation failed | 127 // Sends a message to the browser to notify it that the translation failed |
128 // with |error|. | 128 // with |error|. |
129 void NotifyBrowserTranslationFailed(TranslateErrors::Type error); | 129 void NotifyBrowserTranslationFailed(TranslateErrors::Type error); |
130 | 130 |
131 // Convenience method to access the main frame. Can return NULL, typically | 131 // Convenience method to access the main frame. Can return NULL, typically |
132 // if the page is being closed. | 132 // if the page is being closed. |
133 WebKit::WebFrame* GetMainFrame(); | 133 blink::WebFrame* GetMainFrame(); |
134 | 134 |
135 // ID to represent a page which TranslateHelper captured and determined a | 135 // ID to represent a page which TranslateHelper captured and determined a |
136 // content language. | 136 // content language. |
137 int page_id_; | 137 int page_id_; |
138 | 138 |
139 // The states associated with the current translation. | 139 // The states associated with the current translation. |
140 bool translation_pending_; | 140 bool translation_pending_; |
141 std::string source_lang_; | 141 std::string source_lang_; |
142 std::string target_lang_; | 142 std::string target_lang_; |
143 | 143 |
144 // Time when a page langauge is determined. This is used to know a duration | 144 // Time when a page langauge is determined. This is used to know a duration |
145 // time from showing infobar to requesting translation. | 145 // time from showing infobar to requesting translation. |
146 base::TimeTicks language_determined_time_; | 146 base::TimeTicks language_determined_time_; |
147 | 147 |
148 // Method factory used to make calls to TranslatePageImpl. | 148 // Method factory used to make calls to TranslatePageImpl. |
149 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 149 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 151 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); |
152 }; | 152 }; |
153 | 153 |
154 #endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ | 154 #endif // CHROME_RENDERER_TRANSLATE_TRANSLATE_HELPER_H_ |
OLD | NEW |