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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Returns true if the translate library has been initialized successfully. | 58 // Returns true if the translate library has been initialized successfully. |
59 virtual bool IsTranslateLibReady(); | 59 virtual bool IsTranslateLibReady(); |
60 | 60 |
61 // Returns true if the translation script has finished translating the page. | 61 // Returns true if the translation script has finished translating the page. |
62 virtual bool HasTranslationFinished(); | 62 virtual bool HasTranslationFinished(); |
63 | 63 |
64 // Returns true if the translation script has reported an error performing the | 64 // Returns true if the translation script has reported an error performing the |
65 // translation. | 65 // translation. |
66 virtual bool HasTranslationFailed(); | 66 virtual bool HasTranslationFailed(); |
67 | 67 |
| 68 // Returns the error code generated in translate library. |
| 69 virtual int64_t GetErrorCode(); |
| 70 |
68 // Starts the translation by calling the translate library. This method | 71 // Starts the translation by calling the translate library. This method |
69 // should only be called when the translate script has been injected in the | 72 // should only be called when the translate script has been injected in the |
70 // page. Returns false if the call failed immediately. | 73 // page. Returns false if the call failed immediately. |
71 virtual bool StartTranslation(); | 74 virtual bool StartTranslation(); |
72 | 75 |
73 // Asks the Translate element in the page what the language of the page is. | 76 // Asks the Translate element in the page what the language of the page is. |
74 // Can only be called if a translation has happened and was successful. | 77 // Can only be called if a translation has happened and was successful. |
75 // Returns the language code on success, an empty string on failure. | 78 // Returns the language code on success, an empty string on failure. |
76 virtual std::string GetOriginalPageLanguage(); | 79 virtual std::string GetOriginalPageLanguage(); |
77 | 80 |
(...skipping 14 matching lines...) Expand all Loading... |
92 // and returns the string returned by the script evaluation if the script was | 95 // and returns the string returned by the script evaluation if the script was |
93 // run successfully. Otherwise, returns empty string. | 96 // run successfully. Otherwise, returns empty string. |
94 virtual std::string ExecuteScriptAndGetStringResult( | 97 virtual std::string ExecuteScriptAndGetStringResult( |
95 const std::string& script); | 98 const std::string& script); |
96 | 99 |
97 // Executes the JavaScript code in |script| in the main frame of RenderView. | 100 // Executes the JavaScript code in |script| in the main frame of RenderView. |
98 // and returns the number returned by the script evaluation if the script was | 101 // and returns the number returned by the script evaluation if the script was |
99 // run successfully. Otherwise, returns 0.0. | 102 // run successfully. Otherwise, returns 0.0. |
100 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); | 103 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); |
101 | 104 |
| 105 // Executes the JavaScript code in |script| in the main frame of RenderView. |
| 106 // and returns the integer value returned by the script evaluation if the |
| 107 // script was run successfully. Otherwise, returns 0. |
| 108 virtual int64_t ExecuteScriptAndGetIntegerResult(const std::string& script); |
| 109 |
102 private: | 110 private: |
103 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, TestBuildTranslationScript); | 111 FRIEND_TEST_ALL_PREFIXES(TranslateHelperTest, TestBuildTranslationScript); |
104 | 112 |
105 // Converts language code to the one used in server supporting list. | 113 // Converts language code to the one used in server supporting list. |
106 static void ConvertLanguageCodeSynonym(std::string* code); | 114 static void ConvertLanguageCodeSynonym(std::string* code); |
107 | 115 |
108 // Builds the translation JS used to translate from source_lang to | 116 // Builds the translation JS used to translate from source_lang to |
109 // target_lang. | 117 // target_lang. |
110 static std::string BuildTranslationScript(const std::string& source_lang, | 118 static std::string BuildTranslationScript(const std::string& source_lang, |
111 const std::string& target_lang); | 119 const std::string& target_lang); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 169 |
162 // Method factory used to make calls to TranslatePageImpl. | 170 // Method factory used to make calls to TranslatePageImpl. |
163 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 171 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |
164 | 172 |
165 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 173 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); |
166 }; | 174 }; |
167 | 175 |
168 } // namespace translate | 176 } // namespace translate |
169 | 177 |
170 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 178 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ |
OLD | NEW |