| 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" | 18 |
| 19 @class CWVTranslationController; |
| 19 | 20 |
| 20 class PrefService; | 21 class PrefService; |
| 21 | 22 |
| 22 namespace translate { | 23 namespace translate { |
| 23 class TranslateAcceptLanguages; | 24 class TranslateAcceptLanguages; |
| 24 class TranslatePrefs; | 25 class TranslatePrefs; |
| 25 class TranslateManager; | 26 class TranslateManager; |
| 26 } // namespace translate | 27 } // namespace translate |
| 27 | 28 |
| 28 namespace web { | 29 namespace web { |
| 29 class WebState; | 30 class WebState; |
| 30 } | 31 } |
| 31 | 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 ~WebViewTranslateClient() override; | 40 ~WebViewTranslateClient() override; |
| 40 | 41 |
| 41 // Sets the delegate passed by the embedder. | 42 // This |controller| is assumed to outlive this WebViewTranslateClient. |
| 42 // |delegate| is assumed to outlive this WebViewTranslateClient. | 43 void set_translation_controller(CWVTranslationController* controller) { |
| 43 void set_translate_delegate(id<CWVTranslateDelegate> delegate) { | 44 translation_controller_.reset(controller); |
| 44 delegate_.reset(delegate); | 45 } |
| 46 |
| 47 translate::TranslateManager* translate_manager() { |
| 48 return translate_manager_.get(); |
| 45 } | 49 } |
| 46 | 50 |
| 47 private: | 51 private: |
| 48 friend class web::WebStateUserData<WebViewTranslateClient>; | 52 friend class web::WebStateUserData<WebViewTranslateClient>; |
| 49 | 53 |
| 50 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. | 54 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. |
| 51 explicit WebViewTranslateClient(web::WebState* web_state); | 55 explicit WebViewTranslateClient(web::WebState* web_state); |
| 52 | 56 |
| 53 // TranslateClient implementation. | 57 // TranslateClient implementation. |
| 54 translate::TranslateDriver* GetTranslateDriver() override; | 58 translate::TranslateDriver* GetTranslateDriver() override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 bool triggered_from_menu) override; | 70 bool triggered_from_menu) override; |
| 67 bool IsTranslatableURL(const GURL& url) override; | 71 bool IsTranslatableURL(const GURL& url) override; |
| 68 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; | 72 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; |
| 69 | 73 |
| 70 // web::WebStateObserver implementation. | 74 // web::WebStateObserver implementation. |
| 71 void WebStateDestroyed() override; | 75 void WebStateDestroyed() override; |
| 72 | 76 |
| 73 std::unique_ptr<translate::TranslateManager> translate_manager_; | 77 std::unique_ptr<translate::TranslateManager> translate_manager_; |
| 74 translate::IOSTranslateDriver translate_driver_; | 78 translate::IOSTranslateDriver translate_driver_; |
| 75 | 79 |
| 76 // Delegate provided by the embedder. | 80 // ObjC class that wraps this class. |
| 77 base::WeakNSProtocol<id<CWVTranslateDelegate>> delegate_; | 81 base::WeakNSObject<CWVTranslationController> translation_controller_; |
| 78 | 82 |
| 79 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); | 83 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); |
| 80 }; | 84 }; |
| 81 | 85 |
| 82 } // namespace ios_web_view | 86 } // namespace ios_web_view |
| 83 | 87 |
| 84 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ | 88 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ |
| OLD | NEW |