| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/settings/native_apps_collection_view_controller.h
" | 5 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller.h
" |
| 6 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller_p
rivate.h" | 6 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller_p
rivate.h" |
| 7 | 7 |
| 8 #import <StoreKit/StoreKit.h> | 8 #import <StoreKit/StoreKit.h> |
| 9 | 9 |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "base/mac/foundation_util.h" | 12 #import "base/mac/foundation_util.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics.h" | 16 #include "base/metrics/user_metrics.h" |
| 16 #include "base/metrics/user_metrics_action.h" | 17 #include "base/metrics/user_metrics_action.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 18 #import "ios/chrome/browser/installation_notifier.h" | 21 #import "ios/chrome/browser/installation_notifier.h" |
| 19 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 22 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 23 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 24 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 25 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 23 #import "ios/chrome/browser/ui/settings/cells/native_app_item.h" | 26 #import "ios/chrome/browser/ui/settings/cells/native_app_item.h" |
| 24 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 27 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 25 #import "ios/chrome/common/string_util.h" | 28 #import "ios/chrome/common/string_util.h" |
| 26 #include "ios/chrome/grit/ios_strings.h" | 29 #include "ios/chrome/grit/ios_strings.h" |
| 27 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 30 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 28 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" | 31 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" |
| 29 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" | 32 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" |
| 30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 33 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 31 #include "net/url_request/url_request_context_getter.h" | 34 #include "ios/web/public/web_thread.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 34 | 37 |
| 35 const NSInteger kTagShift = 1000; | 38 const NSInteger kTagShift = 1000; |
| 36 | 39 |
| 37 namespace { | 40 namespace { |
| 38 | 41 |
| 39 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 42 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 40 SectionIdentifierLearnMore = kSectionIdentifierEnumZero, | 43 SectionIdentifierLearnMore = kSectionIdentifierEnumZero, |
| 41 SectionIdentifierApps, | 44 SectionIdentifierApps, |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 typedef NS_ENUM(NSInteger, ItemType) { | 47 typedef NS_ENUM(NSInteger, ItemType) { |
| 45 ItemTypeApp = kItemTypeEnumZero, | 48 ItemTypeApp = kItemTypeEnumZero, |
| 46 ItemTypeLearnMore, | 49 ItemTypeLearnMore, |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 } // namespace | 52 } // namespace |
| 50 | 53 |
| 51 @interface NativeAppsCollectionViewController ()< | 54 @interface NativeAppsCollectionViewController ()< |
| 52 SKStoreProductViewControllerDelegate> { | 55 SKStoreProductViewControllerDelegate> { |
| 53 net::URLRequestContextGetter* _requestContextGetter; // weak | 56 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; |
| 54 base::scoped_nsobject<NSArray> _nativeAppsInSettings; | 57 base::scoped_nsobject<NSArray> _nativeAppsInSettings; |
| 55 BOOL _userDidSomething; | 58 BOOL _userDidSomething; |
| 56 } | 59 } |
| 57 | 60 |
| 58 // List of the native apps visible in Settings. | 61 // List of the native apps visible in Settings. |
| 59 @property(nonatomic, copy) NSArray* appsInSettings; | 62 @property(nonatomic, copy) NSArray* appsInSettings; |
| 60 | 63 |
| 61 // Delegate for App-Store-related operations. | 64 // Delegate for App-Store-related operations. |
| 62 @property(nonatomic, assign) id<StoreKitLauncher> storeKitLauncher; | 65 @property(nonatomic, assign) id<StoreKitLauncher> storeKitLauncher; |
| 63 | 66 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 @end | 96 @end |
| 94 | 97 |
| 95 @implementation NativeAppsCollectionViewController | 98 @implementation NativeAppsCollectionViewController |
| 96 | 99 |
| 97 @synthesize storeKitLauncher = _storeKitLauncher; | 100 @synthesize storeKitLauncher = _storeKitLauncher; |
| 98 | 101 |
| 99 - (id)initWithURLRequestContextGetter: | 102 - (id)initWithURLRequestContextGetter: |
| 100 (net::URLRequestContextGetter*)requestContextGetter { | 103 (net::URLRequestContextGetter*)requestContextGetter { |
| 101 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 104 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 102 if (self) { | 105 if (self) { |
| 103 _requestContextGetter = requestContextGetter; | 106 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( |
| 107 requestContextGetter, web::WebThread::GetBlockingPool()); |
| 104 base::RecordAction(base::UserMetricsAction("MobileGALOpenSettings")); | 108 base::RecordAction(base::UserMetricsAction("MobileGALOpenSettings")); |
| 105 _storeKitLauncher = self; | 109 _storeKitLauncher = self; |
| 106 | 110 |
| 107 [self loadModel]; | 111 [self loadModel]; |
| 108 } | 112 } |
| 109 return self; | 113 return self; |
| 110 } | 114 } |
| 111 | 115 |
| 112 #pragma mark - View lifecycle | 116 #pragma mark - View lifecycle |
| 113 | 117 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 [appCell.installButton addTarget:self | 207 [appCell.installButton addTarget:self |
| 204 action:@selector(installApp:) | 208 action:@selector(installApp:) |
| 205 forControlEvents:UIControlEventTouchUpInside]; | 209 forControlEvents:UIControlEventTouchUpInside]; |
| 206 CollectionViewItem* item = | 210 CollectionViewItem* item = |
| 207 [self.collectionViewModel itemAtIndexPath:indexPath]; | 211 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 208 NativeAppItem* appItem = base::mac::ObjCCastStrict<NativeAppItem>(item); | 212 NativeAppItem* appItem = base::mac::ObjCCastStrict<NativeAppItem>(item); |
| 209 if (!appItem.icon) { | 213 if (!appItem.icon) { |
| 210 // Fetch the real icon. | 214 // Fetch the real icon. |
| 211 base::WeakNSObject<NativeAppsCollectionViewController> weakSelf(self); | 215 base::WeakNSObject<NativeAppsCollectionViewController> weakSelf(self); |
| 212 id<NativeAppMetadata> metadata = [self nativeAppAtIndex:indexPath.item]; | 216 id<NativeAppMetadata> metadata = [self nativeAppAtIndex:indexPath.item]; |
| 213 [metadata | 217 [metadata fetchSmallIconWithImageFetcher:_imageFetcher.get() |
| 214 fetchSmallIconWithContext:_requestContextGetter | 218 completionBlock:^(UIImage* image) { |
| 215 completionBlock:^(UIImage* image) { | 219 base::scoped_nsobject< |
| 216 base::scoped_nsobject<NativeAppsCollectionViewController> | 220 NativeAppsCollectionViewController> |
| 217 strongSelf([weakSelf retain]); | 221 strongSelf([weakSelf retain]); |
| 218 if (!image || !strongSelf) | 222 if (!image || !strongSelf) |
| 219 return; | 223 return; |
| 220 appItem.icon = image; | 224 appItem.icon = image; |
| 221 [strongSelf.get().collectionView | 225 [strongSelf.get().collectionView |
| 222 reloadItemsAtIndexPaths:@[ indexPath ]]; | 226 reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 223 }]; | 227 }]; |
| 224 } | 228 } |
| 225 } | 229 } |
| 226 | 230 |
| 227 - (CollectionViewItem*)learnMoreItem { | 231 - (CollectionViewItem*)learnMoreItem { |
| 228 NSString* learnMoreText = | 232 NSString* learnMoreText = |
| 229 l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SECTION_HEADER); | 233 l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SECTION_HEADER); |
| 230 CollectionViewFooterItem* learnMoreItem = [[[CollectionViewFooterItem alloc] | 234 CollectionViewFooterItem* learnMoreItem = [[[CollectionViewFooterItem alloc] |
| 231 initWithType:ItemTypeLearnMore] autorelease]; | 235 initWithType:ItemTypeLearnMore] autorelease]; |
| 232 learnMoreItem.text = learnMoreText; | 236 learnMoreItem.text = learnMoreText; |
| 233 return learnMoreItem; | 237 return learnMoreItem; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 395 |
| 392 - (NSIndexPath*)indexPathForTag:(NSInteger)shiftedTag { | 396 - (NSIndexPath*)indexPathForTag:(NSInteger)shiftedTag { |
| 393 NSInteger unshiftedTag = shiftedTag - kTagShift; | 397 NSInteger unshiftedTag = shiftedTag - kTagShift; |
| 394 return [NSIndexPath | 398 return [NSIndexPath |
| 395 indexPathForItem:unshiftedTag | 399 indexPathForItem:unshiftedTag |
| 396 inSection:[self.collectionViewModel | 400 inSection:[self.collectionViewModel |
| 397 sectionForSectionIdentifier:SectionIdentifierApps]]; | 401 sectionForSectionIdentifier:SectionIdentifierApps]]; |
| 398 } | 402 } |
| 399 | 403 |
| 400 @end | 404 @end |
| OLD | NEW |