| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "remoting/client/ios/bridge/host_proxy.h" | |
| 6 | |
| 7 #import "remoting/client/ios/host_preferences.h" | |
| 8 #import "remoting/client/ios/bridge/client_instance.h" | |
| 9 #import "remoting/client/ios/bridge/client_proxy.h" | |
| 10 | |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 12 | |
| 13 @implementation HostProxy | |
| 14 | |
| 15 // Override default constructor and initialize internals. | |
| 16 - (id)init { | |
| 17 self = [super init]; | |
| 18 if (self) { | |
| 19 _isConnected = false; | |
| 20 } | |
| 21 return self; | |
| 22 } | |
| 23 | |
| 24 // Override default destructor. | |
| 25 - (void)dealloc { | |
| 26 if (_isConnected) { | |
| 27 [self disconnectFromHost]; | |
| 28 } | |
| 29 | |
| 30 //[super dealloc]; // TODO(nicholss): ARC forbids explicit message send of | |
| 31 //'dealloc' | |
| 32 } | |
| 33 | |
| 34 - (BOOL)isConnected { | |
| 35 return _isConnected; | |
| 36 } | |
| 37 | |
| 38 - (void)connectToHost:(NSString*)username | |
| 39 authToken:(NSString*)token | |
| 40 jabberId:(NSString*)jid | |
| 41 hostId:(NSString*)hostId | |
| 42 publicKey:(NSString*)hostPublicKey | |
| 43 delegate:(id<ClientProxyDelegate>)delegate { | |
| 44 // Implicitly, if currently connected, discard the connection and begin a new | |
| 45 // connection. | |
| 46 [self disconnectFromHost]; | |
| 47 | |
| 48 _hostToClientChannel.reset(new remoting::ClientProxy( | |
| 49 [ClientProxyDelegateWrapper wrapDelegate:delegate])); | |
| 50 | |
| 51 DCHECK(!_clientToHostChannel.get()); | |
| 52 _clientToHostChannel = new remoting::ClientInstance( | |
| 53 _hostToClientChannel->AsWeakPtr(), base::SysNSStringToUTF8(username), | |
| 54 base::SysNSStringToUTF8(token), base::SysNSStringToUTF8(jid), | |
| 55 base::SysNSStringToUTF8(hostId), base::SysNSStringToUTF8(hostPublicKey)); | |
| 56 | |
| 57 HostPreferences* host = [HostPreferences hostForId:hostId]; | |
| 58 _clientToHostChannel->Start(base::SysNSStringToUTF8(host.pairId), | |
| 59 base::SysNSStringToUTF8(host.pairSecret)); | |
| 60 _isConnected = YES; | |
| 61 } | |
| 62 | |
| 63 - (void)authenticationResponse:(NSString*)pin | |
| 64 createPairing:(BOOL)createPairing { | |
| 65 if (_isConnected) { | |
| 66 // Where |deviceId| is first created doesn't matter, but it does have to be | |
| 67 // from an Obj-C file. Creating |deviceId| now, just before passing a copy | |
| 68 // into a C++ interface. | |
| 69 NSString* deviceId = | |
| 70 [[[UIDevice currentDevice] identifierForVendor] UUIDString]; | |
| 71 | |
| 72 _clientToHostChannel->ProvideSecret(base::SysNSStringToUTF8(pin), | |
| 73 createPairing, | |
| 74 base::SysNSStringToUTF8(deviceId)); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 - (void)disconnectFromHost { | |
| 79 if (_isConnected) { | |
| 80 VLOG(1) << "Disconnecting from Host"; | |
| 81 | |
| 82 // |_clientToHostChannel| must be closed before releasing | |
| 83 // |_hostToClientChannel|. | |
| 84 | |
| 85 // |_clientToHostChannel| owns several objects that have references to | |
| 86 // itself. These objects need to be cleaned up before we can release | |
| 87 // |_clientToHostChannel|. | |
| 88 _clientToHostChannel->Cleanup(); | |
| 89 // All other references to |_clientToHostChannel| should now be free. When | |
| 90 // the next statement is executed the destructor is called automatically. | |
| 91 _clientToHostChannel = NULL; | |
| 92 | |
| 93 _hostToClientChannel.reset(); | |
| 94 | |
| 95 _isConnected = NO; | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 - (void)mouseAction:(const webrtc::DesktopVector&)position | |
| 100 wheelDelta:(const webrtc::DesktopVector&)wheelDelta | |
| 101 whichButton:(NSInteger)buttonPressed | |
| 102 buttonDown:(BOOL)buttonIsDown { | |
| 103 if (_isConnected) { | |
| 104 _clientToHostChannel->PerformMouseAction(position, wheelDelta, | |
| 105 (remoting::protocol::MouseEvent_MouseButton) buttonPressed, | |
| 106 buttonIsDown); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 - (void)keyboardAction:(NSInteger)keyCode keyDown:(BOOL)keyIsDown { | |
| 111 if (_isConnected) { | |
| 112 _clientToHostChannel->PerformKeyboardAction(keyCode, keyIsDown); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 @end | |
| OLD | NEW |