Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "remoting/ios/bridge/client_controller.h" | |
| 6 | |
| 7 #import "remoting/ios/data_store.h" | |
| 8 #import "remoting/ios/host_preferences.h" | |
| 9 #import "remoting/ios/bridge/client_bridge.h" | |
| 10 | |
| 11 namespace { | |
| 12 // The value indicateing a successful connection has been established via a call | |
|
dcaiafa
2014/03/19 01:14:15
nit: spelling
aboone
2014/03/21 16:42:07
Done.
| |
| 13 // to reportConnectionStatus | |
| 14 const static int kSuccessfulConnection = 3; | |
| 15 } // namespace | |
| 16 | |
| 17 @interface ClientController (Private) | |
| 18 + (NSString*)getStatusMsgFromInteger:(NSInteger)code; | |
| 19 + (NSString*)getErrorMsgFromInteger:(NSInteger)code; | |
| 20 @end | |
| 21 | |
| 22 // In this file CLIENT and HOST are used to refer to the iOS Applicaition | |
| 23 // written in OBJ_C++ and the Chromium C++ code base, respectively. This class | |
| 24 // is the CLIENT side of the bridge. Most functions simply pass the information | |
| 25 // to the UI, or to the next layer of the bridge. | |
| 26 @implementation ClientController | |
|
dcaiafa
2014/03/19 01:14:15
nit: move class description to header.
aboone
2014/03/21 16:42:07
Done.
| |
| 27 | |
| 28 // Override default contructor and initialize internals | |
| 29 - (id)init { | |
| 30 self = [super init]; | |
| 31 if (self) { | |
| 32 _isConnected = false; | |
| 33 _bridge = new remoting::ClientBridge(); | |
| 34 } | |
| 35 return self; | |
| 36 } | |
| 37 | |
| 38 // Credentials are received from the CLIENT and sent to the HOST. If currently | |
| 39 // connected, discard the connection and begin a new connection. | |
| 40 - (void)connectToHost:(NSString*)username | |
| 41 authToken:(NSString*)token | |
| 42 jabberId:(NSString*)jid | |
| 43 hostId:(NSString*)hostId | |
| 44 publicKey:(NSString*)hostPublicKey | |
| 45 delegate:(id<ClientControllerDelegate>)delegate { | |
| 46 if (_isConnected) { | |
| 47 [self disconnectFromHost]; | |
| 48 } | |
| 49 _delegate = delegate; | |
| 50 | |
| 51 NSString* pairId = @""; | |
| 52 NSString* pairSecret = @""; | |
| 53 | |
| 54 const HostPreferences* hostPrefs = | |
| 55 [[DataStore sharedStore] getHostForId:hostId]; | |
| 56 | |
| 57 // Use the pairing id and secret when known | |
| 58 if (hostPrefs && hostPrefs.pairId && hostPrefs.secret) { | |
| 59 pairId = [hostPrefs.pairId copy]; | |
| 60 pairSecret = [hostPrefs.secret copy]; | |
| 61 } | |
| 62 | |
| 63 _bridge->ConnectToHost([username UTF8String], | |
| 64 [token UTF8String], | |
| 65 [jid UTF8String], | |
| 66 [hostId UTF8String], | |
| 67 [hostPublicKey UTF8String], | |
| 68 [pairId UTF8String], | |
| 69 [pairSecret UTF8String], | |
| 70 self); | |
| 71 | |
| 72 _isConnected = YES; | |
| 73 } | |
| 74 | |
| 75 // CLIENT is asking to close the connection | |
| 76 - (void)disconnectFromHost { | |
| 77 if (!_isConnected) | |
| 78 return; | |
| 79 | |
| 80 _bridge->DisconnectFromHost(); | |
| 81 | |
| 82 _delegate = nil; | |
| 83 _isConnected = NO; | |
| 84 } | |
| 85 | |
| 86 // GET _isConnected | |
| 87 - (BOOL)isConnected { | |
| 88 return _isConnected; | |
| 89 } | |
| 90 | |
| 91 // HOST request for User's PIN | |
| 92 - (void)displayAuthenticationPrompt:(BOOL)pairingSupported { | |
| 93 [_delegate requestHostPin:pairingSupported]; | |
| 94 } | |
| 95 | |
| 96 // HOST requests to save User's connection authorization | |
| 97 - (void)commitPairinedentials:(NSString*)hostId | |
|
dcaiafa
2014/03/19 01:14:15
method name spelling
aboone
2014/03/21 16:42:07
Done.
| |
| 98 pairId:(NSString*)pairId | |
| 99 secret:(NSString*)hostSecret { | |
| 100 const HostPreferences* hostPrefs = | |
| 101 [[DataStore sharedStore] getHostForId:hostId]; | |
| 102 if (hostPrefs == nil) { | |
| 103 hostPrefs = [[DataStore sharedStore] createHost:hostId]; | |
| 104 } | |
| 105 if (hostPrefs) { | |
| 106 hostPrefs.pairId = pairId; | |
| 107 hostPrefs.secret = hostSecret; | |
| 108 | |
| 109 [[DataStore sharedStore] saveChanges]; | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 // Translate a connection status code integer to a NSString description | |
| 114 + (NSString*)getStatusMsgFromInteger:(NSInteger)code { | |
| 115 switch (code) { | |
| 116 case 0: // INITIALIZING | |
| 117 return @"Initializing connection"; | |
| 118 case 1: // CONNECTING | |
| 119 return @"Connecting"; | |
| 120 case 2: // AUTHENTICATED | |
| 121 return @"Authenticated"; | |
| 122 case 3: // CONNECTED | |
| 123 return @"Connected"; | |
| 124 case 4: // FAILED | |
| 125 return @"Connection Failed"; | |
| 126 case 5: // CLOSED | |
| 127 return @"Connection closed"; | |
| 128 default: | |
| 129 return @"Unknown connection state"; | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 // Translate a connection error code integer to a NSString description | |
| 134 + (NSString*)getErrorMsgFromInteger:(NSInteger)code { | |
| 135 switch (code) { | |
| 136 case 1: // PEER_IS_OFFLINE | |
| 137 return @"Requested host is offline."; | |
| 138 case 2: // SESSION_REJECTED | |
| 139 return @"Session was rejected by the host."; | |
| 140 case 3: // INCOMPATIBLE_PROTOCOL | |
| 141 return @"Incompatible Protocol."; | |
| 142 case 4: // AUTHENTICATION_FAILED | |
| 143 return @"Authentication Failed."; | |
| 144 case 5: // CHANNEL_CONNECTION_ERROR | |
| 145 return @"Channel Connection Error"; | |
| 146 case 6: // SIGNALING_ERROR | |
| 147 return @"Signaling Error"; | |
| 148 case 7: // SIGNALING_TIMEOUT | |
| 149 return @"Signaling Timeout"; | |
| 150 case 8: // HOST_OVERLOAD | |
| 151 return @"Host Overload"; | |
| 152 case 9: // UNKNOWN_ERROR | |
| 153 return @"An unknown error has occurred, preventing the session " | |
| 154 "from opening."; | |
| 155 default: | |
| 156 return @"An unknown error code has occurred."; | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 // HOST reporting connection status. Translate the |state| and |error| into a | |
|
dcaiafa
2014/03/19 01:14:15
Please move method descriptions to header.
aboone
2014/03/21 16:42:07
Done.
| |
| 161 // string report or an error condition for the CLIENT UI. | |
| 162 - (void)reportConnectionStatus:(NSInteger)state error:(NSInteger)error { | |
| 163 if (state <= kSuccessfulConnection && error == 0) { | |
| 164 // Report Progress | |
| 165 [_delegate | |
| 166 connectionStatus:[ClientController getStatusMsgFromInteger:state]]; | |
| 167 | |
| 168 if (state == kSuccessfulConnection) { | |
| 169 [_delegate connected]; | |
| 170 } | |
| 171 } else { | |
| 172 [_delegate | |
| 173 connectionStatus:[ClientController getErrorMsgFromInteger:error]]; | |
| 174 [_delegate | |
| 175 connectionFailed:[ClientController getErrorMsgFromInteger:error]]; | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 // CLIENT reporting a mouse input. Only passed on when a connection is | |
| 180 // currently active. | |
| 181 - (void)mouseAction:(const webrtc::DesktopVector&)position | |
| 182 wheelDelta:(const webrtc::DesktopVector&)wheelDelta | |
| 183 whichButton:(NSInteger)buttonPressed | |
| 184 buttonDown:(BOOL)buttonIsDown { | |
| 185 if (_isConnected) { | |
| 186 if (buttonPressed >= 0 && buttonPressed < 5) { | |
| 187 _bridge->session()->PerformMouseAction( | |
| 188 position, wheelDelta, buttonPressed, buttonIsDown); | |
| 189 } | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 // CLIENT reporting a keyboard input. Only passed on when a connection is | |
| 194 // currently active. | |
| 195 - (void)keyboardAction:(NSInteger)keyCode keyDown:(BOOL)keyIsDown { | |
| 196 if (_isConnected) { | |
| 197 _bridge->session()->PerformKeyboardAction(keyCode, keyIsDown); | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 // CLIENT reporting the User's input for their PIN, if needed create a new | |
| 202 // pairing | |
| 203 - (void)authenticationResponse:(NSString*)pin createPair:(BOOL)createPair { | |
| 204 _bridge->session()->ProvideSecret([pin UTF8String], createPair); | |
| 205 } | |
| 206 | |
| 207 // HOST reporting a change in Cursor (mouse) | |
| 208 - (void)updateCursorShape:(const webrtc::DesktopSize&)size | |
| 209 hotspot:(const webrtc::DesktopVector&)hotspot | |
| 210 cursorData:(uint8_t*)data { | |
| 211 [_delegate applyCursor:size hotspot:hotspot cursorData:data]; | |
| 212 } | |
| 213 | |
| 214 // HOST reporting a change in canvas (desktop) | |
| 215 - (void)updateImageBuffer:(const webrtc::DesktopSize&)size | |
| 216 stride:(NSInteger)stride | |
| 217 data:(uint8_t*)data | |
| 218 regions:(const std::vector<webrtc::DesktopRect>&)regions { | |
| 219 [_delegate applyFrame:size stride:stride data:data regions:regions]; | |
| 220 } | |
| 221 | |
| 222 @end | |
| OLD | NEW |