| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" | 5 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 void LocalDiscoveryUIHandler::DeviceChanged( | 346 void LocalDiscoveryUIHandler::DeviceChanged( |
| 347 const std::string& name, | 347 const std::string& name, |
| 348 const DeviceDescription& description) { | 348 const DeviceDescription& description) { |
| 349 device_descriptions_[name] = description; | 349 device_descriptions_[name] = description; |
| 350 | 350 |
| 351 base::DictionaryValue info; | 351 base::DictionaryValue info; |
| 352 | 352 |
| 353 base::StringValue service_key(kKeyPrefixMDns + name); | 353 base::Value service_key(kKeyPrefixMDns + name); |
| 354 | 354 |
| 355 if (description.id.empty()) { | 355 if (description.id.empty()) { |
| 356 info.SetString(kDictionaryKeyServiceName, name); | 356 info.SetString(kDictionaryKeyServiceName, name); |
| 357 info.SetString(kDictionaryKeyDisplayName, description.name); | 357 info.SetString(kDictionaryKeyDisplayName, description.name); |
| 358 info.SetString(kDictionaryKeyDescription, description.description); | 358 info.SetString(kDictionaryKeyDescription, description.description); |
| 359 info.SetString(kDictionaryKeyType, description.type); | 359 info.SetString(kDictionaryKeyType, description.type); |
| 360 info.SetBoolean(kDictionaryKeyIsWifi, false); | 360 info.SetBoolean(kDictionaryKeyIsWifi, false); |
| 361 | 361 |
| 362 web_ui()->CallJavascriptFunctionUnsafe( | 362 web_ui()->CallJavascriptFunctionUnsafe( |
| 363 "local_discovery.onUnregisteredDeviceUpdate", service_key, info); | 363 "local_discovery.onUnregisteredDeviceUpdate", service_key, info); |
| 364 } else { | 364 } else { |
| 365 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 365 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
| 366 | 366 |
| 367 web_ui()->CallJavascriptFunctionUnsafe( | 367 web_ui()->CallJavascriptFunctionUnsafe( |
| 368 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value); | 368 "local_discovery.onUnregisteredDeviceUpdate", service_key, *null_value); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 void LocalDiscoveryUIHandler::DeviceRemoved(const std::string& name) { | 372 void LocalDiscoveryUIHandler::DeviceRemoved(const std::string& name) { |
| 373 device_descriptions_.erase(name); | 373 device_descriptions_.erase(name); |
| 374 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); | 374 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); |
| 375 base::StringValue name_value(kKeyPrefixMDns + name); | 375 base::Value name_value(kKeyPrefixMDns + name); |
| 376 | 376 |
| 377 web_ui()->CallJavascriptFunctionUnsafe( | 377 web_ui()->CallJavascriptFunctionUnsafe( |
| 378 "local_discovery.onUnregisteredDeviceUpdate", name_value, *null_value); | 378 "local_discovery.onUnregisteredDeviceUpdate", name_value, *null_value); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { | 381 void LocalDiscoveryUIHandler::DeviceCacheFlushed() { |
| 382 web_ui()->CallJavascriptFunctionUnsafe( | 382 web_ui()->CallJavascriptFunctionUnsafe( |
| 383 "local_discovery.onDeviceCacheFlushed"); | 383 "local_discovery.onDeviceCacheFlushed"); |
| 384 privet_lister_->DiscoverNewDevices(false); | 384 privet_lister_->DiscoverNewDevices(false); |
| 385 } | 385 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 if (email.empty()) { | 593 if (email.empty()) { |
| 594 label_str = l10n_util::GetStringFUTF16( | 594 label_str = l10n_util::GetStringFUTF16( |
| 595 IDS_LOCAL_DISCOVERY_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, | 595 IDS_LOCAL_DISCOVERY_CLOUD_PRINT_CONNECTOR_DISABLED_LABEL, |
| 596 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); | 596 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT)); |
| 597 } else { | 597 } else { |
| 598 label_str = l10n_util::GetStringFUTF16( | 598 label_str = l10n_util::GetStringFUTF16( |
| 599 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, | 599 IDS_OPTIONS_CLOUD_PRINT_CONNECTOR_ENABLED_LABEL, |
| 600 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), | 600 l10n_util::GetStringUTF16(IDS_GOOGLE_CLOUD_PRINT), |
| 601 base::UTF8ToUTF16(email)); | 601 base::UTF8ToUTF16(email)); |
| 602 } | 602 } |
| 603 base::StringValue label(label_str); | 603 base::Value label(label_str); |
| 604 | 604 |
| 605 web_ui()->CallJavascriptFunctionUnsafe( | 605 web_ui()->CallJavascriptFunctionUnsafe( |
| 606 "local_discovery.setupCloudPrintConnectorSection", disabled, label, | 606 "local_discovery.setupCloudPrintConnectorSection", disabled, label, |
| 607 allowed); | 607 allowed); |
| 608 } | 608 } |
| 609 | 609 |
| 610 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { | 610 void LocalDiscoveryUIHandler::RefreshCloudPrintStatusFromService() { |
| 611 auto* service = GetCloudPrintProxyService(); | 611 auto* service = GetCloudPrintProxyService(); |
| 612 if (service) | 612 if (service) |
| 613 service->RefreshStatusFromService(); | 613 service->RefreshStatusFromService(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 CloudPrintProxyService* LocalDiscoveryUIHandler::GetCloudPrintProxyService() { | 616 CloudPrintProxyService* LocalDiscoveryUIHandler::GetCloudPrintProxyService() { |
| 617 return CloudPrintProxyServiceFactory::GetForProfile( | 617 return CloudPrintProxyServiceFactory::GetForProfile( |
| 618 Profile::FromWebUI(web_ui())); | 618 Profile::FromWebUI(web_ui())); |
| 619 } | 619 } |
| 620 #endif // defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) | 620 #endif // defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) |
| 621 | 621 |
| 622 } // namespace local_discovery | 622 } // namespace local_discovery |
| OLD | NEW |