| 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 "ios/chrome/browser/translate/chrome_ios_translate_client.h" | 5 #include "ios/chrome/browser/translate/chrome_ios_translate_client.h" |
| 6 | 6 |
| 7 #include <utility> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 11 #include "components/infobars/core/infobar.h" | 12 #include "components/infobars/core/infobar.h" |
| 12 #include "components/translate/core/browser/page_translated_details.h" | 13 #include "components/translate/core/browser/page_translated_details.h" |
| 13 #include "components/translate/core/browser/translate_accept_languages.h" | 14 #include "components/translate/core/browser/translate_accept_languages.h" |
| 14 #include "components/translate/core/browser/translate_infobar_delegate.h" | 15 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 15 #include "components/translate/core/browser/translate_manager.h" | 16 #include "components/translate/core/browser/translate_manager.h" |
| 16 #include "components/translate/core/browser/translate_prefs.h" | 17 #include "components/translate/core/browser/translate_prefs.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 translate::TranslateManager* ChromeIOSTranslateClient::GetTranslateManager() { | 55 translate::TranslateManager* ChromeIOSTranslateClient::GetTranslateManager() { |
| 55 return translate_manager_.get(); | 56 return translate_manager_.get(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 // TranslateClient implementation: | 59 // TranslateClient implementation: |
| 59 | 60 |
| 60 scoped_ptr<infobars::InfoBar> ChromeIOSTranslateClient::CreateInfoBar( | 61 scoped_ptr<infobars::InfoBar> ChromeIOSTranslateClient::CreateInfoBar( |
| 61 scoped_ptr<translate::TranslateInfoBarDelegate> delegate) const { | 62 scoped_ptr<translate::TranslateInfoBarDelegate> delegate) const { |
| 62 translate::TranslateStep step = delegate->translate_step(); | 63 translate::TranslateStep step = delegate->translate_step(); |
| 63 | 64 |
| 64 scoped_ptr<InfoBarIOS> infobar(new InfoBarIOS(delegate.Pass())); | 65 scoped_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate))); |
| 65 base::scoped_nsobject<InfoBarController> controller; | 66 base::scoped_nsobject<InfoBarController> controller; |
| 66 switch (step) { | 67 switch (step) { |
| 67 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: | 68 case translate::TRANSLATE_STEP_AFTER_TRANSLATE: |
| 68 controller.reset([[AfterTranslateInfoBarController alloc] | 69 controller.reset([[AfterTranslateInfoBarController alloc] |
| 69 initWithDelegate:infobar.get()]); | 70 initWithDelegate:infobar.get()]); |
| 70 break; | 71 break; |
| 71 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: | 72 case translate::TRANSLATE_STEP_BEFORE_TRANSLATE: |
| 72 controller.reset([[BeforeTranslateInfoBarController alloc] | 73 controller.reset([[BeforeTranslateInfoBarController alloc] |
| 73 initWithDelegate:infobar.get()]); | 74 initWithDelegate:infobar.get()]); |
| 74 break; | 75 break; |
| 75 case translate::TRANSLATE_STEP_NEVER_TRANSLATE: | 76 case translate::TRANSLATE_STEP_NEVER_TRANSLATE: |
| 76 controller.reset([[NeverTranslateInfoBarController alloc] | 77 controller.reset([[NeverTranslateInfoBarController alloc] |
| 77 initWithDelegate:infobar.get()]); | 78 initWithDelegate:infobar.get()]); |
| 78 break; | 79 break; |
| 79 case translate::TRANSLATE_STEP_TRANSLATING: | 80 case translate::TRANSLATE_STEP_TRANSLATING: |
| 80 case translate::TRANSLATE_STEP_TRANSLATE_ERROR: | 81 case translate::TRANSLATE_STEP_TRANSLATE_ERROR: |
| 81 controller.reset([[TranslateMessageInfoBarController alloc] | 82 controller.reset([[TranslateMessageInfoBarController alloc] |
| 82 initWithDelegate:infobar.get()]); | 83 initWithDelegate:infobar.get()]); |
| 83 break; | 84 break; |
| 84 default: | 85 default: |
| 85 NOTREACHED(); | 86 NOTREACHED(); |
| 86 } | 87 } |
| 87 infobar->SetController(controller); | 88 infobar->SetController(controller); |
| 88 return infobar.Pass(); | 89 return std::move(infobar); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void ChromeIOSTranslateClient::ShowTranslateUI( | 92 void ChromeIOSTranslateClient::ShowTranslateUI( |
| 92 translate::TranslateStep step, | 93 translate::TranslateStep step, |
| 93 const std::string& source_language, | 94 const std::string& source_language, |
| 94 const std::string& target_language, | 95 const std::string& target_language, |
| 95 translate::TranslateErrors::Type error_type, | 96 translate::TranslateErrors::Type error_type, |
| 96 bool triggered_from_menu) { | 97 bool triggered_from_menu) { |
| 97 DCHECK(web_state()); | 98 DCHECK(web_state()); |
| 98 if (error_type != translate::TranslateErrors::NONE) | 99 if (error_type != translate::TranslateErrors::NONE) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 const GURL& report_url) { | 147 const GURL& report_url) { |
| 147 NOTREACHED(); | 148 NOTREACHED(); |
| 148 } | 149 } |
| 149 | 150 |
| 150 void ChromeIOSTranslateClient::WebStateDestroyed() { | 151 void ChromeIOSTranslateClient::WebStateDestroyed() { |
| 151 // Translation process can be interrupted. | 152 // Translation process can be interrupted. |
| 152 // Destroying the TranslateManager now guarantees that it never has to deal | 153 // Destroying the TranslateManager now guarantees that it never has to deal |
| 153 // with nullptr WebState. | 154 // with nullptr WebState. |
| 154 translate_manager_.reset(); | 155 translate_manager_.reset(); |
| 155 } | 156 } |
| OLD | NEW |