Chromium Code Reviews| 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. | |
| 68 virtual int64_t GetErrorCode(); | |
|
napper
2017/06/16 12:41:51
Can this method (and the one below) be const?
Takashi Toyoshima
2017/06/16 16:14:17
IMHO, the method causes a side effect should not b
| |
| 69 | |
| 67 // Starts the translation by calling the translate library. This method | 70 // Starts the translation by calling the translate library. This method |
| 68 // should only be called when the translate script has been injected in the | 71 // should only be called when the translate script has been injected in the |
| 69 // page. Returns false if the call failed immediately. | 72 // page. Returns false if the call failed immediately. |
| 70 virtual bool StartTranslation(); | 73 virtual bool StartTranslation(); |
| 71 | 74 |
| 72 // Asks the Translate element in the page what the language of the page is. | 75 // 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. | 76 // Can only be called if a translation has happened and was successful. |
| 74 // Returns the language code on success, an empty string on failure. | 77 // Returns the language code on success, an empty string on failure. |
| 75 virtual std::string GetOriginalPageLanguage(); | 78 virtual std::string GetOriginalPageLanguage(); |
| 76 | 79 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 91 // and returns the string returned by the script evaluation if the script was | 94 // and returns the string returned by the script evaluation if the script was |
| 92 // run successfully. Otherwise, returns empty string. | 95 // run successfully. Otherwise, returns empty string. |
| 93 virtual std::string ExecuteScriptAndGetStringResult( | 96 virtual std::string ExecuteScriptAndGetStringResult( |
| 94 const std::string& script); | 97 const std::string& script); |
| 95 | 98 |
| 96 // Executes the JavaScript code in |script| in the main frame of RenderView. | 99 // 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 | 100 // and returns the number returned by the script evaluation if the script was |
| 98 // run successfully. Otherwise, returns 0.0. | 101 // run successfully. Otherwise, returns 0.0. |
| 99 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); | 102 virtual double ExecuteScriptAndGetDoubleResult(const std::string& script); |
| 100 | 103 |
| 104 // Executes the JavaScript code in |script| in the main frame of RenderView. | |
| 105 // and returns the integer value returned by the script evaluation if the | |
| 106 // script was run successfully. Otherwise, returns |fallback| value. | |
| 107 virtual int64_t ExecuteScriptAndGetIntegerResult(const std::string& script, | |
| 108 int64_t fallback); | |
| 109 | |
| 101 private: | 110 private: |
| 102 // Converts language code to the one used in server supporting list. | 111 // Converts language code to the one used in server supporting list. |
| 103 static void ConvertLanguageCodeSynonym(std::string* code); | 112 static void ConvertLanguageCodeSynonym(std::string* code); |
| 104 | 113 |
| 105 const mojom::ContentTranslateDriverPtr& GetTranslateDriver(); | 114 const mojom::ContentTranslateDriverPtr& GetTranslateDriver(); |
| 106 | 115 |
| 107 // Cleanups all states and pending callbacks associated with the current | 116 // Cleanups all states and pending callbacks associated with the current |
| 108 // running page translation. | 117 // running page translation. |
| 109 void ResetPage(); | 118 void ResetPage(); |
| 110 | 119 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 | 162 |
| 154 // Method factory used to make calls to TranslatePageImpl. | 163 // Method factory used to make calls to TranslatePageImpl. |
| 155 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; | 164 base::WeakPtrFactory<TranslateHelper> weak_method_factory_; |
| 156 | 165 |
| 157 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); | 166 DISALLOW_COPY_AND_ASSIGN(TranslateHelper); |
| 158 }; | 167 }; |
| 159 | 168 |
| 160 } // namespace translate | 169 } // namespace translate |
| 161 | 170 |
| 162 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ | 171 #endif // COMPONENTS_TRANSLATE_CONTENT_RENDERER_TRANSLATE_HELPER_H_ |
| OLD | NEW |