| 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 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 6 #error "This file requires ARC support." | |
| 7 #endif | |
| 8 | |
| 9 #include "remoting/client/ios/bridge/client_proxy.h" | |
| 10 | |
| 11 #import "remoting/base/string_resources.h" | |
| 12 #import "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" | |
| 13 #import "remoting/client/ios/host_preferences.h" | |
| 14 #import "remoting/client/ios/utility.h" | |
| 15 #import "remoting/proto/control.pb.h" | |
| 16 | |
| 17 #include "base/logging.h" | |
| 18 #include "base/strings/string_util.h" | |
| 19 #include "base/strings/sys_string_conversions.h" | |
| 20 | |
| 21 namespace { | |
| 22 // The value indicating a successful connection has been established via a call | |
| 23 // to ReportConnectionStatus. | |
| 24 const static int kSuccessfulConnection = 3; | |
| 25 | |
| 26 NSString* GetStatusMsg(remoting::protocol::ConnectionToHost::State code) { | |
| 27 switch (code) { | |
| 28 case remoting::protocol::ConnectionToHost::INITIALIZING: | |
| 29 return CRD_LOCALIZED_STRING(IDS_FOOTER_WAITING); | |
| 30 case remoting::protocol::ConnectionToHost::CONNECTING: | |
| 31 return CRD_LOCALIZED_STRING(IDS_FOOTER_CONNECTING); | |
| 32 case remoting::protocol::ConnectionToHost::AUTHENTICATED: | |
| 33 // TODO(nicholss): This says "Working..." | |
| 34 return CRD_LOCALIZED_STRING(IDS_WORKING); | |
| 35 case remoting::protocol::ConnectionToHost::CONNECTED: | |
| 36 // TODO(nicholss): This says "Connected:" | |
| 37 return CRD_LOCALIZED_STRING(IDS_LABEL_CONNECTED); | |
| 38 case remoting::protocol::ConnectionToHost::FAILED: | |
| 39 // TODO(nicholss): This says "Authentication failed. Please sign in to | |
| 40 // Chrome again." | |
| 41 return CRD_LOCALIZED_STRING(IDS_ERROR_AUTHENTICATION_FAILED); | |
| 42 case remoting::protocol::ConnectionToHost::CLOSED: | |
| 43 return CRD_LOCALIZED_STRING(IDS_MESSAGE_SESSION_FINISHED); | |
| 44 } | |
| 45 return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); | |
| 46 } | |
| 47 | |
| 48 // Translate a connection error code integer to a NSString description. | |
| 49 NSString* GetErrorMsg(remoting::protocol::ErrorCode code) { | |
| 50 switch (code) { | |
| 51 case remoting::protocol::ErrorCode::OK: | |
| 52 return CRD_LOCALIZED_STRING(IDS_OK); | |
| 53 case remoting::protocol::ErrorCode::INVALID_ACCOUNT: | |
| 54 return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCOUNT); | |
| 55 case remoting::protocol::ErrorCode::MAX_SESSION_LENGTH: | |
| 56 return CRD_LOCALIZED_STRING(IDS_ERROR_MAX_SESSION_LENGTH); | |
| 57 case remoting::protocol::ErrorCode::PEER_IS_OFFLINE: | |
| 58 return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_IS_OFFLINE); | |
| 59 case remoting::protocol::ErrorCode::HOST_CONFIGURATION_ERROR: | |
| 60 return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_CONFIGURATION_ERROR); | |
| 61 case remoting::protocol::ErrorCode::SESSION_REJECTED: | |
| 62 return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCESS_CODE); | |
| 63 case remoting::protocol::ErrorCode::INCOMPATIBLE_PROTOCOL: | |
| 64 return CRD_LOCALIZED_STRING(IDS_ERROR_INCOMPATIBLE_PROTOCOL); | |
| 65 case remoting::protocol::ErrorCode::AUTHENTICATION_FAILED: | |
| 66 return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCESS_CODE); | |
| 67 case remoting::protocol::ErrorCode::CHANNEL_CONNECTION_ERROR: | |
| 68 return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); | |
| 69 case remoting::protocol::ErrorCode::SIGNALING_ERROR: | |
| 70 return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); | |
| 71 case remoting::protocol::ErrorCode::SIGNALING_TIMEOUT: | |
| 72 return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); | |
| 73 case remoting::protocol::ErrorCode::HOST_OVERLOAD: | |
| 74 return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_OVERLOAD); | |
| 75 case remoting::protocol::ErrorCode::UNKNOWN_ERROR: | |
| 76 return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); | |
| 77 } | |
| 78 return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 namespace remoting { | |
| 84 | |
| 85 ClientProxy::ClientProxy(ClientProxyDelegateWrapper* wrapper) { | |
| 86 delegate_ = [wrapper delegate]; | |
| 87 } | |
| 88 | |
| 89 void ClientProxy::ReportConnectionStatus( | |
| 90 protocol::ConnectionToHost::State state, | |
| 91 protocol::ErrorCode error) { | |
| 92 DCHECK(delegate_); | |
| 93 if (state <= kSuccessfulConnection && error == protocol::ErrorCode::OK) { | |
| 94 // Report Progress | |
| 95 [delegate_ connectionStatus:GetStatusMsg(state)]; | |
| 96 | |
| 97 if (state == kSuccessfulConnection) { | |
| 98 [delegate_ connected]; | |
| 99 } | |
| 100 } else { | |
| 101 [delegate_ connectionStatus:GetStatusMsg(state)]; | |
| 102 if (error != protocol::ErrorCode::OK) { | |
| 103 [delegate_ connectionFailed:GetErrorMsg(error)]; | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 void ClientProxy::DisplayAuthenticationPrompt(bool pairing_supported) { | |
| 109 DCHECK(delegate_); | |
| 110 [delegate_ requestHostPin:pairing_supported]; | |
| 111 } | |
| 112 | |
| 113 void ClientProxy::CommitPairingCredentials(const std::string& host_id, | |
| 114 const std::string& pair_id, | |
| 115 const std::string& pair_secret) { | |
| 116 DCHECK(delegate_); | |
| 117 NSString* nsHostId = base::SysUTF8ToNSString(host_id); | |
| 118 NSString* nsPairId = base::SysUTF8ToNSString(pair_id); | |
| 119 NSString* nsPairSecret = base::SysUTF8ToNSString(pair_secret); | |
| 120 | |
| 121 HostPreferences* host = [HostPreferences hostForId:nsHostId]; | |
| 122 host.pairId = nsPairId; | |
| 123 host.pairSecret = nsPairSecret; | |
| 124 | |
| 125 [host saveToKeychain]; | |
| 126 } | |
| 127 | |
| 128 void ClientProxy::RedrawCanvas(webrtc::DesktopFrame* buffer) { | |
| 129 DCHECK(delegate_); | |
| 130 std::vector<webrtc::DesktopRect> rects; | |
| 131 | |
| 132 for (webrtc::DesktopRegion::Iterator i(buffer->updated_region()); | |
| 133 !i.IsAtEnd(); i.Advance()) { | |
| 134 rects.push_back(i.rect()); | |
| 135 } | |
| 136 | |
| 137 [delegate_ applyFrame:buffer->size() | |
| 138 stride:buffer->stride() | |
| 139 data:buffer->data() | |
| 140 rects:rects]; | |
| 141 } | |
| 142 | |
| 143 void ClientProxy::UpdateCursorShape( | |
| 144 const protocol::CursorShapeInfo& cursor_shape) { | |
| 145 DCHECK(delegate_); | |
| 146 const uint8_t* cursor_data = reinterpret_cast<const uint8_t*>( | |
| 147 cursor_shape.data().data()); | |
| 148 [delegate_ applyCursor:webrtc::DesktopSize(cursor_shape.width(), | |
| 149 cursor_shape.height()) | |
| 150 hotspot:webrtc::DesktopVector(cursor_shape.hotspot_x(), | |
| 151 cursor_shape.hotspot_y()) | |
| 152 cursorData:const_cast<uint8_t*>(cursor_data)]; | |
| 153 } | |
| 154 | |
| 155 } // namespace remoting | |
| OLD | NEW |