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/criwv_translate_client.h" | 5 #import "ios/web_view/internal/translate/criwv_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/criwv_browser_state.h" | 22 #include "ios/web_view/internal/criwv_browser_state.h" |
23 #include "ios/web_view/internal/pref_names.h" | 23 #include "ios/web_view/internal/pref_names.h" |
24 #include "ios/web_view/internal/translate/criwv_translate_accept_languages_facto
ry.h" | 24 #include "ios/web_view/internal/translate/criwv_translate_accept_languages_facto
ry.h" |
25 #import "ios/web_view/internal/translate/criwv_translate_manager_impl.h" | 25 #import "ios/web_view/internal/translate/criwv_translate_manager_impl.h" |
| 26 #include "ios/web_view/internal/translate/criwv_translate_ranker_factory.h" |
26 #import "ios/web_view/public/cwv_translate_delegate.h" | 27 #import "ios/web_view/public/cwv_translate_delegate.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 DEFINE_WEB_STATE_USER_DATA_KEY(ios_web_view::CRIWVTranslateClient); | 30 DEFINE_WEB_STATE_USER_DATA_KEY(ios_web_view::CRIWVTranslateClient); |
30 | 31 |
31 namespace ios_web_view { | 32 namespace ios_web_view { |
32 | 33 |
33 CRIWVTranslateClient::CRIWVTranslateClient(web::WebState* web_state) | 34 CRIWVTranslateClient::CRIWVTranslateClient(web::WebState* web_state) |
34 : web::WebStateObserver(web_state), | 35 : web::WebStateObserver(web_state), |
35 translate_manager_(base::MakeUnique<translate::TranslateManager>( | 36 translate_manager_(base::MakeUnique<translate::TranslateManager>( |
36 this, | 37 this, |
| 38 CRIWVTranslateRankerFactory::GetInstance()->GetForBrowserState( |
| 39 CRIWVBrowserState::FromBrowserState( |
| 40 web_state->GetBrowserState())), |
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()) {} |
41 | 45 |
42 CRIWVTranslateClient::~CRIWVTranslateClient() {} | 46 CRIWVTranslateClient::~CRIWVTranslateClient() {} |
43 | 47 |
44 // TranslateClient implementation: | 48 // TranslateClient implementation: |
45 | 49 |
46 std::unique_ptr<infobars::InfoBar> CRIWVTranslateClient::CreateInfoBar( | 50 std::unique_ptr<infobars::InfoBar> CRIWVTranslateClient::CreateInfoBar( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 141 } |
138 | 142 |
139 void CRIWVTranslateClient::WebStateDestroyed() { | 143 void CRIWVTranslateClient::WebStateDestroyed() { |
140 // Translation process can be interrupted. | 144 // Translation process can be interrupted. |
141 // Destroying the TranslateManager now guarantees that it never has to deal | 145 // Destroying the TranslateManager now guarantees that it never has to deal |
142 // with nullptr WebState. | 146 // with nullptr WebState. |
143 translate_manager_.reset(); | 147 translate_manager_.reset(); |
144 } | 148 } |
145 | 149 |
146 } // namespace ios_web_view | 150 } // namespace ios_web_view |
OLD | NEW |