| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/plugin/chromoting_instance.h" | 12 #include "remoting/client/plugin/chromoting_instance.h" |
| 12 #include "remoting/client/plugin/pepper_xmpp_proxy.h" | 13 #include "remoting/client/plugin/pepper_xmpp_proxy.h" |
| 13 | 14 |
| 14 using pp::Var; | 15 using pp::Var; |
| 15 | 16 |
| 16 namespace remoting { | 17 namespace remoting { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; | 21 const char kConnectionInfoUpdate[] = "connectionInfoUpdate"; |
| 21 const char kDebugInfo[] = "debugInfo"; | 22 const char kDebugInfo[] = "debugInfo"; |
| 22 const char kDesktopHeight[] = "desktopHeight"; | 23 const char kDesktopHeight[] = "desktopHeight"; |
| 23 const char kDesktopWidth[] = "desktopWidth"; | 24 const char kDesktopWidth[] = "desktopWidth"; |
| 24 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; | 25 const char kDesktopSizeUpdate[] = "desktopSizeUpdate"; |
| 25 const char kLoginChallenge[] = "loginChallenge"; | 26 const char kLoginChallenge[] = "loginChallenge"; |
| 26 const char kSendIq[] = "sendIq"; | 27 const char kSendIq[] = "sendIq"; |
| 27 const char kQualityAttribute[] = "quality"; | 28 const char kQualityAttribute[] = "quality"; |
| 28 const char kStatusAttribute[] = "status"; | 29 const char kStatusAttribute[] = "status"; |
| 30 const char kVideoBandwidthAttribute[] = "videoBandwidth"; |
| 29 | 31 |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 ChromotingScriptableObject::ChromotingScriptableObject( | 34 ChromotingScriptableObject::ChromotingScriptableObject( |
| 33 ChromotingInstance* instance) | 35 ChromotingInstance* instance) |
| 34 : instance_(instance) { | 36 : instance_(instance) { |
| 35 } | 37 } |
| 36 | 38 |
| 37 ChromotingScriptableObject::~ChromotingScriptableObject() { | 39 ChromotingScriptableObject::~ChromotingScriptableObject() { |
| 38 } | 40 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 | 64 |
| 63 // Debug info to display. | 65 // Debug info to display. |
| 64 AddAttribute(kConnectionInfoUpdate, Var()); | 66 AddAttribute(kConnectionInfoUpdate, Var()); |
| 65 AddAttribute(kDebugInfo, Var()); | 67 AddAttribute(kDebugInfo, Var()); |
| 66 AddAttribute(kDesktopSizeUpdate, Var()); | 68 AddAttribute(kDesktopSizeUpdate, Var()); |
| 67 AddAttribute(kLoginChallenge, Var()); | 69 AddAttribute(kLoginChallenge, Var()); |
| 68 AddAttribute(kSendIq, Var()); | 70 AddAttribute(kSendIq, Var()); |
| 69 AddAttribute(kDesktopWidth, Var(0)); | 71 AddAttribute(kDesktopWidth, Var(0)); |
| 70 AddAttribute(kDesktopHeight, Var(0)); | 72 AddAttribute(kDesktopHeight, Var(0)); |
| 71 | 73 |
| 74 // Statistics. |
| 75 AddAttribute(kVideoBandwidthAttribute, Var()); |
| 76 |
| 72 AddMethod("connect", &ChromotingScriptableObject::DoConnect); | 77 AddMethod("connect", &ChromotingScriptableObject::DoConnect); |
| 73 AddMethod("connectSandboxed", | 78 AddMethod("connectSandboxed", |
| 74 &ChromotingScriptableObject::DoConnectSandboxed); | 79 &ChromotingScriptableObject::DoConnectSandboxed); |
| 75 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); | 80 AddMethod("disconnect", &ChromotingScriptableObject::DoDisconnect); |
| 76 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); | 81 AddMethod("submitLoginInfo", &ChromotingScriptableObject::DoSubmitLogin); |
| 77 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); | 82 AddMethod("onIq", &ChromotingScriptableObject::DoOnIq); |
| 78 } | 83 } |
| 79 | 84 |
| 80 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { | 85 bool ChromotingScriptableObject::HasProperty(const Var& name, Var* exception) { |
| 81 // TODO(ajwong): Check if all these name.is_string() sentinels are required. | 86 // TODO(ajwong): Check if all these name.is_string() sentinels are required. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return Var(); | 124 return Var(); |
| 120 } | 125 } |
| 121 | 126 |
| 122 PropertyNameMap::const_iterator iter = property_names_.find(name.AsString()); | 127 PropertyNameMap::const_iterator iter = property_names_.find(name.AsString()); |
| 123 | 128 |
| 124 // No property found. | 129 // No property found. |
| 125 if (iter == property_names_.end()) { | 130 if (iter == property_names_.end()) { |
| 126 return ScriptableObject::GetProperty(name, exception); | 131 return ScriptableObject::GetProperty(name, exception); |
| 127 } | 132 } |
| 128 | 133 |
| 134 // If this is a statistics attribute then return the value from |
| 135 // ChromotingStats structure. |
| 136 if (name.AsString() == kVideoBandwidthAttribute) { |
| 137 return instance_->GetStats()->video_bandwidth()->Rate(); |
| 138 } |
| 139 |
| 129 // TODO(ajwong): This incorrectly return a null object if a function | 140 // TODO(ajwong): This incorrectly return a null object if a function |
| 130 // property is requested. | 141 // property is requested. |
| 131 return properties_[iter->second].attribute; | 142 return properties_[iter->second].attribute; |
| 132 } | 143 } |
| 133 | 144 |
| 134 void ChromotingScriptableObject::GetAllPropertyNames( | 145 void ChromotingScriptableObject::GetAllPropertyNames( |
| 135 std::vector<Var>* properties, | 146 std::vector<Var>* properties, |
| 136 Var* exception) { | 147 Var* exception) { |
| 137 for (size_t i = 0; i < properties_.size(); i++) { | 148 for (size_t i = 0; i < properties_.size(); i++) { |
| 138 properties->push_back(Var(properties_[i].name)); | 149 properties->push_back(Var(properties_[i].name)); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 *exception = Var("response_xml must be a string."); | 412 *exception = Var("response_xml must be a string."); |
| 402 return Var(); | 413 return Var(); |
| 403 } | 414 } |
| 404 | 415 |
| 405 xmpp_proxy_->OnIq(args[0].AsString()); | 416 xmpp_proxy_->OnIq(args[0].AsString()); |
| 406 | 417 |
| 407 return Var(); | 418 return Var(); |
| 408 } | 419 } |
| 409 | 420 |
| 410 } // namespace remoting | 421 } // namespace remoting |
| OLD | NEW |