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("connectSandboxed", | 88 AddMethod("connectUnsandboxed", |
89 &ChromotingScriptableObject::DoConnectSandboxed); | 89 &ChromotingScriptableObject::DoConnectUnsandboxed); |
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 loginChallenge JS callback."); | 330 LogDebugInfo("Exception when invoking sendiq 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 if (args.size() != 4) { | 335 // Parameter order is: |
336 *exception = Var("Usage: connect(username, host_jid, auth_token)"); | 336 // host_jid |
| 337 // client_jid |
| 338 // access_code (optional) |
| 339 unsigned int arg = 0; |
| 340 if (!args[arg].is_string()) { |
| 341 *exception = Var("The host_jid must be a string."); |
| 342 return Var(); |
| 343 } |
| 344 std::string host_jid = args[arg++].AsString(); |
| 345 |
| 346 if (!args[arg].is_string()) { |
| 347 *exception = Var("The client_jid must be a string."); |
| 348 return Var(); |
| 349 } |
| 350 std::string client_jid = args[arg++].AsString(); |
| 351 |
| 352 std::string access_code; |
| 353 if (args.size() > arg) { |
| 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()."); |
337 return Var(); | 363 return Var(); |
338 } | 364 } |
339 | 365 |
340 ClientConfig config; | 366 LogDebugInfo("Connecting to host."); |
| 367 VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid |
| 368 << ", access_code: " << access_code; |
| 369 instance_->ConnectSandboxed(client_jid, host_jid, access_code); |
341 | 370 |
342 if (!args[0].is_string()) { | 371 return Var(); |
| 372 } |
| 373 |
| 374 Var ChromotingScriptableObject::DoConnectUnsandboxed( |
| 375 const std::vector<Var>& args, |
| 376 Var* exception) { |
| 377 // Parameter order is: |
| 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()) { |
343 *exception = Var("The username must be a string."); | 390 *exception = Var("The username must be a string."); |
344 return Var(); | 391 return Var(); |
345 } | 392 } |
346 config.username = args[0].AsString(); | 393 std::string username = args[arg++].AsString(); |
347 | 394 |
348 if (!args[1].is_string()) { | 395 if (!args[arg].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."); | 396 *exception = Var("The auth_token must be a string."); |
356 return Var(); | 397 return Var(); |
357 } | 398 } |
358 config.auth_token = args[2].AsString(); | 399 std::string auth_token = args[arg++].AsString(); |
359 | 400 |
360 if (!args[3].is_string()) { | 401 std::string access_code; |
361 *exception = Var("nonce must be a string."); | 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()."); |
362 return Var(); | 412 return Var(); |
363 } | 413 } |
364 config.nonce = args[3].AsString(); | |
365 | 414 |
366 LogDebugInfo("Connecting to host."); | 415 LogDebugInfo("Connecting to host."); |
| 416 ClientConfig config; |
| 417 config.host_jid = host_jid; |
| 418 config.username = username; |
| 419 config.auth_token = auth_token; |
| 420 config.nonce = access_code; |
| 421 VLOG(1) << "host_jid: " << host_jid << ", username: " << username |
| 422 << ", access_code: " << access_code; |
367 instance_->Connect(config); | 423 instance_->Connect(config); |
368 | 424 |
369 return Var(); | 425 return Var(); |
370 } | 426 } |
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 | 427 |
407 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, | 428 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, |
408 Var* exception) { | 429 Var* exception) { |
409 LogDebugInfo("Disconnecting from host."); | 430 LogDebugInfo("Disconnecting from host."); |
410 | 431 |
411 instance_->Disconnect(); | 432 instance_->Disconnect(); |
412 return Var(); | 433 return Var(); |
413 } | 434 } |
414 | 435 |
415 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, | 436 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 *exception = Var("response_xml must be a string."); | 485 *exception = Var("response_xml must be a string."); |
465 return Var(); | 486 return Var(); |
466 } | 487 } |
467 | 488 |
468 xmpp_proxy_->OnIq(args[0].AsString()); | 489 xmpp_proxy_->OnIq(args[0].AsString()); |
469 | 490 |
470 return Var(); | 491 return Var(); |
471 } | 492 } |
472 | 493 |
473 } // namespace remoting | 494 } // namespace remoting |
OLD | NEW |