Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/before_translate_infobar_controller.h" | 5 #include "ios/chrome/browser/translate/before_translate_infobar_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include "base/ios/weak_nsobject.h" | |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/strings/grit/components_strings.h" | 15 #include "components/strings/grit/components_strings.h" |
| 15 #include "components/translate/core/browser/translate_infobar_delegate.h" | 16 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 16 #include "ios/chrome/browser/translate/translate_infobar_tags.h" | 17 #include "ios/chrome/browser/translate/translate_infobar_tags.h" |
| 17 #import "ios/chrome/browser/ui/infobars/infobar_view.h" | 18 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
| 18 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" | 19 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 base::string16 originalLanguageWithLink = | 166 base::string16 originalLanguageWithLink = |
| 166 base::SysNSStringToUTF16([[view class] | 167 base::SysNSStringToUTF16([[view class] |
| 167 stringAsLink:originalLanguage | 168 stringAsLink:originalLanguage |
| 168 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); | 169 tag:TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE]); |
| 169 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class] | 170 base::string16 targetLanguageWithLink = base::SysNSStringToUTF16([[view class] |
| 170 stringAsLink:targetLanguage | 171 stringAsLink:targetLanguage |
| 171 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]); | 172 tag:TranslateInfoBarIOSTag::BEFORE_TARGET_LANGUAGE]); |
| 172 NSString* label = | 173 NSString* label = |
| 173 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, | 174 l10n_util::GetNSStringF(IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE_IOS, |
| 174 originalLanguageWithLink, targetLanguageWithLink); | 175 originalLanguageWithLink, targetLanguageWithLink); |
| 176 | |
| 177 base::WeakNSObject<BeforeTranslateInfoBarController> weakSelf(self); | |
| 175 [view addLabel:label | 178 [view addLabel:label |
| 176 action:^(NSUInteger tag) { | 179 action:^(NSUInteger tag) { |
| 177 [self infobarLinkDidPress:tag]; | 180 base::scoped_nsobject<BeforeTranslateInfoBarController> strongSelf( |
| 181 [weakSelf retain]); | |
| 182 [strongSelf infobarLinkDidPress:tag]; | |
|
sdefresne
2017/06/12 14:14:24
ditto
| |
| 178 }]; | 183 }]; |
| 179 } | 184 } |
| 180 | 185 |
| 181 - (void)languageSelectionDone { | 186 - (void)languageSelectionDone { |
| 182 size_t selectedRow = [_languagePicker selectedRowInComponent:0]; | 187 size_t selectedRow = [_languagePicker selectedRowInComponent:0]; |
| 183 std::string lang = _translateInfoBarDelegate->language_code_at(selectedRow); | 188 std::string lang = _translateInfoBarDelegate->language_code_at(selectedRow); |
| 184 if (_languageSelectionType == | 189 if (_languageSelectionType == |
| 185 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE && | 190 TranslateInfoBarIOSTag::BEFORE_SOURCE_LANGUAGE && |
| 186 lang != _translateInfoBarDelegate->target_language_code()) { | 191 lang != _translateInfoBarDelegate->target_language_code()) { |
| 187 _translateInfoBarDelegate->UpdateOriginalLanguage(lang); | 192 _translateInfoBarDelegate->UpdateOriginalLanguage(lang); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 [super removeView]; | 371 [super removeView]; |
| 367 [self dismissLanguageSelectionView]; | 372 [self dismissLanguageSelectionView]; |
| 368 } | 373 } |
| 369 | 374 |
| 370 - (void)detachView { | 375 - (void)detachView { |
| 371 [super detachView]; | 376 [super detachView]; |
| 372 [self dismissLanguageSelectionView]; | 377 [self dismissLanguageSelectionView]; |
| 373 } | 378 } |
| 374 | 379 |
| 375 @end | 380 @end |
| OLD | NEW |