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