| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/chrome/browser/infobars/confirm_infobar_controller.h" | 5 #import "ios/chrome/browser/infobars/confirm_infobar_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "components/infobars/core/confirm_infobar_delegate.h" | 10 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 11 #import "ios/chrome/browser/ui/infobars/infobar_view.h" | 11 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
| 12 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" | 12 #import "ios/chrome/browser/ui/infobars/infobar_view_delegate.h" |
| 13 #import "ios/chrome/browser/ui/infobars/infobar_view_protocol.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/window_open_disposition.h" | 14 #include "ui/base/window_open_disposition.h" |
| 16 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 17 | 16 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) | 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." | 18 #error "This file requires ARC support." |
| 20 #endif | 19 #endif |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 @interface ConfirmInfoBarController () { | 49 @interface ConfirmInfoBarController () { |
| 51 ConfirmInfoBarDelegate* _confirmInfobarDelegate; | 50 ConfirmInfoBarDelegate* _confirmInfobarDelegate; |
| 52 } | 51 } |
| 53 @end | 52 @end |
| 54 | 53 |
| 55 @implementation ConfirmInfoBarController | 54 @implementation ConfirmInfoBarController |
| 56 | 55 |
| 57 #pragma mark - | 56 #pragma mark - |
| 58 #pragma mark InfoBarController | 57 #pragma mark InfoBarController |
| 59 | 58 |
| 60 - (UIView<InfoBarViewProtocol>*)viewForDelegate: | 59 - (InfoBarView*)viewForDelegate:(infobars::InfoBarDelegate*)delegate |
| 61 (infobars::InfoBarDelegate*)delegate | 60 frame:(CGRect)frame { |
| 62 frame:(CGRect)frame { | |
| 63 UIView<InfoBarViewProtocol>* infoBarView; | |
| 64 _confirmInfobarDelegate = delegate->AsConfirmInfoBarDelegate(); | 61 _confirmInfobarDelegate = delegate->AsConfirmInfoBarDelegate(); |
| 65 infoBarView = | 62 InfoBarView* infoBarView = |
| 66 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]; | 63 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]; |
| 67 // Model data. | 64 // Model data. |
| 68 gfx::Image modelIcon = _confirmInfobarDelegate->GetIcon(); | 65 gfx::Image modelIcon = _confirmInfobarDelegate->GetIcon(); |
| 69 int buttons = _confirmInfobarDelegate->GetButtons(); | 66 int buttons = _confirmInfobarDelegate->GetButtons(); |
| 70 NSString* buttonOK = nil; | 67 NSString* buttonOK = nil; |
| 71 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { | 68 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 72 buttonOK = base::SysUTF16ToNSString(_confirmInfobarDelegate->GetButtonLabel( | 69 buttonOK = base::SysUTF16ToNSString(_confirmInfobarDelegate->GetButtonLabel( |
| 73 ConfirmInfoBarDelegate::BUTTON_OK)); | 70 ConfirmInfoBarDelegate::BUTTON_OK)); |
| 74 } | 71 } |
| 75 NSString* buttonCancel = nil; | 72 NSString* buttonCancel = nil; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 102 tag:ConfirmInfoBarUITags::OK | 99 tag:ConfirmInfoBarUITags::OK |
| 103 target:self | 100 target:self |
| 104 action:@selector(infoBarButtonDidPress:)]; | 101 action:@selector(infoBarButtonDidPress:)]; |
| 105 } else { | 102 } else { |
| 106 // No buttons, only message. | 103 // No buttons, only message. |
| 107 DCHECK(!_confirmInfobarDelegate->GetMessageText().empty() && !buttonCancel); | 104 DCHECK(!_confirmInfobarDelegate->GetMessageText().empty() && !buttonCancel); |
| 108 } | 105 } |
| 109 return infoBarView; | 106 return infoBarView; |
| 110 } | 107 } |
| 111 | 108 |
| 112 - (void)updateInfobarLabel:(UIView<InfoBarViewProtocol>*)view { | 109 - (void)updateInfobarLabel:(InfoBarView*)view { |
| 113 if (!_confirmInfobarDelegate->GetMessageText().length()) | 110 if (!_confirmInfobarDelegate->GetMessageText().length()) |
| 114 return; | 111 return; |
| 115 if (_confirmInfobarDelegate->GetLinkText().length()) { | 112 if (_confirmInfobarDelegate->GetLinkText().length()) { |
| 116 base::string16 msgLink = base::SysNSStringToUTF16([[view class] | 113 base::string16 msgLink = base::SysNSStringToUTF16([[view class] |
| 117 stringAsLink:base::SysUTF16ToNSString( | 114 stringAsLink:base::SysUTF16ToNSString( |
| 118 _confirmInfobarDelegate->GetLinkText()) | 115 _confirmInfobarDelegate->GetLinkText()) |
| 119 tag:ConfirmInfoBarUITags::TITLE_LINK]); | 116 tag:ConfirmInfoBarUITags::TITLE_LINK]); |
| 120 base::string16 messageText = _confirmInfobarDelegate->GetMessageText(); | 117 base::string16 messageText = _confirmInfobarDelegate->GetMessageText(); |
| 121 base::ReplaceFirstSubstringAfterOffset( | 118 base::ReplaceFirstSubstringAfterOffset( |
| 122 &messageText, 0, _confirmInfobarDelegate->GetLinkText(), msgLink); | 119 &messageText, 0, _confirmInfobarDelegate->GetLinkText(), msgLink); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (!self.delegate) { | 152 if (!self.delegate) { |
| 156 return; | 153 return; |
| 157 } | 154 } |
| 158 if ([tag unsignedIntegerValue] == ConfirmInfoBarUITags::TITLE_LINK) { | 155 if ([tag unsignedIntegerValue] == ConfirmInfoBarUITags::TITLE_LINK) { |
| 159 _confirmInfobarDelegate->LinkClicked( | 156 _confirmInfobarDelegate->LinkClicked( |
| 160 WindowOpenDisposition::NEW_FOREGROUND_TAB); | 157 WindowOpenDisposition::NEW_FOREGROUND_TAB); |
| 161 } | 158 } |
| 162 } | 159 } |
| 163 | 160 |
| 164 @end | 161 @end |
| OLD | NEW |