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