Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: ios/chrome/browser/native_app_launcher/native_app_infobar_controller.mm

Issue 2508663002: [ios] Move NativeAppLauncher upstream (Closed)
Patch Set: Upstream NativeAppLauncher Files Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/native_app_launcher/native_app_infobar_controller.h"
6
7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h"
10 #include "ios/chrome/grit/ios_strings.h"
11 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
12 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types .h"
13 #include "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16 @interface NativeAppInfoBarController ()
17
18 // Action for any of the user defined buttons.
19 - (void)infoBarButtonDidPress:(UIButton*)button;
20
21 // Notifies the delegate of which action the user took.
22 - (void)userPerformedAction:(NativeAppActionType)userAction;
23
24 // For testing.
25 // Sets the infobar delegate.
26 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate;
27
28 @end
29
30 @implementation NativeAppInfoBarController {
31 NativeAppInfoBarDelegate* nativeAppInfoBarDelegate_; // weak
32 }
33
34 #pragma mark - InfoBarController
35
36 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
37 viewForDelegate:(infobars::InfoBarDelegate*)delegate
rohitrao (ping after 24h) 2016/11/17 03:15:23 This should be indented 4 spaces. Did you run "gi
sdefresne 2016/11/17 06:24:26 Not sure this should be indented by 4 spaces as th
sczs1 2016/11/18 23:42:49 I ran git cl format and it formatted these files.
38 frame:(CGRect)frame {
39 base::scoped_nsobject<UIView<InfoBarViewProtocol>> infoBarView;
40 nativeAppInfoBarDelegate_ = static_cast<NativeAppInfoBarDelegate*>(delegate);
41 DCHECK(nativeAppInfoBarDelegate_);
42 infoBarView.reset(
43 ios::GetChromeBrowserProvider()->CreateInfoBarView(frame, self.delegate));
44
45 // Lays out widgets common to all NativeAppInfobars.
46 [infoBarView
47 addPlaceholderTransparentIcon:native_app_infobar::kSmallIconSize];
48 nativeAppInfoBarDelegate_->FetchSmallAppIcon(^(UIImage* image) {
49 [infoBarView addLeftIconWithRoundedCornersAndShadow:image];
50 });
51 [infoBarView addCloseButtonWithTag:NATIVE_APP_ACTION_DISMISS
52 target:self
53 action:@selector(infoBarButtonDidPress:)];
54
55 auto type = nativeAppInfoBarDelegate_->GetControllerType();
56 switch (type) {
57 case NATIVE_APP_INSTALLER_CONTROLLER: {
58 NSString* buttonMsg =
59 l10n_util::GetNSString(IDS_APP_LAUNCHER_INSTALL_APP_BUTTON_LABEL_IOS);
60 [infoBarView addButton:buttonMsg
61 tag:NATIVE_APP_ACTION_CLICK_INSTALL
62 target:self
63 action:@selector(infoBarButtonDidPress:)];
64 DCHECK(nativeAppInfoBarDelegate_->GetInstallText().length());
65 [infoBarView addLabel:base::SysUTF16ToNSString(
66 nativeAppInfoBarDelegate_->GetInstallText())];
67 break;
68 }
69 case NATIVE_APP_LAUNCHER_CONTROLLER: {
70 NSString* buttonMsg =
71 l10n_util::GetNSString(IDS_APP_LAUNCHER_OPEN_APP_BUTTON_LABEL_IOS);
72 [infoBarView addButton:buttonMsg
73 tag:NATIVE_APP_ACTION_CLICK_LAUNCH
74 target:self
75 action:@selector(infoBarButtonDidPress:)];
76 DCHECK(nativeAppInfoBarDelegate_->GetLaunchText().length());
77 [infoBarView addLabel:base::SysUTF16ToNSString(
78 nativeAppInfoBarDelegate_->GetLaunchText())];
79 break;
80 }
81 case NATIVE_APP_OPEN_POLICY_CONTROLLER: {
82 NSString* labelMsg = base::SysUTF16ToNSString(
83 nativeAppInfoBarDelegate_->GetOpenPolicyText());
84 DCHECK(nativeAppInfoBarDelegate_->GetOpenPolicyText().length());
85 NSString* buttonOnceString = base::SysUTF16ToNSString(
86 nativeAppInfoBarDelegate_->GetOpenOnceText());
87 NSString* buttonAlwaysString = base::SysUTF16ToNSString(
88 nativeAppInfoBarDelegate_->GetOpenAlwaysText());
89 [infoBarView addLabel:labelMsg];
90 [infoBarView addButton1:buttonOnceString
91 tag1:NATIVE_APP_ACTION_CLICK_ONCE
92 button2:buttonAlwaysString
93 tag2:NATIVE_APP_ACTION_CLICK_ALWAYS
94 target:self
95 action:@selector(infoBarButtonDidPress:)];
96 break;
97 }
98 }
99 return infoBarView;
100 }
101
102 - (void)infoBarButtonDidPress:(UIButton*)button {
103 DCHECK(nativeAppInfoBarDelegate_);
104 DCHECK([button isKindOfClass:[UIButton class]]);
105 // This press might have occurred after the user has already pressed a button,
106 // in which case the view has been detached from the delegate and this press
107 // should be ignored.
108 if (!self.delegate) {
109 return;
110 }
111 self.delegate->InfoBarDidCancel();
112 NativeAppActionType action = static_cast<NativeAppActionType>([button tag]);
113 [self userPerformedAction:action];
114 }
115
116 - (void)userPerformedAction:(NativeAppActionType)userAction {
117 nativeAppInfoBarDelegate_->UserPerformedAction(userAction);
118 }
119
120 #pragma mark - Testing
121
122 - (void)setInfoBarDelegate:(NativeAppInfoBarDelegate*)delegate {
123 nativeAppInfoBarDelegate_ = delegate;
124 }
125
126 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698