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" | 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 // Sets the delegate passed by the embedder. | 40 // This |controller| will outlive this class. |
|
michaeldo
2017/05/08 15:15:48
Keeping the original wording seems clearer to me:
jzw1
2017/05/09 00:47:20
Done.
| |
| 40 // |delegate| is assumed to outlive this WebViewTranslateClient. | 41 void set_translation_controller(CWVTranslationController* controller) { |
| 41 void set_translate_delegate(id<CWVTranslateDelegate> delegate) { | 42 translation_controller_.reset(controller); |
| 42 delegate_.reset(delegate); | 43 } |
| 44 | |
| 45 translate::TranslateManager* translate_manager() { | |
| 46 return translate_manager_.get(); | |
| 43 } | 47 } |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 friend class web::WebStateUserData<WebViewTranslateClient>; | 50 friend class web::WebStateUserData<WebViewTranslateClient>; |
| 47 | 51 |
| 48 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. | 52 // The lifetime of WebViewTranslateClient is managed by WebStateUserData. |
| 49 explicit WebViewTranslateClient(web::WebState* web_state); | 53 explicit WebViewTranslateClient(web::WebState* web_state); |
| 50 ~WebViewTranslateClient() override; | 54 ~WebViewTranslateClient() override; |
| 51 | 55 |
| 52 // TranslateClient implementation. | 56 // TranslateClient implementation. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 65 bool triggered_from_menu) override; | 69 bool triggered_from_menu) override; |
| 66 bool IsTranslatableURL(const GURL& url) override; | 70 bool IsTranslatableURL(const GURL& url) override; |
| 67 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; | 71 void ShowReportLanguageDetectionErrorUI(const GURL& report_url) override; |
| 68 | 72 |
| 69 // web::WebStateObserver implementation. | 73 // web::WebStateObserver implementation. |
| 70 void WebStateDestroyed() override; | 74 void WebStateDestroyed() override; |
| 71 | 75 |
| 72 std::unique_ptr<translate::TranslateManager> translate_manager_; | 76 std::unique_ptr<translate::TranslateManager> translate_manager_; |
| 73 translate::IOSTranslateDriver translate_driver_; | 77 translate::IOSTranslateDriver translate_driver_; |
| 74 | 78 |
| 75 // Delegate provided by the embedder. | 79 // ObjC class that wraps this class. |
| 76 base::WeakNSProtocol<id<CWVTranslateDelegate>> delegate_; | 80 base::WeakNSObject<CWVTranslationController> translation_controller_; |
| 77 | 81 |
| 78 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); | 82 DISALLOW_COPY_AND_ASSIGN(WebViewTranslateClient); |
| 79 }; | 83 }; |
| 80 | 84 |
| 81 } // namespace ios_web_view | 85 } // namespace ios_web_view |
| 82 | 86 |
| 83 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ | 87 #endif // IOS_WEB_VIEW_INTERNAL_TRANSLATE_WEB_VIEW_TRANSLATE_CLIENT_H_ |
| OLD | NEW |