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 COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 5 #ifndef COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ |
6 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 6 #define COMPONENTS_TRANSLATE_CONTENT_RENDERER_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" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // We use histograms for recording these metrics. On Android, the renderer can | 76 // We use histograms for recording these metrics. On Android, the renderer can |
77 // be killed without the chance to clean up or transmit these histograms, | 77 // be killed without the chance to clean up or transmit these histograms, |
78 // leading to dropped metrics. To work around this, this method forces an IPC | 78 // leading to dropped metrics. To work around this, this method forces an IPC |
79 // message to be sent to the browser process immediately. | 79 // message to be sent to the browser process immediately. |
80 class TranslateHelper : public content::RenderViewObserver { | 80 class TranslateHelper : public content::RenderViewObserver { |
81 public: | 81 public: |
82 explicit TranslateHelper(content::RenderView* render_view, | 82 explicit TranslateHelper(content::RenderView* render_view, |
83 int world_id, | 83 int world_id, |
84 int extension_group, | 84 int extension_group, |
85 const std::string& extension_scheme); | 85 const std::string& extension_scheme); |
86 virtual ~TranslateHelper(); | 86 ~TranslateHelper() override; |
87 | 87 |
88 // Informs us that the page's text has been extracted. | 88 // Informs us that the page's text has been extracted. |
89 void PageCaptured(const base::string16& contents); | 89 void PageCaptured(const base::string16& contents); |
90 | 90 |
91 // Lets the translation system know that we are preparing to navigate to | 91 // Lets the translation system know that we are preparing to navigate to |
92 // the specified URL. If there is anything that can or should be done before | 92 // the specified URL. If there is anything that can or should be done before |
93 // this URL loads, this is the time to prepare for it. | 93 // this URL loads, this is the time to prepare for it. |
94 void PrepareForUrl(const GURL& url); | 94 void PrepareForUrl(const GURL& url); |
95 | 95 |
96 protected: | 96 protected: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 // Converts language code to the one used in server supporting list. | 174 // Converts language code to the one used in server supporting list. |
175 static void ConvertLanguageCodeSynonym(std::string* code); | 175 static void ConvertLanguageCodeSynonym(std::string* code); |
176 | 176 |
177 // Returns whether the page associated with |document| is a candidate for | 177 // Returns whether the page associated with |document| is a candidate for |
178 // translation. Some pages can explictly specify (via a meta-tag) that they | 178 // translation. Some pages can explictly specify (via a meta-tag) that they |
179 // should not be translated. | 179 // should not be translated. |
180 static bool IsTranslationAllowed(blink::WebDocument* document); | 180 static bool IsTranslationAllowed(blink::WebDocument* document); |
181 | 181 |
182 // RenderViewObserver implementation. | 182 // RenderViewObserver implementation. |
183 virtual bool OnMessageReceived(const IPC::Message& message) override; | 183 bool OnMessageReceived(const IPC::Message& message) override; |
184 | 184 |
185 // Informs us that the page's text has been extracted. | 185 // Informs us that the page's text has been extracted. |
186 void PageCapturedImpl(int page_seq_no, const base::string16& contents); | 186 void PageCapturedImpl(int page_seq_no, const base::string16& contents); |
187 | 187 |
188 // Cancels any translation that is currently being performed. This does not | 188 // Cancels any translation that is currently being performed. This does not |
189 // revert existing translations. | 189 // revert existing translations. |
190 void CancelPendingTranslation(); | 190 void CancelPendingTranslation(); |
191 | 191 |
192 // Checks if the current running page translation is finished or errored and | 192 // Checks if the current running page translation is finished or errored and |
193 // notifies the browser accordingly. If the translation has not terminated, | 193 // notifies the browser accordingly. If the translation has not terminated, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 275 |
276 // Method factory used to make calls to TranslatePageImpl. | 276 // Method factory used to make calls to TranslatePageImpl. |
277 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 277 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |
278 | 278 |
279 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 279 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); |
280 }; | 280 }; |
281 | 281 |
282 } // namespace translate | 282 } // namespace translate |
283 | 283 |
284 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 284 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ |
OLD | NEW |