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