Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ | 5 #ifndef IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ |
| 6 #define IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ | 6 #define IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #import "base/ios/weak_nsobject.h" | 11 #import "base/ios/weak_nsobject.h" |
| 12 #include "components/translate/core/browser/translate_client.h" | 12 #include "components/translate/core/browser/translate_client.h" |
| 13 #include "components/translate/core/browser/translate_step.h" | 13 #include "components/translate/core/browser/translate_step.h" |
| 14 #include "components/translate/core/common/translate_errors.h" | 14 #include "components/translate/core/common/translate_errors.h" |
| 15 #import "components/translate/ios/browser/ios_translate_driver.h" | 15 #import "components/translate/ios/browser/ios_translate_driver.h" |
| 16 #include "ios/web/public/web_state/web_state_observer.h" | 16 #include "ios/web/public/web_state/web_state_observer.h" |
| 17 #import "ios/web/public/web_state/web_state_user_data.h" | 17 #import "ios/web/public/web_state/web_state_user_data.h" |
| 18 #import "ios/web_view/public/cwv_translate_delegate.h" | |
| 19 | 18 |
| 20 class PrefService; | 19 class PrefService; |
| 21 | 20 |
| 22 namespace translate { | 21 namespace translate { |
| 23 class TranslateAcceptLanguages; | 22 class TranslateAcceptLanguages; |
| 24 class TranslatePrefs; | 23 class TranslatePrefs; |
| 25 class TranslateManager; | 24 class TranslateManager; |
| 26 } // namespace translate | 25 } // namespace translate |
| 27 | 26 |
| 28 namespace web { | 27 namespace web { |
| 29 class WebState; | 28 class WebState; |
| 30 } | 29 } |
| 31 | 30 |
| 31 @class CWVTranslationController; | |
| 32 | |
| 32 namespace ios_web_view { | 33 namespace ios_web_view { |
| 33 | 34 |
| 34 class WebViewTranslateClient | 35 class WebViewTranslateClient |
| 35 : public translate::TranslateClient, | 36 : public translate::TranslateClient, |
| 36 public web::WebStateObserver, | 37 public web::WebStateObserver, |
| 37 public web::WebStateUserData<WebViewTranslateClient> { | 38 public web::WebStateUserData<WebViewTranslateClient> { |
| 38 public: | 39 public: |
| 39 // Sets the delegate passed by the embedder. | 40 void set_cwv_translation_controller(CWVTranslationController* controller) { |
| 40 // |delegate| is assumed to outlive this WebViewTranslateClient. | 41 cwv_translation_controller_.reset(controller); |
| 41 void set_translate_delegate(id<CWVTranslateDelegate> delegate) { | 42 } |
| 42 delegate_.reset(delegate); | 43 |
| 44 translate::TranslateManager* GetTranslateManager() { | |
|
Eugene But (OOO till 7-30)
2017/04/28 03:07:29
Please be consistent with naming style GetTranslat
jzw1
2017/04/28 05:43:36
Done.
| |
| 45 return translate_manager_.get(); | |
| 43 } | 46 } |
| 44 | 47 |
| 45 private: | 48 private: |
| 46 friend class web::WebStateUserData<WebViewTranslateClient>; | 49 friend class web::WebStateUserData<WebViewTranslateClient>; |
| 47 | 50 |
| 48 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. | 51 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. |
| 49 explicit WebViewTranslateClient(web::WebState* web_state); | 52 explicit WebViewTranslateClient(web::WebState* web_state); |
| 50 ~WebViewTranslateClient() override; | 53 ~WebViewTranslateClient() override; |
| 51 | 54 |
| 52 // TranslateClient implementation. | 55 // TranslateClient implementation. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 65 bool triggered_from_menu) override; | 68 bool triggered_from_menu) override; |
| 66 bool IsTranslatableURL(const GURL& url) override; | 69 bool IsTranslatableURL(const GURL& url) override; |
| 67 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; | 70 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; |
| 68 | 71 |
| 69 // web::WebStateObserver implementation. | 72 // web::WebStateObserver implementation. |
| 70 void WebStateDestroyed() override; | 73 void WebStateDestroyed() override; |
| 71 | 74 |
| 72 std::unique_ptr<translate::TranslateManager> translate_manager_; | 75 std::unique_ptr<translate::TranslateManager> translate_manager_; |
| 73 translate::IOSTranslateDriver translate_driver_; | 76 translate::IOSTranslateDriver translate_driver_; |
| 74 | 77 |
| 75 // Delegate provided by the embedder. | 78 base::WeakNSObject<CWVTranslationController> cwv_translation_controller_; |
|
Eugene But (OOO till 7-30)
2017/04/28 03:07:29
cwv_ prefix is unnecessary
jzw1
2017/04/28 05:43:36
Done.
| |
| 76 base::WeakNSProtocol<id<CWVTranslateDelegate>> delegate_; | |
| 77 | 79 |
| 78 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); | 80 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); |
| 79 }; | 81 }; |
| 80 | 82 |
| 81 } // namespace ios_web_view | 83 } // namespace ios_web_view |
| 82 | 84 |
| 83 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ | 85 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ |
| OLD | NEW |