| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_navigation_controller
.h" | 5 #import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller
.h" |
| 6 | 6 |
| 7 #import <StoreKit/StoreKit.h> | 7 #import <StoreKit/StoreKit.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 10 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 11 #include "components/infobars/core/infobar_manager.h" | 14 #include "components/infobars/core/infobar_manager.h" |
| 12 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
| 13 #import "ios/chrome/browser/installation_notifier.h" | 16 #import "ios/chrome/browser/installation_notifier.h" |
| 14 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" | 17 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" |
| 15 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h" | 18 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h" |
| 16 #import "ios/chrome/browser/open_url_util.h" | 19 #import "ios/chrome/browser/open_url_util.h" |
| 17 #import "ios/chrome/browser/tabs/tab.h" | 20 #import "ios/chrome/browser/tabs/tab.h" |
| 18 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 21 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 19 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" | 22 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" |
| 20 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" | 23 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" |
| 21 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" | 24 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" |
| 22 #include "ios/web/public/web_state/web_state.h" | 25 #include "ios/web/public/web_state/web_state.h" |
| 26 #include "ios/web/public/web_thread.h" |
| 23 #import "ios/web/web_state/ui/crw_web_controller.h" | 27 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 24 #import "net/base/mac/url_conversions.h" | 28 #import "net/base/mac/url_conversions.h" |
| 25 #include "net/url_request/url_request_context_getter.h" | |
| 26 | 29 |
| 27 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 28 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
| 29 #endif | 32 #endif |
| 30 | 33 |
| 31 using base::UserMetricsAction; | 34 using base::UserMetricsAction; |
| 32 | 35 |
| 33 @interface NativeAppNavigationController () | 36 @interface NativeAppNavigationController () |
| 34 // Shows a native app infobar by looking at the page's URL and by checking | 37 // Shows a native app infobar by looking at the page's URL and by checking |
| 35 // wheter that infobar should be bypassed or not. | 38 // wheter that infobar should be bypassed or not. |
| 36 - (void)showInfoBarIfNecessary; | 39 - (void)showInfoBarIfNecessary; |
| 37 | 40 |
| 38 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| | 41 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| |
| 39 - (NSMutableSet*)appsPossiblyBeingInstalled; | 42 - (NSMutableSet*)appsPossiblyBeingInstalled; |
| 40 | 43 |
| 41 // Records what type of infobar was opened. | 44 // Records what type of infobar was opened. |
| 42 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type | 45 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type |
| 43 onLinkNavigation:(BOOL)isLinkNavigation; | 46 onLinkNavigation:(BOOL)isLinkNavigation; |
| 44 | 47 |
| 45 @end | 48 @end |
| 46 | 49 |
| 47 @implementation NativeAppNavigationController { | 50 @implementation NativeAppNavigationController { |
| 48 // WebState provides access to the *TabHelper objects. This will eventually | 51 // WebState provides access to the *TabHelper objects. This will eventually |
| 49 // replace the need to have |_tab| in this object. | 52 // replace the need to have |_tab| in this object. |
| 50 web::WebState* _webState; | 53 web::WebState* _webState; |
| 51 // A reference to the URLRequestContextGetter needed to fetch icons. | 54 // ImageFetcher needed to fetch the icons. |
| 52 scoped_refptr<net::URLRequestContextGetter> _requestContextGetter; | 55 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; |
| 53 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab | 56 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab |
| 54 // states such as navigation manager and whether it is a pre-rendered tab. | 57 // states such as navigation manager and whether it is a pre-rendered tab. |
| 55 // Use |webState| whenever possible. | 58 // Use |webState| whenever possible. |
| 56 __weak Tab* _tab; | 59 __weak Tab* _tab; |
| 57 id<NativeAppMetadata> _metadata; | 60 id<NativeAppMetadata> _metadata; |
| 58 // A set of appIds encoded as NSStrings. | 61 // A set of appIds encoded as NSStrings. |
| 59 NSMutableSet* _appsPossiblyBeingInstalled; | 62 NSMutableSet* _appsPossiblyBeingInstalled; |
| 60 } | 63 } |
| 61 | 64 |
| 62 // Designated initializer. Use this instead of -init. | 65 // Designated initializer. Use this instead of -init. |
| 63 - (instancetype)initWithWebState:(web::WebState*)webState | 66 - (instancetype)initWithWebState:(web::WebState*)webState |
| 64 requestContextGetter:(net::URLRequestContextGetter*)context | 67 requestContextGetter:(net::URLRequestContextGetter*)context |
| 65 tab:(Tab*)tab { | 68 tab:(Tab*)tab { |
| 66 self = [super init]; | 69 self = [super init]; |
| 67 if (self) { | 70 if (self) { |
| 68 DCHECK(context); | 71 DCHECK(context); |
| 69 _requestContextGetter = context; | 72 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( |
| 73 context, web::WebThread::GetBlockingPool()); |
| 70 DCHECK(webState); | 74 DCHECK(webState); |
| 71 _webState = webState; | 75 _webState = webState; |
| 72 // Allows |tab| to be nil for unit testing. If not nil, it should have the | 76 // Allows |tab| to be nil for unit testing. If not nil, it should have the |
| 73 // same webState. | 77 // same webState. |
| 74 DCHECK(!tab || [tab webState] == webState); | 78 DCHECK(!tab || [tab webState] == webState); |
| 75 _tab = tab; | 79 _tab = tab; |
| 76 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; | 80 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; |
| 77 } | 81 } |
| 78 return self; | 82 return self; |
| 79 } | 83 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 164 |
| 161 - (NSString*)appId { | 165 - (NSString*)appId { |
| 162 return [_metadata appId]; | 166 return [_metadata appId]; |
| 163 } | 167 } |
| 164 | 168 |
| 165 - (NSString*)appName { | 169 - (NSString*)appName { |
| 166 return [_metadata appName]; | 170 return [_metadata appName]; |
| 167 } | 171 } |
| 168 | 172 |
| 169 - (void)fetchSmallIconWithCompletionBlock:(void (^)(UIImage*))block { | 173 - (void)fetchSmallIconWithCompletionBlock:(void (^)(UIImage*))block { |
| 170 [_metadata fetchSmallIconWithContext:_requestContextGetter.get() | 174 [_metadata fetchSmallIconWithImageFetcher:_imageFetcher.get() |
| 171 completionBlock:block]; | 175 completionBlock:block]; |
| 172 } | 176 } |
| 173 | 177 |
| 174 - (void)openStore { | 178 - (void)openStore { |
| 175 // Register to get a notification when the app is installed. | 179 // Register to get a notification when the app is installed. |
| 176 [[InstallationNotifier sharedInstance] | 180 [[InstallationNotifier sharedInstance] |
| 177 registerForInstallationNotifications:self | 181 registerForInstallationNotifications:self |
| 178 withSelector:@selector(appDidInstall:) | 182 withSelector:@selector(appDidInstall:) |
| 179 forScheme:[_metadata anyScheme]]; | 183 forScheme:[_metadata anyScheme]]; |
| 180 NSString* appIdString = [self appId]; | 184 NSString* appIdString = [self appId]; |
| 181 // Defensively early return if native app metadata returns an nil string for | 185 // Defensively early return if native app metadata returns an nil string for |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { | 235 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { |
| 232 appIDToRemove = appID; | 236 appIDToRemove = appID; |
| 233 *stop = YES; | 237 *stop = YES; |
| 234 } | 238 } |
| 235 }]; | 239 }]; |
| 236 DCHECK(appIDToRemove); | 240 DCHECK(appIDToRemove); |
| 237 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; | 241 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; |
| 238 } | 242 } |
| 239 | 243 |
| 240 @end | 244 @end |
| OLD | NEW |