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

Side by Side Diff: remoting/ios/app/client_connection_view_controller.mm

Issue 2917253002: [CRD iOS] Create RemotingClient in ClientConnectionViewController (Closed)
Patch Set: fix Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/client_connection_view_controller.h" 9 #import "remoting/ios/app/client_connection_view_controller.h"
10 10
11 #import "base/mac/bind_objc_block.h"
11 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MDCActivityIndicator.h" 12 #import "ios/third_party/material_components_ios/src/components/ActivityIndicato r/src/MDCActivityIndicator.h"
12 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h" 13 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate rialButtons.h"
13 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr c/MaterialNavigationBar.h" 14 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr c/MaterialNavigationBar.h"
15 #import "remoting/ios/app/host_view_controller.h"
14 #import "remoting/ios/app/pin_entry_view.h" 16 #import "remoting/ios/app/pin_entry_view.h"
15 #import "remoting/ios/domain/client_session_details.h" 17 #import "remoting/ios/domain/client_session_details.h"
18 #import "remoting/ios/domain/host_info.h"
19 #import "remoting/ios/facade/remoting_authentication.h"
20 #import "remoting/ios/facade/remoting_service.h"
16 #import "remoting/ios/session/remoting_client.h" 21 #import "remoting/ios/session/remoting_client.h"
17 22
18 #include "base/strings/sys_string_conversions.h" 23 #include "base/strings/sys_string_conversions.h"
19 #include "remoting/protocol/client_authentication_config.h" 24 #include "remoting/protocol/client_authentication_config.h"
20 25
21 static const CGFloat kIconRadius = 30.f; 26 static const CGFloat kIconRadius = 30.f;
22 static const CGFloat kActivityIndicatorStrokeWidth = 3.f; 27 static const CGFloat kActivityIndicatorStrokeWidth = 3.f;
23 static const CGFloat kActivityIndicatorRadius = 33.f; 28 static const CGFloat kActivityIndicatorRadius = 33.f;
24 29
25 static const CGFloat kPinEntryViewWidth = 240.f; 30 static const CGFloat kPinEntryViewWidth = 240.f;
26 static const CGFloat kPinEntryViewHeight = 90.f; 31 static const CGFloat kPinEntryViewHeight = 90.f;
27 32
28 static const CGFloat kCenterShift = -80.f; 33 static const CGFloat kCenterShift = -80.f;
29 static const CGFloat kPadding = 20.f; 34 static const CGFloat kPadding = 20.f;
30 static const CGFloat kMargin = 20.f; 35 static const CGFloat kMargin = 20.f;
31 36
32 static const CGFloat kBarHeight = 58.f; 37 static const CGFloat kBarHeight = 58.f;
33 38
34 static const CGFloat kKeyboardAnimationTime = 0.3; 39 static const CGFloat kKeyboardAnimationTime = 0.3;
35 40
36 @interface ClientConnectionViewController ()<PinEntryDelegate> { 41 @interface ClientConnectionViewController ()<PinEntryDelegate> {
37 UIImageView* _iconView; 42 UIImageView* _iconView;
38 MDCActivityIndicator* _activityIndicator; 43 MDCActivityIndicator* _activityIndicator;
39 UILabel* _statusLabel; 44 UILabel* _statusLabel;
40 MDCNavigationBar* _navBar; 45 MDCNavigationBar* _navBar;
41 PinEntryView* _pinEntryView; 46 PinEntryView* _pinEntryView;
42 NSString* _remoteHostName; 47 NSString* _remoteHostName;
48 RemotingClient* _client;
43 } 49 }
44 @end 50 @end
45 51
46 @implementation ClientConnectionViewController 52 @implementation ClientConnectionViewController
47 53
48 @synthesize state = _state; 54 @synthesize state = _state;
49 @synthesize delegate = _delegate;
50 55
51 - (id)init { 56 - (instancetype)initWithHostInfo:(HostInfo*)hostInfo {
52 self = [super init]; 57 self = [super init];
53 if (self) { 58 if (self) {
59 _client = [[RemotingClient alloc] init];
60
61 __weak RemotingClient* weakClient = _client;
62 [[RemotingService SharedInstance].authentication
63 callbackWithAccessToken:base::BindBlockArc(^(
64 remoting::OAuthTokenGetter::Status status,
65 const std::string& user_email,
66 const std::string& access_token) {
67 [weakClient connectToHost:hostInfo
68 username:base::SysUTF8ToNSString(user_email)
69 accessToken:base::SysUTF8ToNSString(access_token)];
70 })];
71
72 _remoteHostName = hostInfo.hostName;
73
54 // TODO(yuweih): This logic may be reused by other views. 74 // TODO(yuweih): This logic may be reused by other views.
55 UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeSystem]; 75 UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
56 [cancelButton setTitle:@"CANCEL" forState:UIControlStateNormal]; 76 [cancelButton setTitle:@"CANCEL" forState:UIControlStateNormal];
57 [cancelButton setImage:[[UIImage imageNamed:@"Back"] 77 [cancelButton setImage:[[UIImage imageNamed:@"Back"]
58 imageFlippedForRightToLeftLayoutDirection] 78 imageFlippedForRightToLeftLayoutDirection]
59 forState:UIControlStateNormal]; 79 forState:UIControlStateNormal];
60 [cancelButton addTarget:self 80 [cancelButton addTarget:self
61 action:@selector(didTapCancel:) 81 action:@selector(didTapCancel:)
62 forControlEvents:UIControlEventTouchUpInside]; 82 forControlEvents:UIControlEventTouchUpInside];
63 self.navigationItem.leftBarButtonItem = 83 self.navigationItem.leftBarButtonItem =
(...skipping 11 matching lines...) Expand all
75 95
76 // Attach navBar to the top of the view. 96 // Attach navBar to the top of the view.
77 [NSLayoutConstraint activateConstraints:@[ 97 [NSLayoutConstraint activateConstraints:@[
78 [[_navBar topAnchor] constraintEqualToAnchor:[self.view topAnchor]], 98 [[_navBar topAnchor] constraintEqualToAnchor:[self.view topAnchor]],
79 [[_navBar leadingAnchor] 99 [[_navBar leadingAnchor]
80 constraintEqualToAnchor:[self.view leadingAnchor]], 100 constraintEqualToAnchor:[self.view leadingAnchor]],
81 [[_navBar trailingAnchor] 101 [[_navBar trailingAnchor]
82 constraintEqualToAnchor:[self.view trailingAnchor]], 102 constraintEqualToAnchor:[self.view trailingAnchor]],
83 [[_navBar heightAnchor] constraintEqualToConstant:kBarHeight], 103 [[_navBar heightAnchor] constraintEqualToConstant:kBarHeight],
84 ]]; 104 ]];
85
86 _remoteHostName = @"";
87 } 105 }
88 return self; 106 return self;
89 } 107 }
90 108
91 #pragma mark - UIViewController 109 #pragma mark - UIViewController
92 110
93 - (void)loadView { 111 - (void)loadView {
94 [super loadView]; 112 [super loadView];
95 113
96 self.view.backgroundColor = [UIColor blackColor]; 114 self.view.backgroundColor = [UIColor blackColor];
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 198
181 [_activityIndicator startAnimating]; 199 [_activityIndicator startAnimating];
182 } 200 }
183 201
184 - (void)viewWillDisappear:(BOOL)animated { 202 - (void)viewWillDisappear:(BOOL)animated {
185 [super viewWillDisappear:animated]; 203 [super viewWillDisappear:animated];
186 [_activityIndicator stopAnimating]; 204 [_activityIndicator stopAnimating];
187 [[NSNotificationCenter defaultCenter] removeObserver:self]; 205 [[NSNotificationCenter defaultCenter] removeObserver:self];
188 } 206 }
189 207
208 - (BOOL)prefersStatusBarHidden {
209 return YES;
210 }
211
190 #pragma mark - Keyboard 212 #pragma mark - Keyboard
191 213
192 - (void)keyboardWillShow:(NSNotification*)notification { 214 - (void)keyboardWillShow:(NSNotification*)notification {
193 CGSize keyboardSize = 215 CGSize keyboardSize =
194 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] 216 [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey]
195 CGRectValue] 217 CGRectValue]
196 .size; 218 .size;
197 219
198 [UIView 220 [UIView
199 animateWithDuration:kKeyboardAnimationTime 221 animateWithDuration:kKeyboardAnimationTime
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 break; 255 break;
234 case ClientViewConnected: 256 case ClientViewConnected:
235 [self showConnectedState]; 257 [self showConnectedState];
236 break; 258 break;
237 case ClientViewClosed: 259 case ClientViewClosed:
238 [self dismissViewControllerAnimated:YES completion:nil]; 260 [self dismissViewControllerAnimated:YES completion:nil];
239 break; 261 break;
240 } 262 }
241 } 263 }
242 264
243 - (void)setDelegate:(id<ClientConnectionViewControllerDelegate>)delegate {
244 _delegate = delegate;
245 if (_delegate) {
246 _remoteHostName = [_delegate getConnectingHostName];
247 // To get the view to use the new remote host name.
248 [self setState:_state];
249 }
250 }
251
252 #pragma mark - Private 265 #pragma mark - Private
253 266
254 - (void)showConnectingState { 267 - (void)showConnectingState {
255 [_pinEntryView endEditing:YES]; 268 [_pinEntryView endEditing:YES];
256 _statusLabel.text = 269 _statusLabel.text =
257 [NSString stringWithFormat:@"Connecting to %@", _remoteHostName]; 270 [NSString stringWithFormat:@"Connecting to %@", _remoteHostName];
258 [_activityIndicator stopAnimating]; 271 [_activityIndicator stopAnimating];
259 _activityIndicator.cycleColors = @[ [UIColor whiteColor] ]; 272 _activityIndicator.cycleColors = @[ [UIColor whiteColor] ];
260 _activityIndicator.indicatorMode = MDCActivityIndicatorModeIndeterminate; 273 _activityIndicator.indicatorMode = MDCActivityIndicatorModeIndeterminate;
261 _activityIndicator.hidden = NO; 274 _activityIndicator.hidden = NO;
(...skipping 13 matching lines...) Expand all
275 [_pinEntryView endEditing:YES]; 288 [_pinEntryView endEditing:YES];
276 _statusLabel.text = 289 _statusLabel.text =
277 [NSString stringWithFormat:@"Connected to %@", _remoteHostName]; 290 [NSString stringWithFormat:@"Connected to %@", _remoteHostName];
278 _activityIndicator.progress = 0.0; 291 _activityIndicator.progress = 0.0;
279 _pinEntryView.hidden = YES; 292 _pinEntryView.hidden = YES;
280 _activityIndicator.hidden = NO; 293 _activityIndicator.hidden = NO;
281 _activityIndicator.indicatorMode = MDCActivityIndicatorModeDeterminate; 294 _activityIndicator.indicatorMode = MDCActivityIndicatorModeDeterminate;
282 _activityIndicator.cycleColors = @[ [UIColor greenColor] ]; 295 _activityIndicator.cycleColors = @[ [UIColor greenColor] ];
283 [_activityIndicator startAnimating]; 296 [_activityIndicator startAnimating];
284 _activityIndicator.progress = 1.0; 297 _activityIndicator.progress = 1.0;
298
299 HostViewController* hostViewController =
300 [[HostViewController alloc] initWithClient:_client];
301 _client = nil;
302
303 __weak UIViewController* parentController = self.presentingViewController;
304
285 [self dismissViewControllerAnimated:YES 305 [self dismissViewControllerAnimated:YES
nicholss 2017/06/05 18:24:13 I think if you set this animated and the animated
Yuwei 2017/06/05 19:07:25 Done. This does fix the transition but I still se
286 completion:^{ 306 completion:^{
287 [_delegate clientConnected]; 307 [parentController
308 presentViewController:hostViewController
309 animated:YES
310 completion:nil];
288 }]; 311 }];
289 } 312 }
290 313
291 - (void)didProvidePin:(NSString*)pin createPairing:(BOOL)createPairing { 314 - (void)didProvidePin:(NSString*)pin createPairing:(BOOL)createPairing {
292 // TODO(nicholss): There is an open question if createPairing is supported on 315 // TODO(nicholss): There is an open question if createPairing is supported on
293 // iOS. Need to fingure this out. 316 // iOS. Need to fingure this out.
294 [[NSNotificationCenter defaultCenter] 317 [[NSNotificationCenter defaultCenter]
295 postNotificationName:kHostSessionPinProvided 318 postNotificationName:kHostSessionPinProvided
296 object:self 319 object:self
297 userInfo:[NSDictionary dictionaryWithObject:pin 320 userInfo:[NSDictionary dictionaryWithObject:pin
298 forKey:kHostSessionPin]]; 321 forKey:kHostSessionPin]];
299 } 322 }
300 323
301 - (void)didTapCancel:(id)sender { 324 - (void)didTapCancel:(id)sender {
302 NSLog(@"%@ was tapped.", NSStringFromClass([sender class])); 325 _client = nil;
303 // TODO(nicholss): Need to cancel the pending connection.
304 [self dismissViewControllerAnimated:YES completion:nil]; 326 [self dismissViewControllerAnimated:YES completion:nil];
305 } 327 }
306 328
307 - (void)hostSessionStatusChanged:(NSNotification*)notification { 329 - (void)hostSessionStatusChanged:(NSNotification*)notification {
330 NSLog(@"hostSessionStatusChanged: %@", [notification userInfo]);
308 ClientConnectionViewState state; 331 ClientConnectionViewState state;
309 ClientSessionDetails* sessionDetails = 332 ClientSessionDetails* sessionDetails =
310 [[notification userInfo] objectForKey:kSessionDetails]; 333 [[notification userInfo] objectForKey:kSessionDetails];
311 switch (sessionDetails.state) { 334 switch (sessionDetails.state) {
312 case SessionInitializing: 335 case SessionInitializing:
313 // Same as HostConnecting in UI. Fall-though. 336 // Same as HostConnecting in UI. Fall-though.
314 case SessionAuthenticated: 337 case SessionAuthenticated:
315 // Same as HostConnecting in UI. Fall-though. 338 // Same as HostConnecting in UI. Fall-though.
316 case SessionConnecting: 339 case SessionConnecting:
317 state = ClientViewConnecting; 340 state = ClientViewConnecting;
(...skipping 12 matching lines...) Expand all
330 default: 353 default:
331 LOG(ERROR) << "Unknown State for Session, " << sessionDetails.state; 354 LOG(ERROR) << "Unknown State for Session, " << sessionDetails.state;
332 return; 355 return;
333 } 356 }
334 [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 357 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
335 [self setState:state]; 358 [self setState:state];
336 }]; 359 }];
337 } 360 }
338 361
339 @end 362 @end
OLDNEW
« no previous file with comments | « remoting/ios/app/client_connection_view_controller.h ('k') | remoting/ios/app/remoting_view_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698