| 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/memory/ptr_util.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 11 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" | 13 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 14 #include "components/infobars/core/infobar_manager.h" | 14 #include "components/infobars/core/infobar_manager.h" |
| 15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 15 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
| 16 #import "ios/chrome/browser/installation_notifier.h" | 16 #import "ios/chrome/browser/installation_notifier.h" |
| 17 #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" |
| 18 #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" |
| 19 #import "ios/chrome/browser/open_url_util.h" | 19 #import "ios/chrome/browser/open_url_util.h" |
| 20 #import "ios/chrome/browser/store_kit/store_kit_tab_helper.h" |
| 21 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" |
| 20 #import "ios/chrome/browser/tabs/tab.h" | 22 #import "ios/chrome/browser/tabs/tab.h" |
| 21 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 23 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 22 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" | 24 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" |
| 23 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" | 25 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types
.h" |
| 24 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" | 26 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" |
| 25 #include "ios/web/public/web_state/web_state.h" | 27 #include "ios/web/public/web_state/web_state.h" |
| 26 #include "ios/web/public/web_thread.h" | 28 #include "ios/web/public/web_thread.h" |
| 27 #import "ios/web/web_state/ui/crw_web_controller.h" | 29 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 28 #import "net/base/mac/url_conversions.h" | 30 #import "net/base/mac/url_conversions.h" |
| 29 | 31 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| | 43 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| |
| 42 - (NSMutableSet*)appsPossiblyBeingInstalled; | 44 - (NSMutableSet*)appsPossiblyBeingInstalled; |
| 43 | 45 |
| 44 // Records what type of infobar was opened. | 46 // Records what type of infobar was opened. |
| 45 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type | 47 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type |
| 46 onLinkNavigation:(BOOL)isLinkNavigation; | 48 onLinkNavigation:(BOOL)isLinkNavigation; |
| 47 | 49 |
| 48 @end | 50 @end |
| 49 | 51 |
| 50 @implementation NativeAppNavigationController { | 52 @implementation NativeAppNavigationController { |
| 51 // WebState provides access to the *TabHelper objects. This will eventually | 53 // WebState provides access to the *TabHelper objects. |
| 52 // replace the need to have |_tab| in this object. | |
| 53 web::WebState* _webState; | 54 web::WebState* _webState; |
| 54 // ImageFetcher needed to fetch the icons. | 55 // ImageFetcher needed to fetch the icons. |
| 55 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; | 56 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; |
| 56 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab | |
| 57 // states such as navigation manager and whether it is a pre-rendered tab. | |
| 58 // Use |webState| whenever possible. | |
| 59 __weak Tab* _tab; | |
| 60 id<NativeAppMetadata> _metadata; | 57 id<NativeAppMetadata> _metadata; |
| 61 // A set of appIds encoded as NSStrings. | 58 // A set of appIds encoded as NSStrings. |
| 62 NSMutableSet* _appsPossiblyBeingInstalled; | 59 NSMutableSet* _appsPossiblyBeingInstalled; |
| 63 } | 60 } |
| 64 | 61 |
| 65 // Designated initializer. Use this instead of -init. | 62 // Designated initializer. Use this instead of -init. |
| 66 - (instancetype)initWithWebState:(web::WebState*)webState | 63 - (instancetype)initWithWebState:(web::WebState*)webState |
| 67 requestContextGetter:(net::URLRequestContextGetter*)context | 64 requestContextGetter:(net::URLRequestContextGetter*)context { |
| 68 tab:(Tab*)tab { | |
| 69 self = [super init]; | 65 self = [super init]; |
| 70 if (self) { | 66 if (self) { |
| 71 DCHECK(context); | 67 DCHECK(context); |
| 72 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( | 68 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( |
| 73 context, web::WebThread::GetBlockingPool()); | 69 context, web::WebThread::GetBlockingPool()); |
| 74 DCHECK(webState); | 70 DCHECK(webState); |
| 75 _webState = webState; | 71 _webState = webState; |
| 76 // Allows |tab| to be nil for unit testing. If not nil, it should have the | |
| 77 // same webState. | |
| 78 DCHECK(!tab || [tab webState] == webState); | |
| 79 _tab = tab; | |
| 80 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; | 72 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; |
| 81 } | 73 } |
| 82 return self; | 74 return self; |
| 83 } | 75 } |
| 84 | 76 |
| 85 - (void)copyStateFrom:(NativeAppNavigationController*)controller { | 77 - (void)copyStateFrom:(NativeAppNavigationController*)controller { |
| 86 DCHECK(controller); | 78 DCHECK(controller); |
| 87 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] | 79 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] |
| 88 initWithSet:[controller appsPossiblyBeingInstalled]]; | 80 initWithSet:[controller appsPossiblyBeingInstalled]]; |
| 89 for (NSString* appIdString in _appsPossiblyBeingInstalled) { | 81 for (NSString* appIdString in _appsPossiblyBeingInstalled) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 registerForInstallationNotifications:self | 173 registerForInstallationNotifications:self |
| 182 withSelector:@selector(appDidInstall:) | 174 withSelector:@selector(appDidInstall:) |
| 183 forScheme:[_metadata anyScheme]]; | 175 forScheme:[_metadata anyScheme]]; |
| 184 NSString* appIdString = [self appId]; | 176 NSString* appIdString = [self appId]; |
| 185 // Defensively early return if native app metadata returns an nil string for | 177 // Defensively early return if native app metadata returns an nil string for |
| 186 // appId which can cause subsequent -addObject: to throw exceptions. | 178 // appId which can cause subsequent -addObject: to throw exceptions. |
| 187 if (![appIdString length]) | 179 if (![appIdString length]) |
| 188 return; | 180 return; |
| 189 DCHECK(![_appsPossiblyBeingInstalled containsObject:appIdString]); | 181 DCHECK(![_appsPossiblyBeingInstalled containsObject:appIdString]); |
| 190 [_appsPossiblyBeingInstalled addObject:appIdString]; | 182 [_appsPossiblyBeingInstalled addObject:appIdString]; |
| 191 // TODO(crbug.com/684063): Preferred method is to add a helper object to | 183 StoreKitTabHelper* tab_helper = StoreKitTabHelper::FromWebState(_webState); |
| 192 // WebState and use the helper object to launch Store Kit. | 184 if (tab_helper) |
| 193 [_tab openAppStore:appIdString]; | 185 tab_helper->OpenAppStore(appIdString); |
| 194 } | 186 } |
| 195 | 187 |
| 196 - (void)launchApp:(const GURL&)URL { | 188 - (void)launchApp:(const GURL&)URL { |
| 197 // TODO(crbug.com/353957): Pass the ChromeIdentity to | 189 // TODO(crbug.com/353957): Pass the ChromeIdentity to |
| 198 // -launchURLWithURL:identity: | 190 // -launchURLWithURL:identity: |
| 199 GURL launchURL([_metadata launchURLWithURL:URL identity:nil]); | 191 GURL launchURL([_metadata launchURLWithURL:URL identity:nil]); |
| 200 if (launchURL.is_valid()) { | 192 if (launchURL.is_valid()) { |
| 201 OpenUrlWithCompletionHandler(net::NSURLWithGURL(launchURL), nil); | 193 OpenUrlWithCompletionHandler(net::NSURLWithGURL(launchURL), nil); |
| 202 } | 194 } |
| 203 } | 195 } |
| 204 | 196 |
| 205 - (void)updateMetadataWithUserAction:(NativeAppActionType)userAction { | 197 - (void)updateMetadataWithUserAction:(NativeAppActionType)userAction { |
| 206 [_metadata updateWithUserAction:userAction]; | 198 [_metadata updateWithUserAction:userAction]; |
| 207 } | 199 } |
| 208 | 200 |
| 209 #pragma mark - | 201 #pragma mark - |
| 210 #pragma mark CRWWebControllerObserver methods | 202 #pragma mark CRWWebControllerObserver methods |
| 211 | 203 |
| 212 - (void)pageLoaded:(CRWWebController*)webController { | 204 - (void)pageLoaded:(CRWWebController*)webController { |
| 213 if (![_tab isPrerenderTab]) | 205 Tab* tab = LegacyTabHelper::GetTabForWebState(_webState); |
| 206 if (![tab isPrerenderTab]) |
| 214 [self showInfoBarIfNecessary]; | 207 [self showInfoBarIfNecessary]; |
| 215 } | 208 } |
| 216 | 209 |
| 217 - (void)webControllerWillClose:(CRWWebController*)webController { | 210 - (void)webControllerWillClose:(CRWWebController*)webController { |
| 218 [webController removeObserver:self]; | 211 [webController removeObserver:self]; |
| 219 } | 212 } |
| 220 | 213 |
| 221 - (void)appDidInstall:(NSNotification*)notification { | 214 - (void)appDidInstall:(NSNotification*)notification { |
| 222 [self removeAppFromNotification:notification]; | 215 [self removeAppFromNotification:notification]; |
| 223 [self showInfoBarIfNecessary]; | 216 [self showInfoBarIfNecessary]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 235 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { | 228 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { |
| 236 appIDToRemove = appID; | 229 appIDToRemove = appID; |
| 237 *stop = YES; | 230 *stop = YES; |
| 238 } | 231 } |
| 239 }]; | 232 }]; |
| 240 DCHECK(appIDToRemove); | 233 DCHECK(appIDToRemove); |
| 241 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; | 234 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; |
| 242 } | 235 } |
| 243 | 236 |
| 244 @end | 237 @end |
| OLD | NEW |