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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 SetException("clearPairedClients: bad number of arguments"); | 1104 SetException("clearPairedClients: bad number of arguments"); |
1105 return false; | 1105 return false; |
1106 } | 1106 } |
1107 | 1107 |
1108 if (!NPVARIANT_IS_OBJECT(args[0])) { | 1108 if (!NPVARIANT_IS_OBJECT(args[0])) { |
1109 SetException("clearPairedClients: invalid callback parameter"); | 1109 SetException("clearPairedClients: invalid callback parameter"); |
1110 return false; | 1110 return false; |
1111 } | 1111 } |
1112 | 1112 |
1113 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); | 1113 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); |
1114 pairing_registry_->ClearAllPairings( | 1114 if (pairing_registry_) { |
1115 base::Bind(&HostNPScriptObject::InvokeBooleanCallback, weak_ptr_, | 1115 pairing_registry_->ClearAllPairings( |
1116 callback_obj)); | 1116 base::Bind(&HostNPScriptObject::InvokeBooleanCallback, weak_ptr_, |
| 1117 callback_obj)); |
| 1118 } else { |
| 1119 InvokeBooleanCallback(callback_obj, false); |
| 1120 } |
1117 | 1121 |
1118 return true; | 1122 return true; |
1119 } | 1123 } |
1120 | 1124 |
1121 bool HostNPScriptObject::DeletePairedClient(const NPVariant* args, | 1125 bool HostNPScriptObject::DeletePairedClient(const NPVariant* args, |
1122 uint32_t arg_count, | 1126 uint32_t arg_count, |
1123 NPVariant* result) { | 1127 NPVariant* result) { |
1124 if (arg_count != 2) { | 1128 if (arg_count != 2) { |
1125 SetException("deletePairedClient: bad number of arguments"); | 1129 SetException("deletePairedClient: bad number of arguments"); |
1126 return false; | 1130 return false; |
1127 } | 1131 } |
1128 | 1132 |
1129 if (!NPVARIANT_IS_STRING(args[0])) { | 1133 if (!NPVARIANT_IS_STRING(args[0])) { |
1130 SetException("deletePairedClient: bad clientId parameter"); | 1134 SetException("deletePairedClient: bad clientId parameter"); |
1131 return false; | 1135 return false; |
1132 } | 1136 } |
1133 | 1137 |
1134 if (!NPVARIANT_IS_OBJECT(args[1])) { | 1138 if (!NPVARIANT_IS_OBJECT(args[1])) { |
1135 SetException("deletePairedClient: invalid callback parameter"); | 1139 SetException("deletePairedClient: invalid callback parameter"); |
1136 return false; | 1140 return false; |
1137 } | 1141 } |
1138 | 1142 |
1139 std::string client_id = StringFromNPVariant(args[0]); | 1143 std::string client_id = StringFromNPVariant(args[0]); |
1140 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[1])); | 1144 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[1])); |
1141 pairing_registry_->DeletePairing( | 1145 if (pairing_registry_) { |
1142 client_id, | 1146 pairing_registry_->DeletePairing( |
1143 base::Bind(&HostNPScriptObject::InvokeBooleanCallback, | 1147 client_id, |
1144 weak_ptr_, callback_obj)); | 1148 base::Bind(&HostNPScriptObject::InvokeBooleanCallback, |
| 1149 weak_ptr_, callback_obj)); |
| 1150 } else { |
| 1151 InvokeBooleanCallback(callback_obj, false); |
| 1152 } |
1145 | 1153 |
1146 return true; | 1154 return true; |
1147 } | 1155 } |
1148 | 1156 |
1149 bool HostNPScriptObject::GetHostName(const NPVariant* args, | 1157 bool HostNPScriptObject::GetHostName(const NPVariant* args, |
1150 uint32_t arg_count, | 1158 uint32_t arg_count, |
1151 NPVariant* result) { | 1159 NPVariant* result) { |
1152 if (arg_count != 1) { | 1160 if (arg_count != 1) { |
1153 SetException("getHostName: bad number of arguments"); | 1161 SetException("getHostName: bad number of arguments"); |
1154 return false; | 1162 return false; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 SetException("getPairedClients: bad number of arguments"); | 1326 SetException("getPairedClients: bad number of arguments"); |
1319 return false; | 1327 return false; |
1320 } | 1328 } |
1321 | 1329 |
1322 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); | 1330 ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0])); |
1323 if (!callback_obj.get()) { | 1331 if (!callback_obj.get()) { |
1324 SetException("getPairedClients: invalid callback parameter"); | 1332 SetException("getPairedClients: invalid callback parameter"); |
1325 return false; | 1333 return false; |
1326 } | 1334 } |
1327 | 1335 |
1328 pairing_registry_->GetAllPairings( | 1336 if (pairing_registry_) { |
1329 base::Bind(&HostNPScriptObject::InvokeGetPairedClientsCallback, | 1337 pairing_registry_->GetAllPairings( |
1330 weak_ptr_, callback_obj)); | 1338 base::Bind(&HostNPScriptObject::InvokeGetPairedClientsCallback, |
| 1339 weak_ptr_, callback_obj)); |
| 1340 } else { |
| 1341 scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue); |
| 1342 InvokeGetPairedClientsCallback(callback_obj, no_paired_clients.Pass()); |
| 1343 } |
1331 return true; | 1344 return true; |
1332 } | 1345 } |
1333 | 1346 |
1334 bool HostNPScriptObject::GetUsageStatsConsent(const NPVariant* args, | 1347 bool HostNPScriptObject::GetUsageStatsConsent(const NPVariant* args, |
1335 uint32_t arg_count, | 1348 uint32_t arg_count, |
1336 NPVariant* result) { | 1349 NPVariant* result) { |
1337 if (arg_count != 1) { | 1350 if (arg_count != 1) { |
1338 SetException("getUsageStatsConsent: bad number of arguments"); | 1351 SetException("getUsageStatsConsent: bad number of arguments"); |
1339 return false; | 1352 return false; |
1340 } | 1353 } |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1705 } | 1718 } |
1706 | 1719 |
1707 void HostNPScriptObject::SetException(const std::string& exception_string) { | 1720 void HostNPScriptObject::SetException(const std::string& exception_string) { |
1708 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); | 1721 DCHECK(plugin_task_runner_->BelongsToCurrentThread()); |
1709 | 1722 |
1710 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); | 1723 g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); |
1711 LOG(INFO) << exception_string; | 1724 LOG(INFO) << exception_string; |
1712 } | 1725 } |
1713 | 1726 |
1714 } // namespace remoting | 1727 } // namespace remoting |
OLD | NEW |