| 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 #import "ios/chrome/browser/native_app_launcher/native_app_infobar_controller.h" | 5 #import "ios/chrome/browser/native_app_launcher/native_app_infobar_controller.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" | 10 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" |
| 11 #import "ios/chrome/browser/ui/infobars/infobar_view.h" |
| 12 #include "ios/chrome/browser/ui/infobars/infobar_view_protocol.h" |
| 11 #include "ios/chrome/grit/ios_strings.h" | 13 #include "ios/chrome/grit/ios_strings.h" |
| 12 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | |
| 13 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" | 14 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" |
| 14 #include "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h" | |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 | 16 |
| 17 @interface NativeAppInfoBarController () | 17 @interface NativeAppInfoBarController () |
| 18 | 18 |
| 19 // Action for any of the user defined buttons. | 19 // Action for any of the user defined buttons. |
| 20 - (void)infoBarButtonDidPress:(UIButton*)button; | 20 - (void)infoBarButtonDidPress:(UIButton*)button; |
| 21 | 21 |
| 22 // Notifies the delegate of which action the user took. | 22 // Notifies the delegate of which action the user took. |
| 23 - (void)userPerformedAction:(NativeAppActionType)userAction; | 23 - (void)userPerformedAction:(NativeAppActionType)userAction; |
| 24 | 24 |
| 25 // For testing. | 25 // For testing. |
| 26 // Sets the infobar delegate. | 26 // Sets the infobar delegate. |
| 27 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate; | 27 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate; |
| 28 | 28 |
| 29 @end | 29 @end |
| 30 | 30 |
| 31 @implementation NativeAppInfoBarController { | 31 @implementation NativeAppInfoBarController { |
| 32 NativeAppInfoBarDelegate* nativeAppInfoBarDelegate_; // weak | 32 NativeAppInfoBarDelegate* nativeAppInfoBarDelegate_; // weak |
| 33 } | 33 } |
| 34 | 34 |
| 35 #pragma mark - InfoBarController | 35 #pragma mark - InfoBarController |
| 36 | 36 |
| 37 - (UIView<InfoBarViewProtocol>*)viewForDelegate: | 37 - (UIView<InfoBarViewProtocol>*)viewForDelegate: |
| 38 (infobars::InfoBarDelegate*)delegate | 38 (infobars::InfoBarDelegate*)delegate |
| 39 frame:(CGRect)frame { | 39 frame:(CGRect)frame { |
| 40 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; | 40 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView; |
| 41 nativeAppInfoBarDelegate_ = static_cast<NativeAppInfoBarDelegate*>(delegate); | 41 nativeAppInfoBarDelegate_ = static_cast<NativeAppInfoBarDelegate*>(delegate); |
| 42 DCHECK(nativeAppInfoBarDelegate_); | 42 DCHECK(nativeAppInfoBarDelegate_); |
| 43 infoBarView.reset( | 43 infoBarView.reset( |
| 44 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate)); | 44 [[InfoBarView alloc] initWithFrame:frame delegate:self.delegate]); |
| 45 | 45 |
| 46 // Lays out widgets common to all NativeAppInfobars. | 46 // Lays out widgets common to all NativeAppInfobars. |
| 47 [infoBarView | 47 [infoBarView |
| 48 addPlaceholderTransparentIcon:native_app_infobar::kSmallIconSize]; | 48 addPlaceholderTransparentIcon:native_app_infobar::kSmallIconSize]; |
| 49 nativeAppInfoBarDelegate_->FetchSmallAppIcon(^(UIImage* image) { | 49 nativeAppInfoBarDelegate_->FetchSmallAppIcon(^(UIImage* image) { |
| 50 [infoBarView addLeftIconWithRoundedCornersAndShadow:image]; | 50 [infoBarView addLeftIconWithRoundedCornersAndShadow:image]; |
| 51 }); | 51 }); |
| 52 [infoBarView addCloseButtonWithTag:NATIVE_APP_ACTION_DISMISS | 52 [infoBarView addCloseButtonWithTag:NATIVE_APP_ACTION_DISMISS |
| 53 target:self | 53 target:self |
| 54 action:@selector(infoBarButtonDidPress:)]; | 54 action:@selector(infoBarButtonDidPress:)]; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 nativeAppInfoBarDelegate_->UserPerformedAction(userAction); | 118 nativeAppInfoBarDelegate_->UserPerformedAction(userAction); |
| 119 } | 119 } |
| 120 | 120 |
| 121 #pragma mark - Testing | 121 #pragma mark - Testing |
| 122 | 122 |
| 123 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate { | 123 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate { |
| 124 nativeAppInfoBarDelegate_ = delegate; | 124 nativeAppInfoBarDelegate_ = delegate; |
| 125 } | 125 } |
| 126 | 126 |
| 127 @end | 127 @end |
| OLD | NEW |