OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
7 #endif | 7 #endif |
8 | 8 |
9 #import "remoting/ios/app/app_delegate.h" | 9 #import "remoting/ios/app/app_delegate.h" |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
14 | 14 |
15 #import "remoting/ios/app/app_view_controller.h" | 15 #import "remoting/ios/app/app_view_controller.h" |
16 #import "remoting/ios/app/remoting_view_controller.h" | 16 #import "remoting/ios/app/remoting_view_controller.h" |
17 #import "remoting/ios/facade/remoting_authentication.h" | 17 #import "remoting/ios/facade/remoting_oauth_authentication.h" |
18 #import "remoting/ios/facade/remoting_service.h" | 18 #import "remoting/ios/facade/remoting_service.h" |
19 | 19 |
20 @interface AppDelegate () { | 20 @interface AppDelegate () { |
21 AppViewController* _appViewController; | 21 AppViewController* _appViewController; |
22 } | 22 } |
23 @end | 23 @end |
24 | 24 |
25 @implementation AppDelegate | 25 @implementation AppDelegate |
26 | 26 |
27 @synthesize window = _window; | 27 @synthesize window = _window; |
28 | 28 |
29 - (BOOL)application:(UIApplication*)application | 29 - (BOOL)application:(UIApplication*)application |
30 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | 30 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions { |
31 self.window = | 31 self.window = |
32 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | 32 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
33 self.window.backgroundColor = [UIColor whiteColor]; | 33 self.window.backgroundColor = [UIColor whiteColor]; |
34 _appViewController = [[AppViewController alloc] init]; | |
35 [[RemotingService SharedInstance] | |
36 setAuthentication:_appViewController.authentication]; | |
nicholss
2017/06/21 21:31:06
This feels backwards to me. The view controller sh
Yuwei
2017/06/21 22:44:15
Done. It's now injected in the main function.
| |
34 return YES; | 37 return YES; |
35 } | 38 } |
36 | 39 |
37 - (BOOL)application:(UIApplication*)application | 40 - (BOOL)application:(UIApplication*)application |
38 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | 41 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { |
39 [self launchRemotingViewController]; | 42 [self launchRemotingViewController]; |
40 return YES; | 43 return YES; |
41 } | 44 } |
42 | 45 |
43 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { | 46 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { |
47 if (![_appViewController.authentication | |
nicholss
2017/06/21 21:31:06
Could it be cleaner to wrap this method in somethi
Yuwei
2017/06/21 22:44:15
Done. Use marco here. I put the DCHECK here just t
| |
48 isKindOfClass:[RemotingOAuthAuthentication class]]) { | |
49 NSLog(@"OAuth authentication is not supported."); | |
50 return NO; | |
51 } | |
52 | |
44 NSMutableDictionary* components = [[NSMutableDictionary alloc] init]; | 53 NSMutableDictionary* components = [[NSMutableDictionary alloc] init]; |
45 NSArray* urlComponents = [[url query] componentsSeparatedByString:@"&"]; | 54 NSArray* urlComponents = [[url query] componentsSeparatedByString:@"&"]; |
46 | 55 |
47 for (NSString* componentPair in urlComponents) { | 56 for (NSString* componentPair in urlComponents) { |
48 NSArray* pair = [componentPair componentsSeparatedByString:@"="]; | 57 NSArray* pair = [componentPair componentsSeparatedByString:@"="]; |
49 NSString* key = [[pair firstObject] stringByRemovingPercentEncoding]; | 58 NSString* key = [[pair firstObject] stringByRemovingPercentEncoding]; |
50 NSString* value = [[pair lastObject] stringByRemovingPercentEncoding]; | 59 NSString* value = [[pair lastObject] stringByRemovingPercentEncoding]; |
51 [components setObject:value forKey:key]; | 60 [components setObject:value forKey:key]; |
52 } | 61 } |
53 NSString* authorizationCode = [components objectForKey:@"code"]; | 62 NSString* authorizationCode = [components objectForKey:@"code"]; |
54 | 63 |
55 [[RemotingService SharedInstance].authentication | 64 [(RemotingOAuthAuthentication*)_appViewController.authentication |
56 authenticateWithAuthorizationCode:authorizationCode]; | 65 authenticateWithAuthorizationCode:authorizationCode]; |
57 | 66 |
58 [self launchRemotingViewController]; | 67 [self launchRemotingViewController]; |
59 return YES; | 68 return YES; |
60 } | 69 } |
61 | 70 |
62 #pragma mark - Public | 71 #pragma mark - Public |
63 - (void)showMenuAnimated:(BOOL)animated { | 72 - (void)showMenuAnimated:(BOOL)animated { |
64 DCHECK(_appViewController != nil); | 73 DCHECK(_appViewController != nil); |
65 [_appViewController showMenuAnimated:animated]; | 74 [_appViewController showMenuAnimated:animated]; |
(...skipping 15 matching lines...) Expand all Loading... | |
81 return (AppDelegate*)UIApplication.sharedApplication.delegate; | 90 return (AppDelegate*)UIApplication.sharedApplication.delegate; |
82 } | 91 } |
83 | 92 |
84 #pragma mark - Private | 93 #pragma mark - Private |
85 | 94 |
86 - (void)launchRemotingViewController { | 95 - (void)launchRemotingViewController { |
87 RemotingViewController* vc = [[RemotingViewController alloc] init]; | 96 RemotingViewController* vc = [[RemotingViewController alloc] init]; |
88 UINavigationController* navController = | 97 UINavigationController* navController = |
89 [[UINavigationController alloc] initWithRootViewController:vc]; | 98 [[UINavigationController alloc] initWithRootViewController:vc]; |
90 navController.navigationBarHidden = true; | 99 navController.navigationBarHidden = true; |
91 | 100 _appViewController.mainViewController = navController; |
92 _appViewController = | |
93 [[AppViewController alloc] initWithMainViewController:navController]; | |
94 self.window.rootViewController = _appViewController; | 101 self.window.rootViewController = _appViewController; |
95 [self.window makeKeyAndVisible]; | 102 [self.window makeKeyAndVisible]; |
96 } | 103 } |
97 | 104 |
98 @end | 105 @end |
OLD | NEW |