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_scriptable_object.h" | 5 #include "remoting/client/plugin/chromoting_scriptable_object.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 // TODO(wez): Remove this when crbug.com/86353 is complete. | 9 // TODO(wez): Remove this when crbug.com/86353 is complete. |
10 #include "ppapi/cpp/private/var_private.h" | 10 #include "ppapi/cpp/private/var_private.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kApiVersionAttribute[] = "apiVersion"; | 24 const char kApiVersionAttribute[] = "apiVersion"; |
25 const char kApiMinVersionAttribute[] = "apiMinVersion"; | 25 const char kApiMinVersionAttribute[] = "apiMinVersion"; |
26 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; | 26 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; |
27 const char kDebugInfo[] = "debugInfo"; | 27 const char kDebugInfo[] = "debugInfo"; |
28 const char kDesktopHeight[] = "desktopHeight"; | 28 const char kDesktopHeight[] = "desktopHeight"; |
29 const char kDesktopWidth[] = "desktopWidth"; | 29 const char kDesktopWidth[] = "desktopWidth"; |
30 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; | 30 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; |
31 const char kLoginChallenge[] = "loginChallenge"; | |
32 const char kSendIq[] = "sendIq"; | 31 const char kSendIq[] = "sendIq"; |
33 const char kStatusAttribute[] = "status"; | 32 const char kStatusAttribute[] = "status"; |
34 const char kErrorAttribute[] = "error"; | 33 const char kErrorAttribute[] = "error"; |
35 const char kVideoBandwidthAttribute[] = "videoBandwidth"; | 34 const char kVideoBandwidthAttribute[] = "videoBandwidth"; |
36 const char kVideoFrameRateAttribute[] = "videoFrameRate"; | 35 const char kVideoFrameRateAttribute[] = "videoFrameRate"; |
37 const char kVideoCaptureLatencyAttribute[] = "videoCaptureLatency"; | 36 const char kVideoCaptureLatencyAttribute[] = "videoCaptureLatency"; |
38 const char kVideoEncodeLatencyAttribute[] = "videoEncodeLatency"; | 37 const char kVideoEncodeLatencyAttribute[] = "videoEncodeLatency"; |
39 const char kVideoDecodeLatencyAttribute[] = "videoDecodeLatency"; | 38 const char kVideoDecodeLatencyAttribute[] = "videoDecodeLatency"; |
40 const char kVideoRenderLatencyAttribute[] = "videoRenderLatency"; | 39 const char kVideoRenderLatencyAttribute[] = "videoRenderLatency"; |
41 const char kRoundTripLatencyAttribute[] = "roundTripLatency"; | 40 const char kRoundTripLatencyAttribute[] = "roundTripLatency"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 AddAttribute("ERROR_NONE", Var(ERROR_NONE)); | 81 AddAttribute("ERROR_NONE", Var(ERROR_NONE)); |
83 AddAttribute("ERROR_HOST_IS_OFFLINE", Var(ERROR_HOST_IS_OFFLINE)); | 82 AddAttribute("ERROR_HOST_IS_OFFLINE", Var(ERROR_HOST_IS_OFFLINE)); |
84 AddAttribute("ERROR_SESSION_REJECTED", Var(ERROR_SESSION_REJECTED)); | 83 AddAttribute("ERROR_SESSION_REJECTED", Var(ERROR_SESSION_REJECTED)); |
85 AddAttribute("ERROR_INCOMPATIBLE_PROTOCOL", Var(ERROR_INCOMPATIBLE_PROTOCOL)); | 84 AddAttribute("ERROR_INCOMPATIBLE_PROTOCOL", Var(ERROR_INCOMPATIBLE_PROTOCOL)); |
86 AddAttribute("ERROR_FAILURE_NONE", Var(ERROR_NETWORK_FAILURE)); | 85 AddAttribute("ERROR_FAILURE_NONE", Var(ERROR_NETWORK_FAILURE)); |
87 | 86 |
88 // Debug info to display. | 87 // Debug info to display. |
89 AddAttribute(kConnectionInfoUpdate, Var()); | 88 AddAttribute(kConnectionInfoUpdate, Var()); |
90 AddAttribute(kDebugInfo, Var()); | 89 AddAttribute(kDebugInfo, Var()); |
91 AddAttribute(kDesktopSizeUpdate, Var()); | 90 AddAttribute(kDesktopSizeUpdate, Var()); |
92 AddAttribute(kLoginChallenge, Var()); | |
93 AddAttribute(kSendIq, Var()); | 91 AddAttribute(kSendIq, Var()); |
94 AddAttribute(kDesktopWidth, Var(0)); | 92 AddAttribute(kDesktopWidth, Var(0)); |
95 AddAttribute(kDesktopHeight, Var(0)); | 93 AddAttribute(kDesktopHeight, Var(0)); |
96 | 94 |
97 // Statistics. | 95 // Statistics. |
98 AddAttribute(kVideoBandwidthAttribute, Var()); | 96 AddAttribute(kVideoBandwidthAttribute, Var()); |
99 AddAttribute(kVideoFrameRateAttribute, Var()); | 97 AddAttribute(kVideoFrameRateAttribute, Var()); |
100 AddAttribute(kVideoCaptureLatencyAttribute, Var()); | 98 AddAttribute(kVideoCaptureLatencyAttribute, Var()); |
101 AddAttribute(kVideoEncodeLatencyAttribute, Var()); | 99 AddAttribute(kVideoEncodeLatencyAttribute, Var()); |
102 AddAttribute(kVideoDecodeLatencyAttribute, Var()); | 100 AddAttribute(kVideoDecodeLatencyAttribute, Var()); |
103 AddAttribute(kVideoRenderLatencyAttribute, Var()); | 101 AddAttribute(kVideoRenderLatencyAttribute, Var()); |
104 AddAttribute(kRoundTripLatencyAttribute, Var()); | 102 AddAttribute(kRoundTripLatencyAttribute, Var()); |
105 | 103 |
106 AddMethod("connect", &ChromotingScriptableObject::DoConnect); | 104 AddMethod("connect", &ChromotingScriptableObject::DoConnect); |
107 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); | 105 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); |
108 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); | |
109 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); | 106 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); |
110 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); | 107 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); |
111 AddMethod("releaseAllKeys", &ChromotingScriptableObject::DoReleaseAllKeys); | 108 AddMethod("releaseAllKeys", &ChromotingScriptableObject::DoReleaseAllKeys); |
112 } | 109 } |
113 | 110 |
114 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { | 111 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { |
115 // TODO(ajwong): Check if all these name.is_string() sentinels are required. | 112 // TODO(ajwong): Check if all these name.is_string() sentinels are required. |
116 if (!name.is_string()) { | 113 if (!name.is_string()) { |
117 *exception = Var("HasProperty expects a string for the name."); | 114 *exception = Var("HasProperty expects a string for the name."); |
118 return false; | 115 return false; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 190 |
194 void ChromotingScriptableObject::SetProperty(const Var& name, | 191 void ChromotingScriptableObject::SetProperty(const Var& name, |
195 const Var& value, | 192 const Var& value, |
196 Var* exception) { | 193 Var* exception) { |
197 // TODO(ajwong): Check if all these name.is_string() sentinels are required. | 194 // TODO(ajwong): Check if all these name.is_string() sentinels are required. |
198 if (!name.is_string()) { | 195 if (!name.is_string()) { |
199 *exception = Var("SetProperty expects a string for the name."); | 196 *exception = Var("SetProperty expects a string for the name."); |
200 return; | 197 return; |
201 } | 198 } |
202 | 199 |
203 // Allow writing to connectionInfoUpdate or loginChallenge. See top of | 200 // Not all properties are mutable. |
204 // chromoting_scriptable_object.h for the object interface definition. | |
205 std::string property_name = name.AsString(); | 201 std::string property_name = name.AsString(); |
206 if (property_name != kConnectionInfoUpdate && | 202 if (property_name != kConnectionInfoUpdate && |
207 property_name != kDebugInfo && | 203 property_name != kDebugInfo && |
208 property_name != kDesktopSizeUpdate && | 204 property_name != kDesktopSizeUpdate && |
209 property_name != kLoginChallenge && | |
210 property_name != kSendIq && | 205 property_name != kSendIq && |
211 property_name != kDesktopWidth && | 206 property_name != kDesktopWidth && |
212 property_name != kDesktopHeight) { | 207 property_name != kDesktopHeight) { |
213 *exception = | 208 *exception = |
214 Var("Cannot set property " + property_name + " on this object."); | 209 Var("Cannot set property " + property_name + " on this object."); |
215 return; | 210 return; |
216 } | 211 } |
217 | 212 |
218 // Since we're whitelisting the property that are settable above, we can | 213 // Since we're whitelisting the property that are settable above, we can |
219 // assume that the property exists in the map. | 214 // assume that the property exists in the map. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (properties_[width_index].attribute.AsInt() != width || | 270 if (properties_[width_index].attribute.AsInt() != width || |
276 properties_[height_index].attribute.AsInt() != height) { | 271 properties_[height_index].attribute.AsInt() != height) { |
277 properties_[width_index].attribute = Var(width); | 272 properties_[width_index].attribute = Var(width); |
278 properties_[height_index].attribute = Var(height); | 273 properties_[height_index].attribute = Var(height); |
279 SignalDesktopSizeChange(); | 274 SignalDesktopSizeChange(); |
280 } | 275 } |
281 | 276 |
282 VLOG(1) << "Update desktop size to: " << width << " x " << height; | 277 VLOG(1) << "Update desktop size to: " << width << " x " << height; |
283 } | 278 } |
284 | 279 |
285 void ChromotingScriptableObject::SignalLoginChallenge() { | |
286 plugin_message_loop_->PostTask( | |
287 FROM_HERE, task_factory_.NewRunnableMethod( | |
288 &ChromotingScriptableObject::DoSignalLoginChallenge)); | |
289 } | |
290 | |
291 void ChromotingScriptableObject::AttachXmppProxy(PepperXmppProxy* xmpp_proxy) { | 280 void ChromotingScriptableObject::AttachXmppProxy(PepperXmppProxy* xmpp_proxy) { |
292 xmpp_proxy_ = xmpp_proxy; | 281 xmpp_proxy_ = xmpp_proxy; |
293 } | 282 } |
294 | 283 |
295 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { | 284 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { |
296 plugin_message_loop_->PostTask( | 285 plugin_message_loop_->PostTask( |
297 FROM_HERE, task_factory_.NewRunnableMethod( | 286 FROM_HERE, task_factory_.NewRunnableMethod( |
298 &ChromotingScriptableObject::DoSendIq, message_xml)); | 287 &ChromotingScriptableObject::DoSendIq, message_xml)); |
299 } | 288 } |
300 | 289 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 328 |
340 // |this| must not be touched after Call() returns. | 329 // |this| must not be touched after Call() returns. |
341 cb.Call(Var(), &exception); | 330 cb.Call(Var(), &exception); |
342 | 331 |
343 if (!exception.is_undefined()) { | 332 if (!exception.is_undefined()) { |
344 LOG(ERROR) << "Exception when invoking JS callback" | 333 LOG(ERROR) << "Exception when invoking JS callback" |
345 << exception.DebugString(); | 334 << exception.DebugString(); |
346 } | 335 } |
347 } | 336 } |
348 | 337 |
349 void ChromotingScriptableObject::DoSignalLoginChallenge() { | |
350 Var exception; | |
351 VarPrivate cb = GetProperty(Var(kLoginChallenge), &exception); | |
352 | |
353 // |this| must not be touched after Call() returns. | |
354 cb.Call(Var(), &exception); | |
355 | |
356 if (!exception.is_undefined()) | |
357 LOG(ERROR) << "Exception when invoking loginChallenge JS callback."; | |
358 } | |
359 | |
360 void ChromotingScriptableObject::DoSendIq(const std::string& message_xml) { | 338 void ChromotingScriptableObject::DoSendIq(const std::string& message_xml) { |
361 Var exception; | 339 Var exception; |
362 VarPrivate cb = GetProperty(Var(kSendIq), &exception); | 340 VarPrivate cb = GetProperty(Var(kSendIq), &exception); |
363 | 341 |
364 // |this| must not be touched after Call() returns. | 342 // |this| must not be touched after Call() returns. |
365 cb.Call(Var(), Var(message_xml), &exception); | 343 cb.Call(Var(), Var(message_xml), &exception); |
366 | 344 |
367 if (!exception.is_undefined()) | 345 if (!exception.is_undefined()) |
368 LOG(ERROR) << "Exception when invoking sendiq JS callback."; | 346 LOG(ERROR) << "Exception when invoking sendiq JS callback."; |
369 } | 347 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 return Var(); | 399 return Var(); |
422 } | 400 } |
423 | 401 |
424 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, | 402 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, |
425 Var* exception) { | 403 Var* exception) { |
426 VLOG(1) << "Disconnecting from host."; | 404 VLOG(1) << "Disconnecting from host."; |
427 instance_->Disconnect(); | 405 instance_->Disconnect(); |
428 return Var(); | 406 return Var(); |
429 } | 407 } |
430 | 408 |
431 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, | |
432 Var* exception) { | |
433 if (args.size() != 2) { | |
434 *exception = Var("Usage: login(username, password)"); | |
435 return Var(); | |
436 } | |
437 | |
438 if (!args[0].is_string()) { | |
439 *exception = Var("Username must be a string."); | |
440 return Var(); | |
441 } | |
442 std::string username = args[0].AsString(); | |
443 | |
444 if (!args[1].is_string()) { | |
445 *exception = Var("Password must be a string."); | |
446 return Var(); | |
447 } | |
448 std::string password = args[1].AsString(); | |
449 | |
450 VLOG(1) << "Submitting login info to host."; | |
451 instance_->SubmitLoginInfo(username, password); | |
452 return Var(); | |
453 } | |
454 | |
455 Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args, | 409 Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args, |
456 Var* exception) { | 410 Var* exception) { |
457 if (args.size() != 1) { | 411 if (args.size() != 1) { |
458 *exception = Var("Usage: setScaleToFit(scale_to_fit)"); | 412 *exception = Var("Usage: setScaleToFit(scale_to_fit)"); |
459 return Var(); | 413 return Var(); |
460 } | 414 } |
461 | 415 |
462 if (!args[0].is_bool()) { | 416 if (!args[0].is_bool()) { |
463 *exception = Var("scale_to_fit must be a boolean."); | 417 *exception = Var("scale_to_fit must be a boolean."); |
464 return Var(); | 418 return Var(); |
(...skipping 25 matching lines...) Expand all Loading... |
490 const std::vector<pp::Var>& args, pp::Var* exception) { | 444 const std::vector<pp::Var>& args, pp::Var* exception) { |
491 if (args.size() != 0) { | 445 if (args.size() != 0) { |
492 *exception = Var("Usage: DoReleaseAllKeys()"); | 446 *exception = Var("Usage: DoReleaseAllKeys()"); |
493 return Var(); | 447 return Var(); |
494 } | 448 } |
495 instance_->ReleaseAllKeys(); | 449 instance_->ReleaseAllKeys(); |
496 return Var(); | 450 return Var(); |
497 } | 451 } |
498 | 452 |
499 } // namespace remoting | 453 } // namespace remoting |
OLD | NEW |