OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/host/plugin/host_script_object.h" | 5 #include "remoting/host/plugin/host_script_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 pairing_registry_ = CreatePairingRegistry(worker_thread_); | 124 pairing_registry_ = CreatePairingRegistry(worker_thread_); |
125 } | 125 } |
126 | 126 |
127 HostNPScriptObject::~HostNPScriptObject() { | 127 HostNPScriptObject::~HostNPScriptObject() { |
128 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 128 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
129 | 129 |
130 HostLogHandler::UnregisterLoggingScriptObject(this); | 130 HostLogHandler::UnregisterLoggingScriptObject(this); |
131 | 131 |
132 // Stop the It2Me host if the caller forgot to. | 132 // Stop the It2Me host if the caller forgot to. |
133 if (it2me_impl_.get()) { | 133 if (it2me_host_.get()) { |
134 it2me_impl_->Disconnect(); | 134 it2me_host_->Disconnect(); |
135 it2me_impl_ = NULL; | 135 it2me_host_ = NULL; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 bool HostNPScriptObject::HasMethod(const std::string& method_name) { | 139 bool HostNPScriptObject::HasMethod(const std::string& method_name) { |
140 VLOG(2) << "HasMethod " << method_name; | 140 VLOG(2) << "HasMethod " << method_name; |
141 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 141 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
142 return (method_name == kFuncNameConnect || | 142 return (method_name == kFuncNameConnect || |
143 method_name == kFuncNameDisconnect || | 143 method_name == kFuncNameDisconnect || |
144 method_name == kFuncNameLocalize || | 144 method_name == kFuncNameLocalize || |
145 method_name == kFuncNameClearPairedClients || | 145 method_name == kFuncNameClearPairedClients || |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 | 309 |
310 bool HostNPScriptObject::SetProperty(const std::string& property_name, | 310 bool HostNPScriptObject::SetProperty(const std::string& property_name, |
311 const NPVariant* value) { | 311 const NPVariant* value) { |
312 VLOG(2) << "SetProperty " << property_name; | 312 VLOG(2) << "SetProperty " << property_name; |
313 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 313 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
314 | 314 |
315 if (property_name == kAttrNameOnNatTraversalPolicyChanged) { | 315 if (property_name == kAttrNameOnNatTraversalPolicyChanged) { |
316 if (NPVARIANT_IS_OBJECT(*value)) { | 316 if (NPVARIANT_IS_OBJECT(*value)) { |
317 on_nat_traversal_policy_changed_func_ = NPVARIANT_TO_OBJECT(*value); | 317 on_nat_traversal_policy_changed_func_ = NPVARIANT_TO_OBJECT(*value); |
318 if (it2me_impl_.get()) { | 318 if (it2me_host_.get()) { |
319 // Ask the It2Me implementation to notify the web-app of the policy. | 319 // Ask the It2Me host to notify the web-app of the policy. |
320 it2me_impl_->RequestNatPolicy(); | 320 it2me_host_->RequestNatPolicy(); |
321 } | 321 } |
322 return true; | 322 return true; |
323 } else { | 323 } else { |
324 SetException("SetProperty: unexpected type for property " + | 324 SetException("SetProperty: unexpected type for property " + |
325 property_name); | 325 property_name); |
326 } | 326 } |
327 return false; | 327 return false; |
328 } | 328 } |
329 | 329 |
330 if (property_name == kAttrNameOnStateChanged) { | 330 if (property_name == kAttrNameOnStateChanged) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 NPVariant* result) { | 447 NPVariant* result) { |
448 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 448 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
449 | 449 |
450 LOG(INFO) << "Connecting..."; | 450 LOG(INFO) << "Connecting..."; |
451 | 451 |
452 if (arg_count != 2) { | 452 if (arg_count != 2) { |
453 SetException("connect: bad number of arguments"); | 453 SetException("connect: bad number of arguments"); |
454 return false; | 454 return false; |
455 } | 455 } |
456 | 456 |
457 if (it2me_impl_.get()) { | 457 if (it2me_host_.get()) { |
458 SetException("connect: can be called only when disconnected"); | 458 SetException("connect: can be called only when disconnected"); |
459 return false; | 459 return false; |
460 } | 460 } |
461 | 461 |
462 XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_; | 462 XmppSignalStrategy::XmppServerConfig xmpp_config = xmpp_server_config_; |
463 | 463 |
464 xmpp_config.username = StringFromNPVariant(args[0]); | 464 xmpp_config.username = StringFromNPVariant(args[0]); |
465 if (xmpp_config.username.empty()) { | 465 if (xmpp_config.username.empty()) { |
466 SetException("connect: bad username argument"); | 466 SetException("connect: bad username argument"); |
467 return false; | 467 return false; |
468 } | 468 } |
469 | 469 |
470 std::string auth_service_with_token = StringFromNPVariant(args[1]); | 470 std::string auth_service_with_token = StringFromNPVariant(args[1]); |
471 ParseAuthTokenWithService(auth_service_with_token, &xmpp_config.auth_token, | 471 ParseAuthTokenWithService(auth_service_with_token, &xmpp_config.auth_token, |
472 &xmpp_config.auth_service); | 472 &xmpp_config.auth_service); |
473 if (xmpp_config.auth_token.empty()) { | 473 if (xmpp_config.auth_token.empty()) { |
474 SetException("connect: auth_service_with_token argument has empty token"); | 474 SetException("connect: auth_service_with_token argument has empty token"); |
475 return false; | 475 return false; |
476 } | 476 } |
477 | 477 |
478 // Create threads for the Chromoting host & desktop environment to use. | 478 // Create threads for the Chromoting host & desktop environment to use. |
479 scoped_ptr<ChromotingHostContext> host_context = | 479 scoped_ptr<ChromotingHostContext> host_context = |
480 ChromotingHostContext::Create(plugin_task_runner_); | 480 ChromotingHostContext::Create(plugin_task_runner_); |
481 if (!host_context) { | 481 if (!host_context) { |
482 SetException("connect: failed to start threads"); | 482 SetException("connect: failed to start threads"); |
483 return false; | 483 return false; |
484 } | 484 } |
485 | 485 |
486 // Create the It2Me host implementation and start connecting. | 486 // Create the It2Me host and start connecting. |
487 it2me_impl_ = new It2MeImpl( | 487 it2me_host_ = new It2MeHost( |
488 host_context.Pass(), plugin_task_runner_, weak_ptr_, | 488 host_context.Pass(), plugin_task_runner_, weak_ptr_, |
489 xmpp_config, directory_bot_jid_); | 489 xmpp_config, directory_bot_jid_); |
490 it2me_impl_->Connect(); | 490 it2me_host_->Connect(); |
491 | 491 |
492 return true; | 492 return true; |
493 } | 493 } |
494 | 494 |
495 bool HostNPScriptObject::Disconnect(const NPVariant* args, | 495 bool HostNPScriptObject::Disconnect(const NPVariant* args, |
496 uint32_t arg_count, | 496 uint32_t arg_count, |
497 NPVariant* result) { | 497 NPVariant* result) { |
498 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 498 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
499 if (arg_count != 0) { | 499 if (arg_count != 0) { |
500 SetException("disconnect: bad number of arguments"); | 500 SetException("disconnect: bad number of arguments"); |
501 return false; | 501 return false; |
502 } | 502 } |
503 | 503 |
504 if (it2me_impl_.get()) { | 504 if (it2me_host_.get()) { |
505 it2me_impl_->Disconnect(); | 505 it2me_host_->Disconnect(); |
506 it2me_impl_ = NULL; | 506 it2me_host_ = NULL; |
507 } | 507 } |
508 | 508 |
509 return true; | 509 return true; |
510 } | 510 } |
511 | 511 |
512 bool HostNPScriptObject::Localize(const NPVariant* args, | 512 bool HostNPScriptObject::Localize(const NPVariant* args, |
513 uint32_t arg_count, | 513 uint32_t arg_count, |
514 NPVariant* result) { | 514 NPVariant* result) { |
515 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 515 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
516 if (arg_count != 1) { | 516 if (arg_count != 1) { |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 } | 1101 } |
1102 | 1102 |
1103 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1103 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1104 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1104 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1105 | 1105 |
1106 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1106 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1107 LOG(INFO) << exception_string; | 1107 LOG(INFO) << exception_string; |
1108 } | 1108 } |
1109 | 1109 |
1110 } // namespace remoting | 1110 } // namespace remoting |
OLD | NEW |