Chromium Code Reviews| 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/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "ppapi/cpp/var.h" | 9 #include "ppapi/cpp/var.h" |
| 10 #include "remoting/client/client_config.h" | 10 #include "remoting/client/client_config.h" |
| 11 #include "remoting/client/chromoting_stats.h" | 11 #include "remoting/client/chromoting_stats.h" |
| 12 #include "remoting/client/plugin/chromoting_instance.h" | 12 #include "remoting/client/plugin/chromoting_instance.h" |
| 13 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 13 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
| 14 | 14 |
| 15 using pp::Var; | 15 using pp::Var; |
| 16 | 16 |
| 17 namespace remoting { | 17 namespace remoting { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; | 21 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; |
| 22 const char kDebugInfo[] = "debugInfo"; | 22 const char kDebugInfo[] = "debugInfo"; |
| 23 const char kDesktopHeight[] = "desktopHeight"; | 23 const char kDesktopHeight[] = "desktopHeight"; |
| 24 const char kDesktopWidth[] = "desktopWidth"; | 24 const char kDesktopWidth[] = "desktopWidth"; |
| 25 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; | 25 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; |
| 26 const char kLoginChallenge[] = "loginChallenge"; | 26 const char kLoginChallenge[] = "loginChallenge"; |
| 27 const char kSandboxedAttribute[] = "sandboxed"; | |
| 27 const char kSendIq[] = "sendIq"; | 28 const char kSendIq[] = "sendIq"; |
| 28 const char kQualityAttribute[] = "quality"; | 29 const char kQualityAttribute[] = "quality"; |
| 29 const char kStatusAttribute[] = "status"; | 30 const char kStatusAttribute[] = "status"; |
| 30 const char kVideoBandwidthAttribute[] = "videoBandwidth"; | 31 const char kVideoBandwidthAttribute[] = "videoBandwidth"; |
| 31 const char kVideoCaptureLatencyAttribute[] = "videoCaptureLatency"; | 32 const char kVideoCaptureLatencyAttribute[] = "videoCaptureLatency"; |
| 32 const char kVideoEncodeLatencyAttribute[] = "videoEncodeLatency"; | 33 const char kVideoEncodeLatencyAttribute[] = "videoEncodeLatency"; |
| 33 const char kVideoDecodeLatencyAttribute[] = "videoDecodeLatency"; | 34 const char kVideoDecodeLatencyAttribute[] = "videoDecodeLatency"; |
| 34 const char kVideoRenderLatencyAttribute[] = "videoRenderLatency"; | 35 const char kVideoRenderLatencyAttribute[] = "videoRenderLatency"; |
| 35 const char kRoundTripLatencyAttribute[] = "roundTripLatency"; | 36 const char kRoundTripLatencyAttribute[] = "roundTripLatency"; |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 ChromotingScriptableObject::ChromotingScriptableObject( | 40 ChromotingScriptableObject::ChromotingScriptableObject( |
| 40 ChromotingInstance* instance) | 41 ChromotingInstance* instance) |
| 41 : instance_(instance) { | 42 : instance_(instance) { |
| 42 } | 43 } |
| 43 | 44 |
| 44 ChromotingScriptableObject::~ChromotingScriptableObject() { | 45 ChromotingScriptableObject::~ChromotingScriptableObject() { |
| 45 } | 46 } |
| 46 | 47 |
| 47 void ChromotingScriptableObject::Init() { | 48 void ChromotingScriptableObject::Init() { |
| 48 // Property addition order should match the interface description at the | 49 // Property addition order should match the interface description at the |
| 49 // top of chromoting_scriptable_object.h. | 50 // top of chromoting_scriptable_object.h. |
| 50 | 51 |
| 51 // Connection status. | 52 // Connection status. |
| 52 AddAttribute(kStatusAttribute, Var(STATUS_UNKNOWN)); | 53 AddAttribute(kStatusAttribute, Var(STATUS_UNKNOWN)); |
| 53 | 54 |
| 55 // Sandbox status. | |
| 56 AddAttribute(kSandboxedAttribute, Var(true)); | |
| 57 | |
| 54 // Connection status values. | 58 // Connection status values. |
| 55 AddAttribute("STATUS_UNKNOWN", Var(STATUS_UNKNOWN)); | 59 AddAttribute("STATUS_UNKNOWN", Var(STATUS_UNKNOWN)); |
| 56 AddAttribute("STATUS_CONNECTING", Var(STATUS_CONNECTING)); | 60 AddAttribute("STATUS_CONNECTING", Var(STATUS_CONNECTING)); |
| 57 AddAttribute("STATUS_INITIALIZING", Var(STATUS_INITIALIZING)); | 61 AddAttribute("STATUS_INITIALIZING", Var(STATUS_INITIALIZING)); |
| 58 AddAttribute("STATUS_CONNECTED", Var(STATUS_CONNECTED)); | 62 AddAttribute("STATUS_CONNECTED", Var(STATUS_CONNECTED)); |
| 59 AddAttribute("STATUS_CLOSED", Var(STATUS_CLOSED)); | 63 AddAttribute("STATUS_CLOSED", Var(STATUS_CLOSED)); |
| 60 AddAttribute("STATUS_FAILED", Var(STATUS_FAILED)); | 64 AddAttribute("STATUS_FAILED", Var(STATUS_FAILED)); |
| 61 | 65 |
| 62 // Connection quality. | 66 // Connection quality. |
| 63 AddAttribute(kQualityAttribute, Var(QUALITY_UNKNOWN)); | 67 AddAttribute(kQualityAttribute, Var(QUALITY_UNKNOWN)); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 78 | 82 |
| 79 // Statistics. | 83 // Statistics. |
| 80 AddAttribute(kVideoBandwidthAttribute, Var()); | 84 AddAttribute(kVideoBandwidthAttribute, Var()); |
| 81 AddAttribute(kVideoCaptureLatencyAttribute, Var()); | 85 AddAttribute(kVideoCaptureLatencyAttribute, Var()); |
| 82 AddAttribute(kVideoEncodeLatencyAttribute, Var()); | 86 AddAttribute(kVideoEncodeLatencyAttribute, Var()); |
| 83 AddAttribute(kVideoDecodeLatencyAttribute, Var()); | 87 AddAttribute(kVideoDecodeLatencyAttribute, Var()); |
| 84 AddAttribute(kVideoRenderLatencyAttribute, Var()); | 88 AddAttribute(kVideoRenderLatencyAttribute, Var()); |
| 85 AddAttribute(kRoundTripLatencyAttribute, Var()); | 89 AddAttribute(kRoundTripLatencyAttribute, Var()); |
| 86 | 90 |
| 87 AddMethod("connect", &ChromotingScriptableObject::DoConnect); | 91 AddMethod("connect", &ChromotingScriptableObject::DoConnect); |
| 88 AddMethod("connectSandboxed", | |
| 89 &ChromotingScriptableObject::DoConnectSandboxed); | |
| 90 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); | 92 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); |
| 91 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); | 93 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); |
| 92 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); | 94 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); |
| 95 AddMethod("setSandboxed", &ChromotingScriptableObject::DoSetSandboxed); | |
| 93 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); | 96 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); |
| 94 } | 97 } |
| 95 | 98 |
| 96 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { | 99 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { |
| 97 // TODO(ajwong): Check if all these name.is_string() sentinels are required. | 100 // TODO(ajwong): Check if all these name.is_string() sentinels are required. |
| 98 if (!name.is_string()) { | 101 if (!name.is_string()) { |
| 99 *exception = Var("HasProperty expects a string for the name."); | 102 *exception = Var("HasProperty expects a string for the name."); |
| 100 return false; | 103 return false; |
| 101 } | 104 } |
| 102 | 105 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 323 |
| 321 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { | 324 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { |
| 322 Var exception; | 325 Var exception; |
| 323 Var cb = GetProperty(Var(kSendIq), &exception); | 326 Var cb = GetProperty(Var(kSendIq), &exception); |
| 324 | 327 |
| 325 // Var() means call the object directly as a function rather than calling | 328 // Var() means call the object directly as a function rather than calling |
| 326 // a method in the object. | 329 // a method in the object. |
| 327 cb.Call(Var(), Var(message_xml), &exception); | 330 cb.Call(Var(), Var(message_xml), &exception); |
| 328 | 331 |
| 329 if (!exception.is_undefined()) | 332 if (!exception.is_undefined()) |
| 330 LogDebugInfo("Exception when invoking loginChallenge JS callback."); | 333 LogDebugInfo("Exception when invoking sendiq JS callback."); |
| 331 } | 334 } |
| 332 | 335 |
| 333 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, | 336 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, |
| 334 Var* exception) { | 337 Var* exception) { |
| 335 if (args.size() != 4) { | 338 int sandboxed_index = property_names_[kSandboxedAttribute]; |
| 336 *exception = Var("Usage: connect(username, host_jid, auth_token)"); | 339 bool sandboxed = properties_[sandboxed_index].attribute.AsBool(); |
| 340 | |
| 341 // Parameter order is: | |
| 342 // host_jid | |
| 343 // auth_type: ACCESS_CODE or AUTHENTICATE | |
| 344 // if sandboxed: | |
| 345 // client_jid | |
| 346 // else: | |
| 347 // username (TODO remove support for non-sandboxed) | |
| 348 // xmpp_auth_token | |
| 349 // if ACCESS_CODE: | |
| 350 // access_code | |
| 351 unsigned int arg = 0; | |
| 352 if (!args[arg].is_string()) { | |
| 353 *exception = Var("The host_jid must be a string."); | |
| 354 return Var(); | |
| 355 } | |
| 356 std::string host_jid = args[arg++].AsString(); | |
| 357 | |
| 358 if (!args[arg].is_string()) { | |
| 359 *exception = Var("The authentication type must be a string."); | |
| 360 return Var(); | |
| 361 } | |
| 362 std::string auth_type = args[arg++].AsString(); | |
| 363 bool use_access_code = (auth_type == "ACCESS_CODE"); | |
| 364 | |
| 365 std::string client_jid; | |
| 366 std::string username; | |
| 367 std::string auth_token; | |
| 368 if (sandboxed) { | |
| 369 if (!args[arg].is_string()) { | |
| 370 *exception = Var("The client_jid must be a string."); | |
| 371 return Var(); | |
| 372 } | |
| 373 client_jid = args[arg++].AsString(); | |
| 374 } else { | |
| 375 // TODO(garykac): Remove support for non-sandboxed connections. | |
| 376 if (!args[arg].is_string()) { | |
| 377 *exception = Var("The username must be a string."); | |
| 378 return Var(); | |
| 379 } | |
| 380 username = args[arg++].AsString(); | |
| 381 | |
| 382 if (!args[arg].is_string()) { | |
| 383 *exception = Var("The auth_token must be a string."); | |
| 384 return Var(); | |
| 385 } | |
| 386 auth_token = args[arg++].AsString(); | |
| 387 } | |
| 388 | |
| 389 std::string access_code; | |
| 390 if (use_access_code) { | |
| 391 if (!args[arg].is_string()) { | |
| 392 *exception = Var("The access code must be a string."); | |
| 393 return Var(); | |
| 394 } | |
| 395 access_code = args[arg++].AsString(); | |
| 396 } | |
| 397 | |
| 398 if (args.size() != arg) { | |
| 399 *exception = Var("Too many agruments passed to connect()."); | |
| 337 return Var(); | 400 return Var(); |
| 338 } | 401 } |
| 339 | 402 |
| 340 ClientConfig config; | 403 LogDebugInfo("Connecting to host."); |
| 341 | 404 if (sandboxed) { |
| 342 if (!args[0].is_string()) { | 405 VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid |
| 343 *exception = Var("The username must be a string."); | 406 << ", access_code: " << access_code; |
| 344 return Var(); | 407 instance_->ConnectSandboxed(client_jid, host_jid, access_code); |
| 408 } else { | |
| 409 ClientConfig config; | |
| 410 config.host_jid = host_jid; | |
| 411 config.username = username; | |
| 412 config.auth_token = auth_token; | |
| 413 config.nonce = access_code; | |
| 414 VLOG(1) << "host_jid: " << host_jid << ", username: " << username | |
| 415 << ", access_code: " << access_code; | |
| 416 instance_->Connect(config); | |
| 345 } | 417 } |
| 346 config.username = args[0].AsString(); | |
| 347 | |
| 348 if (!args[1].is_string()) { | |
| 349 *exception = Var("The host_jid must be a string."); | |
| 350 return Var(); | |
| 351 } | |
| 352 config.host_jid = args[1].AsString(); | |
| 353 | |
| 354 if (!args[2].is_string()) { | |
| 355 *exception = Var("The auth_token must be a string."); | |
| 356 return Var(); | |
| 357 } | |
| 358 config.auth_token = args[2].AsString(); | |
| 359 | |
| 360 if (!args[3].is_string()) { | |
| 361 *exception = Var("nonce must be a string."); | |
| 362 return Var(); | |
| 363 } | |
| 364 config.nonce = args[3].AsString(); | |
| 365 | |
| 366 LogDebugInfo("Connecting to host."); | |
| 367 instance_->Connect(config); | |
| 368 | 418 |
| 369 return Var(); | 419 return Var(); |
| 370 } | 420 } |
| 371 | |
| 372 Var ChromotingScriptableObject::DoConnectSandboxed( | |
| 373 const std::vector<Var>& args, Var* exception) { | |
| 374 if (args.size() != 3) { | |
| 375 *exception = Var("Usage: connectSandboxed(your_jid, host_jid, nonce)"); | |
| 376 return Var(); | |
| 377 } | |
| 378 | |
| 379 std::string your_jid; | |
| 380 if (!args[0].is_string()) { | |
| 381 *exception = Var("your_jid must be a string."); | |
| 382 return Var(); | |
| 383 } | |
| 384 your_jid = args[0].AsString(); | |
| 385 | |
| 386 std::string host_jid; | |
| 387 if (!args[1].is_string()) { | |
| 388 *exception = Var("host_jid must be a string."); | |
| 389 return Var(); | |
| 390 } | |
| 391 host_jid = args[1].AsString(); | |
| 392 | |
| 393 std::string nonce; | |
| 394 if (!args[2].is_string()) { | |
| 395 *exception = Var("nonce must be a string."); | |
| 396 return Var(); | |
| 397 } | |
| 398 nonce = args[2].AsString(); | |
| 399 | |
| 400 VLOG(1) << "your_jid: " << your_jid << ", host_jid: " << host_jid | |
| 401 << ", nonce: " << nonce; | |
| 402 instance_->ConnectSandboxed(your_jid, host_jid, nonce); | |
| 403 | |
| 404 return Var(); | |
| 405 } | |
| 406 | 421 |
| 407 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, | 422 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, |
| 408 Var* exception) { | 423 Var* exception) { |
| 409 LogDebugInfo("Disconnecting from host."); | 424 LogDebugInfo("Disconnecting from host."); |
| 410 | 425 |
| 411 instance_->Disconnect(); | 426 instance_->Disconnect(); |
| 412 return Var(); | 427 return Var(); |
| 413 } | 428 } |
| 414 | 429 |
| 415 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, | 430 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 446 if (!args[0].is_bool()) { | 461 if (!args[0].is_bool()) { |
| 447 *exception = Var("scale_to_fit must be a boolean."); | 462 *exception = Var("scale_to_fit must be a boolean."); |
| 448 return Var(); | 463 return Var(); |
| 449 } | 464 } |
| 450 | 465 |
| 451 LogDebugInfo("Setting scale-to-fit."); | 466 LogDebugInfo("Setting scale-to-fit."); |
| 452 instance_->SetScaleToFit(args[0].AsBool()); | 467 instance_->SetScaleToFit(args[0].AsBool()); |
| 453 return Var(); | 468 return Var(); |
| 454 } | 469 } |
| 455 | 470 |
| 471 Var ChromotingScriptableObject::DoSetSandboxed(const std::vector<Var>& args, | |
| 472 Var* exception) { | |
| 473 if (args.size() != 1) { | |
| 474 *exception = Var("Usage: setSandboxed(sandboxed)"); | |
|
Wez
2011/05/20 22:38:59
Why do we have a method for this, rather than sett
| |
| 475 return Var(); | |
| 476 } | |
| 477 | |
| 478 if (!args[0].is_bool()) { | |
| 479 *exception = Var("sandboxed must be a boolean."); | |
| 480 return Var(); | |
| 481 } | |
| 482 | |
| 483 LogDebugInfo("Setting sandboxed."); | |
| 484 int sandboxed_index = property_names_[kSandboxedAttribute]; | |
| 485 properties_[sandboxed_index].attribute = args[0].AsBool(); | |
| 486 return Var(); | |
| 487 } | |
| 488 | |
| 456 Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, | 489 Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, |
| 457 Var* exception) { | 490 Var* exception) { |
| 458 if (args.size() != 1) { | 491 if (args.size() != 1) { |
| 459 *exception = Var("Usage: onIq(response_xml)"); | 492 *exception = Var("Usage: onIq(response_xml)"); |
| 460 return Var(); | 493 return Var(); |
| 461 } | 494 } |
| 462 | 495 |
| 463 if (!args[0].is_string()) { | 496 if (!args[0].is_string()) { |
| 464 *exception = Var("response_xml must be a string."); | 497 *exception = Var("response_xml must be a string."); |
| 465 return Var(); | 498 return Var(); |
| 466 } | 499 } |
| 467 | 500 |
| 468 xmpp_proxy_->OnIq(args[0].AsString()); | 501 xmpp_proxy_->OnIq(args[0].AsString()); |
| 469 | 502 |
| 470 return Var(); | 503 return Var(); |
| 471 } | 504 } |
| 472 | 505 |
| 473 } // namespace remoting | 506 } // namespace remoting |
| OLD | NEW |