| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 // Statistics. | 79 // Statistics. |
| 80 AddAttribute(kVideoBandwidthAttribute, Var()); | 80 AddAttribute(kVideoBandwidthAttribute, Var()); |
| 81 AddAttribute(kVideoCaptureLatencyAttribute, Var()); | 81 AddAttribute(kVideoCaptureLatencyAttribute, Var()); |
| 82 AddAttribute(kVideoEncodeLatencyAttribute, Var()); | 82 AddAttribute(kVideoEncodeLatencyAttribute, Var()); |
| 83 AddAttribute(kVideoDecodeLatencyAttribute, Var()); | 83 AddAttribute(kVideoDecodeLatencyAttribute, Var()); |
| 84 AddAttribute(kVideoRenderLatencyAttribute, Var()); | 84 AddAttribute(kVideoRenderLatencyAttribute, Var()); |
| 85 AddAttribute(kRoundTripLatencyAttribute, Var()); | 85 AddAttribute(kRoundTripLatencyAttribute, Var()); |
| 86 | 86 |
| 87 AddMethod("connect", &ChromotingScriptableObject::DoConnect); | 87 AddMethod("connect", &ChromotingScriptableObject::DoConnect); |
| 88 AddMethod("connectUnsandboxed", | 88 AddMethod("connectSandboxed", |
| 89 &ChromotingScriptableObject::DoConnectUnsandboxed); | 89 &ChromotingScriptableObject::DoConnectSandboxed); |
| 90 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); | 90 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); |
| 91 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); | 91 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); |
| 92 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); | 92 AddMethod("setScaleToFit", &ChromotingScriptableObject::DoSetScaleToFit); |
| 93 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); | 93 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { | 96 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { |
| 97 // TODO(ajwong): Check if all these name.is_string() sentinels are required. | 97 // TODO(ajwong): Check if all these name.is_string() sentinels are required. |
| 98 if (!name.is_string()) { | 98 if (!name.is_string()) { |
| 99 *exception = Var("HasProperty expects a string for the name."); | 99 *exception = Var("HasProperty expects a string for the name."); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 320 |
| 321 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { | 321 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { |
| 322 Var exception; | 322 Var exception; |
| 323 Var cb = GetProperty(Var(kSendIq), &exception); | 323 Var cb = GetProperty(Var(kSendIq), &exception); |
| 324 | 324 |
| 325 // Var() means call the object directly as a function rather than calling | 325 // Var() means call the object directly as a function rather than calling |
| 326 // a method in the object. | 326 // a method in the object. |
| 327 cb.Call(Var(), Var(message_xml), &exception); | 327 cb.Call(Var(), Var(message_xml), &exception); |
| 328 | 328 |
| 329 if (!exception.is_undefined()) | 329 if (!exception.is_undefined()) |
| 330 LogDebugInfo("Exception when invoking sendiq JS callback."); | 330 LogDebugInfo("Exception when invoking loginChallenge JS callback."); |
| 331 } | 331 } |
| 332 | 332 |
| 333 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, | 333 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, |
| 334 Var* exception) { | 334 Var* exception) { |
| 335 // Parameter order is: | 335 if (args.size() != 4) { |
| 336 // host_jid | 336 *exception = Var("Usage: connect(username, host_jid, auth_token)"); |
| 337 // client_jid | 337 return Var(); |
| 338 // access_code (optional) | 338 } |
| 339 unsigned int arg = 0; | 339 |
| 340 if (!args[arg].is_string()) { | 340 ClientConfig config; |
| 341 |
| 342 if (!args[0].is_string()) { |
| 343 *exception = Var("The username must be a string."); |
| 344 return Var(); |
| 345 } |
| 346 config.username = args[0].AsString(); |
| 347 |
| 348 if (!args[1].is_string()) { |
| 341 *exception = Var("The host_jid must be a string."); | 349 *exception = Var("The host_jid must be a string."); |
| 342 return Var(); | 350 return Var(); |
| 343 } | 351 } |
| 344 std::string host_jid = args[arg++].AsString(); | 352 config.host_jid = args[1].AsString(); |
| 345 | 353 |
| 346 if (!args[arg].is_string()) { | 354 if (!args[2].is_string()) { |
| 347 *exception = Var("The client_jid must be a string."); | 355 *exception = Var("The auth_token must be a string."); |
| 348 return Var(); | 356 return Var(); |
| 349 } | 357 } |
| 350 std::string client_jid = args[arg++].AsString(); | 358 config.auth_token = args[2].AsString(); |
| 351 | 359 |
| 352 std::string access_code; | 360 if (!args[3].is_string()) { |
| 353 if (args.size() > arg) { | 361 *exception = Var("nonce must be a string."); |
| 354 if (!args[arg].is_string()) { | |
| 355 *exception = Var("The access code must be a string."); | |
| 356 return Var(); | |
| 357 } | |
| 358 access_code = args[arg++].AsString(); | |
| 359 } | |
| 360 | |
| 361 if (args.size() != arg) { | |
| 362 *exception = Var("Too many agruments passed to connect()."); | |
| 363 return Var(); | 362 return Var(); |
| 364 } | 363 } |
| 364 config.nonce = args[3].AsString(); |
| 365 | 365 |
| 366 LogDebugInfo("Connecting to host."); | 366 LogDebugInfo("Connecting to host."); |
| 367 VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid | 367 instance_->Connect(config); |
| 368 << ", access_code: " << access_code; | |
| 369 instance_->ConnectSandboxed(client_jid, host_jid, access_code); | |
| 370 | 368 |
| 371 return Var(); | 369 return Var(); |
| 372 } | 370 } |
| 373 | 371 |
| 374 Var ChromotingScriptableObject::DoConnectUnsandboxed( | 372 Var ChromotingScriptableObject::DoConnectSandboxed( |
| 375 const std::vector<Var>& args, | 373 const std::vector<Var>& args, Var* exception) { |
| 376 Var* exception) { | 374 if (args.size() != 3) { |
| 377 // Parameter order is: | 375 *exception = Var("Usage: connectSandboxed(your_jid, host_jid, nonce)"); |
| 378 // host_jid | |
| 379 // username | |
| 380 // xmpp_token | |
| 381 // access_code (optional) | |
| 382 unsigned int arg = 0; | |
| 383 if (!args[arg].is_string()) { | |
| 384 *exception = Var("The host_jid must be a string."); | |
| 385 return Var(); | |
| 386 } | |
| 387 std::string host_jid = args[arg++].AsString(); | |
| 388 | |
| 389 if (!args[arg].is_string()) { | |
| 390 *exception = Var("The username must be a string."); | |
| 391 return Var(); | |
| 392 } | |
| 393 std::string username = args[arg++].AsString(); | |
| 394 | |
| 395 if (!args[arg].is_string()) { | |
| 396 *exception = Var("The auth_token must be a string."); | |
| 397 return Var(); | |
| 398 } | |
| 399 std::string auth_token = args[arg++].AsString(); | |
| 400 | |
| 401 std::string access_code; | |
| 402 if (args.size() > arg) { | |
| 403 if (!args[arg].is_string()) { | |
| 404 *exception = Var("The access code must be a string."); | |
| 405 return Var(); | |
| 406 } | |
| 407 access_code = args[arg++].AsString(); | |
| 408 } | |
| 409 | |
| 410 if (args.size() != arg) { | |
| 411 *exception = Var("Too many agruments passed to connect()."); | |
| 412 return Var(); | 376 return Var(); |
| 413 } | 377 } |
| 414 | 378 |
| 415 LogDebugInfo("Connecting to host."); | 379 std::string your_jid; |
| 416 ClientConfig config; | 380 if (!args[0].is_string()) { |
| 417 config.host_jid = host_jid; | 381 *exception = Var("your_jid must be a string."); |
| 418 config.username = username; | 382 return Var(); |
| 419 config.auth_token = auth_token; | 383 } |
| 420 config.nonce = access_code; | 384 your_jid = args[0].AsString(); |
| 421 VLOG(1) << "host_jid: " << host_jid << ", username: " << username | 385 |
| 422 << ", access_code: " << access_code; | 386 std::string host_jid; |
| 423 instance_->Connect(config); | 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); |
| 424 | 403 |
| 425 return Var(); | 404 return Var(); |
| 426 } | 405 } |
| 427 | 406 |
| 428 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, | 407 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, |
| 429 Var* exception) { | 408 Var* exception) { |
| 430 LogDebugInfo("Disconnecting from host."); | 409 LogDebugInfo("Disconnecting from host."); |
| 431 | 410 |
| 432 instance_->Disconnect(); | 411 instance_->Disconnect(); |
| 433 return Var(); | 412 return Var(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 *exception = Var("response_xml must be a string."); | 464 *exception = Var("response_xml must be a string."); |
| 486 return Var(); | 465 return Var(); |
| 487 } | 466 } |
| 488 | 467 |
| 489 xmpp_proxy_->OnIq(args[0].AsString()); | 468 xmpp_proxy_->OnIq(args[0].AsString()); |
| 490 | 469 |
| 491 return Var(); | 470 return Var(); |
| 492 } | 471 } |
| 493 | 472 |
| 494 } // namespace remoting | 473 } // namespace remoting |
| OLD | NEW |