Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: ios/chrome/browser/native_app_launcher/native_app_navigation_controller.mm

Issue 2731443003: Removed CRWWebController dependency from NativeAppNavigationController. (Closed)
Patch Set: Fixed dependencies Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/tabs/tab.h" 20 #import "ios/chrome/browser/tabs/tab.h"
21 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 21 #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" 22 #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" 23 #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" 24 #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" 25 #include "ios/web/public/web_state/web_state.h"
26 #import "ios/web/public/web_state/web_state_observer_bridge.h"
26 #include "ios/web/public/web_thread.h" 27 #include "ios/web/public/web_thread.h"
27 #import "ios/web/web_state/ui/crw_web_controller.h"
28 #import "net/base/mac/url_conversions.h" 28 #import "net/base/mac/url_conversions.h"
29 29
30 #if !defined(__has_feature) || !__has_feature(objc_arc) 30 #if !defined(__has_feature) || !__has_feature(objc_arc)
31 #error "This file requires ARC support." 31 #error "This file requires ARC support."
32 #endif 32 #endif
33 33
34 using base::UserMetricsAction; 34 using base::UserMetricsAction;
35 35
36 @interface NativeAppNavigationController () 36 @interface NativeAppNavigationController ()<
37 CRWWebStateObserver,
38 NativeAppNavigationControllerProtocol>
37 // Shows a native app infobar by looking at the page's URL and by checking 39 // Shows a native app infobar by looking at the page's URL and by checking
38 // wheter that infobar should be bypassed or not. 40 // wheter that infobar should be bypassed or not.
39 - (void)showInfoBarIfNecessary; 41 - (void)showInfoBarIfNecessary;
40 42
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. This will eventually
52 // replace the need to have |_tab| in this object. 54 // replace the need to have |_tab| in this object.
53 web::WebState* _webState; 55 web::WebState* _webState;
54 // ImageFetcher needed to fetch the icons. 56 // ImageFetcher needed to fetch the icons.
55 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; 57 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher;
56 // DEPRECATED: Tab hosting the infobar and is also used for accessing Tab 58 // 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. 59 // states such as navigation manager and whether it is a pre-rendered tab.
58 // Use |webState| whenever possible. 60 // Use |webState| whenever possible.
59 __weak Tab* _tab; 61 __weak Tab* _tab;
60 id<NativeAppMetadata> _metadata; 62 id<NativeAppMetadata> _metadata;
61 // A set of appIds encoded as NSStrings. 63 // A set of appIds encoded as NSStrings.
62 NSMutableSet* _appsPossiblyBeingInstalled; 64 NSMutableSet* _appsPossiblyBeingInstalled;
65 // Allows this class to subscribe for CRWWebStateObserver callbacks.
66 std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
63 } 67 }
64 68
65 // Designated initializer. Use this instead of -init. 69 // Designated initializer. Use this instead of -init.
66 - (instancetype)initWithWebState:(web::WebState*)webState 70 - (instancetype)initWithWebState:(web::WebState*)webState
67 requestContextGetter:(net::URLRequestContextGetter*)context 71 requestContextGetter:(net::URLRequestContextGetter*)context
68 tab:(Tab*)tab { 72 tab:(Tab*)tab {
69 self = [super init]; 73 self = [super init];
70 if (self) { 74 if (self) {
71 DCHECK(context); 75 DCHECK(context);
72 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( 76 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>(
73 context, web::WebThread::GetBlockingPool()); 77 context, web::WebThread::GetBlockingPool());
74 DCHECK(webState); 78 DCHECK(webState);
75 _webState = webState; 79 _webState = webState;
76 // Allows |tab| to be nil for unit testing. If not nil, it should have the 80 // Allows |tab| to be nil for unit testing. If not nil, it should have the
77 // same webState. 81 // same webState.
78 DCHECK(!tab || [tab webState] == webState); 82 DCHECK(!tab || [tab webState] == webState);
79 _tab = tab; 83 _tab = tab;
80 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init]; 84 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] init];
85 _webStateObserver.reset(new web::WebStateObserverBridge(webState, self));
81 } 86 }
82 return self; 87 return self;
83 } 88 }
84 89
85 - (void)copyStateFrom:(NativeAppNavigationController*)controller { 90 - (void)copyStateFrom:(NativeAppNavigationController*)controller {
86 DCHECK(controller); 91 DCHECK(controller);
87 _appsPossiblyBeingInstalled = [[NSMutableSet alloc] 92 _appsPossiblyBeingInstalled = [[NSMutableSet alloc]
88 initWithSet:[controller appsPossiblyBeingInstalled]]; 93 initWithSet:[controller appsPossiblyBeingInstalled]];
89 for (NSString* appIdString in _appsPossiblyBeingInstalled) { 94 for (NSString* appIdString in _appsPossiblyBeingInstalled) {
90 DCHECK([appIdString isKindOfClass:[NSString class]]); 95 DCHECK([appIdString isKindOfClass:[NSString class]]);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (launchURL.is_valid()) { 205 if (launchURL.is_valid()) {
201 OpenUrlWithCompletionHandler(net::NSURLWithGURL(launchURL), nil); 206 OpenUrlWithCompletionHandler(net::NSURLWithGURL(launchURL), nil);
202 } 207 }
203 } 208 }
204 209
205 - (void)updateMetadataWithUserAction:(NativeAppActionType)userAction { 210 - (void)updateMetadataWithUserAction:(NativeAppActionType)userAction {
206 [_metadata updateWithUserAction:userAction]; 211 [_metadata updateWithUserAction:userAction];
207 } 212 }
208 213
209 #pragma mark - 214 #pragma mark -
210 #pragma mark CRWWebControllerObserver methods 215 #pragma mark CRWWebStateObserver methods
211 216
212 - (void)pageLoaded:(CRWWebController*)webController { 217 - (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
213 if (![_tab isPrerenderTab]) 218 if (success && ![_tab isPrerenderTab])
214 [self showInfoBarIfNecessary]; 219 [self showInfoBarIfNecessary];
215 } 220 }
216 221
217 - (void)webControllerWillClose:(CRWWebController*)webController { 222 - (void)webStateDestroyed:(web::WebState*)webState {
218 [webController removeObserver:self]; 223 _webState = nullptr;
219 } 224 }
220 225
226 #pragma mark -
227 #pragma mark Private methods
pkl (ping after 24h if needed) 2017/03/03 16:45:30 nit: Can we just use one line? Like this: #pragma
Eugene But (OOO till 7-30) 2017/03/03 19:42:07 Done. Fixed in other 2 places as well.
228
221 - (void)appDidInstall:(NSNotification*)notification { 229 - (void)appDidInstall:(NSNotification*)notification {
222 [self removeAppFromNotification:notification]; 230 [self removeAppFromNotification:notification];
223 [self showInfoBarIfNecessary]; 231 [self showInfoBarIfNecessary];
224 } 232 }
225 233
226 - (void)removeAppFromNotification:(NSNotification*)notification { 234 - (void)removeAppFromNotification:(NSNotification*)notification {
227 DCHECK([[notification object] isKindOfClass:[InstallationNotifier class]]); 235 DCHECK([[notification object] isKindOfClass:[InstallationNotifier class]]);
228 NSString* schemeOfInstalledApp = [notification name]; 236 NSString* schemeOfInstalledApp = [notification name];
229 __block NSString* appIDToRemove = nil; 237 __block NSString* appIDToRemove = nil;
230 [_appsPossiblyBeingInstalled 238 [_appsPossiblyBeingInstalled
231 enumerateObjectsUsingBlock:^(id appID, BOOL* stop) { 239 enumerateObjectsUsingBlock:^(id appID, BOOL* stop) {
232 NSURL* appURL = 240 NSURL* appURL =
233 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager() 241 [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager()
234 schemeForAppId:appID]; 242 schemeForAppId:appID];
235 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) { 243 if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) {
236 appIDToRemove = appID; 244 appIDToRemove = appID;
237 *stop = YES; 245 *stop = YES;
238 } 246 }
239 }]; 247 }];
240 DCHECK(appIDToRemove); 248 DCHECK(appIDToRemove);
241 [_appsPossiblyBeingInstalled removeObject:appIDToRemove]; 249 [_appsPossiblyBeingInstalled removeObject:appIDToRemove];
242 } 250 }
243 251
244 @end 252 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698