| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Returns true if the translate library has been initialized successfully. | 57 // Returns true if the translate library has been initialized successfully. |
| 58 virtual bool IsTranslateLibReady(); | 58 virtual bool IsTranslateLibReady(); |
| 59 | 59 |
| 60 // Returns true if the translation script has finished translating the page. | 60 // Returns true if the translation script has finished translating the page. |
| 61 virtual bool HasTranslationFinished(); | 61 virtual bool HasTranslationFinished(); |
| 62 | 62 |
| 63 // Returns true if the translation script has reported an error performing the | 63 // Returns true if the translation script has reported an error performing the |
| 64 // translation. | 64 // translation. |
| 65 virtual bool HasTranslationFailed(); | 65 virtual bool HasTranslationFailed(); |
| 66 | 66 |
| 67 // Returns the error code generated in translate library if there was an |
| 68 // error. Otherwise, returns |fallback| value. |
| 69 virtual int64_t GetErrorCodeWithFallback(TranslateErrors::Type fallback); |
| 70 |
| 67 // Starts the translation by calling the translate library. This method | 71 // Starts the translation by calling the translate library. This method |
| 68 // 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 |
| 69 // page. Returns false if the call failed immediately. | 73 // page. Returns false if the call failed immediately. |
| 70 virtual bool StartTranslation(); | 74 virtual bool StartTranslation(); |
| 71 | 75 |
| 72 // 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. |
| 73 // 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. |
| 74 // Returns the language code on success, an empty string on failure. | 78 // Returns the language code on success, an empty string on failure. |
| 75 virtual std::string GetOriginalPageLanguage(); | 79 virtual std::string GetOriginalPageLanguage(); |
| 76 | 80 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 91 // 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 |
| 92 // run successfully. Otherwise, returns empty string. | 96 // run successfully. Otherwise, returns empty string. |
| 93 virtual std::string ExecuteScriptAndGetStringResult( | 97 virtual std::string ExecuteScriptAndGetStringResult( |
| 94 const std::string& script); | 98 const std::string& script); |
| 95 | 99 |
| 96 // 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. |
| 97 // 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 |
| 98 // run successfully. Otherwise, returns 0.0. | 102 // run successfully. Otherwise, returns 0.0. |
| 99 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); | 103 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); |
| 100 | 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 |fallback| value. |
| 108 virtual int64_t ExecuteScriptAndGetIntegerResult(const std::string& script, |
| 109 int64_t fallback); |
| 110 |
| 101 private: | 111 private: |
| 102 // Converts language code to the one used in server supporting list. | 112 // Converts language code to the one used in server supporting list. |
| 103 static void ConvertLanguageCodeSynonym(std::string* code); | 113 static void ConvertLanguageCodeSynonym(std::string* code); |
| 104 | 114 |
| 105 const mojom::ContentTranslateDriverPtr& GetTranslateDriver(); | 115 const mojom::ContentTranslateDriverPtr& GetTranslateDriver(); |
| 106 | 116 |
| 107 // Cleanups all states and pending callbacks associated with the current | 117 // Cleanups all states and pending callbacks associated with the current |
| 108 // running page translation. | 118 // running page translation. |
| 109 void ResetPage(); | 119 void ResetPage(); |
| 110 | 120 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 163 |
| 154 // Method factory used to make calls to TranslatePageImpl. | 164 // Method factory used to make calls to TranslatePageImpl. |
| 155 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 165 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |
| 156 | 166 |
| 157 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 167 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); |
| 158 }; | 168 }; |
| 159 | 169 |
| 160 } // namespace translate | 170 } // namespace translate |
| 161 | 171 |
| 162 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 172 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ |
| OLD | NEW |