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" | |
19 | 18 |
20 @interface AppDelegate () { | 19 @interface AppDelegate () { |
21 AppViewController* _appViewController; | 20 AppViewController* _appViewController; |
22 } | 21 } |
23 @end | 22 @end |
24 | 23 |
25 @implementation AppDelegate | 24 @implementation AppDelegate |
26 | 25 |
27 @synthesize window = _window; | 26 @synthesize window = _window; |
28 | 27 |
29 - (BOOL)application:(UIApplication*)application | 28 - (BOOL)application:(UIApplication*)application |
30 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | 29 willFinishLaunchingWithOptions:(NSDictionary*)launchOptions { |
31 self.window = | 30 self.window = |
32 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | 31 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; |
33 self.window.backgroundColor = [UIColor whiteColor]; | 32 self.window.backgroundColor = [UIColor whiteColor]; |
34 return YES; | 33 return YES; |
35 } | 34 } |
36 | 35 |
37 - (BOOL)application:(UIApplication*)application | 36 - (BOOL)application:(UIApplication*)application |
38 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { | 37 didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { |
39 [self launchRemotingViewController]; | 38 [self launchRemotingViewController]; |
40 return YES; | 39 return YES; |
41 } | 40 } |
42 | 41 |
| 42 #ifndef NDEBUG |
43 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { | 43 - (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { |
| 44 DCHECK([RemotingService.instance.authentication |
| 45 isKindOfClass:[RemotingOAuthAuthentication class]]); |
| 46 |
44 NSMutableDictionary* components = [[NSMutableDictionary alloc] init]; | 47 NSMutableDictionary* components = [[NSMutableDictionary alloc] init]; |
45 NSArray* urlComponents = [[url query] componentsSeparatedByString:@"&"]; | 48 NSArray* urlComponents = [[url query] componentsSeparatedByString:@"&"]; |
46 | 49 |
47 for (NSString* componentPair in urlComponents) { | 50 for (NSString* componentPair in urlComponents) { |
48 NSArray* pair = [componentPair componentsSeparatedByString:@"="]; | 51 NSArray* pair = [componentPair componentsSeparatedByString:@"="]; |
49 NSString* key = [[pair firstObject] stringByRemovingPercentEncoding]; | 52 NSString* key = [[pair firstObject] stringByRemovingPercentEncoding]; |
50 NSString* value = [[pair lastObject] stringByRemovingPercentEncoding]; | 53 NSString* value = [[pair lastObject] stringByRemovingPercentEncoding]; |
51 [components setObject:value forKey:key]; | 54 [components setObject:value forKey:key]; |
52 } | 55 } |
53 NSString* authorizationCode = [components objectForKey:@"code"]; | 56 NSString* authorizationCode = [components objectForKey:@"code"]; |
54 | 57 |
55 [[RemotingService SharedInstance].authentication | 58 [(RemotingOAuthAuthentication*)RemotingService.instance.authentication |
56 authenticateWithAuthorizationCode:authorizationCode]; | 59 authenticateWithAuthorizationCode:authorizationCode]; |
57 | 60 |
58 [self launchRemotingViewController]; | 61 [self launchRemotingViewController]; |
59 return YES; | 62 return YES; |
60 } | 63 } |
| 64 #endif // ifndef NDEBUG |
61 | 65 |
62 #pragma mark - Public | 66 #pragma mark - Public |
63 - (void)showMenuAnimated:(BOOL)animated { | 67 - (void)showMenuAnimated:(BOOL)animated { |
64 DCHECK(_appViewController != nil); | 68 DCHECK(_appViewController != nil); |
65 [_appViewController showMenuAnimated:animated]; | 69 [_appViewController showMenuAnimated:animated]; |
66 } | 70 } |
67 | 71 |
68 - (void)hideMenuAnimated:(BOOL)animated { | 72 - (void)hideMenuAnimated:(BOOL)animated { |
69 DCHECK(_appViewController != nil); | 73 DCHECK(_appViewController != nil); |
70 [_appViewController hideMenuAnimated:animated]; | 74 [_appViewController hideMenuAnimated:animated]; |
(...skipping 10 matching lines...) Expand all Loading... |
81 return (AppDelegate*)UIApplication.sharedApplication.delegate; | 85 return (AppDelegate*)UIApplication.sharedApplication.delegate; |
82 } | 86 } |
83 | 87 |
84 #pragma mark - Private | 88 #pragma mark - Private |
85 | 89 |
86 - (void)launchRemotingViewController { | 90 - (void)launchRemotingViewController { |
87 RemotingViewController* vc = [[RemotingViewController alloc] init]; | 91 RemotingViewController* vc = [[RemotingViewController alloc] init]; |
88 UINavigationController* navController = | 92 UINavigationController* navController = |
89 [[UINavigationController alloc] initWithRootViewController:vc]; | 93 [[UINavigationController alloc] initWithRootViewController:vc]; |
90 navController.navigationBarHidden = true; | 94 navController.navigationBarHidden = true; |
91 | |
92 _appViewController = | 95 _appViewController = |
93 [[AppViewController alloc] initWithMainViewController:navController]; | 96 [[AppViewController alloc] initWithMainViewController:navController]; |
94 self.window.rootViewController = _appViewController; | 97 self.window.rootViewController = _appViewController; |
95 [self.window makeKeyAndVisible]; | 98 [self.window makeKeyAndVisible]; |
96 } | 99 } |
97 | 100 |
98 @end | 101 @end |
OLD | NEW |