diff --git a/remoting/client/display/BUILD.gn b/remoting/client/display/BUILD.gn index c2d5007bbe37cd..168a831ead6078 100644 --- a/remoting/client/display/BUILD.gn +++ b/remoting/client/display/BUILD.gn @@ -27,8 +27,10 @@ source_set("display") { "sys_opengl.h", ] - deps = [ + public_deps = [ "//remoting/proto", + ] + deps = [ "//third_party/libyuv", "//third_party/webrtc/base:rtc_base_approved", ] diff --git a/remoting/client/ios/BUILD.gn b/remoting/client/ios/BUILD.gn index 55b1894b1745a9..2aee3e41f6797c 100644 --- a/remoting/client/ios/BUILD.gn +++ b/remoting/client/ios/BUILD.gn @@ -10,7 +10,6 @@ group("all") { deps = [ ":ios_core", "./app:all", - "./bridge:all", ] } @@ -19,7 +18,6 @@ group("all_test") { deps = [ ":ios_core_unit_tests", - "./bridge:bridge_unit_tests", ] } @@ -33,8 +31,6 @@ source_set("ios_core") { "key_input.h", "key_input.mm", "key_map_us.h", - "utility.h", - "utility.mm", ] if (!is_chrome_branded) { diff --git a/remoting/client/ios/DEPS b/remoting/client/ios/DEPS index be89c524d9b1ab..55a863d4d6c791 100644 --- a/remoting/client/ios/DEPS +++ b/remoting/client/ios/DEPS @@ -5,7 +5,6 @@ include_rules = [ "+ios/third_party/material_components_ios/src", "+remoting/codec", "+remoting/client/ios", - "+remoting/client/ios/bridge", "+remoting/signaling", "+third_party/libjingle_xmpp", "+third_party/webrtc", diff --git a/remoting/client/ios/bridge/BUILD.gn b/remoting/client/ios/bridge/BUILD.gn deleted file mode 100644 index bc4c658bb670c1..00000000000000 --- a/remoting/client/ios/bridge/BUILD.gn +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//build/config/ios/rules.gni") - -group("all") { - testonly = true - - deps = [ - ":bridge", - ":bridge_unit_tests", - ] -} - -source_set("bridge") { - include_dirs = [ - "$root_gen_dir", - "//third_party/protobuf/src", - ] - - sources = [ - "client_instance.cc", - "client_instance.h", - "client_proxy.h", - "client_proxy.mm", - "client_proxy_delegate.h", - "client_proxy_delegate_wrapper.h", - "client_proxy_delegate_wrapper.mm", - "frame_consumer_bridge.cc", - "frame_consumer_bridge.h", - "host_proxy.h", - "host_proxy.mm", - ] - - public_deps = [ - "//remoting/protocol", - "//third_party/webrtc/base:rtc_base", - "//third_party/webrtc/modules/desktop_capture:primitives", - ] - - deps = [ - "//base", - "//net", - "//remoting/client/ios:ios_core", - "//remoting/resources:strings", - "//ui/base", - "//ui/gfx", - "//ui/resources", - "//ui/strings:ui_strings", - ] - - libs = [ - "Accelerate.framework", - "AudioToolbox.framework", - "CoreAudio.framework", - "CoreData.framework", - "CoreMIDI.framework", - "CoreVideo.framework", - "CoreGraphics.framework", - "GLKit.framework", - "OpenGLES.framework", - "Webkit.framework", - ] - - configs += [ "//build/config/compiler:enable_arc" ] -} - -source_set("bridge_unit_tests") { - testonly = true - - include_dirs = [ - "$root_gen_dir", - "//third_party/protobuf/src", - ] - - sources = [ - "client_instance_unittest.mm", - "client_proxy_unittest.mm", - - # "frame_consumer_bridge_unittest.cc", - "host_proxy_unittest.mm", - ] - - deps = [ - ":bridge", - "//testing/gtest", - ] - - configs += [ "//build/config/compiler:enable_arc" ] - - data = [] -} diff --git a/remoting/client/ios/bridge/DEPS b/remoting/client/ios/bridge/DEPS deleted file mode 100644 index 796de70f93c478..00000000000000 --- a/remoting/client/ios/bridge/DEPS +++ /dev/null @@ -1,9 +0,0 @@ -include_rules = [ - "+google/protobuf", - "+remoting/codec", - "+remoting/client/ios", - "+remoting/signaling", - "+third_party/libjingle_xmpp", - "+third_party/webrtc", - "+third_party/protobuf/src", -] diff --git a/remoting/client/ios/bridge/client_instance.cc b/remoting/client/ios/bridge/client_instance.cc deleted file mode 100644 index 17c6bb6f45306d..00000000000000 --- a/remoting/client/ios/bridge/client_instance.cc +++ /dev/null @@ -1,363 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/client/ios/bridge/client_instance.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/logging.h" -#include "base/memory/ptr_util.h" -#include "base/synchronization/waitable_event.h" -#include "jingle/glue/thread_wrapper.h" -#include "net/socket/client_socket_factory.h" -#include "remoting/base/chromium_url_request.h" -#include "remoting/base/url_request_context_getter.h" -#include "remoting/client/audio_player.h" -//#include "remoting/client/client_status_logger.h" -#include "remoting/client/ios/bridge/client_proxy.h" -#include "remoting/proto/event.pb.h" -#include "remoting/protocol/chromium_port_allocator_factory.h" -#include "remoting/protocol/client_authentication_config.h" -#include "remoting/protocol/host_stub.h" -#include "remoting/protocol/negotiating_client_authenticator.h" -#include "remoting/protocol/transport_context.h" -#include "remoting/signaling/delegating_signal_strategy.h" - - -//#include "remoting/client/ios/audio_player_buffer.h" // TODO(nicholss): need -// to also pull in the player and attach to buffer. - -// TODO(nicholss): There is another client instance used by android. Need to -// merge the two. - -namespace { -const char* const kXmppServer = "talk.google.com"; -// const char kDirectoryBotJid[] = "remoting@bot.talk.google.com"; -} // namespace - -namespace remoting { - -ClientInstance::ClientInstance(const base::WeakPtr& proxy, - const std::string& username, - const std::string& auth_token, - const std::string& host_jid, - const std::string& host_id, - const std::string& host_pubkey) - : proxyToClient_(proxy), host_jid_(host_jid), device_id_() { - if (!base::MessageLoop::current()) { - ui_loop_ = new base::MessageLoop(base::MessageLoop::TYPE_UI); - base::MessageLoopForUI::current()->Attach(); - } else { - ui_loop_ = base::MessageLoopForUI::current(); - } - - // |ui_loop_| runs on the main thread, so |ui_task_runner_| will run on the - // main thread. We can not kill the main thread when the message loop becomes - // idle so the callback function does nothing (as opposed to the typical - // base::MessageLoop::QuitClosure()) - ui_task_runner_ = new AutoThreadTaskRunner(ui_loop_->task_runner(), - base::Bind(&base::DoNothing)); - - network_task_runner_ = AutoThread::CreateWithType( - "native_net", ui_task_runner_, base::MessageLoop::TYPE_IO); - file_task_runner_ = AutoThread::CreateWithType("native_file", ui_task_runner_, - base::MessageLoop::TYPE_IO); - audio_task_runner_ = AutoThread::CreateWithType( - "native_audio", ui_task_runner_, base::MessageLoop::TYPE_IO); - - url_requester_ = - new URLRequestContextGetter(network_task_runner_, file_task_runner_); - - DCHECK(ui_task_runner_->BelongsToCurrentThread()); - - // Initialize XMPP config. - xmpp_config_.host = kXmppServer; - xmpp_config_.username = username; - xmpp_config_.auth_token = auth_token; - - client_auth_config_.host_id = host_id; - client_auth_config_.fetch_secret_callback = - base::Bind(&ClientInstance::FetchSecret, this); - // client_auth_config_.fetch_third_party_token_callback = - // std::unique_ptr(); -} - -ClientInstance::~ClientInstance() {} - -void ClientInstance::Start(const std::string& pairing_id, - const std::string& pairing_secret) { - DCHECK(ui_task_runner_->BelongsToCurrentThread()); - - client_auth_config_.pairing_client_id = pairing_id; - client_auth_config_.pairing_secret = pairing_secret; - - view_.reset(new FrameConsumerBridge( - this, base::Bind(&ClientProxy::RedrawCanvas, proxyToClient_))); - - network_task_runner_->PostTask( - FROM_HERE, - base::Bind(&ClientInstance::ConnectToHostOnNetworkThread, this)); -} - -void ClientInstance::Cleanup() { - DCHECK(ui_task_runner_->BelongsToCurrentThread()); - - // |view_| must be destroyed on the UI thread before the producer is gone. - view_.reset(); - - network_task_runner_->PostTask( - FROM_HERE, - base::Bind(&ClientInstance::DisconnectFromHostOnNetworkThread, this)); -} - -// HOST attempts to continue automatically with previously supplied credentials, -// if it can't it requests the user's PIN. -void ClientInstance::FetchSecret( - bool pairable, - const protocol::SecretFetchedCallback& callback) { - if (!ui_task_runner_->BelongsToCurrentThread()) { - ui_task_runner_->PostTask( - FROM_HERE, - base::Bind(&ClientInstance::FetchSecret, this, pairable, callback)); - return; - } - - pin_callback_ = callback; - - if (proxyToClient_) { - // We attempted to connect using an existing pairing that was rejected. - // Unless we forget about the stale credentials, we'll continue trying - // them. - proxyToClient_->CommitPairingCredentials(client_auth_config_.host_id, "", - ""); - - proxyToClient_->DisplayAuthenticationPrompt(pairable); - } -} - -void ClientInstance::ProvideSecret(const std::string& pin, - bool create_pairing, - const std::string& device_id) { - DCHECK(ui_task_runner_->BelongsToCurrentThread()); - create_pairing_ = create_pairing; - device_id_ = device_id; - - // Before this function can be called, FetchSecret must have been called, - // which creates |pin_callback_| - DCHECK(!pin_callback_.is_null()); - network_task_runner_->PostTask(FROM_HERE, base::Bind(pin_callback_, pin)); -} - -void ClientInstance::PerformMouseAction( - const webrtc::DesktopVector& position, - const webrtc::DesktopVector& wheel_delta, - protocol::MouseEvent_MouseButton button, - bool button_down) { - if (!network_task_runner_->BelongsToCurrentThread()) { - network_task_runner_->PostTask( - FROM_HERE, base::Bind(&ClientInstance::PerformMouseAction, this, - position, wheel_delta, button, button_down)); - return; - } - - protocol::MouseEvent action; - action.set_x(position.x()); - action.set_y(position.y()); - action.set_wheel_delta_x(wheel_delta.x()); - action.set_wheel_delta_y(wheel_delta.y()); - action.set_button(button); - - // TODO(nicholss) this throws a npe when there is a delay on connecting to a - // host + touch. - client_->input_stub()->InjectMouseEvent(action); -} - -void ClientInstance::PerformKeyboardAction(int key_code, bool key_down) { - if (!network_task_runner_->BelongsToCurrentThread()) { - network_task_runner_->PostTask( - FROM_HERE, base::Bind(&ClientInstance::PerformKeyboardAction, this, - key_code, key_down)); - return; - } - - protocol::KeyEvent action; - action.set_usb_keycode(key_code); - action.set_pressed(key_down); - client_->input_stub()->InjectKeyEvent(action); -} - -void ClientInstance::OnConnectionState(protocol::ConnectionToHost::State state, - protocol::ErrorCode error) { - DCHECK(network_task_runner_->BelongsToCurrentThread()); - - // client_status_logger_->LogSessionStateChange(state, error); - - ui_task_runner_->PostTask( - FROM_HERE, base::Bind(&ClientInstance::HandleConnectionStateOnUIThread, - this, state, error)); -} - -void ClientInstance::OnConnectionReady(bool ready) { - // We ignore this message, since OnConnectionState tells us the same thing. -} - -void ClientInstance::OnRouteChanged(const std::string& channel_name, - const protocol::TransportRoute& route) { - VLOG(1) << "Using " << protocol::TransportRoute::GetTypeString(route.type) - << " connection for " << channel_name << " channel"; -} - -void ClientInstance::SetCapabilities(const std::string& capabilities) {} - -void ClientInstance::SetPairingResponse( - const protocol::PairingResponse& response) { - if (!ui_task_runner_->BelongsToCurrentThread()) { - ui_task_runner_->PostTask( - FROM_HERE, - base::Bind(&ClientInstance::SetPairingResponse, this, response)); - return; - } - - VLOG(1) << "Successfully established pairing with host"; - - if (proxyToClient_) - proxyToClient_->CommitPairingCredentials(client_auth_config_.host_id, - response.client_id(), - response.shared_secret()); -} - -void ClientInstance::DeliverHostMessage( - const protocol::ExtensionMessage& message) { - NOTIMPLEMENTED(); -} - -void ClientInstance::SetDesktopSize(const webrtc::DesktopSize& size, - const webrtc::DesktopVector& dpi) { - // ClientInstance get size from the frames and it doesn't use DPI, so this - // call can be ignored. -} - -// Returning interface of protocol::ClipboardStub. -protocol::ClipboardStub* ClientInstance::GetClipboardStub() { - return this; -} - -// Returning interface of protocol::CursorShapeStub. -protocol::CursorShapeStub* ClientInstance::GetCursorShapeStub() { - return this; -} - -void ClientInstance::InjectClipboardEvent( - const protocol::ClipboardEvent& event) { - NOTIMPLEMENTED(); -} - -void ClientInstance::SetCursorShape(const protocol::CursorShapeInfo& shape) { - if (!ui_task_runner_->BelongsToCurrentThread()) { - ui_task_runner_->PostTask( - FROM_HERE, base::Bind(&ClientInstance::SetCursorShape, this, shape)); - return; - } - if (proxyToClient_) - proxyToClient_->UpdateCursorShape(shape); -} - -void ClientInstance::ConnectToHostOnNetworkThread() { - DCHECK(network_task_runner_->BelongsToCurrentThread()); - - jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); - - client_context_.reset(new ClientContext(network_task_runner_)); - client_context_->Start(); - - perf_tracker_.reset(new protocol::PerformanceTracker()); - - video_renderer_.reset(new SoftwareVideoRenderer(view_.get())); - // TODO(nicholss): SoftwareVideoRenderer was changed to now have Initialize, - // but it is unclear how to integrate into existing code. - // video_renderer_->Initialize(client_context_, perf_tracker_.get())); - - client_.reset(new ChromotingClient( - client_context_.get(), this, video_renderer_.get(), - nullptr // TODO(nicholss): GetAudioConsumer().get() - )); - - signaling_.reset( - new XmppSignalStrategy(net::ClientSocketFactory::GetDefaultFactory(), - url_requester_, xmpp_config_)); - - // client_status_logger_.reset(new ClientStatusLogger( - // ServerLogEntry::ME2ME, signaling_.get(), kDirectoryBotJid)); - - protocol::NetworkSettings network_settings( - protocol::NetworkSettings::NAT_TRAVERSAL_FULL); - - // Use Chrome's network stack to allocate ports for peer-to-peer channels. - - scoped_refptr transport_context = - new protocol::TransportContext( - signaling_.get(), - base::WrapUnique(new protocol::ChromiumPortAllocatorFactory()), - base::WrapUnique(new ChromiumUrlRequestFactory(url_requester_)), - protocol::NetworkSettings( - protocol::NetworkSettings::NAT_TRAVERSAL_FULL), - protocol::TransportRole::CLIENT); - - client_->Start(signaling_.get(), client_auth_config_, transport_context, - host_jid_, std::string()); -} - -// TODO(nicholss): Port audio impl for iOS. -// base::WeakPtr ClientInstance::GetAudioConsumer() { -// if (!audio_player_) { -// audio_player_ = AudioPlayerIos::CreateAudioPlayer( -// network_task_runner_, -// audio_task_runner_); -// } -// -// return audio_player_->GetAudioConsumer(); -// } - -void ClientInstance::DisconnectFromHostOnNetworkThread() { - DCHECK(network_task_runner_->BelongsToCurrentThread()); - - // |client_| must be torn down before |signaling_|. - client_.reset(); - // client_status_logger_.reset(); - signaling_.reset(); - perf_tracker_.reset(); - // audio_consumer_->reset(); // TODO(nicholss): Or should this be a call to - // Stop? - // audio_player_->reset(); // TODO(nicholss): Or should this be a call to - // Stop? - video_renderer_.reset(); - client_context_->Stop(); -} - -void ClientInstance::HandleConnectionStateOnUIThread( - protocol::ConnectionToHost::State state, - protocol::ErrorCode error) { - if (create_pairing_ && device_id_.length() > 0 && - state == protocol::ConnectionToHost::CONNECTED) { - DoPairing(); - } - - if (proxyToClient_) - proxyToClient_->ReportConnectionStatus(state, error); -} - -void ClientInstance::DoPairing() { - if (!network_task_runner_->BelongsToCurrentThread()) { - network_task_runner_->PostTask( - FROM_HERE, base::Bind(&ClientInstance::DoPairing, this)); - return; - } - - VLOG(1) << "Attempting to pair with host"; - protocol::PairingRequest request; - request.set_client_name(device_id_); - client_->host_stub()->RequestPairing(request); -} - -} // namespace remoting diff --git a/remoting/client/ios/bridge/client_instance.h b/remoting/client/ios/bridge/client_instance.h deleted file mode 100644 index e769f412f3b80d..00000000000000 --- a/remoting/client/ios/bridge/client_instance.h +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_CLIENT_INSTANCE_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_CLIENT_INSTANCE_H_ - -#include -#include - -#include "base/bind.h" -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/message_loop/message_loop.h" -#include "net/url_request/url_request_context_getter.h" -#include "remoting/base/auto_thread.h" -#include "remoting/client/chromoting_client.h" -#include "remoting/client/client_context.h" -#include "remoting/client/client_user_interface.h" -#include "remoting/client/ios/bridge/frame_consumer_bridge.h" -#include "remoting/client/software_video_renderer.h" -#include "remoting/proto/control.pb.h" -#include "remoting/proto/event.pb.h" -#include "remoting/protocol/audio_stub.h" -#include "remoting/protocol/clipboard_stub.h" -#include "remoting/protocol/cursor_shape_stub.h" -#include "remoting/protocol/network_settings.h" -#include "remoting/protocol/performance_tracker.h" -#include "remoting/protocol/transport_context.h" -#include "remoting/signaling/xmpp_signal_strategy.h" - -//#include "remoting/client/ios/audio_player_ios.h" - -namespace remoting { - -// class AudioPlayerIos; -class ClientProxy; -// class ClientStatusLogger; -class FrameConsumerBridge; - -// TODO(nicholss): Delete this Class. It needs to use the client version of -// ClientInstance. ClientUserInterface that indirectly makes and receives OBJ_C -// calls from the UI application. -class ClientInstance : public ClientUserInterface, - public protocol::ClipboardStub, - public protocol::CursorShapeStub, - public base::RefCountedThreadSafe { - public: - // Initiates a connection with the specified host. Call from the UI thread. To - // connect with an unpaired host, pass in |pairing_id| and |pairing_secret| as - // empty strings. - ClientInstance(const base::WeakPtr& proxy, - const std::string& username, - const std::string& auth_token, - const std::string& host_jid, - const std::string& host_id, - const std::string& host_pubkey); - - // Begins the connection process. Should not be called again until after - // |CleanUp|. - void Start(const std::string& pairing_id, const std::string& pairing_secret); - - // Terminates the current connection (if it hasn't already failed) and cleans - // up. Must be called before destruction can occur or a memory leak may occur. - void Cleanup(); - - // Notifies the user interface that the user needs to enter a PIN. The - // current authentication attempt is put on hold until |callback| is invoked. - // May be called on any thread. - void FetchSecret(bool pairable, - const protocol::SecretFetchedCallback& callback); - - // Provides the user's PIN and resumes the host authentication attempt. Call - // on the UI thread once the user has finished entering this PIN into the UI, - // but only after the UI has been asked to provide a PIN (via FetchSecret()). - void ProvideSecret(const std::string& pin, - bool create_pair, - const std::string& device_id); - - // Moves the host's cursor to the specified coordinates, optionally with some - // mouse button depressed. If |button| is BUTTON_UNDEFINED, no click is made. - void PerformMouseAction(const webrtc::DesktopVector& position, - const webrtc::DesktopVector& wheel_delta, - protocol::MouseEvent_MouseButton button, - bool button_down); - - // Sends the provided keyboard scan code to the host. - void PerformKeyboardAction(int key_code, bool key_down); - - // ClientUserInterface implementation. - void OnConnectionState(protocol::ConnectionToHost::State state, - protocol::ErrorCode error) override; - void OnConnectionReady(bool ready) override; - void OnRouteChanged(const std::string& channel_name, - const protocol::TransportRoute& route) override; - void SetCapabilities(const std::string& capabilities) override; - void SetPairingResponse(const protocol::PairingResponse& response) override; - void DeliverHostMessage(const protocol::ExtensionMessage& message) override; - protocol::ClipboardStub* GetClipboardStub() override; - protocol::CursorShapeStub* GetCursorShapeStub() override; - - // CursorShapeStub implementation. - void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; - - // ClipboardStub implementation. - void SetCursorShape(const protocol::CursorShapeInfo& shape) override; - - void SetDesktopSize(const webrtc::DesktopSize& size, - const webrtc::DesktopVector& dpi) override; - - scoped_refptr display_task_runner() { - return ui_task_runner_; - } - - scoped_refptr network_task_runner() { - return network_task_runner_; - } - - scoped_refptr file_task_runner() { - return file_task_runner_; - } - - scoped_refptr audio_task_runner() { - return audio_task_runner_; - } - - private: - // This object is ref-counted, so it cleans itself up. - ~ClientInstance() override; - - void ConnectToHostOnNetworkThread(); - void DisconnectFromHostOnNetworkThread(); - - void HandleConnectionStateOnUIThread(protocol::ConnectionToHost::State state, - protocol::ErrorCode error); - - // Request pairing from the host. - void DoPairing(); - - // base::WeakPtr GetAudioConsumer(); - - // Proxy to exchange messages between the - // common Chromoting protocol and UI Application. - base::WeakPtr proxyToClient_; - - // ID of the host we are connecting to. - std::string host_jid_; - - protocol::ClientAuthenticationConfig client_auth_config_; - - // This group of variables is to be used on the display thread. - std::unique_ptr video_renderer_; - std::unique_ptr view_; - - // This group of variables is to be used on the network thread. - std::unique_ptr client_context_; - std::unique_ptr perf_tracker_; - std::unique_ptr client_; - XmppSignalStrategy::XmppServerConfig xmpp_config_; - std::unique_ptr signaling_; // Must outlive client_ - - // TODO(nicholss): Migrate to ClientTelemetryLogger - // std::unique_ptr client_status_logger_; - - // This group of variables is to be used on the audio thread. - // std::unique_ptr audio_player_; - - // Pass this the user's PIN once we have it. To be assigned and accessed on - // the UI thread, but must be posted to the network thread to call it. - protocol::SecretFetchedCallback pin_callback_; - - // Indicates whether to establish a new pairing with this host. This is - // modified in ProvideSecret(), but thereafter to be used only from the - // network thread. (This is safe because ProvideSecret() is invoked at most - // once per run, and always before any reference to this flag.) - bool create_pairing_ = false; - - // A unique identifier for the user's device. - // Only to be used when a pairing is created. - std::string device_id_; - - // Chromium code's connection to the OBJ_C message loop. Once created the - // MessageLoop will live for the life of the program. An attempt was made to - // create the primary message loop earlier in the programs life, but a - // MessageLoop requires ARC to be disabled. - base::MessageLoop* ui_loop_; - - // References to native threads. - scoped_refptr ui_task_runner_; - scoped_refptr network_task_runner_; - scoped_refptr file_task_runner_; - scoped_refptr audio_task_runner_; - - scoped_refptr url_requester_; - - friend class base::RefCountedThreadSafe; - - DISALLOW_COPY_AND_ASSIGN(ClientInstance); -}; - -} // namespace remoting - -#endif // REMOTING_CLIENT_IOS_BRIDGE_CLIENT_INSTANCE_H_ diff --git a/remoting/client/ios/bridge/client_instance_unittest.mm b/remoting/client/ios/bridge/client_instance_unittest.mm deleted file mode 100644 index d0e6a17595a8c6..00000000000000 --- a/remoting/client/ios/bridge/client_instance_unittest.mm +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/client/ios/bridge/client_instance.h" - -#import "remoting/client/ios/host_preferences.h" -#import "testing/gtest_mac.h" - -#include "base/compiler_specific.h" -#include "base/mac/scoped_nsobject.h" -#include "base/run_loop.h" -#include "base/strings/sys_string_conversions.h" -#include "base/synchronization/waitable_event.h" -#include "remoting/base/constants.h" -#include "remoting/client/ios/bridge/client_proxy.h" -#include "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" -#include "remoting/proto/event.pb.h" -#include "remoting/protocol/clipboard_stub.h" - -@interface ClientProxyDelegateForClientInstanceTester - : NSObject - -- (void)resetDidReceiveSomething; - -// Validating what was received is outside of the scope for this test unit. See -// ClientProxyUnittest for those tests. -@property(nonatomic, assign) BOOL didReceiveSomething; - -@end - -@implementation ClientProxyDelegateForClientInstanceTester - -@synthesize didReceiveSomething = _didReceiveSomething; - -- (void)resetDidReceiveSomething { - _didReceiveSomething = false; -} - -- (void)requestHostPin:(BOOL)pairingSupported { - _didReceiveSomething = true; -} - -- (void)connected { - _didReceiveSomething = true; -} - -- (void)connectionStatus:(NSString*)statusMessage { - _didReceiveSomething = true; -} - -- (void)connectionFailed:(NSString*)errorMessage { - _didReceiveSomething = true; -} - -- (void)applyFrame:(const webrtc::DesktopSize&)size - stride:(NSInteger)stride - data:(uint8_t*)data - rects:(const std::vector&)rects { - _didReceiveSomething = true; -} - -- (void)applyCursor:(const webrtc::DesktopSize&)size - hotspot:(const webrtc::DesktopVector&)hotspot - cursorData:(uint8_t*)data { - _didReceiveSomething = true; -} - -@end - -namespace remoting { - -namespace { - -NSString* const kHostId = @"HostIdTest"; -NSString* const kPairingId = @"PairingIdTest"; -NSString* const kPairingSecret = @"PairingSecretTest"; -NSString* const kSecretPin = @"SecretPinTest"; -NSString* const kDeviceId = @"TestingDevice"; - -// TODO(aboone) should be able to call RunLoop().RunUntilIdle() instead but -// MessagePumpUIApplication::DoRun is marked NOTREACHED() -void RunCFMessageLoop() { - int result; - do { // Repeat until no messages remain - result = CFRunLoopRunInMode( - kCFRunLoopDefaultMode, - 0, // Execute queued messages, do not wait for additional messages - YES); // Do only one message at a time - } while (result != kCFRunLoopRunStopped && result != kCFRunLoopRunFinished && - result != kCFRunLoopRunTimedOut); -} - -void SecretPinCallBack(const std::string& secret) { - ASSERT_STREQ(base::SysNSStringToUTF8(kSecretPin).c_str(), secret.c_str()); -} - -} // namespace - -class ClientInstanceTest : public ::testing::Test { - protected: - void SetUp() override { - testDelegate_.reset( - [[ClientProxyDelegateForClientInstanceTester alloc] init]); - proxy_.reset(new ClientProxy( - [ClientProxyDelegateWrapper wrapDelegate:testDelegate_])); - instance_ = new ClientInstance(proxy_->AsWeakPtr(), "", "", "", "", ""); - } - - void TearDown() override { - // Ensure memory is not leaking - // Notice Cleanup is safe to call, regardless of if Start() was ever called. - instance_->Cleanup(); - RunCFMessageLoop(); - // An object on the network thread which owns a reference to |instance_| may - // be cleaned up 'soon', but not immediately. Lets wait it out, up to 1 - // second. - for (int i = 0; i < 100; i++) { - if (!instance_->HasOneRef()) { - [NSThread sleepForTimeInterval:.01]; - } else { - break; - } - } - - // Remove the last reference from |instance_|, and destructor is called. - ASSERT_TRUE(instance_->HasOneRef()); - instance_ = NULL; - } - - void AssertAcknowledged(BOOL wasAcknowledged) { - ASSERT_EQ(wasAcknowledged, [testDelegate_ didReceiveSomething]); - // Reset for the next test - [testDelegate_ resetDidReceiveSomething]; - } - - void TestStatusAndError(protocol::ConnectionToHost::State state, - protocol::ErrorCode error) { - instance_->OnConnectionState(state, error); - AssertAcknowledged(true); - } - - void TestConnectionStatus(protocol::ConnectionToHost::State state) { - TestStatusAndError(state, protocol::ErrorCode::OK); - TestStatusAndError(state, protocol::ErrorCode::PEER_IS_OFFLINE); - TestStatusAndError(state, protocol::ErrorCode::SESSION_REJECTED); - TestStatusAndError(state, protocol::ErrorCode::INCOMPATIBLE_PROTOCOL); - TestStatusAndError(state, protocol::ErrorCode::AUTHENTICATION_FAILED); - TestStatusAndError(state, protocol::ErrorCode::CHANNEL_CONNECTION_ERROR); - TestStatusAndError(state, protocol::ErrorCode::SIGNALING_ERROR); - TestStatusAndError(state, protocol::ErrorCode::SIGNALING_TIMEOUT); - TestStatusAndError(state, protocol::ErrorCode::HOST_OVERLOAD); - TestStatusAndError(state, protocol::ErrorCode::UNKNOWN_ERROR); - } - - base::scoped_nsobject - testDelegate_; - std::unique_ptr proxy_; - scoped_refptr instance_; -}; - -TEST_F(ClientInstanceTest, Create) { - // This is a test for memory leaking. Ensure a completely unused instance of - // ClientInstance is destructed. - - ASSERT_TRUE(instance_.get() != NULL); - ASSERT_TRUE(instance_->HasOneRef()); -} - -TEST_F(ClientInstanceTest, CreateAndStart) { - // This is a test for memory leaking. Ensure a properly used instance of - // ClientInstance is destructed. - - ASSERT_TRUE(instance_.get() != NULL); - ASSERT_TRUE(instance_->HasOneRef()); - - instance_->Start("", ""); - RunCFMessageLoop(); - ASSERT_TRUE(!instance_->HasOneRef()); // more than one -} - -TEST_F(ClientInstanceTest, SecretPin) { - NSString* hostId = kHostId; - NSString* pairingId = kPairingId; - NSString* pairingSecret = kPairingSecret; - - HostPreferences* newHost = [HostPreferences hostForId:hostId]; - newHost.pairId = pairingId; - newHost.pairSecret = pairingSecret; - [newHost saveToKeychain]; - - // Suggesting that our pairing Id is known, but since it is not the correct - // credentials expect the stored value to be discarded before requesting the - // PIN. - instance_ = new ClientInstance(proxy_->AsWeakPtr(), "", "", "", - base::SysNSStringToUTF8(kHostId), ""); - - instance_->Start(base::SysNSStringToUTF8(kPairingId), - base::SysNSStringToUTF8(kPairingSecret)); - RunCFMessageLoop(); - - instance_->FetchSecret(false, base::Bind(&SecretPinCallBack)); - RunCFMessageLoop(); - AssertAcknowledged(true); - - HostPreferences* host = [HostPreferences hostForId:hostId]; - - // The pairing information was discarded. - ASSERT_TRUE([host.pairId isEqualToString:@""]); - ASSERT_TRUE([host.pairSecret isEqualToString:@""]); - - instance_->ProvideSecret(base::SysNSStringToUTF8(kSecretPin), false, - base::SysNSStringToUTF8(kDeviceId)); - RunCFMessageLoop(); -} - -TEST_F(ClientInstanceTest, NoProxy) { - // After the proxy is released, we still expect quite a few functions to be - // able to run, but not produce any output. Some of these are just being - // executed for code coverage, the outputs are not pertinent to this test - // unit. - proxy_.reset(); - - instance_->Start("", ""); - RunCFMessageLoop(); - - instance_->FetchSecret(false, base::Bind(&SecretPinCallBack)); - AssertAcknowledged(false); - - instance_->ProvideSecret(base::SysNSStringToUTF8(kSecretPin), false, - base::SysNSStringToUTF8(kDeviceId)); - AssertAcknowledged(false); - - instance_->PerformMouseAction(webrtc::DesktopVector(0, 0), - webrtc::DesktopVector(0, 0), - (protocol::MouseEvent_MouseButton)0, false); - AssertAcknowledged(false); - - instance_->PerformKeyboardAction(0, false); - AssertAcknowledged(false); - - instance_->OnConnectionState(protocol::ConnectionToHost::State::CONNECTED, - protocol::ErrorCode::OK); - AssertAcknowledged(false); - - instance_->OnConnectionReady(false); - AssertAcknowledged(false); - - instance_->OnRouteChanged("", protocol::TransportRoute()); - AssertAcknowledged(false); - - // SetCapabilities requires a host connection to be established - // instance_->SetCapabilities(""); - // AssertAcknowledged(false); - - instance_->SetPairingResponse(protocol::PairingResponse()); - AssertAcknowledged(false); - - instance_->DeliverHostMessage(protocol::ExtensionMessage()); - AssertAcknowledged(false); - - ASSERT_TRUE(instance_->GetClipboardStub() != NULL); - ASSERT_TRUE(instance_->GetCursorShapeStub() != NULL); - - protocol::ClipboardEvent event; - event.set_mime_type(kMimeTypeTextUtf8); - event.set_data("Test data."); - instance_->InjectClipboardEvent(event); - AssertAcknowledged(false); - - instance_->SetCursorShape(protocol::CursorShapeInfo()); - AssertAcknowledged(false); -} - -TEST_F(ClientInstanceTest, OnConnectionStateINITIALIZING) { - TestConnectionStatus(protocol::ConnectionToHost::State::INITIALIZING); -} - -TEST_F(ClientInstanceTest, OnConnectionStateCONNECTING) { - TestConnectionStatus(protocol::ConnectionToHost::State::CONNECTING); -} - -TEST_F(ClientInstanceTest, OnConnectionStateAUTHENTICATED) { - TestConnectionStatus(protocol::ConnectionToHost::State::AUTHENTICATED); -} - -TEST_F(ClientInstanceTest, OnConnectionStateCONNECTED) { - TestConnectionStatus(protocol::ConnectionToHost::State::CONNECTED); -} - -TEST_F(ClientInstanceTest, OnConnectionStateFAILED) { - TestConnectionStatus(protocol::ConnectionToHost::State::FAILED); -} - -TEST_F(ClientInstanceTest, OnConnectionStateCLOSED) { - TestConnectionStatus(protocol::ConnectionToHost::State::CLOSED); -} - -TEST_F(ClientInstanceTest, OnConnectionReady) { - instance_->OnConnectionReady(true); - AssertAcknowledged(false); - instance_->OnConnectionReady(false); - AssertAcknowledged(false); -} - -TEST_F(ClientInstanceTest, OnRouteChanged) { - // Not expecting anything to happen - protocol::TransportRoute route; - - route.type = protocol::TransportRoute::DIRECT; - instance_->OnRouteChanged("", route); - AssertAcknowledged(false); - - route.type = protocol::TransportRoute::STUN; - instance_->OnRouteChanged("", route); - AssertAcknowledged(false); - - route.type = protocol::TransportRoute::RELAY; - instance_->OnRouteChanged("", route); - AssertAcknowledged(false); -} - -TEST_F(ClientInstanceTest, SetCursorShape) { - instance_->SetCursorShape(protocol::CursorShapeInfo()); - AssertAcknowledged(true); -} - -} // namespace remoting diff --git a/remoting/client/ios/bridge/client_proxy.h b/remoting/client/ios/bridge/client_proxy.h deleted file mode 100644 index c31e879215c802..00000000000000 --- a/remoting/client/ios/bridge/client_proxy.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_H_ - -#include -#include -#include - -#include "base/memory/weak_ptr.h" -#include "remoting/protocol/connection_to_host.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" - -#if defined(__OBJC__) -@class ClientProxyDelegateWrapper; -#else // __OBJC__ -class ClientProxyDelegateWrapper; -#endif // __OBJC__ - -namespace remoting { - -// class AudioConsumer; - -namespace protocol { -class CursorShapeInfo; -} // namespace protocol - -// Proxies incoming common Chromoting protocol (HOST) to the UI Application -// (CLIENT). The HOST will have a Weak reference to call member functions on -// the UI Thread. -class ClientProxy : public base::SupportsWeakPtr { - public: - ClientProxy(ClientProxyDelegateWrapper* wrapper); - - // Notifies the user of the current connection status. - void ReportConnectionStatus(protocol::ConnectionToHost::State state, - protocol::ErrorCode error); - - // Display a dialog box asking the user to enter a PIN. - void DisplayAuthenticationPrompt(bool pairing_supported); - - // Saves new pairing credentials to permanent storage. An empty string - // represents the unknown value, do not use the NULL value. - void CommitPairingCredentials(const std::string& host_id, - const std::string& pair_id, - const std::string& pair_secret); - - // Delivers the latest image buffer for the canvas. - void RedrawCanvas(webrtc::DesktopFrame* buffer); - - // Updates cursor. - void UpdateCursorShape(const protocol::CursorShapeInfo& cursor_shape); - - private: - // Pointer to the UI application which implements the ClientProxyDelegate. - // (id) is similar to a (void*) |delegate_| is set from accepting a - // strongly typed @interface which wraps the @protocol ClientProxyDelegate. - // see comments for host_proxy_delegate_wrapper.h - id delegate_; - - DISALLOW_COPY_AND_ASSIGN(ClientProxy); -}; - -} // namespace remoting - -#endif // REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_H_ diff --git a/remoting/client/ios/bridge/client_proxy.mm b/remoting/client/ios/bridge/client_proxy.mm deleted file mode 100644 index 6dae2c6ed33343..00000000000000 --- a/remoting/client/ios/bridge/client_proxy.mm +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - -#include "remoting/client/ios/bridge/client_proxy.h" - -#import "remoting/base/string_resources.h" -#import "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" -#import "remoting/client/ios/host_preferences.h" -#import "remoting/client/ios/utility.h" -#import "remoting/proto/control.pb.h" - -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/sys_string_conversions.h" - -namespace { -// The value indicating a successful connection has been established via a call -// to ReportConnectionStatus. -const static int kSuccessfulConnection = 3; - -NSString* GetStatusMsg(remoting::protocol::ConnectionToHost::State code) { - switch (code) { - case remoting::protocol::ConnectionToHost::INITIALIZING: - return CRD_LOCALIZED_STRING(IDS_FOOTER_WAITING); - case remoting::protocol::ConnectionToHost::CONNECTING: - return CRD_LOCALIZED_STRING(IDS_FOOTER_CONNECTING); - case remoting::protocol::ConnectionToHost::AUTHENTICATED: - // TODO(nicholss): This says "Working..." - return CRD_LOCALIZED_STRING(IDS_WORKING); - case remoting::protocol::ConnectionToHost::CONNECTED: - // TODO(nicholss): This says "Connected:" - return CRD_LOCALIZED_STRING(IDS_LABEL_CONNECTED); - case remoting::protocol::ConnectionToHost::FAILED: - // TODO(nicholss): This says "Authentication failed. Please sign in to - // Chrome again." - return CRD_LOCALIZED_STRING(IDS_ERROR_AUTHENTICATION_FAILED); - case remoting::protocol::ConnectionToHost::CLOSED: - return CRD_LOCALIZED_STRING(IDS_MESSAGE_SESSION_FINISHED); - } - return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); -} - -// Translate a connection error code integer to a NSString description. -NSString* GetErrorMsg(remoting::protocol::ErrorCode code) { - switch (code) { - case remoting::protocol::ErrorCode::OK: - return CRD_LOCALIZED_STRING(IDS_OK); - case remoting::protocol::ErrorCode::INVALID_ACCOUNT: - return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCOUNT); - case remoting::protocol::ErrorCode::MAX_SESSION_LENGTH: - return CRD_LOCALIZED_STRING(IDS_ERROR_MAX_SESSION_LENGTH); - case remoting::protocol::ErrorCode::PEER_IS_OFFLINE: - return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_IS_OFFLINE); - case remoting::protocol::ErrorCode::HOST_CONFIGURATION_ERROR: - return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_CONFIGURATION_ERROR); - case remoting::protocol::ErrorCode::SESSION_REJECTED: - return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCESS_CODE); - case remoting::protocol::ErrorCode::INCOMPATIBLE_PROTOCOL: - return CRD_LOCALIZED_STRING(IDS_ERROR_INCOMPATIBLE_PROTOCOL); - case remoting::protocol::ErrorCode::AUTHENTICATION_FAILED: - return CRD_LOCALIZED_STRING(IDS_ERROR_INVALID_ACCESS_CODE); - case remoting::protocol::ErrorCode::CHANNEL_CONNECTION_ERROR: - return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); - case remoting::protocol::ErrorCode::SIGNALING_ERROR: - return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); - case remoting::protocol::ErrorCode::SIGNALING_TIMEOUT: - return CRD_LOCALIZED_STRING(IDS_ERROR_P2P_FAILURE); - case remoting::protocol::ErrorCode::HOST_OVERLOAD: - return CRD_LOCALIZED_STRING(IDS_ERROR_HOST_OVERLOAD); - case remoting::protocol::ErrorCode::UNKNOWN_ERROR: - return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); - } - return CRD_LOCALIZED_STRING(IDS_ERROR_UNEXPECTED); -} - -} // namespace - -namespace remoting { - -ClientProxy::ClientProxy(ClientProxyDelegateWrapper* wrapper) { - delegate_ = [wrapper delegate]; -} - -void ClientProxy::ReportConnectionStatus( - protocol::ConnectionToHost::State state, - protocol::ErrorCode error) { - DCHECK(delegate_); - if (state <= kSuccessfulConnection && error == protocol::ErrorCode::OK) { - // Report Progress - [delegate_ connectionStatus:GetStatusMsg(state)]; - - if (state == kSuccessfulConnection) { - [delegate_ connected]; - } - } else { - [delegate_ connectionStatus:GetStatusMsg(state)]; - if (error != protocol::ErrorCode::OK) { - [delegate_ connectionFailed:GetErrorMsg(error)]; - } - } -} - -void ClientProxy::DisplayAuthenticationPrompt(bool pairing_supported) { - DCHECK(delegate_); - [delegate_ requestHostPin:pairing_supported]; -} - -void ClientProxy::CommitPairingCredentials(const std::string& host_id, - const std::string& pair_id, - const std::string& pair_secret) { - DCHECK(delegate_); - NSString* nsHostId = base::SysUTF8ToNSString(host_id); - NSString* nsPairId = base::SysUTF8ToNSString(pair_id); - NSString* nsPairSecret = base::SysUTF8ToNSString(pair_secret); - - HostPreferences* host = [HostPreferences hostForId:nsHostId]; - host.pairId = nsPairId; - host.pairSecret = nsPairSecret; - - [host saveToKeychain]; -} - -void ClientProxy::RedrawCanvas(webrtc::DesktopFrame* buffer) { - DCHECK(delegate_); - std::vector rects; - - for (webrtc::DesktopRegion::Iterator i(buffer->updated_region()); - !i.IsAtEnd(); i.Advance()) { - rects.push_back(i.rect()); - } - - [delegate_ applyFrame:buffer->size() - stride:buffer->stride() - data:buffer->data() - rects:rects]; -} - -void ClientProxy::UpdateCursorShape( - const protocol::CursorShapeInfo& cursor_shape) { - DCHECK(delegate_); - const uint8_t* cursor_data = reinterpret_cast( - cursor_shape.data().data()); - [delegate_ applyCursor:webrtc::DesktopSize(cursor_shape.width(), - cursor_shape.height()) - hotspot:webrtc::DesktopVector(cursor_shape.hotspot_x(), - cursor_shape.hotspot_y()) - cursorData:const_cast(cursor_data)]; -} - -} // namespace remoting diff --git a/remoting/client/ios/bridge/client_proxy_delegate.h b/remoting/client/ios/bridge/client_proxy_delegate.h deleted file mode 100644 index 9868f1e14c6742..00000000000000 --- a/remoting/client/ios/bridge/client_proxy_delegate.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_H_ - -#import -#import - -#include - -#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" - -// Contract to provide for callbacks from the common Chromoting protocol to the -// UI Application. -@protocol ClientProxyDelegate - -// HOST request for client to input their PIN. -- (void)requestHostPin:(BOOL)pairingSupported; - -// HOST notification that a connection has been successfully opened. -- (void)connected; - -// HOST notification for a change in connections status. -- (void)connectionStatus:(NSString*)statusMessage; - -// HOST notification that a connection has failed. -- (void)connectionFailed:(NSString*)errorMessage; - -// A new Canvas (desktop) update has arrived. -- (void)applyFrame:(const webrtc::DesktopSize&)size - stride:(NSInteger)stride - data:(uint8_t*)data - rects:(const std::vector&)regions; - -// A new Cursor (mouse) update has arrived. -- (void)applyCursor:(const webrtc::DesktopSize&)size - hotspot:(const webrtc::DesktopVector&)hotspot - cursorData:(uint8_t*)data; -@end - -#endif // REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_H_ diff --git a/remoting/client/ios/bridge/client_proxy_delegate_wrapper.h b/remoting/client/ios/bridge/client_proxy_delegate_wrapper.h deleted file mode 100644 index 9d5de4e325aa0e..00000000000000 --- a/remoting/client/ios/bridge/client_proxy_delegate_wrapper.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_WRAPPER_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_WRAPPER_H_ - -#import -#import - -#include - -#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" - -#import "remoting/client/ios/bridge/client_proxy_delegate.h" - -// Wraps ClientProxyDelegate in a class so C++ can accept a strongly typed -// pointer. C++ does not understand the id<> convention of passing around a -// OBJ_C @protocol pointer. So the @protocol is wrapped and the class is passed -// around. After accepting an instance of ClientProxyDelegateWrapper, the -// @protocol can be referenced as type (id), which is similar to a (void*). - -@interface ClientProxyDelegateWrapper : NSObject - -@property(nonatomic, retain, readonly) id delegate; - -- (id)init __unavailable; - -+ (id)wrapDelegate:(id)delegate; - -@end - -#endif // REMOTING_CLIENT_IOS_BRIDGE_HOST_PROXY_DELEGATE_WRAPPER_H_ diff --git a/remoting/client/ios/bridge/client_proxy_delegate_wrapper.mm b/remoting/client/ios/bridge/client_proxy_delegate_wrapper.mm deleted file mode 100644 index 0297b9b624df63..00000000000000 --- a/remoting/client/ios/bridge/client_proxy_delegate_wrapper.mm +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - -#import "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" - -@interface ClientProxyDelegateWrapper (Private) -- (id)initWithDelegate:(id)delegate; -@end - -@implementation ClientProxyDelegateWrapper - -@synthesize delegate = _delegate; - -- (id)initWithDelegate:(id)delegate { - self = [super init]; - if (self) { - _delegate = delegate; - } - return self; -} - -+ (id)wrapDelegate:(id)delegate { - return [[ClientProxyDelegateWrapper alloc] initWithDelegate:delegate]; -} - -@end diff --git a/remoting/client/ios/bridge/client_proxy_unittest.mm b/remoting/client/ios/bridge/client_proxy_unittest.mm deleted file mode 100644 index 66faf2167243c4..00000000000000 --- a/remoting/client/ios/bridge/client_proxy_unittest.mm +++ /dev/null @@ -1,372 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - -#import "remoting/client/ios/bridge/client_proxy.h" - -#import "base/compiler_specific.h" -#import "testing/gtest_mac.h" - -#import "remoting/client/ios/host_preferences.h" -#import "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" - -#include "base/strings/sys_string_conversions.h" -#include "remoting/proto/control.pb.h" -#include "remoting/proto/event.pb.h" - -@interface ClientProxyDelegateTester : NSObject -@property(nonatomic, assign) BOOL isConnected; -@property(nonatomic, copy) NSString* statusMessage; -@property(nonatomic, copy) NSString* errorMessage; -@property(nonatomic, assign) BOOL isPairingSupported; -@property(nonatomic, assign) webrtc::DesktopSize size; -@property(nonatomic, assign) NSInteger stride; -@property(nonatomic, assign) uint8_t* data; -@property(nonatomic, assign) std::vector rects; -@property(nonatomic, assign) webrtc::DesktopVector hotspot; -@end - -@implementation ClientProxyDelegateTester - -@synthesize isConnected = _isConnected; -@synthesize statusMessage = _statusMessage; -@synthesize errorMessage = _errorMessage; -@synthesize isPairingSupported = _isPairingSupported; -@synthesize size = _size; -@synthesize stride = _stride; -@synthesize data = _data; -@synthesize rects = _rects; -@synthesize hotspot = _hotspot; - -- (void)connected { - _isConnected = true; -} - -- (void)connectionStatus:(NSString*)statusMessage { - _statusMessage = statusMessage; -} - -- (void)connectionFailed:(NSString*)errorMessage { - _errorMessage = errorMessage; -} - -- (void)requestHostPin:(BOOL)pairingSupported { - _isPairingSupported = pairingSupported; -} - -- (void)applyFrame:(const webrtc::DesktopSize&)size - stride:(NSInteger)stride - data:(uint8_t*)data - rects:(const std::vector&)rects { - _size = size; - _stride = stride; - _data = data; - _rects.assign(rects.begin(), rects.end()); -} - -- (void)applyCursor:(const webrtc::DesktopSize&)size - hotspot:(const webrtc::DesktopVector&)hotspot - cursorData:(uint8_t*)data { - _size = size; - _hotspot = hotspot; - _data = data; -} - -@end - -namespace remoting { - -namespace { - -NSString* kStatusINITIALIZING = @"Initializing connection"; -NSString* kStatusCONNECTING = @"Connecting"; -NSString* kStatusAUTHENTICATED = @"Authenticated"; -NSString* kStatusCONNECTED = @"Connected"; -NSString* kStatusFAILED = @"Connection Failed"; -NSString* kStatusCLOSED = @"Connection closed"; -NSString* kStatusDEFAULT = @"Unknown connection state"; - -NSString* kErrorPEER_IS_OFFLINE = @"Requested host is offline."; -NSString* kErrorSESSION_REJECTED = @"Session was rejected by the host."; -NSString* kErrorINCOMPATIBLE_PROTOCOL = @"Incompatible Protocol."; -NSString* kErrorAUTHENTICATION_FAILED = @"Authentication Failed."; -NSString* kErrorCHANNEL_CONNECTION_ERROR = @"Channel Connection Error"; -NSString* kErrorSIGNALING_ERROR = @"Signaling Error"; -NSString* kErrorSIGNALING_TIMEOUT = @"Signaling Timeout"; -NSString* kErrorHOST_OVERLOAD = @"Host Overload"; -NSString* kErrorUNKNOWN_ERROR = - @"An unknown error has occurred, preventing the session from opening."; -NSString* kErrorDEFAULT = @"An unknown error code has occurred."; - -const webrtc::DesktopSize kFrameSize(100, 100); - -// Note these are disjoint regions. Testing intersecting regions is beyond the -// scope of this test class. -const webrtc::DesktopRect kFrameSubRect1 = - webrtc::DesktopRect::MakeXYWH(0, 0, 10, 10); -const webrtc::DesktopRect kFrameSubRect2 = - webrtc::DesktopRect::MakeXYWH(11, 11, 10, 10); -const webrtc::DesktopRect kFrameSubRect3 = - webrtc::DesktopRect::MakeXYWH(22, 22, 10, 10); - -const int kCursorHeight = 10; -const int kCursorWidth = 20; -const int kCursorHotSpotX = 4; -const int kCursorHotSpotY = 8; -// |kCursorDataLength| is assumed to be evenly divisible by 4 -const int kCursorDataLength = kCursorHeight * kCursorWidth; -const uint32_t kCursorDataPattern = 0xF0E1D2C3; - -NSString* const kHostName = @"ClientProxyHostNameTest"; -NSString* const kPairingId = @"ClientProxyPairingIdTest"; -NSString* const kPairingSecret = @"ClientProxyPairingSecretTest"; - -} // namespace - -class ClientProxyTest : public ::testing::Test { - protected: - void SetUp() override { - delegateTester_ = [[ClientProxyDelegateTester alloc] init]; - clientProxy_.reset(new ClientProxy( - [ClientProxyDelegateWrapper wrapDelegate:delegateTester_])); - } - - void ResetIsConnected() { delegateTester_.isConnected = false; } - - void TestConnnectionStatus(protocol::ConnectionToHost::State state, - NSString* expectedStatusMsg) { - ResetIsConnected(); - clientProxy_->ReportConnectionStatus(state, protocol::ErrorCode::OK); - EXPECT_NSEQ(expectedStatusMsg, delegateTester_.statusMessage); - - if (state == protocol::ConnectionToHost::State::CONNECTED) { - EXPECT_TRUE(delegateTester_.isConnected); - } else { - EXPECT_FALSE(delegateTester_.isConnected); - } - - TestErrorMessages(state, expectedStatusMsg); - } - - void TestForError(protocol::ConnectionToHost::State state, - protocol::ErrorCode errorCode, - NSString* expectedStatusMsg, - NSString* expectedErrorMsg) { - ResetIsConnected(); - clientProxy_->ReportConnectionStatus(state, errorCode); - EXPECT_FALSE(delegateTester_.isConnected); - EXPECT_NSEQ(expectedStatusMsg, delegateTester_.statusMessage); - EXPECT_NSEQ(expectedErrorMsg, delegateTester_.errorMessage); - } - - void TestErrorMessages(protocol::ConnectionToHost::State state, - NSString* expectedStatusMsg) { - TestForError(state, protocol::ErrorCode::AUTHENTICATION_FAILED, - expectedStatusMsg, kErrorAUTHENTICATION_FAILED); - TestForError(state, protocol::ErrorCode::CHANNEL_CONNECTION_ERROR, - expectedStatusMsg, kErrorCHANNEL_CONNECTION_ERROR); - TestForError(state, protocol::ErrorCode::HOST_OVERLOAD, expectedStatusMsg, - kErrorHOST_OVERLOAD); - TestForError(state, protocol::ErrorCode::INCOMPATIBLE_PROTOCOL, - expectedStatusMsg, kErrorINCOMPATIBLE_PROTOCOL); - TestForError(state, protocol::ErrorCode::PEER_IS_OFFLINE, expectedStatusMsg, - kErrorPEER_IS_OFFLINE); - TestForError(state, protocol::ErrorCode::SESSION_REJECTED, - expectedStatusMsg, kErrorSESSION_REJECTED); - TestForError(state, protocol::ErrorCode::SIGNALING_ERROR, expectedStatusMsg, - kErrorSIGNALING_ERROR); - TestForError(state, protocol::ErrorCode::SIGNALING_TIMEOUT, - expectedStatusMsg, kErrorSIGNALING_TIMEOUT); - TestForError(state, protocol::ErrorCode::UNKNOWN_ERROR, expectedStatusMsg, - kErrorUNKNOWN_ERROR); - TestForError(state, static_cast(999), - expectedStatusMsg, kErrorDEFAULT); - } - - void ValidateHost(const std::string& hostName, - const std::string& pairingId, - const std::string& pairingSecret) { - NSString* hostNameAsNSString = base::SysUTF8ToNSString(hostName); - - // Check if credentials are currently stored, and if so, delete them. - HostPreferences* existingHost = - [HostPreferences hostForId:hostNameAsNSString]; - if (existingHost != nil) { - existingHost.pairId = @""; - existingHost.pairSecret = @""; - [existingHost saveToKeychain]; - } - - clientProxy_->CommitPairingCredentials(hostName, pairingId, pairingSecret); - - // Fetch new credentials from keychain. - HostPreferences* host = [HostPreferences hostForId:hostNameAsNSString]; - - ASSERT_TRUE(host != nil); - ASSERT_TRUE([base::SysUTF8ToNSString(hostName) - isEqualToString:host.hostId]); - - if (pairingId.length() > 0) { - ASSERT_TRUE([base::SysUTF8ToNSString(pairingId) - isEqualToString:host.pairId]); - } else { - ASSERT_TRUE([host.pairId isEqualToString:@""]); - } - - if (pairingSecret.length() > 0) { - ASSERT_TRUE([base::SysUTF8ToNSString(pairingSecret) - isEqualToString:host.pairSecret]); - } else { - ASSERT_TRUE([host.pairSecret isEqualToString:@""]); - } - } - - std::unique_ptr clientProxy_; - ClientProxyDelegateTester* delegateTester_; - ClientProxyDelegateWrapper* delegateWrapper_; -}; - -// TODO(nicholss): Commenting these tests out for now until we settle on -// what the final strings will be. -// TEST_F(ClientProxyTest, ReportConnectionStatusINITIALIZING) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::INITIALIZING, -// kStatusINITIALIZING); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusCONNECTING) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::CONNECTING, -// kStatusCONNECTING); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusAUTHENTICATED) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::AUTHENTICATED, -// kStatusAUTHENTICATED); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusCONNECTED) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::CONNECTED, -// kStatusCONNECTED); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusFAILED) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::FAILED, -// kStatusFAILED); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusCLOSED) { -// TestConnnectionStatus(protocol::ConnectionToHost::State::CLOSED, -// kStatusCLOSED); -// } -// -// TEST_F(ClientProxyTest, ReportConnectionStatusDEFAULT) { -// TestConnnectionStatus(static_cast(999), -// kStatusDEFAULT); -// } - -TEST_F(ClientProxyTest, DisplayAuthenticationPrompt) { - clientProxy_->DisplayAuthenticationPrompt(true); - ASSERT_TRUE(delegateTester_.isPairingSupported); - clientProxy_->DisplayAuthenticationPrompt(false); - ASSERT_FALSE(delegateTester_.isPairingSupported); -} - -TEST_F(ClientProxyTest, CommitPairingCredentialsBasic) { - ValidateHost("", "", ""); -} - -TEST_F(ClientProxyTest, CommitPairingCredentialsExtended) { - ValidateHost(base::SysNSStringToUTF8(kHostName), - base::SysNSStringToUTF8(kPairingId), - base::SysNSStringToUTF8(kPairingSecret)); -} - -// TODO(nicholss): Re-enable these tests. Activly changing how rendering -// is done for the app at the moment. -// TEST_F(ClientProxyTest, RedrawCanvasBasic) { -// webrtc::BasicDesktopFrame frame(webrtc::DesktopSize(1, 1)); -// webrtc::DesktopRegion regions; -// regions.AddRect(webrtc::DesktopRect::MakeLTRB(0, 0, 1, 1)); -// -// clientProxy_->RedrawCanvas(webrtc::DesktopSize(1, 1), &frame, regions); -// -// ASSERT_TRUE(webrtc::DesktopSize(1, 1).equals(delegateTester_.size)); -// ASSERT_EQ(4, delegateTester_.stride); -// ASSERT_TRUE(delegateTester_.data != NULL); -// ASSERT_EQ(1, delegateTester_.regions.size()); -// ASSERT_TRUE(delegateTester_.regions[0].equals( -// webrtc::DesktopRect::MakeLTRB(0, 0, 1, 1))); -// } -// -// TEST_F(ClientProxyTest, RedrawCanvasExtended) { -// webrtc::BasicDesktopFrame frame(kFrameSize); -// webrtc::DesktopRegion regions; -// regions.AddRect(kFrameSubRect1); -// regions.AddRect(kFrameSubRect2); -// regions.AddRect(kFrameSubRect3); -// -// clientProxy_->RedrawCanvas(kFrameSize, &frame, regions); -// -// ASSERT_TRUE(kFrameSize.equals(delegateTester_.size)); -// ASSERT_EQ(kFrameSize.width() * webrtc::DesktopFrame::kBytesPerPixel, -// delegateTester_.stride); -// ASSERT_TRUE(delegateTester_.data != NULL); -// ASSERT_EQ(3, delegateTester_.regions.size()); -// ASSERT_TRUE(delegateTester_.regions[0].equals(kFrameSubRect1)); -// ASSERT_TRUE(delegateTester_.regions[1].equals(kFrameSubRect2)); -// ASSERT_TRUE(delegateTester_.regions[2].equals(kFrameSubRect3)); -// } - -TEST_F(ClientProxyTest, UpdateCursorBasic) { - protocol::CursorShapeInfo cursor_proto; - cursor_proto.set_width(1); - cursor_proto.set_height(1); - cursor_proto.set_hotspot_x(0); - cursor_proto.set_hotspot_y(0); - - char data[4]; - memset(data, 0xFF, 4); - - cursor_proto.set_data(data); - - clientProxy_->UpdateCursorShape(cursor_proto); - - ASSERT_EQ(1, delegateTester_.size.width()); - ASSERT_EQ(1, delegateTester_.size.height()); - ASSERT_EQ(0, delegateTester_.hotspot.x()); - ASSERT_EQ(0, delegateTester_.hotspot.y()); - ASSERT_TRUE(delegateTester_.data != NULL); - for (int i = 0; i < 4; i++) { - ASSERT_EQ(0xFF, delegateTester_.data[i]); - } -} - -TEST_F(ClientProxyTest, UpdateCursorExtended) { - protocol::CursorShapeInfo cursor_proto; - cursor_proto.set_width(kCursorWidth); - cursor_proto.set_height(kCursorHeight); - cursor_proto.set_hotspot_x(kCursorHotSpotX); - cursor_proto.set_hotspot_y(kCursorHotSpotY); - - char data[kCursorDataLength]; - memset_pattern4(data, &kCursorDataPattern, kCursorDataLength); - - cursor_proto.set_data(data); - - clientProxy_->UpdateCursorShape(cursor_proto); - - ASSERT_EQ(kCursorWidth, delegateTester_.size.width()); - ASSERT_EQ(kCursorHeight, delegateTester_.size.height()); - ASSERT_EQ(kCursorHotSpotX, delegateTester_.hotspot.x()); - ASSERT_EQ(kCursorHotSpotY, delegateTester_.hotspot.y()); - ASSERT_TRUE(delegateTester_.data != NULL); - for (int i = 0; i < kCursorDataLength / 4; i++) { - ASSERT_TRUE(memcmp(&delegateTester_.data[i * 4], &kCursorDataPattern, 4) == - 0); - } -} - -} // namespace remoting diff --git a/remoting/client/ios/bridge/frame_consumer_bridge.cc b/remoting/client/ios/bridge/frame_consumer_bridge.cc deleted file mode 100644 index f1292352d32c01..00000000000000 --- a/remoting/client/ios/bridge/frame_consumer_bridge.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/client/ios/bridge/frame_consumer_bridge.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/memory/ptr_util.h" -#include "base/synchronization/waitable_event.h" -#include "remoting/base/util.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" - -namespace remoting { - -FrameConsumerBridge::FrameConsumerBridge(ClientInstance* client_instance, - const OnFrameCallback callback) - : callback_(callback), runtime_(client_instance), weak_factory_(this) {} - -FrameConsumerBridge::~FrameConsumerBridge() {} - -std::unique_ptr FrameConsumerBridge::AllocateFrame( - const webrtc::DesktopSize& size) { - return base::WrapUnique(new webrtc::BasicDesktopFrame(size)); -} - -void FrameConsumerBridge::RenderFrame( - std::unique_ptr frame) { - DCHECK(runtime_->display_task_runner()->BelongsToCurrentThread()); - // Draw the frame - callback_.Run(frame.get()); -} - -void FrameConsumerBridge::DrawFrame(std::unique_ptr frame, - const base::Closure& done) { - DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); - - runtime_->display_task_runner()->PostTaskAndReply( - FROM_HERE, base::Bind(&FrameConsumerBridge::RenderFrame, - weak_factory_.GetWeakPtr(), base::Passed(&frame)), - base::Bind(&FrameConsumerBridge::OnFrameRendered, - weak_factory_.GetWeakPtr(), done)); -} - -void FrameConsumerBridge::OnFrameRendered(const base::Closure& done) { - DCHECK(runtime_->network_task_runner()->BelongsToCurrentThread()); - - if (!done.is_null()) - done.Run(); -} - -FrameConsumerBridge::PixelFormat FrameConsumerBridge::GetPixelFormat() { - return FORMAT_RGBA; -} - -} // namespace remoting diff --git a/remoting/client/ios/bridge/frame_consumer_bridge.h b/remoting/client/ios/bridge/frame_consumer_bridge.h deleted file mode 100644 index ca51821f72cc1f..00000000000000 --- a/remoting/client/ios/bridge/frame_consumer_bridge.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_FRAME_CONSUMER_BRIDGE_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_FRAME_CONSUMER_BRIDGE_H_ - -#include -#include - -#include "base/callback.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_vector.h" -#include "base/memory/weak_ptr.h" -#include "remoting/client/ios/bridge/client_instance.h" -#include "remoting/protocol/frame_consumer.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" - -namespace remoting { - -class ClientInstance; - -// TODO(nicholss): It should be possible to use remoting/client/ -// dual_buffer_frame_consumer.h instead of this class. -class FrameConsumerBridge : public protocol::FrameConsumer { - public: - typedef base::Callback OnFrameCallback; - - // A callback is provided to return frame updates asynchronously. - explicit FrameConsumerBridge(ClientInstance* client_instance, - const OnFrameCallback callback); - - ~FrameConsumerBridge() override; - - std::unique_ptr AllocateFrame( - const webrtc::DesktopSize& size) override; - - void DrawFrame(std::unique_ptr frame, - const base::Closure& done) override; - - PixelFormat GetPixelFormat() override; - - private: - void RenderFrame(std::unique_ptr frame); - - void OnFrameRendered(const base::Closure& done); - - OnFrameCallback callback_; - - ClientInstance* runtime_; - - webrtc::DesktopSize view_size_; - - base::WeakPtrFactory weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(FrameConsumerBridge); -}; - -} // namespace remoting - -#endif // REMOTING_CLIENT_IOS_BRIDGE_FRAME_CONSUMER_BRIDGE_H_ diff --git a/remoting/client/ios/bridge/frame_consumer_bridge_unittest.cc b/remoting/client/ios/bridge/frame_consumer_bridge_unittest.cc deleted file mode 100644 index 61e2ec94ff1a87..00000000000000 --- a/remoting/client/ios/bridge/frame_consumer_bridge_unittest.cc +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/client/ios/bridge/frame_consumer_bridge.h" - -#include -#include -#include - -#include "base/bind.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_region.h" - -namespace { -const webrtc::DesktopSize kFrameSize(100, 100); -const webrtc::DesktopVector kDpi(100, 100); - -const webrtc::DesktopRect FrameRect() { - return webrtc::DesktopRect::MakeSize(kFrameSize); -} - -webrtc::DesktopRegion FrameRegion() { - return webrtc::DesktopRegion(FrameRect()); -} - -void FrameDelivery(webrtc::DesktopFrame* buffer, - const webrtc::DesktopRegion& region) { - ASSERT_TRUE(buffer->size().equals(kFrameSize)); - ASSERT_TRUE(region.Equals(FrameRegion())); -}; - -} // namespace - -namespace remoting { - -class FrameProducerTester : public FrameProducer { - public: - virtual ~FrameProducerTester(){}; - - void DrawBuffer(webrtc::DesktopFrame* buffer) override { - frames.push(buffer); - }; - - void InvalidateRegion(const webrtc::DesktopRegion& region) override { - NOTIMPLEMENTED(); - }; - - void RequestReturnBuffers(const base::Closure& done) override { - // Don't have to actually return the buffers. This function is really - // saying don't use the references anymore, they are now invalid. - while (!frames.empty()) { - frames.pop(); - } - done.Run(); - }; - - void SetOutputSizeAndClip(const webrtc::DesktopSize& view_size, - const webrtc::DesktopRect& clip_area) override { - viewSize = view_size; - clipArea = clip_area; - }; - - std::queue frames; - webrtc::DesktopSize viewSize; - webrtc::DesktopRect clipArea; -}; - -class FrameConsumerBridgeTest : public ::testing::Test { - protected: - void SetUp() override { - frameProducer_.reset(new FrameProducerTester()); - frameConsumer_.reset(new FrameConsumerBridge(base::Bind(&FrameDelivery))); - frameConsumer_->Initialize(frameProducer_.get()); - } - void TearDown() override {} - - std::unique_ptr frameProducer_; - std::unique_ptr frameConsumer_; -}; - -TEST(FrameConsumerBridgeTest_NotInitialized, CreateAndRelease) { - std::unique_ptr frameConsumer_( - new FrameConsumerBridge(base::Bind(&FrameDelivery))); - ASSERT_TRUE(frameConsumer_.get() != NULL); - frameConsumer_.reset(); - ASSERT_TRUE(frameConsumer_.get() == NULL); -} - -// TODO(nicholss): FrameConsumer has changed since last integration. -// Need to update the tests. -// TEST_F(FrameConsumerBridgeTest, ApplyBuffer) { -// webrtc::DesktopFrame* frame = NULL; -// ASSERT_EQ(0, frameProducer_->frames.size()); -// frameConsumer_->SetSourceSize(kFrameSize, kDpi); -// ASSERT_EQ(1, frameProducer_->frames.size()); -// -// // Return the frame, and ensure we get it back -// frame = frameProducer_->frames.front(); -// frameProducer_->frames.pop(); -// ASSERT_EQ(0, frameProducer_->frames.size()); -// frameConsumer_->ApplyBuffer( -// kFrameSize, FrameRect(), frame, FrameRegion(), FrameRegion()); -// ASSERT_EQ(1, frameProducer_->frames.size()); -// ASSERT_TRUE(frame == frameProducer_->frames.front()); -// ASSERT_TRUE(frame->data() == frameProducer_->frames.front()->data()); -// -// // Change the SourceSize, we should get a new frame, but when the old frame -// is -// // submitted we will not get it back. -// frameConsumer_->SetSourceSize(webrtc::DesktopSize(1, 1), kDpi); -// ASSERT_EQ(2, frameProducer_->frames.size()); -// frame = frameProducer_->frames.front(); -// frameProducer_->frames.pop(); -// ASSERT_EQ(1, frameProducer_->frames.size()); -// frameConsumer_->ApplyBuffer( -// kFrameSize, FrameRect(), frame, FrameRegion(), FrameRegion()); -// ASSERT_EQ(1, frameProducer_->frames.size()); -// } -// -// TEST_F(FrameConsumerBridgeTest, SetSourceSize) { -// frameConsumer_->SetSourceSize(webrtc::DesktopSize(0, 0), -// webrtc::DesktopVector(0, 0)); -// ASSERT_TRUE(frameProducer_->viewSize.equals(webrtc::DesktopSize(0, 0))); -// ASSERT_TRUE(frameProducer_->clipArea.equals( -// webrtc::DesktopRect::MakeLTRB(0, 0, 0, 0))); -// ASSERT_EQ(1, frameProducer_->frames.size()); -// ASSERT_TRUE( -// frameProducer_->frames.front()->size().equals(webrtc::DesktopSize(0, -// 0))); -// -// frameConsumer_->SetSourceSize(kFrameSize, kDpi); -// ASSERT_TRUE(frameProducer_->viewSize.equals(kFrameSize)); -// ASSERT_TRUE(frameProducer_->clipArea.equals(FrameRect())); -// ASSERT_EQ(2, frameProducer_->frames.size()); -// frameProducer_->frames.pop(); -// ASSERT_TRUE(frameProducer_->frames.front()->size().equals(kFrameSize)); -// } - -} // namespace remoting diff --git a/remoting/client/ios/bridge/host_proxy.h b/remoting/client/ios/bridge/host_proxy.h deleted file mode 100644 index b0ec6bf42419d6..00000000000000 --- a/remoting/client/ios/bridge/host_proxy.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_BRIDGE_CLIENT_PROXY_H_ -#define REMOTING_CLIENT_IOS_BRIDGE_CLIENT_PROXY_H_ - -#import -#import - -#include - -#import "remoting/client/ios/bridge/client_proxy_delegate_wrapper.h" - -#include "base/memory/ref_counted.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" - -namespace remoting { -class ClientInstance; -class ClientProxy; -} // namespace remoting - -// HostProxy is one channel of a bridge from the UI Application (CLIENT) and the -// common Chromoting protocol (HOST). HostProxy proxies message from the UI -// application to the host. The reverse channel, ClientProxy, is owned by the -// HostProxy to control deconstruction order, but is shared with the -// ClientInstance to perform work. - -@interface HostProxy : NSObject { - @private - // Host to Client channel. - std::unique_ptr _hostToClientChannel; - // Client to Host channel, must be released before |_hostToClientChannel|. - scoped_refptr _clientToHostChannel; - // Connection state. - BOOL _isConnected; -} - -// TRUE when a connection has been established successfully. -- (BOOL)isConnected; - -// Forwards credentials from CLIENT and to HOST and begins establishing a -// connection. -- (void)connectToHost:(NSString*)username - authToken:(NSString*)token - jabberId:(NSString*)jid - hostId:(NSString*)hostId - publicKey:(NSString*)hostPublicKey - delegate:(id)delegate; - -// Report from CLIENT with the user's PIN. -- (void)authenticationResponse:(NSString*)pin createPairing:(BOOL)createPairing; - -// CLIENT initiated disconnection. -- (void)disconnectFromHost; - -// Report from CLIENT of mouse input. -- (void)mouseAction:(const webrtc::DesktopVector&)position - wheelDelta:(const webrtc::DesktopVector&)wheelDelta - whichButton:(NSInteger)buttonPressed - buttonDown:(BOOL)buttonIsDown; - -// Report from CLIENT of keyboard input. -- (void)keyboardAction:(NSInteger)keyCode keyDown:(BOOL)keyIsDown; - -@end - -#endif // REMOTING_CLIENT_IOS_BRIDGE_CLIENT_PROXY_H_ diff --git a/remoting/client/ios/bridge/host_proxy.mm b/remoting/client/ios/bridge/host_proxy.mm deleted file mode 100644 index 30f4f44eaf9f76..00000000000000 --- a/remoting/client/ios/bridge/host_proxy.mm +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "remoting/client/ios/bridge/host_proxy.h" - -#import "remoting/client/ios/host_preferences.h" -#import "remoting/client/ios/bridge/client_instance.h" -#import "remoting/client/ios/bridge/client_proxy.h" - -#include "base/strings/sys_string_conversions.h" - -@implementation HostProxy - -// Override default constructor and initialize internals. -- (id)init { - self = [super init]; - if (self) { - _isConnected = false; - } - return self; -} - -// Override default destructor. -- (void)dealloc { - if (_isConnected) { - [self disconnectFromHost]; - } - - //[super dealloc]; // TODO(nicholss): ARC forbids explicit message send of - //'dealloc' -} - -- (BOOL)isConnected { - return _isConnected; -} - -- (void)connectToHost:(NSString*)username - authToken:(NSString*)token - jabberId:(NSString*)jid - hostId:(NSString*)hostId - publicKey:(NSString*)hostPublicKey - delegate:(id)delegate { - // Implicitly, if currently connected, discard the connection and begin a new - // connection. - [self disconnectFromHost]; - - _hostToClientChannel.reset(new remoting::ClientProxy( - [ClientProxyDelegateWrapper wrapDelegate:delegate])); - - DCHECK(!_clientToHostChannel.get()); - _clientToHostChannel = new remoting::ClientInstance( - _hostToClientChannel->AsWeakPtr(), base::SysNSStringToUTF8(username), - base::SysNSStringToUTF8(token), base::SysNSStringToUTF8(jid), - base::SysNSStringToUTF8(hostId), base::SysNSStringToUTF8(hostPublicKey)); - - HostPreferences* host = [HostPreferences hostForId:hostId]; - _clientToHostChannel->Start(base::SysNSStringToUTF8(host.pairId), - base::SysNSStringToUTF8(host.pairSecret)); - _isConnected = YES; -} - -- (void)authenticationResponse:(NSString*)pin - createPairing:(BOOL)createPairing { - if (_isConnected) { - // Where |deviceId| is first created doesn't matter, but it does have to be - // from an Obj-C file. Creating |deviceId| now, just before passing a copy - // into a C++ interface. - NSString* deviceId = - [[[UIDevice currentDevice] identifierForVendor] UUIDString]; - - _clientToHostChannel->ProvideSecret(base::SysNSStringToUTF8(pin), - createPairing, - base::SysNSStringToUTF8(deviceId)); - } -} - -- (void)disconnectFromHost { - if (_isConnected) { - VLOG(1) << "Disconnecting from Host"; - - // |_clientToHostChannel| must be closed before releasing - // |_hostToClientChannel|. - - // |_clientToHostChannel| owns several objects that have references to - // itself. These objects need to be cleaned up before we can release - // |_clientToHostChannel|. - _clientToHostChannel->Cleanup(); - // All other references to |_clientToHostChannel| should now be free. When - // the next statement is executed the destructor is called automatically. - _clientToHostChannel = NULL; - - _hostToClientChannel.reset(); - - _isConnected = NO; - } -} - -- (void)mouseAction:(const webrtc::DesktopVector&)position - wheelDelta:(const webrtc::DesktopVector&)wheelDelta - whichButton:(NSInteger)buttonPressed - buttonDown:(BOOL)buttonIsDown { - if (_isConnected) { - _clientToHostChannel->PerformMouseAction(position, wheelDelta, - (remoting::protocol::MouseEvent_MouseButton) buttonPressed, - buttonIsDown); - } -} - -- (void)keyboardAction:(NSInteger)keyCode keyDown:(BOOL)keyIsDown { - if (_isConnected) { - _clientToHostChannel->PerformKeyboardAction(keyCode, keyIsDown); - } -} - -@end diff --git a/remoting/client/ios/bridge/host_proxy_unittest.mm b/remoting/client/ios/bridge/host_proxy_unittest.mm deleted file mode 100644 index 79f37ccd538ff2..00000000000000 --- a/remoting/client/ios/bridge/host_proxy_unittest.mm +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - -#import "remoting/client/ios/bridge/host_proxy.h" - -#import "base/compiler_specific.h" -#import "testing/gtest_mac.h" - -namespace remoting { - -class HostProxyTest : public ::testing::Test { - protected: - void SetUp() override { hostProxy_ = [[HostProxy alloc] init]; } - - void CallPassThroughFunctions() { - [hostProxy_ mouseAction:webrtc::DesktopVector(0, 0) - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:0 - buttonDown:NO]; - [hostProxy_ keyboardAction:0 keyDown:NO]; - } - - HostProxy* hostProxy_; -}; - -TEST_F(HostProxyTest, ConnectDisconnect) { - CallPassThroughFunctions(); - - ASSERT_FALSE([hostProxy_ isConnected]); - [hostProxy_ connectToHost:@"" - authToken:@"" - jabberId:@"" - hostId:@"" - publicKey:@"" - delegate:nil]; - ASSERT_TRUE([hostProxy_ isConnected]); - - CallPassThroughFunctions(); - - [hostProxy_ disconnectFromHost]; - ASSERT_FALSE([hostProxy_ isConnected]); - - CallPassThroughFunctions(); -} - -} // namespace remoting diff --git a/remoting/client/ios/display/BUILD.gn b/remoting/client/ios/display/BUILD.gn index 548667d81a596a..643b0339e9c581 100644 --- a/remoting/client/ios/display/BUILD.gn +++ b/remoting/client/ios/display/BUILD.gn @@ -27,7 +27,6 @@ source_set("display") { public_deps = [ "//remoting/client", "//remoting/client/display", - "//remoting/client/ios/bridge", "//third_party/webrtc/base:rtc_base_approved", ] diff --git a/remoting/client/ios/utility.h b/remoting/client/ios/utility.h deleted file mode 100644 index 2306e355028eee..00000000000000 --- a/remoting/client/ios/utility.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_CLIENT_IOS_UTILITY_H_ -#define REMOTING_CLIENT_IOS_UTILITY_H_ - -#import -#import -#import -#include - -#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" -#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" - -#import "remoting/client/ios/bridge/host_proxy.h" - -#define CRD_LOCALIZED_STRING(stringId) \ - [Utility localizedStringForKey:@ #stringId dummyId:stringId] - -typedef struct { - GLKVector2 geometryVertex; - GLKVector2 textureVertex; -} TexturedVertex; - -typedef struct { - TexturedVertex bl; - TexturedVertex br; - TexturedVertex tl; - TexturedVertex tr; -} TexturedQuad; - -typedef struct { - GLuint name; - webrtc::DesktopRect rect; - // The draw surface is a triangle strip (triangles defined by the intersecting - // vertexes) to create a rectangle surface. - // 1****3 - // | / | - // | / | - // 2****4 - // This also determines the resolution of our surface, being a unit (NxN) grid - // with finite divisions. For our surface N = 1, and the number of divisions - // respects the CLIENT's desktop resolution. - TexturedQuad quad; -} TextureContainer; - -typedef struct { - std::unique_ptr image; - std::unique_ptr offset; -} GLRegion; - -@interface Utility : NSObject - -+ (BOOL)isPad; - -+ (BOOL)isInLandscapeMode; - -// Return the resolution in respect to orientation. -+ (CGSize)getOrientatedSize:(CGSize)size - shouldWidthBeLongestSide:(BOOL)shouldWidthBeLongestSide; - -+ (void)showAlert:(NSString*)title message:(NSString*)message; - -+ (NSString*)appVersionNumberDisplayString; - -// GL Binding Context requires some specific flags for the type of textures -// being drawn. -+ (void)bindTextureForIOS:(GLuint)glName; - -// Sometimes it is necessary to read gl errors. This is called in various -// places while working in the GL Context. -+ (void)logGLErrorCode:(NSString*)funcName; - -+ (void)drawSubRectToGLFromRectOfSize:(const webrtc::DesktopSize&)rectSize - subRect:(const webrtc::DesktopRect&)subRect - data:(const uint8_t*)data; - -+ (void)moveMouse:(HostProxy*)controller at:(const webrtc::DesktopVector&)point; - -+ (void)leftClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point; - -+ (void)middleClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point; - -+ (void)rightClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point; - -+ (void)mouseScroll:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point - delta:(const webrtc::DesktopVector&)delta; - -// Wrapper around NSLocalizedString. Don't call this directly. Use -// CRD_LOCALIZED_STRING instead. |dummyId| is ignored. It's used by -// CRD_LOCALIZED_STRING to force the compiler to resolve the constant name. -+ (NSString*)localizedStringForKey:(NSString*)key dummyId:(int)dummyId; - -// Objective-C friendly wrapper around ReplaceStringPlaceholders. -+ (NSString*)stringWithL10nFormat:(NSString*)format - withReplacements:(NSArray*)replacements; - -@end - -#endif // REMOTING_CLIENT_IOS_UTILITY_H_ diff --git a/remoting/client/ios/utility.mm b/remoting/client/ios/utility.mm deleted file mode 100644 index 23a4faf1be6383..00000000000000 --- a/remoting/client/ios/utility.mm +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#if !defined(__has_feature) || !__has_feature(objc_arc) -#error "This file requires ARC support." -#endif - -#import "remoting/client/ios/utility.h" - -#include "base/logging.h" -#include "base/strings/string_util.h" -#include "base/strings/sys_string_conversions.h" - -@implementation Utility - -+ (BOOL)isPad { - return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); -} - -+ (BOOL)isInLandscapeMode { - UIInterfaceOrientation orientation = - [UIApplication sharedApplication].statusBarOrientation; - - if ((orientation == UIInterfaceOrientationLandscapeLeft) || - (orientation == UIInterfaceOrientationLandscapeRight)) { - return YES; - } - return NO; -} - -+ (CGSize)getOrientatedSize:(CGSize)size - shouldWidthBeLongestSide:(BOOL)shouldWidthBeLongestSide { - if (shouldWidthBeLongestSide && (size.height > size.width)) { - return CGSizeMake(size.height, size.width); - } - return size; -} - -+ (void)showAlert:(NSString*)title message:(NSString*)message { - UIAlertController* alert; - alert = - [UIAlertController alertControllerWithTitle:title - message:message - preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction* defaultAction = - [UIAlertAction actionWithTitle:@"OK" - style:UIAlertActionStyleDefault - handler:^(UIAlertAction* action){ - }]; - - [alert addAction:defaultAction]; - [[UIApplication sharedApplication].delegate.window.rootViewController - presentViewController:alert - animated:YES - completion:nil]; -} - -+ (NSString*)appVersionNumberDisplayString { - NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; - - NSString* version = - [infoDictionary objectForKey:@"CFBundleShortVersionString"]; - - return [NSString stringWithFormat:@"Version %@", version]; -} - -+ (void)bindTextureForIOS:(GLuint)glName { - glBindTexture(GL_TEXTURE_2D, glName); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -} - -+ (void)logGLErrorCode:(NSString*)funcName { - GLenum errorCode = 1; - - while (errorCode != 0) { - errorCode = glGetError(); // I don't know why this is returning an error - // on the first call to this function, but if I - // don't read it, then stuff doesn't work... - VLOG_IF(0, errorCode) << "GLerror in " << - [funcName cStringUsingEncoding:NSUTF8StringEncoding] << ": " - << std::hex << errorCode << std::dec; - } -} - -+ (void)drawSubRectToGLFromRectOfSize:(const webrtc::DesktopSize&)rectSize - subRect:(const webrtc::DesktopRect&)subRect - data:(const uint8_t*)data { - DCHECK(rectSize.width() >= subRect.width()); - DCHECK(rectSize.height() >= subRect.height()); - DCHECK(subRect.left() >= 0); - DCHECK(subRect.top() >= 0); - DCHECK(data); - - glTexSubImage2D(GL_TEXTURE_2D, 0, subRect.left(), subRect.top(), - subRect.width(), subRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, - data); -} - -+ (void)moveMouse:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point { - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:0 - buttonDown:NO]; -} - -+ (void)leftClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point { - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:1 - buttonDown:YES]; - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:1 - buttonDown:NO]; -} - -+ (void)middleClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point { - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:2 - buttonDown:YES]; - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:2 - buttonDown:NO]; -} - -+ (void)rightClickOn:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point { - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:3 - buttonDown:YES]; - [controller mouseAction:point - wheelDelta:webrtc::DesktopVector(0, 0) - whichButton:3 - buttonDown:NO]; -} - -+ (void)mouseScroll:(HostProxy*)controller - at:(const webrtc::DesktopVector&)point - delta:(const webrtc::DesktopVector&)delta { - [controller mouseAction:point wheelDelta:delta whichButton:0 buttonDown:NO]; -} - -+ (NSString*)localizedStringForKey:(NSString*)key dummyId:(int)dummyId { - return NSLocalizedString(key, nil); -} - -+ (NSString*)stringWithL10nFormat:(NSString*)format - withReplacements:(NSArray*)replacements { - std::string format_str(base::SysNSStringToUTF8(format)); - std::vector replacements_str; - - for (NSString* replacement in replacements) { - DCHECK([replacement isKindOfClass:[NSString class]]); - replacements_str.push_back(base::SysNSStringToUTF8(replacement)); - } - - std::string formatted_str( - base::ReplaceStringPlaceholders(format_str, replacements_str, nullptr)); - return base::SysUTF8ToNSString(formatted_str); -} - -@end