| 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 #include "chrome/browser/translate/chrome_translate_client.h" | 5 #include "chrome/browser/translate/chrome_translate_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 15 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/translate/translate_accept_languages_factory.h" | 17 #include "chrome/browser/translate/translate_accept_languages_factory.h" |
| 18 #include "chrome/browser/translate/translate_service.h" | 18 #include "chrome/browser/translate/translate_service.h" |
| 19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 21 #include "chrome/browser/ui/browser_tabstrip.h" | 21 #include "chrome/browser/ui/browser_tabstrip.h" |
| 22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/ui/translate/translate_bubble_factory.h" | 24 #include "chrome/browser/ui/translate/translate_bubble_factory.h" |
| 25 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "components/translate/content/common/translate_messages.h" | |
| 29 #include "components/translate/core/browser/language_state.h" | 28 #include "components/translate/core/browser/language_state.h" |
| 30 #include "components/translate/core/browser/page_translated_details.h" | 29 #include "components/translate/core/browser/page_translated_details.h" |
| 31 #include "components/translate/core/browser/translate_accept_languages.h" | 30 #include "components/translate/core/browser/translate_accept_languages.h" |
| 32 #include "components/translate/core/browser/translate_download_manager.h" | 31 #include "components/translate/core/browser/translate_download_manager.h" |
| 33 #include "components/translate/core/browser/translate_infobar_delegate.h" | 32 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 34 #include "components/translate/core/browser/translate_manager.h" | 33 #include "components/translate/core/browser/translate_manager.h" |
| 35 #include "components/translate/core/browser/translate_prefs.h" | 34 #include "components/translate/core/browser/translate_prefs.h" |
| 36 #include "components/translate/core/common/language_detection_details.h" | 35 #include "components/translate/core/common/language_detection_details.h" |
| 37 #include "components/variations/service/variations_service.h" | 36 #include "components/variations/service/variations_service.h" |
| 38 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (!auto_translate_language.empty()) { | 130 if (!auto_translate_language.empty()) { |
| 132 *target = auto_translate_language; | 131 *target = auto_translate_language; |
| 133 return; | 132 return; |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 *target = | 136 *target = |
| 138 translate::TranslateManager::GetTargetLanguage(translate_prefs.get()); | 137 translate::TranslateManager::GetTargetLanguage(translate_prefs.get()); |
| 139 } | 138 } |
| 140 | 139 |
| 140 // static |
| 141 void ChromeTranslateClient::BindContentTranslateDriver( |
| 142 content::RenderFrameHost* render_frame_host, |
| 143 translate::mojom::ContentTranslateDriverRequest request) { |
| 144 content::WebContents* web_contents = |
| 145 content::WebContents::FromRenderFrameHost(render_frame_host); |
| 146 if (!web_contents) |
| 147 return; |
| 148 |
| 149 ChromeTranslateClient* instance = |
| 150 ChromeTranslateClient::FromWebContents(web_contents); |
| 151 // We try to bind to the driver, but if driver is not ready for now or totally |
| 152 // not available for this render frame host, the request will be just dropped, |
| 153 // this would cause closing the message pipe which would raise connection |
| 154 // error to peer side. |
| 155 if (!instance) |
| 156 return; |
| 157 |
| 158 instance->translate_driver().BindRequest(std::move(request)); |
| 159 } |
| 160 |
| 141 translate::TranslateManager* ChromeTranslateClient::GetTranslateManager() { | 161 translate::TranslateManager* ChromeTranslateClient::GetTranslateManager() { |
| 142 return translate_manager_.get(); | 162 return translate_manager_.get(); |
| 143 } | 163 } |
| 144 | 164 |
| 145 void ChromeTranslateClient::ShowTranslateUI( | 165 void ChromeTranslateClient::ShowTranslateUI( |
| 146 translate::TranslateStep step, | 166 translate::TranslateStep step, |
| 147 const std::string& source_language, | 167 const std::string& source_language, |
| 148 const std::string& target_language, | 168 const std::string& target_language, |
| 149 translate::TranslateErrors::Type error_type, | 169 translate::TranslateErrors::Type error_type, |
| 150 bool triggered_from_menu) { | 170 bool triggered_from_menu) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (GetLanguageState().InTranslateNavigation()) | 329 if (GetLanguageState().InTranslateNavigation()) |
| 310 return; | 330 return; |
| 311 } | 331 } |
| 312 | 332 |
| 313 TranslateBubbleFactory::Show(browser->window(), web_contents(), step, | 333 TranslateBubbleFactory::Show(browser->window(), web_contents(), step, |
| 314 error_type); | 334 error_type); |
| 315 #else | 335 #else |
| 316 NOTREACHED(); | 336 NOTREACHED(); |
| 317 #endif | 337 #endif |
| 318 } | 338 } |
| OLD | NEW |