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" | |
| 9 // TODO(wez): Remove this when crbug.com/86353 is complete. | 8 // TODO(wez): Remove this when crbug.com/86353 is complete. |
| 10 #include "ppapi/cpp/private/var_private.h" | 9 #include "ppapi/cpp/private/var_private.h" |
| 11 #include "remoting/base/auth_token_util.h" | 10 #include "remoting/base/auth_token_util.h" |
| 12 #include "remoting/client/client_config.h" | 11 #include "remoting/client/client_config.h" |
| 13 #include "remoting/client/chromoting_stats.h" | 12 #include "remoting/client/chromoting_stats.h" |
| 14 #include "remoting/client/plugin/chromoting_instance.h" | 13 #include "remoting/client/plugin/chromoting_instance.h" |
| 15 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 14 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
| 16 | 15 |
| 17 using pp::Var; | 16 using pp::Var; |
| 18 using pp::VarPrivate; | 17 using pp::VarPrivate; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 221 } |
| 223 | 222 |
| 224 return (this->*(properties_[iter->second].method))(args, exception); | 223 return (this->*(properties_[iter->second].method))(args, exception); |
| 225 } | 224 } |
| 226 | 225 |
| 227 void ChromotingScriptableObject::SetConnectionInfo(ConnectionStatus status, | 226 void ChromotingScriptableObject::SetConnectionInfo(ConnectionStatus status, |
| 228 ConnectionQuality quality) { | 227 ConnectionQuality quality) { |
| 229 int status_index = property_names_[kStatusAttribute]; | 228 int status_index = property_names_[kStatusAttribute]; |
| 230 int quality_index = property_names_[kQualityAttribute]; | 229 int quality_index = property_names_[kQualityAttribute]; |
| 231 | 230 |
| 232 LogDebugInfo( | 231 LOG(INFO) << "Connection status is updated: " << status; |
| 233 base::StringPrintf("Connection status is updated: %d.", status)); | |
| 234 | 232 |
| 235 if (properties_[status_index].attribute.AsInt() != status || | 233 if (properties_[status_index].attribute.AsInt() != status || |
| 236 properties_[quality_index].attribute.AsInt() != quality) { | 234 properties_[quality_index].attribute.AsInt() != quality) { |
| 237 // Update the connection state properties.. | 235 // Update the connection state properties.. |
| 238 properties_[status_index].attribute = Var(status); | 236 properties_[status_index].attribute = Var(status); |
| 239 properties_[quality_index].attribute = Var(quality); | 237 properties_[quality_index].attribute = Var(quality); |
| 240 | 238 |
| 241 // Signal the Chromoting Tab UI to get the update connection state values. | 239 // Signal the Chromoting Tab UI to get the update connection state values. |
| 242 SignalConnectionInfoChange(); | 240 SignalConnectionInfoChange(); |
| 243 } | 241 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 261 int width_index = property_names_[kDesktopWidth]; | 259 int width_index = property_names_[kDesktopWidth]; |
| 262 int height_index = property_names_[kDesktopHeight]; | 260 int height_index = property_names_[kDesktopHeight]; |
| 263 | 261 |
| 264 if (properties_[width_index].attribute.AsInt() != width || | 262 if (properties_[width_index].attribute.AsInt() != width || |
| 265 properties_[height_index].attribute.AsInt() != height) { | 263 properties_[height_index].attribute.AsInt() != height) { |
| 266 properties_[width_index].attribute = Var(width); | 264 properties_[width_index].attribute = Var(width); |
| 267 properties_[height_index].attribute = Var(height); | 265 properties_[height_index].attribute = Var(height); |
| 268 SignalDesktopSizeChange(); | 266 SignalDesktopSizeChange(); |
| 269 } | 267 } |
| 270 | 268 |
| 271 LogDebugInfo(base::StringPrintf("Update desktop size to: %d x %d.", | 269 LOG(INFO) << "Update desktop size to: " << width << " x " << height; |
| 272 width, height)); | |
| 273 } | 270 } |
| 274 | 271 |
| 275 void ChromotingScriptableObject::AddAttribute(const std::string& name, | 272 void ChromotingScriptableObject::AddAttribute(const std::string& name, |
| 276 Var attribute) { | 273 Var attribute) { |
| 277 property_names_[name] = properties_.size(); | 274 property_names_[name] = properties_.size(); |
| 278 properties_.push_back(PropertyDescriptor(name, attribute)); | 275 properties_.push_back(PropertyDescriptor(name, attribute)); |
| 279 } | 276 } |
| 280 | 277 |
| 281 void ChromotingScriptableObject::AddMethod(const std::string& name, | 278 void ChromotingScriptableObject::AddMethod(const std::string& name, |
| 282 MethodHandler handler) { | 279 MethodHandler handler) { |
| 283 property_names_[name] = properties_.size(); | 280 property_names_[name] = properties_.size(); |
| 284 properties_.push_back(PropertyDescriptor(name, handler)); | 281 properties_.push_back(PropertyDescriptor(name, handler)); |
| 285 } | 282 } |
| 286 | 283 |
| 287 void ChromotingScriptableObject::SignalConnectionInfoChange() { | 284 void ChromotingScriptableObject::SignalConnectionInfoChange() { |
| 288 Var exception; | 285 Var exception; |
| 289 VarPrivate cb = GetProperty(Var(kConnectionInfoUpdate), &exception); | 286 VarPrivate cb = GetProperty(Var(kConnectionInfoUpdate), &exception); |
| 290 | 287 |
| 291 // Var() means call the object directly as a function rather than calling | 288 // Var() means call the object directly as a function rather than calling |
| 292 // a method in the object. | 289 // a method in the object. |
| 293 cb.Call(Var(), &exception); | 290 cb.Call(Var(), &exception); |
| 294 | 291 |
| 295 if (!exception.is_undefined()) | 292 if (!exception.is_undefined()) |
| 296 LogDebugInfo( | 293 LOG(ERROR) << "Exception when invoking connectionInfoUpdate JS callback."; |
| 297 "Exception when invoking connectionInfoUpdate JS callback."); | |
| 298 } | 294 } |
| 299 | 295 |
| 300 void ChromotingScriptableObject::SignalDesktopSizeChange() { | 296 void ChromotingScriptableObject::SignalDesktopSizeChange() { |
| 301 Var exception; | 297 Var exception; |
| 302 VarPrivate cb = GetProperty(Var(kDesktopSizeUpdate), &exception); | 298 VarPrivate cb = GetProperty(Var(kDesktopSizeUpdate), &exception); |
| 303 | 299 |
| 304 // Var() means call the object directly as a function rather than calling | 300 // Var() means call the object directly as a function rather than calling |
| 305 // a method in the object. | 301 // a method in the object. |
| 306 cb.Call(Var(), &exception); | 302 cb.Call(Var(), &exception); |
| 307 | 303 |
| 308 if (!exception.is_undefined()) { | 304 if (!exception.is_undefined()) { |
| 309 LOG(WARNING) << "Exception when invoking JS callback" | 305 LOG(WARNING) << "Exception when invoking JS callback" |
|
dmac
2011/07/21 23:37:07
Should this be LOG(ERROR) to match the others?
garykac
2011/08/02 00:15:37
Done.
| |
| 310 << exception.DebugString(); | 306 << exception.DebugString(); |
| 311 } | 307 } |
| 312 } | 308 } |
| 313 | 309 |
| 314 void ChromotingScriptableObject::SignalLoginChallenge() { | 310 void ChromotingScriptableObject::SignalLoginChallenge() { |
| 315 Var exception; | 311 Var exception; |
| 316 VarPrivate cb = GetProperty(Var(kLoginChallenge), &exception); | 312 VarPrivate cb = GetProperty(Var(kLoginChallenge), &exception); |
| 317 | 313 |
| 318 // Var() means call the object directly as a function rather than calling | 314 // Var() means call the object directly as a function rather than calling |
| 319 // a method in the object. | 315 // a method in the object. |
| 320 cb.Call(Var(), &exception); | 316 cb.Call(Var(), &exception); |
| 321 | 317 |
| 322 if (!exception.is_undefined()) | 318 if (!exception.is_undefined()) |
| 323 LogDebugInfo("Exception when invoking loginChallenge JS callback."); | 319 LOG(ERROR) << "Exception when invoking loginChallenge JS callback."; |
| 324 } | 320 } |
| 325 | 321 |
| 326 void ChromotingScriptableObject::AttachXmppProxy(PepperXmppProxy* xmpp_proxy) { | 322 void ChromotingScriptableObject::AttachXmppProxy(PepperXmppProxy* xmpp_proxy) { |
| 327 xmpp_proxy_ = xmpp_proxy; | 323 xmpp_proxy_ = xmpp_proxy; |
| 328 } | 324 } |
| 329 | 325 |
| 330 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { | 326 void ChromotingScriptableObject::SendIq(const std::string& message_xml) { |
| 331 Var exception; | 327 Var exception; |
| 332 VarPrivate cb = GetProperty(Var(kSendIq), &exception); | 328 VarPrivate cb = GetProperty(Var(kSendIq), &exception); |
| 333 | 329 |
| 334 // Var() means call the object directly as a function rather than calling | 330 // Var() means call the object directly as a function rather than calling |
| 335 // a method in the object. | 331 // a method in the object. |
| 336 cb.Call(Var(), Var(message_xml), &exception); | 332 cb.Call(Var(), Var(message_xml), &exception); |
| 337 | 333 |
| 338 if (!exception.is_undefined()) | 334 if (!exception.is_undefined()) |
| 339 LogDebugInfo("Exception when invoking sendiq JS callback."); | 335 LOG(ERROR) << "Exception when invoking sendiq JS callback."; |
| 340 } | 336 } |
| 341 | 337 |
| 342 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, | 338 Var ChromotingScriptableObject::DoConnect(const std::vector<Var>& args, |
| 343 Var* exception) { | 339 Var* exception) { |
| 344 // Parameter order is: | 340 // Parameter order is: |
| 345 // host_jid | 341 // host_jid |
| 346 // host_public_key | 342 // host_public_key |
| 347 // client_jid | 343 // client_jid |
| 348 // access_code (optional) | 344 // access_code (optional) |
| 349 unsigned int arg = 0; | 345 unsigned int arg = 0; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 372 return Var(); | 368 return Var(); |
| 373 } | 369 } |
| 374 access_code = args[arg++].AsString(); | 370 access_code = args[arg++].AsString(); |
| 375 } | 371 } |
| 376 | 372 |
| 377 if (args.size() != arg) { | 373 if (args.size() != arg) { |
| 378 *exception = Var("Too many agruments passed to connect()."); | 374 *exception = Var("Too many agruments passed to connect()."); |
| 379 return Var(); | 375 return Var(); |
| 380 } | 376 } |
| 381 | 377 |
| 382 LogDebugInfo("Connecting to host."); | 378 LOG(INFO) << "Connecting to host."; |
| 383 VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid | 379 VLOG(1) << "client_jid: " << client_jid << ", host_jid: " << host_jid |
| 384 << ", access_code: " << access_code; | 380 << ", access_code: " << access_code; |
| 385 ClientConfig config; | 381 ClientConfig config; |
| 386 config.local_jid = client_jid; | 382 config.local_jid = client_jid; |
| 387 config.host_jid = host_jid; | 383 config.host_jid = host_jid; |
| 388 config.host_public_key = host_public_key; | 384 config.host_public_key = host_public_key; |
| 389 config.access_code = access_code; | 385 config.access_code = access_code; |
| 390 instance_->Connect(config); | 386 instance_->Connect(config); |
| 391 | 387 |
| 392 return Var(); | 388 return Var(); |
| 393 } | 389 } |
| 394 | 390 |
| 395 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, | 391 Var ChromotingScriptableObject::DoDisconnect(const std::vector<Var>& args, |
| 396 Var* exception) { | 392 Var* exception) { |
| 397 LogDebugInfo("Disconnecting from host."); | 393 LOG(INFO) << "Disconnecting from host."; |
| 398 | 394 |
| 399 instance_->Disconnect(); | 395 instance_->Disconnect(); |
| 400 return Var(); | 396 return Var(); |
| 401 } | 397 } |
| 402 | 398 |
| 403 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, | 399 Var ChromotingScriptableObject::DoSubmitLogin(const std::vector<Var>& args, |
| 404 Var* exception) { | 400 Var* exception) { |
| 405 if (args.size() != 2) { | 401 if (args.size() != 2) { |
| 406 *exception = Var("Usage: login(username, password)"); | 402 *exception = Var("Usage: login(username, password)"); |
| 407 return Var(); | 403 return Var(); |
| 408 } | 404 } |
| 409 | 405 |
| 410 if (!args[0].is_string()) { | 406 if (!args[0].is_string()) { |
| 411 *exception = Var("Username must be a string."); | 407 *exception = Var("Username must be a string."); |
| 412 return Var(); | 408 return Var(); |
| 413 } | 409 } |
| 414 std::string username = args[0].AsString(); | 410 std::string username = args[0].AsString(); |
| 415 | 411 |
| 416 if (!args[1].is_string()) { | 412 if (!args[1].is_string()) { |
| 417 *exception = Var("Password must be a string."); | 413 *exception = Var("Password must be a string."); |
| 418 return Var(); | 414 return Var(); |
| 419 } | 415 } |
| 420 std::string password = args[1].AsString(); | 416 std::string password = args[1].AsString(); |
| 421 | 417 |
| 422 LogDebugInfo("Submitting login info to host."); | 418 LOG(INFO) << "Submitting login info to host."; |
| 423 instance_->SubmitLoginInfo(username, password); | 419 instance_->SubmitLoginInfo(username, password); |
| 424 return Var(); | 420 return Var(); |
| 425 } | 421 } |
| 426 | 422 |
| 427 Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args, | 423 Var ChromotingScriptableObject::DoSetScaleToFit(const std::vector<Var>& args, |
| 428 Var* exception) { | 424 Var* exception) { |
| 429 if (args.size() != 1) { | 425 if (args.size() != 1) { |
| 430 *exception = Var("Usage: setScaleToFit(scale_to_fit)"); | 426 *exception = Var("Usage: setScaleToFit(scale_to_fit)"); |
| 431 return Var(); | 427 return Var(); |
| 432 } | 428 } |
| 433 | 429 |
| 434 if (!args[0].is_bool()) { | 430 if (!args[0].is_bool()) { |
| 435 *exception = Var("scale_to_fit must be a boolean."); | 431 *exception = Var("scale_to_fit must be a boolean."); |
| 436 return Var(); | 432 return Var(); |
| 437 } | 433 } |
| 438 | 434 |
| 439 LogDebugInfo("Setting scale-to-fit."); | 435 LOG(INFO) << "Setting scale-to-fit."; |
| 440 instance_->SetScaleToFit(args[0].AsBool()); | 436 instance_->SetScaleToFit(args[0].AsBool()); |
| 441 return Var(); | 437 return Var(); |
| 442 } | 438 } |
| 443 | 439 |
| 444 Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, | 440 Var ChromotingScriptableObject::DoOnIq(const std::vector<Var>& args, |
| 445 Var* exception) { | 441 Var* exception) { |
| 446 if (args.size() != 1) { | 442 if (args.size() != 1) { |
| 447 *exception = Var("Usage: onIq(response_xml)"); | 443 *exception = Var("Usage: onIq(response_xml)"); |
| 448 return Var(); | 444 return Var(); |
| 449 } | 445 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 462 const std::vector<pp::Var>& args, pp::Var* exception) { | 458 const std::vector<pp::Var>& args, pp::Var* exception) { |
| 463 if (args.size() != 0) { | 459 if (args.size() != 0) { |
| 464 *exception = Var("Usage: DoReleaseAllKeys()"); | 460 *exception = Var("Usage: DoReleaseAllKeys()"); |
| 465 return Var(); | 461 return Var(); |
| 466 } | 462 } |
| 467 instance_->ReleaseAllKeys(); | 463 instance_->ReleaseAllKeys(); |
| 468 return Var(); | 464 return Var(); |
| 469 } | 465 } |
| 470 | 466 |
| 471 } // namespace remoting | 467 } // namespace remoting |
| OLD | NEW |