| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/client/plugin/chromoting_instance.h" | 5 #include "remoting/client/plugin/chromoting_instance.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 // TODO(sergeyu): We should not depend on renderer here. Instead P2P | 19 // TODO(sergeyu): We should not depend on renderer here. Instead P2P |
| 20 // Pepper API should be used. Remove this dependency. | 20 // Pepper API should be used. Remove this dependency. |
| 21 // crbug.com/74951 | 21 // crbug.com/74951 |
| 22 #include "content/renderer/p2p/ipc_network_manager.h" | 22 #include "content/renderer/p2p/ipc_network_manager.h" |
| 23 #include "content/renderer/p2p/ipc_socket_factory.h" | 23 #include "content/renderer/p2p/ipc_socket_factory.h" |
| 24 #include "ppapi/c/dev/ppb_query_policy_dev.h" | 24 #include "ppapi/c/dev/ppb_query_policy_dev.h" |
| 25 #include "ppapi/cpp/completion_callback.h" | 25 #include "ppapi/cpp/completion_callback.h" |
| 26 #include "ppapi/cpp/input_event.h" | 26 #include "ppapi/cpp/input_event.h" |
| 27 #include "ppapi/cpp/rect.h" | 27 #include "ppapi/cpp/rect.h" |
| 28 // TODO(wez): Remove this when crbug.com/86353 is complete. | 28 // TODO(wez): Remove this when crbug.com/86353 is complete. |
| 29 #include "ppapi/cpp/private/var_private.h" | 29 #include "ppapi/cpp/private/var_private.h" |
| 30 #include "remoting/base/task_thread_proxy.h" |
| 31 #include "remoting/base/util.h" |
| 30 #include "remoting/client/client_config.h" | 32 #include "remoting/client/client_config.h" |
| 31 #include "remoting/client/chromoting_client.h" | 33 #include "remoting/client/chromoting_client.h" |
| 32 #include "remoting/client/rectangle_update_decoder.h" | 34 #include "remoting/client/rectangle_update_decoder.h" |
| 33 #include "remoting/client/plugin/chromoting_scriptable_object.h" | 35 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
| 34 #include "remoting/client/plugin/pepper_client_logger.h" | |
| 35 #include "remoting/client/plugin/pepper_input_handler.h" | 36 #include "remoting/client/plugin/pepper_input_handler.h" |
| 36 #include "remoting/client/plugin/pepper_port_allocator_session.h" | 37 #include "remoting/client/plugin/pepper_port_allocator_session.h" |
| 37 #include "remoting/client/plugin/pepper_view.h" | 38 #include "remoting/client/plugin/pepper_view.h" |
| 38 #include "remoting/client/plugin/pepper_view_proxy.h" | 39 #include "remoting/client/plugin/pepper_view_proxy.h" |
| 39 #include "remoting/client/plugin/pepper_util.h" | 40 #include "remoting/client/plugin/pepper_util.h" |
| 40 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 41 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
| 41 #include "remoting/jingle_glue/jingle_thread.h" | 42 #include "remoting/jingle_glue/jingle_thread.h" |
| 42 #include "remoting/proto/auth.pb.h" | 43 #include "remoting/proto/auth.pb.h" |
| 43 #include "remoting/protocol/connection_to_host.h" | 44 #include "remoting/protocol/connection_to_host.h" |
| 44 #include "remoting/protocol/host_stub.h" | 45 #include "remoting/protocol/host_stub.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 | 57 |
| 57 const char kClientFirewallTraversalPolicyName[] = | 58 const char kClientFirewallTraversalPolicyName[] = |
| 58 "remote_access.client_firewall_traversal"; | 59 "remote_access.client_firewall_traversal"; |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 PPP_PolicyUpdate_Dev ChromotingInstance::kPolicyUpdatedInterface = { | 63 PPP_PolicyUpdate_Dev ChromotingInstance::kPolicyUpdatedInterface = { |
| 63 &ChromotingInstance::PolicyUpdatedThunk, | 64 &ChromotingInstance::PolicyUpdatedThunk, |
| 64 }; | 65 }; |
| 65 | 66 |
| 67 // This flag blocks LOGs to the UI if we're already in the middle of logging |
| 68 // to the UI. This prevents a potential infinite loop if we encounter an error |
| 69 // while sending the log message to the UI. |
| 70 static bool g_logging_to_plugin = false; |
| 71 static ChromotingInstance* g_logging_instance = NULL; |
| 72 static logging::LogMessageHandlerFunction g_logging_old_handler = NULL; |
| 73 |
| 66 const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting"; | 74 const char* ChromotingInstance::kMimeType = "pepper-application/x-chromoting"; |
| 67 | 75 |
| 68 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) | 76 ChromotingInstance::ChromotingInstance(PP_Instance pp_instance) |
| 69 : pp::InstancePrivate(pp_instance), | 77 : pp::InstancePrivate(pp_instance), |
| 70 initialized_(false), | 78 initialized_(false), |
| 71 scale_to_fit_(false), | 79 scale_to_fit_(false), |
| 72 logger_(this), | |
| 73 enable_client_nat_traversal_(false), | 80 enable_client_nat_traversal_(false), |
| 74 initial_policy_received_(false), | 81 initial_policy_received_(false), |
| 75 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 82 task_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 76 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); | 83 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE | PP_INPUTEVENT_CLASS_WHEEL); |
| 77 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); | 84 RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD); |
| 85 |
| 86 log_proxy_ = new TaskThreadProxy(MessageLoop::current()); |
| 87 |
| 88 // Set up log message handler. |
| 89 // Note that this approach doesn't quite support having multiple instances |
| 90 // of Chromoting running. In that case, the most recently opened tab will |
| 91 // grab all the debug log messages, and when any Chromoting tab is closed |
| 92 // the logging handler will go away. |
| 93 // Since having multiple Chromoting tabs is not a primary use case, and this |
| 94 // is just debug logging, we're punting improving debug log support for that |
| 95 // case. |
| 96 if (g_logging_old_handler == NULL) |
| 97 g_logging_old_handler = logging::GetLogMessageHandler(); |
| 98 logging::SetLogMessageHandler(&LogToUI); |
| 99 g_logging_instance = this; |
| 78 } | 100 } |
| 79 | 101 |
| 80 ChromotingInstance::~ChromotingInstance() { | 102 ChromotingInstance::~ChromotingInstance() { |
| 81 DCHECK(CurrentlyOnPluginThread()); | 103 DCHECK(CurrentlyOnPluginThread()); |
| 82 | 104 |
| 105 // Detach the log proxy so we don't log anything else to the UI. |
| 106 log_proxy_->Detach(); |
| 107 |
| 108 // Remove log message handler. |
| 109 logging::SetLogMessageHandler(g_logging_old_handler); |
| 110 g_logging_old_handler = NULL; |
| 111 g_logging_instance = NULL; |
| 112 |
| 83 if (client_.get()) { | 113 if (client_.get()) { |
| 84 base::WaitableEvent done_event(true, false); | 114 base::WaitableEvent done_event(true, false); |
| 85 client_->Stop(base::Bind(&base::WaitableEvent::Signal, | 115 client_->Stop(base::Bind(&base::WaitableEvent::Signal, |
| 86 base::Unretained(&done_event))); | 116 base::Unretained(&done_event))); |
| 87 done_event.Wait(); | 117 done_event.Wait(); |
| 88 } | 118 } |
| 89 | 119 |
| 90 // Stopping the context shutdown all chromoting threads. This is a requirement | 120 // Stopping the context shutdown all chromoting threads. This is a requirement |
| 91 // before we can call Detach() on |view_proxy_|. | 121 // before we can call Detach() on |view_proxy_|. |
| 92 context_.Stop(); | 122 context_.Stop(); |
| 93 | 123 |
| 94 view_proxy_->Detach(); | 124 view_proxy_->Detach(); |
| 95 } | 125 } |
| 96 | 126 |
| 97 bool ChromotingInstance::Init(uint32_t argc, | 127 bool ChromotingInstance::Init(uint32_t argc, |
| 98 const char* argn[], | 128 const char* argn[], |
| 99 const char* argv[]) { | 129 const char* argv[]) { |
| 100 CHECK(!initialized_); | 130 CHECK(!initialized_); |
| 101 initialized_ = true; | 131 initialized_ = true; |
| 102 | 132 |
| 103 logger_.VLog(1, "Started ChromotingInstance::Init"); | 133 VLOG(1) << "Started ChromotingInstance::Init"; |
| 104 | 134 |
| 105 // Start all the threads. | 135 // Start all the threads. |
| 106 context_.Start(); | 136 context_.Start(); |
| 107 | 137 |
| 108 SubscribeToNatTraversalPolicy(); | 138 SubscribeToNatTraversalPolicy(); |
| 109 | 139 |
| 110 // Create the chromoting objects that don't depend on the network connection. | 140 // Create the chromoting objects that don't depend on the network connection. |
| 111 view_.reset(new PepperView(this, &context_)); | 141 view_.reset(new PepperView(this, &context_)); |
| 112 view_proxy_ = new PepperViewProxy(this, view_.get()); | 142 view_proxy_ = new PepperViewProxy(this, view_.get()); |
| 113 rectangle_decoder_ = new RectangleUpdateDecoder( | 143 rectangle_decoder_ = new RectangleUpdateDecoder( |
| 114 context_.decode_message_loop(), view_proxy_); | 144 context_.decode_message_loop(), view_proxy_); |
| 115 | 145 |
| 116 // Default to a medium grey. | 146 // Default to a medium grey. |
| 117 view_->SetSolidFill(0xFFCDCDCD); | 147 view_->SetSolidFill(0xFFCDCDCD); |
| 118 | 148 |
| 119 return true; | 149 return true; |
| 120 } | 150 } |
| 121 | 151 |
| 122 void ChromotingInstance::Connect(const ClientConfig& config) { | 152 void ChromotingInstance::Connect(const ClientConfig& config) { |
| 123 DCHECK(CurrentlyOnPluginThread()); | 153 DCHECK(CurrentlyOnPluginThread()); |
| 124 | 154 |
| 125 // This can only happen at initialization if the Javascript connect call | 155 // This can only happen at initialization if the Javascript connect call |
| 126 // occurs before the enterprise policy is read. We are guaranteed that the | 156 // occurs before the enterprise policy is read. We are guaranteed that the |
| 127 // enterprise policy is pushed at least once, we we delay the connect call. | 157 // enterprise policy is pushed at least once, we we delay the connect call. |
| 128 if (!initial_policy_received_) { | 158 if (!initial_policy_received_) { |
| 129 logger_.Log(logging::LOG_INFO, | 159 LOG(INFO) << "Delaying connect until initial policy is read."; |
| 130 "Delaying connect until initial policy is read."); | |
| 131 delayed_connect_.reset( | 160 delayed_connect_.reset( |
| 132 task_factory_.NewRunnableMethod(&ChromotingInstance::Connect, | 161 task_factory_.NewRunnableMethod(&ChromotingInstance::Connect, |
| 133 config)); | 162 config)); |
| 134 return; | 163 return; |
| 135 } | 164 } |
| 136 | 165 |
| 137 webkit::ppapi::PluginInstance* plugin_instance = | 166 webkit::ppapi::PluginInstance* plugin_instance = |
| 138 webkit::ppapi::ResourceTracker::Get()->GetInstance(pp_instance()); | 167 webkit::ppapi::ResourceTracker::Get()->GetInstance(pp_instance()); |
| 139 | 168 |
| 140 P2PSocketDispatcher* socket_dispatcher = | 169 P2PSocketDispatcher* socket_dispatcher = |
| 141 plugin_instance->delegate()->GetP2PSocketDispatcher(); | 170 plugin_instance->delegate()->GetP2PSocketDispatcher(); |
| 142 | 171 |
| 143 IpcNetworkManager* network_manager = NULL; | 172 IpcNetworkManager* network_manager = NULL; |
| 144 IpcPacketSocketFactory* socket_factory = NULL; | 173 IpcPacketSocketFactory* socket_factory = NULL; |
| 145 PortAllocatorSessionFactory* session_factory = | 174 PortAllocatorSessionFactory* session_factory = |
| 146 CreatePepperPortAllocatorSessionFactory(this); | 175 CreatePepperPortAllocatorSessionFactory(this); |
| 147 | 176 |
| 148 // If we don't have socket dispatcher for IPC (e.g. P2P API is | 177 // If we don't have socket dispatcher for IPC (e.g. P2P API is |
| 149 // disabled), then JingleSessionManager will try to use physical sockets. | 178 // disabled), then JingleSessionManager will try to use physical sockets. |
| 150 if (socket_dispatcher) { | 179 if (socket_dispatcher) { |
| 151 logger_.VLog(1, "Creating IpcNetworkManager and IpcPacketSocketFactory."); | 180 VLOG(1) << "Creating IpcNetworkManager and IpcPacketSocketFactory."; |
| 152 network_manager = new IpcNetworkManager(socket_dispatcher); | 181 network_manager = new IpcNetworkManager(socket_dispatcher); |
| 153 socket_factory = new IpcPacketSocketFactory(socket_dispatcher); | 182 socket_factory = new IpcPacketSocketFactory(socket_dispatcher); |
| 154 } | 183 } |
| 155 | 184 |
| 156 host_connection_.reset(new protocol::ConnectionToHost( | 185 host_connection_.reset(new protocol::ConnectionToHost( |
| 157 context_.network_message_loop(), network_manager, socket_factory, | 186 context_.network_message_loop(), network_manager, socket_factory, |
| 158 session_factory, enable_client_nat_traversal_)); | 187 session_factory, enable_client_nat_traversal_)); |
| 159 input_handler_.reset(new PepperInputHandler(&context_, | 188 input_handler_.reset(new PepperInputHandler(&context_, |
| 160 host_connection_.get(), | 189 host_connection_.get(), |
| 161 view_proxy_)); | 190 view_proxy_)); |
| 162 | 191 |
| 163 client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), | 192 client_.reset(new ChromotingClient(config, &context_, host_connection_.get(), |
| 164 view_proxy_, rectangle_decoder_.get(), | 193 view_proxy_, rectangle_decoder_.get(), |
| 165 input_handler_.get(), &logger_, NULL)); | 194 input_handler_.get(), NULL)); |
| 166 | 195 |
| 167 logger_.Log(logging::LOG_INFO, "Connecting."); | 196 LOG(INFO) << "Connecting."; |
| 168 | 197 |
| 169 // Setup the XMPP Proxy. | 198 // Setup the XMPP Proxy. |
| 170 ChromotingScriptableObject* scriptable_object = GetScriptableObject(); | 199 ChromotingScriptableObject* scriptable_object = GetScriptableObject(); |
| 171 scoped_refptr<PepperXmppProxy> xmpp_proxy = | 200 scoped_refptr<PepperXmppProxy> xmpp_proxy = |
| 172 new PepperXmppProxy(scriptable_object->AsWeakPtr(), | 201 new PepperXmppProxy(scriptable_object->AsWeakPtr(), |
| 173 context_.jingle_thread()->message_loop()); | 202 context_.jingle_thread()->message_loop()); |
| 174 scriptable_object->AttachXmppProxy(xmpp_proxy); | 203 scriptable_object->AttachXmppProxy(xmpp_proxy); |
| 175 | 204 |
| 176 // Kick off the connection. | 205 // Kick off the connection. |
| 177 client_->Start(xmpp_proxy); | 206 client_->Start(xmpp_proxy); |
| 178 | 207 |
| 179 logger_.Log(logging::LOG_INFO, "Connection status: Initializing"); | 208 LOG(INFO) << "Connection status: Initializing"; |
| 180 GetScriptableObject()->SetConnectionInfo(STATUS_INITIALIZING, | 209 GetScriptableObject()->SetConnectionInfo(STATUS_INITIALIZING, |
| 181 QUALITY_UNKNOWN); | 210 QUALITY_UNKNOWN); |
| 182 } | 211 } |
| 183 | 212 |
| 184 void ChromotingInstance::Disconnect() { | 213 void ChromotingInstance::Disconnect() { |
| 185 DCHECK(CurrentlyOnPluginThread()); | 214 DCHECK(CurrentlyOnPluginThread()); |
| 186 | 215 |
| 187 logger_.Log(logging::LOG_INFO, "Disconnecting from host."); | 216 LOG(INFO) << "Disconnecting from host."; |
| 188 if (client_.get()) { | 217 if (client_.get()) { |
| 189 // TODO(sergeyu): Should we disconnect asynchronously? | 218 // TODO(sergeyu): Should we disconnect asynchronously? |
| 190 base::WaitableEvent done_event(true, false); | 219 base::WaitableEvent done_event(true, false); |
| 191 client_->Stop(base::Bind(&base::WaitableEvent::Signal, | 220 client_->Stop(base::Bind(&base::WaitableEvent::Signal, |
| 192 base::Unretained(&done_event))); | 221 base::Unretained(&done_event))); |
| 193 done_event.Wait(); | 222 done_event.Wait(); |
| 194 client_.reset(); | 223 client_.reset(); |
| 195 } | 224 } |
| 196 | 225 |
| 197 input_handler_.reset(); | 226 input_handler_.reset(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 280 } |
| 252 | 281 |
| 253 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { | 282 case PP_INPUTEVENT_TYPE_CONTEXTMENU: { |
| 254 // We need to return true here or else we'll get a local (plugin) context | 283 // We need to return true here or else we'll get a local (plugin) context |
| 255 // menu instead of the mouseup event for the right click. | 284 // menu instead of the mouseup event for the right click. |
| 256 return true; | 285 return true; |
| 257 } | 286 } |
| 258 | 287 |
| 259 case PP_INPUTEVENT_TYPE_KEYDOWN: { | 288 case PP_INPUTEVENT_TYPE_KEYDOWN: { |
| 260 pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); | 289 pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); |
| 261 logger_.VLog(3, "PP_INPUTEVENT_TYPE_KEYDOWN key=%d", key.GetKeyCode()); | 290 VLOG(3) << "PP_INPUTEVENT_TYPE_KEYDOWN" << " key=" << key.GetKeyCode(); |
| 262 pih->HandleKeyEvent(true, key); | 291 pih->HandleKeyEvent(true, key); |
| 263 return true; | 292 return true; |
| 264 } | 293 } |
| 265 | 294 |
| 266 case PP_INPUTEVENT_TYPE_KEYUP: { | 295 case PP_INPUTEVENT_TYPE_KEYUP: { |
| 267 pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); | 296 pp::KeyboardInputEvent key = pp::KeyboardInputEvent(event); |
| 268 logger_.VLog(3, "PP_INPUTEVENT_TYPE_KEYUP key=%d", key.GetKeyCode()); | 297 VLOG(3) << "PP_INPUTEVENT_TYPE_KEYUP" << " key=" << key.GetKeyCode(); |
| 269 pih->HandleKeyEvent(false, key); | 298 pih->HandleKeyEvent(false, key); |
| 270 return true; | 299 return true; |
| 271 } | 300 } |
| 272 | 301 |
| 273 case PP_INPUTEVENT_TYPE_CHAR: { | 302 case PP_INPUTEVENT_TYPE_CHAR: { |
| 274 pih->HandleCharacterEvent(pp::KeyboardInputEvent(event)); | 303 pih->HandleCharacterEvent(pp::KeyboardInputEvent(event)); |
| 275 return true; | 304 return true; |
| 276 } | 305 } |
| 277 | 306 |
| 278 default: { | 307 default: { |
| 279 LOG(INFO) << "Unhandled input event: " << event.GetType(); | 308 LOG(INFO) << "Unhandled input event: " << event.GetType(); |
| 280 break; | 309 break; |
| 281 } | 310 } |
| 282 } | 311 } |
| 283 | 312 |
| 284 return false; | 313 return false; |
| 285 } | 314 } |
| 286 | 315 |
| 287 ChromotingScriptableObject* ChromotingInstance::GetScriptableObject() { | 316 ChromotingScriptableObject* ChromotingInstance::GetScriptableObject() { |
| 288 pp::VarPrivate object = GetInstanceObject(); | 317 pp::VarPrivate object = GetInstanceObject(); |
| 289 if (!object.is_undefined()) { | 318 if (!object.is_undefined()) { |
| 290 pp::deprecated::ScriptableObject* so = object.AsScriptableObject(); | 319 pp::deprecated::ScriptableObject* so = object.AsScriptableObject(); |
| 291 DCHECK(so != NULL); | 320 DCHECK(so != NULL); |
| 292 return static_cast<ChromotingScriptableObject*>(so); | 321 return static_cast<ChromotingScriptableObject*>(so); |
| 293 } | 322 } |
| 294 logger_.Log(logging::LOG_ERROR, | 323 LOG(ERROR) << "Unable to get ScriptableObject for Chromoting plugin."; |
| 295 "Unable to get ScriptableObject for Chromoting plugin."); | |
| 296 return NULL; | 324 return NULL; |
| 297 } | 325 } |
| 298 | 326 |
| 299 void ChromotingInstance::SubmitLoginInfo(const std::string& username, | 327 void ChromotingInstance::SubmitLoginInfo(const std::string& username, |
| 300 const std::string& password) { | 328 const std::string& password) { |
| 301 if (host_connection_->state() != | 329 if (host_connection_->state() != |
| 302 protocol::ConnectionToHost::STATE_CONNECTED) { | 330 protocol::ConnectionToHost::STATE_CONNECTED) { |
| 303 logger_.Log(logging::LOG_INFO, | 331 LOG(INFO) << "Client not connected or already authenticated."; |
| 304 "Client not connected or already authenticated."); | |
| 305 return; | 332 return; |
| 306 } | 333 } |
| 307 | 334 |
| 308 protocol::LocalLoginCredentials* credentials = | 335 protocol::LocalLoginCredentials* credentials = |
| 309 new protocol::LocalLoginCredentials(); | 336 new protocol::LocalLoginCredentials(); |
| 310 credentials->set_type(protocol::PASSWORD); | 337 credentials->set_type(protocol::PASSWORD); |
| 311 credentials->set_username(username); | 338 credentials->set_username(username); |
| 312 credentials->set_credential(password.data(), password.length()); | 339 credentials->set_credential(password.data(), password.length()); |
| 313 | 340 |
| 314 host_connection_->host_stub()->BeginSessionRequest( | 341 host_connection_->host_stub()->BeginSessionRequest( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 325 scale_to_fit_ = scale_to_fit; | 352 scale_to_fit_ = scale_to_fit; |
| 326 if (scale_to_fit) { | 353 if (scale_to_fit) { |
| 327 rectangle_decoder_->SetScaleRatios(view_->GetHorizontalScaleRatio(), | 354 rectangle_decoder_->SetScaleRatios(view_->GetHorizontalScaleRatio(), |
| 328 view_->GetVerticalScaleRatio()); | 355 view_->GetVerticalScaleRatio()); |
| 329 } else { | 356 } else { |
| 330 rectangle_decoder_->SetScaleRatios(1.0, 1.0); | 357 rectangle_decoder_->SetScaleRatios(1.0, 1.0); |
| 331 } | 358 } |
| 332 rectangle_decoder_->RefreshFullFrame(); | 359 rectangle_decoder_->RefreshFullFrame(); |
| 333 } | 360 } |
| 334 | 361 |
| 335 void ChromotingInstance::Log(int severity, const char* format, ...) { | 362 // static |
| 336 va_list ap; | 363 bool ChromotingInstance::LogToUI(int severity, const char* file, int line, |
| 337 va_start(ap, format); | 364 size_t message_start, |
| 338 logger_.va_Log(severity, format, ap); | 365 const std::string& str) { |
| 339 va_end(ap); | 366 if (g_logging_instance) { |
| 367 std::string message = remoting::GetTimestampString(); |
| 368 message += (str.c_str() + message_start); |
| 369 g_logging_instance->log_proxy_->Call( |
| 370 base::Bind(&ChromotingInstance::ProcessLogToUI, |
| 371 base::Unretained(g_logging_instance), message)); |
| 372 } |
| 373 |
| 374 if (g_logging_old_handler) |
| 375 return (g_logging_old_handler)(severity, file, line, message_start, str); |
| 376 return false; |
| 340 } | 377 } |
| 341 | 378 |
| 342 void ChromotingInstance::VLog(int verboselevel, const char* format, ...) { | 379 void ChromotingInstance::ProcessLogToUI(const std::string& message) { |
| 343 va_list ap; | 380 if (!g_logging_to_plugin) { |
| 344 va_start(ap, format); | 381 ChromotingScriptableObject* cso = GetScriptableObject(); |
| 345 logger_.va_VLog(verboselevel, format, ap); | 382 if (cso) { |
| 346 va_end(ap); | 383 g_logging_to_plugin = true; |
| 384 cso->LogDebugInfo(message); |
| 385 g_logging_to_plugin = false; |
| 386 } |
| 387 } |
| 347 } | 388 } |
| 348 | 389 |
| 349 pp::Var ChromotingInstance::GetInstanceObject() { | 390 pp::Var ChromotingInstance::GetInstanceObject() { |
| 350 if (instance_object_.is_undefined()) { | 391 if (instance_object_.is_undefined()) { |
| 351 ChromotingScriptableObject* object = new ChromotingScriptableObject(this); | 392 ChromotingScriptableObject* object = new ChromotingScriptableObject(this); |
| 352 object->Init(); | 393 object->Init(); |
| 353 | 394 |
| 354 // The pp::Var takes ownership of object here. | 395 // The pp::Var takes ownership of object here. |
| 355 instance_object_ = pp::VarPrivate(this, object); | 396 instance_object_ = pp::VarPrivate(this, object); |
| 356 } | 397 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 434 } |
| 394 | 435 |
| 395 bool ChromotingInstance::IsNatTraversalAllowed( | 436 bool ChromotingInstance::IsNatTraversalAllowed( |
| 396 const std::string& policy_json) { | 437 const std::string& policy_json) { |
| 397 int error_code = base::JSONReader::JSON_NO_ERROR; | 438 int error_code = base::JSONReader::JSON_NO_ERROR; |
| 398 std::string error_message; | 439 std::string error_message; |
| 399 scoped_ptr<base::Value> policy(base::JSONReader::ReadAndReturnError( | 440 scoped_ptr<base::Value> policy(base::JSONReader::ReadAndReturnError( |
| 400 policy_json, true, &error_code, &error_message)); | 441 policy_json, true, &error_code, &error_message)); |
| 401 | 442 |
| 402 if (!policy.get()) { | 443 if (!policy.get()) { |
| 403 logger_.Log(logging::LOG_ERROR, "Error %d parsing policy: %s.", | 444 LOG(ERROR) << "Error " << error_code << " parsing policy: " |
| 404 error_code, error_message.c_str()); | 445 << error_message << "."; |
| 405 return false; | 446 return false; |
| 406 } | 447 } |
| 407 | 448 |
| 408 if (!policy->IsType(base::Value::TYPE_DICTIONARY)) { | 449 if (!policy->IsType(base::Value::TYPE_DICTIONARY)) { |
| 409 logger_.Log(logging::LOG_ERROR, "Policy must be a dictionary"); | 450 LOG(ERROR) << "Policy must be a dictionary"; |
| 410 return false; | 451 return false; |
| 411 } | 452 } |
| 412 | 453 |
| 413 base::DictionaryValue* dictionary = | 454 base::DictionaryValue* dictionary = |
| 414 static_cast<base::DictionaryValue*>(policy.get()); | 455 static_cast<base::DictionaryValue*>(policy.get()); |
| 415 bool traversal_policy = false; | 456 bool traversal_policy = false; |
| 416 if (!dictionary->GetBoolean(kClientFirewallTraversalPolicyName, | 457 if (!dictionary->GetBoolean(kClientFirewallTraversalPolicyName, |
| 417 &traversal_policy)) { | 458 &traversal_policy)) { |
| 418 // Disable NAT traversal on any failure of reading the policy. | 459 // Disable NAT traversal on any failure of reading the policy. |
| 419 return false; | 460 return false; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 439 | 480 |
| 440 initial_policy_received_ = true; | 481 initial_policy_received_ = true; |
| 441 enable_client_nat_traversal_ = traversal_policy; | 482 enable_client_nat_traversal_ = traversal_policy; |
| 442 | 483 |
| 443 if (delayed_connect_.get()) { | 484 if (delayed_connect_.get()) { |
| 444 RunTaskOnPluginThread(delayed_connect_.release()); | 485 RunTaskOnPluginThread(delayed_connect_.release()); |
| 445 } | 486 } |
| 446 } | 487 } |
| 447 | 488 |
| 448 } // namespace remoting | 489 } // namespace remoting |
| OLD | NEW |