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 #import "ios/web_view/internal/translate/web_view_translate_client.h" | 5 #import "ios/web_view/internal/translate/web_view_translate_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "components/infobars/core/infobar.h" | 12 #include "components/infobars/core/infobar.h" |
| 13 #include "components/prefs/pref_service.h" | 13 #include "components/prefs/pref_service.h" |
| 14 #include "components/translate/core/browser/page_translated_details.h" | 14 #include "components/translate/core/browser/page_translated_details.h" |
| 15 #include "components/translate/core/browser/translate_accept_languages.h" | 15 #include "components/translate/core/browser/translate_accept_languages.h" |
| 16 #include "components/translate/core/browser/translate_infobar_delegate.h" | 16 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 17 #include "components/translate/core/browser/translate_manager.h" | 17 #include "components/translate/core/browser/translate_manager.h" |
| 18 #include "components/translate/core/browser/translate_prefs.h" | 18 #include "components/translate/core/browser/translate_prefs.h" |
| 19 #include "components/translate/core/browser/translate_step.h" | 19 #include "components/translate/core/browser/translate_step.h" |
| 20 #include "ios/web/public/browser_state.h" | 20 #include "ios/web/public/browser_state.h" |
| 21 #import "ios/web/public/web_state/web_state.h" | 21 #import "ios/web/public/web_state/web_state.h" |
| 22 #include "ios/web_view/internal/pref_names.h" | 22 #include "ios/web_view/internal/pref_names.h" |
| 23 #import "ios/web_view/internal/translate/cwv_translate_manager_impl.h" | 23 #import "ios/web_view/internal/translate/cwv_translate_manager_impl.h" |
| 24 #include "ios/web_view/internal/translate/web_view_translate_accept_languages_fa ctory.h" | 24 #include "ios/web_view/internal/translate/web_view_translate_accept_languages_fa ctory.h" |
| 25 #include "ios/web_view/internal/web_view_browser_state.h" | 25 #include "ios/web_view/internal/web_view_browser_state.h" |
| 26 #import "ios/web_view/public/cwv_translate_delegate.h" | 26 #import "ios/web_view/public/cwv_translate_delegate.h" |
| 27 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 28 | 28 |
| 29 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 30 #error "This file requires ARC support." | |
| 31 #endif | |
| 32 | |
| 29 DEFINE_WEB_STATE_USER_DATA_KEY(ios_web_view::WebViewTranslateClient); | 33 DEFINE_WEB_STATE_USER_DATA_KEY(ios_web_view::WebViewTranslateClient); |
| 30 | 34 |
| 31 namespace ios_web_view { | 35 namespace ios_web_view { |
| 32 | 36 |
| 33 WebViewTranslateClient::WebViewTranslateClient(web::WebState* web_state) | 37 WebViewTranslateClient::WebViewTranslateClient(web::WebState* web_state) |
| 34 : web::WebStateObserver(web_state), | 38 : web::WebStateObserver(web_state), |
| 35 translate_manager_(base::MakeUnique<translate::TranslateManager>( | 39 translate_manager_(base::MakeUnique<translate::TranslateManager>( |
| 36 this, | 40 this, |
| 37 prefs::kAcceptLanguages)), | 41 prefs::kAcceptLanguages)), |
| 38 translate_driver_(web_state, | 42 translate_driver_(web_state, |
| 39 web_state->GetNavigationManager(), | 43 web_state->GetNavigationManager(), |
| 40 translate_manager_.get()) {} | 44 translate_manager_.get()), |
| 45 delegate_(nil) {} | |
|
michaeldo
2017/03/21 16:29:18
please fix closing paren location and format to li
Hiroshi Ichikawa
2017/03/22 01:32:16
Removed after switching to WeakNSProtocol.
| |
| 41 | 46 |
| 42 WebViewTranslateClient::~WebViewTranslateClient() = default; | 47 WebViewTranslateClient::~WebViewTranslateClient() = default; |
| 43 | 48 |
| 44 // TranslateClient implementation: | 49 // TranslateClient implementation: |
| 45 | 50 |
| 46 std::unique_ptr<infobars::InfoBar> WebViewTranslateClient::CreateInfoBar( | 51 std::unique_ptr<infobars::InfoBar> WebViewTranslateClient::CreateInfoBar( |
| 47 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate) const { | 52 std::unique_ptr<translate::TranslateInfoBarDelegate> delegate) const { |
| 48 NOTREACHED(); | 53 NOTREACHED(); |
| 49 return nullptr; | 54 return nullptr; |
| 50 } | 55 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 143 } |
| 139 | 144 |
| 140 void WebViewTranslateClient::WebStateDestroyed() { | 145 void WebViewTranslateClient::WebStateDestroyed() { |
| 141 // Translation process can be interrupted. | 146 // Translation process can be interrupted. |
| 142 // Destroying the TranslateManager now guarantees that it never has to deal | 147 // Destroying the TranslateManager now guarantees that it never has to deal |
| 143 // with nullptr WebState. | 148 // with nullptr WebState. |
| 144 translate_manager_.reset(); | 149 translate_manager_.reset(); |
| 145 } | 150 } |
| 146 | 151 |
| 147 } // namespace ios_web_view | 152 } // namespace ios_web_view |
| OLD | NEW |