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/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
11 #include "components/infobars/core/infobar_manager.h" | 11 #include "components/infobars/core/infobar_manager.h" |
12 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" | 12 #include "ios/chrome/browser/infobars/infobar_manager_impl.h" |
13 #import "ios/chrome/browser/installation_notifier.h" | 13 #import "ios/chrome/browser/installation_notifier.h" |
14 #include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h" | 14 #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" | 15 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h" |
16 #import "ios/chrome/browser/open_url_util.h" | 16 #import "ios/chrome/browser/open_url_util.h" |
17 #import "ios/chrome/browser/tabs/tab.h" | 17 #import "ios/chrome/browser/tabs/tab.h" |
18 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 18 #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" | 19 #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" | 20 #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" | 21 #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" | 22 #include "ios/web/public/web_state/web_state.h" |
23 #import "ios/web/web_state/ui/crw_web_controller.h" | |
23 #import "net/base/mac/url_conversions.h" | 24 #import "net/base/mac/url_conversions.h" |
24 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
25 | 26 |
27 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
28 #error "This file requires ARC support." | |
29 #endif | |
30 | |
26 using base::UserMetricsAction; | 31 using base::UserMetricsAction; |
27 | 32 |
28 @interface NativeAppNavigationController () | 33 @interface NativeAppNavigationController () |
29 // Shows a native app infobar by looking at the page's URL and by checking | 34 // Shows a native app infobar by looking at the page's URL and by checking |
30 // wheter that infobar should be bypassed or not. | 35 // wheter that infobar should be bypassed or not. |
31 - (void)showInfoBarIfNecessary; | 36 - (void)showInfoBarIfNecessary; |
32 | 37 |
33 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| | 38 // Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled| |
34 - (NSMutableSet*)appsPossiblyBeingInstalled; | 39 - (NSMutableSet*)appsPossiblyBeingInstalled; |
35 | 40 |
36 // Records what type of infobar was opened. | 41 // Records what type of infobar was opened. |
37 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type | 42 - (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type |
38 onLinkNavigation:(BOOL)isLinkNavigation; | 43 onLinkNavigation:(BOOL)isLinkNavigation; |
39 | 44 |
40 @end | 45 @end |
41 | 46 |
42 @implementation NativeAppNavigationController { | 47 @implementation NativeAppNavigationController { |
43 // WebState provides access to the *TabHelper objects. This will eventually | 48 // WebState provides access to the *TabHelper objects. This will eventually |
44 // replace the need to have |_tab| in this object. | 49 // replace the need to have |_tab| in this object. |
45 web::WebState* _webState; | 50 web::WebState* _webState; |
46 // A reference to the URLRequestContextGetter needed to fetch icons. | 51 // A reference to the URLRequestContextGetter needed to fetch icons. |
47 scoped_refptr<net::URLRequestContextGetter> _requestContextGetter; | 52 scoped_refptr<net::URLRequestContextGetter> _requestContextGetter; |
48 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab | 53 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab |
49 // states such as navigation manager and whether it is a pre-rendered tab. | 54 // states such as navigation manager and whether it is a pre-rendered tab. |
50 // Use |webState| whenever possible. | 55 // Use |webState| whenever possible. |
51 __unsafe_unretained Tab* _tab; // weak | 56 __unsafe_unretained Tab* _tab; // weak |
stkhapugin
2017/01/31 14:17:54
This can now become a __weak.
| |
52 base::scoped_nsprotocol<id<NativeAppMetadata>> _metadata; | 57 id<NativeAppMetadata> _metadata; |
53 // A set of appIds encoded as NSStrings. | 58 // A set of appIds encoded as NSStrings. |
54 base::scoped_nsobject<NSMutableSet> _appsPossiblyBeingInstalled; | 59 NSMutableSet* _appsPossiblyBeingInstalled; |
55 } | 60 } |
56 | 61 |
57 // Designated initializer. Use this instead of -init. | 62 // Designated initializer. Use this instead of -init. |
58 - (instancetype)initWithWebState:(web::WebState*)webState | 63 - (instancetype)initWithWebState:(web::WebState*)webState |
59 requestContextGetter:(net::URLRequestContextGetter*)context | 64 requestContextGetter:(net::URLRequestContextGetter*)context |
60 tab:(Tab*)tab { | 65 tab:(Tab*)tab { |
61 self = [super init]; | 66 self = [super init]; |
62 if (self) { | 67 if (self) { |
63 DCHECK(context); | 68 DCHECK(context); |
64 _requestContextGetter = context; | 69 _requestContextGetter = context; |
65 DCHECK(webState); | 70 DCHECK(webState); |
66 _webState = webState; | 71 _webState = webState; |
67 // Allows |tab| to be nil for unit testing. If not nil, it should have the | 72 // Allows |tab| to be nil for unit testing. If not nil, it should have the |
68 // same webState. | 73 // same webState. |
69 DCHECK(!tab || [tab webState] == webState); | 74 DCHECK(!tab || [tab webState] == webState); |
70 _tab = tab; | 75 _tab = tab; |
71 _appsPossiblyBeingInstalled.reset([[NSMutableSet alloc] init]); | 76 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; |
72 } | 77 } |
73 return self; | 78 return self; |
74 } | 79 } |
75 | 80 |
76 - (void)copyStateFrom:(NativeAppNavigationController*)controller { | 81 - (void)copyStateFrom:(NativeAppNavigationController*)controller { |
77 DCHECK(controller); | 82 DCHECK(controller); |
78 _appsPossiblyBeingInstalled.reset([[NSMutableSet alloc] | 83 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] |
79 initWithSet:[controller appsPossiblyBeingInstalled]]); | 84 initWithSet:[controller appsPossiblyBeingInstalled]]; |
80 for (NSString* appIdString in _appsPossiblyBeingInstalled.get()) { | 85 for (NSString* appIdString in _appsPossiblyBeingInstalled) { |
81 DCHECK([appIdString isKindOfClass:[NSString class]]); | 86 DCHECK([appIdString isKindOfClass:[NSString class]]); |
82 NSURL* appURL = | 87 NSURL* appURL = |
83 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() | 88 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() |
84 schemeForAppId:appIdString]; | 89 schemeForAppId:appIdString]; |
85 [[InstallationNotifier sharedInstance] | 90 [[InstallationNotifier sharedInstance] |
86 registerForInstallationNotifications:self | 91 registerForInstallationNotifications:self |
87 withSelector:@selector(appDidInstall:) | 92 withSelector:@selector(appDidInstall:) |
88 forScheme:[appURL scheme]]; | 93 forScheme:[appURL scheme]]; |
89 } | 94 } |
90 [self showInfoBarIfNecessary]; | 95 [self showInfoBarIfNecessary]; |
91 } | 96 } |
92 | 97 |
93 - (void)dealloc { | 98 - (void)dealloc { |
94 [[InstallationNotifier sharedInstance] unregisterForNotifications:self]; | 99 [[InstallationNotifier sharedInstance] unregisterForNotifications:self]; |
95 [super dealloc]; | |
96 } | 100 } |
97 | 101 |
98 - (NSMutableSet*)appsPossiblyBeingInstalled { | 102 - (NSMutableSet*)appsPossiblyBeingInstalled { |
99 return _appsPossiblyBeingInstalled; | 103 return _appsPossiblyBeingInstalled; |
100 } | 104 } |
101 | 105 |
102 - (void)showInfoBarIfNecessary { | 106 - (void)showInfoBarIfNecessary { |
103 // Find a potential matching native app. | 107 // Find a potential matching native app. |
104 GURL pageURL = _webState->GetLastCommittedURL(); | 108 GURL pageURL = _webState->GetLastCommittedURL(); |
105 _metadata.reset( | 109 _metadata = [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() |
106 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() | 110 nativeAppForURL:pageURL]; |
107 newNativeAppForURL:pageURL]); | |
108 if (!_metadata || [_metadata shouldBypassInfoBars]) | 111 if (!_metadata || [_metadata shouldBypassInfoBars]) |
109 return; | 112 return; |
110 | 113 |
111 // Select the infobar type. | 114 // Select the infobar type. |
112 NativeAppControllerType type; | 115 NativeAppControllerType type; |
113 bool isLinkNavigation = native_app_launcher::IsLinkNavigation(_webState); | 116 bool isLinkNavigation = native_app_launcher::IsLinkNavigation(_webState); |
114 if ([_metadata canOpenURL:pageURL]) { // App is installed. | 117 if ([_metadata canOpenURL:pageURL]) { // App is installed. |
115 type = isLinkNavigation && ![_metadata shouldAutoOpenLinks] | 118 type = isLinkNavigation && ![_metadata shouldAutoOpenLinks] |
116 ? NATIVE_APP_OPEN_POLICY_CONTROLLER | 119 ? NATIVE_APP_OPEN_POLICY_CONTROLLER |
117 : NATIVE_APP_LAUNCHER_CONTROLLER; | 120 : NATIVE_APP_LAUNCHER_CONTROLLER; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { | 231 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { |
229 appIDToRemove = appID; | 232 appIDToRemove = appID; |
230 *stop = YES; | 233 *stop = YES; |
231 } | 234 } |
232 }]; | 235 }]; |
233 DCHECK(appIDToRemove); | 236 DCHECK(appIDToRemove); |
234 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; | 237 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; |
235 } | 238 } |
236 | 239 |
237 @end | 240 @end |
OLD | NEW |