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

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

Issue 2508663002: [ios] Move NativeAppLauncher upstream (Closed)
Patch Set: String description change Created 4 years 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 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h"
6
7 #import <Foundation/Foundation.h>
8
9 #include <memory>
10 #include <utility>
11
12 #include "base/strings/sys_string_conversions.h"
13 #include "components/infobars/core/infobar_manager.h"
14 #import "ios/chrome/browser/native_app_launcher/native_app_infobar_controller.h"
15 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller _protocol.h"
16 #include "ios/chrome/grit/ios_strings.h"
17 #include "ui/base/l10n/l10n_util.h"
18
19 namespace native_app_infobar {
20 const CGSize kSmallIconSize = {29.0, 29.0};
21 } // namespace native_app_infobar
22
23 NativeAppInfoBarDelegate::NativeAppInfoBarDelegate(
24 id<NativeAppNavigationControllerProtocol> controller,
25 const GURL& pageURL,
26 NativeAppControllerType type)
27 : controller_(controller), pageURL_(pageURL), type_(type) {}
sdefresne 2016/11/22 10:16:19 ditto
sczs1 2016/11/22 17:11:23 Done.
28
29 NativeAppInfoBarDelegate::~NativeAppInfoBarDelegate() {}
30
31 // static
32 bool NativeAppInfoBarDelegate::Create(
33 infobars::InfoBarManager* manager,
34 id<NativeAppNavigationControllerProtocol> controllerProtocol,
sdefresne 2016/11/22 10:16:19 This is a c++ variable, so it should use_cpp_namin
sczs1 2016/11/22 17:11:23 Done.
35 const GURL& pageURL,
sdefresne 2016/11/22 10:16:19 ditto
sczs1 2016/11/22 17:11:23 Done.
36 NativeAppControllerType type) {
37 DCHECK(manager);
38 std::unique_ptr<NativeAppInfoBarDelegate> delegate(
sdefresne 2016/11/22 10:16:19 Can you use base::MakeUnique<> here and below, thi
39 new NativeAppInfoBarDelegate(controllerProtocol, pageURL, type));
40 std::unique_ptr<InfoBarIOS> infobar(new InfoBarIOS(std::move(delegate)));
41 base::scoped_nsobject<NativeAppInfoBarController> controller(
42 [[NativeAppInfoBarController alloc] initWithDelegate:infobar.get()]);
43 infobar->SetController(controller);
44 return !!manager->AddInfoBar(std::move(infobar));
45 }
46
47 bool NativeAppInfoBarDelegate::ShouldExpire(
48 const NavigationDetails& details) const {
49 return details.is_navigation_to_different_page;
50 }
51
52 NativeAppInfoBarDelegate*
53 NativeAppInfoBarDelegate::AsNativeAppInfoBarDelegate() {
54 return this;
55 }
56
57 base::string16 NativeAppInfoBarDelegate::GetInstallText() const {
58 return l10n_util::GetStringFUTF16(
59 IDS_IOS_APP_LAUNCHER_OPEN_IN_APP_QUESTION_MESSAGE,
60 base::SysNSStringToUTF16([controller_ appName]));
61 }
62
63 base::string16 NativeAppInfoBarDelegate::GetLaunchText() const {
64 return l10n_util::GetStringFUTF16(
65 IDS_IOS_APP_LAUNCHER_OPEN_IN_APP_QUESTION_MESSAGE,
66 base::SysNSStringToUTF16([controller_ appName]));
67 }
68
69 base::string16 NativeAppInfoBarDelegate::GetOpenPolicyText() const {
70 return l10n_util::GetStringFUTF16(
71 IDS_IOS_APP_LAUNCHER_OPEN_IN_LABEL,
72 base::SysNSStringToUTF16([controller_ appName]));
73 }
74
75 base::string16 NativeAppInfoBarDelegate::GetOpenOnceText() const {
76 return l10n_util::GetStringUTF16(IDS_IOS_APP_LAUNCHER_OPEN_ONCE_BUTTON);
77 }
78
79 base::string16 NativeAppInfoBarDelegate::GetOpenAlwaysText() const {
80 return l10n_util::GetStringUTF16(IDS_IOS_APP_LAUNCHER_OPEN_ALWAYS_BUTTON);
81 }
82
83 NSString* NativeAppInfoBarDelegate::GetAppId() const {
84 return [controller_ appId];
85 }
86
87 infobars::InfoBarDelegate::Type NativeAppInfoBarDelegate::GetInfoBarType()
88 const {
89 return PAGE_ACTION_TYPE;
90 }
91
92 infobars::InfoBarDelegate::InfoBarIdentifier
93 NativeAppInfoBarDelegate::GetIdentifier() const {
94 switch (type_) {
95 case NATIVE_APP_INSTALLER_CONTROLLER:
96 return NATIVE_APP_INSTALLER_INFOBAR_DELEGATE;
97 case NATIVE_APP_LAUNCHER_CONTROLLER:
98 return NATIVE_APP_LAUNCHER_INFOBAR_DELEGATE;
99 case NATIVE_APP_OPEN_POLICY_CONTROLLER:
100 return NATIVE_APP_OPEN_POLICY_INFOBAR_DELEGATE;
101 }
102 }
103
104 bool NativeAppInfoBarDelegate::EqualsDelegate(
105 infobars::InfoBarDelegate* delegate) const {
106 NativeAppInfoBarDelegate* nativeAppInfoBarDelegate =
107 delegate->AsNativeAppInfoBarDelegate();
108 return nativeAppInfoBarDelegate &&
109 [nativeAppInfoBarDelegate->GetAppId() isEqualToString:GetAppId()];
110 }
111
112 void NativeAppInfoBarDelegate::FetchSmallAppIcon(void (^block)(UIImage*)) {
113 [controller_ fetchSmallIconWithCompletionBlock:block];
114 }
115
116 void NativeAppInfoBarDelegate::UserPerformedAction(
117 NativeAppActionType userAction) {
118 [controller_ updateMetadataWithUserAction:userAction];
119 switch (userAction) {
120 case NATIVE_APP_ACTION_CLICK_INSTALL:
121 DCHECK(type_ == NATIVE_APP_INSTALLER_CONTROLLER);
122 [controller_ openStore];
123 break;
124 case NATIVE_APP_ACTION_CLICK_LAUNCH:
125 DCHECK(type_ == NATIVE_APP_LAUNCHER_CONTROLLER);
126 [controller_ launchApp:pageURL_];
127 break;
128 case NATIVE_APP_ACTION_CLICK_ONCE:
129 DCHECK(type_ == NATIVE_APP_OPEN_POLICY_CONTROLLER);
130 [controller_ launchApp:pageURL_];
131 break;
132 case NATIVE_APP_ACTION_CLICK_ALWAYS:
133 DCHECK(type_ == NATIVE_APP_OPEN_POLICY_CONTROLLER);
134 [controller_ launchApp:pageURL_];
135 break;
136 case NATIVE_APP_ACTION_DISMISS:
137 break;
138 case NATIVE_APP_ACTION_IGNORE:
139 case NATIVE_APP_ACTION_COUNT:
140 NOTREACHED();
141 break;
142 }
143 }
144
145 NativeAppControllerType NativeAppInfoBarDelegate::GetControllerType() const {
146 return type_;
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698