Chromium Code Reviews| Index: chrome/browser/devtools/devtools_ui_bindings.cc |
| diff --git a/chrome/browser/devtools/devtools_ui_bindings.cc b/chrome/browser/devtools/devtools_ui_bindings.cc |
| index 91c8e15961c4498f37f758265a6baeb3cbb2d310..3c4afe185a9c9f8e4c8985f3e2b7ace61085c7b1 100644 |
| --- a/chrome/browser/devtools/devtools_ui_bindings.cc |
| +++ b/chrome/browser/devtools/devtools_ui_bindings.cc |
| @@ -918,30 +918,79 @@ void DevToolsUIBindings::ResetZoom() { |
| void DevToolsUIBindings::SetDevicesDiscoveryConfig( |
| bool discover_usb_devices, |
| bool port_forwarding_enabled, |
| - const std::string& port_forwarding_config) { |
| - base::DictionaryValue* config_dict = nullptr; |
| - std::unique_ptr<base::Value> parsed_config = |
| + const std::string& port_forwarding_config, |
| + bool network_discovery_enabled, |
| + const std::string& network_discovery_config) { |
| + base::DictionaryValue* port_forwarding_dict = nullptr; |
| + std::unique_ptr<base::Value> parsed_port_forwarding = |
| base::JSONReader::Read(port_forwarding_config); |
| - if (!parsed_config || !parsed_config->GetAsDictionary(&config_dict)) |
| + if (!parsed_port_forwarding || |
| + !parsed_port_forwarding->GetAsDictionary(&port_forwarding_dict)) { |
| + return; |
| + } |
| + |
| + base::ListValue* network_list = nullptr; |
| + std::unique_ptr<base::Value> parsed_network = |
| + base::JSONReader::Read(network_discovery_config); |
| + if (!parsed_network || !parsed_network->GetAsList(&network_list)) |
| return; |
| profile_->GetPrefs()->SetBoolean( |
| prefs::kDevToolsDiscoverUsbDevicesEnabled, discover_usb_devices); |
| profile_->GetPrefs()->SetBoolean( |
| prefs::kDevToolsPortForwardingEnabled, port_forwarding_enabled); |
| - profile_->GetPrefs()->Set( |
| - prefs::kDevToolsPortForwardingConfig, *config_dict); |
| + profile_->GetPrefs()->Set(prefs::kDevToolsPortForwardingConfig, |
| + *port_forwarding_dict); |
| + profile_->GetPrefs()->SetBoolean(prefs::kDevToolsDiscoverTCPTargetsEnabled, |
| + network_discovery_enabled); |
| + profile_->GetPrefs()->Set(prefs::kDevToolsTCPDiscoveryConfig, *network_list); |
| } |
| void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() { |
| - CallClientFunction( |
| - "DevToolsAPI.devicesDiscoveryConfigChanged", |
| - profile_->GetPrefs()->FindPreference( |
| - prefs::kDevToolsDiscoverUsbDevicesEnabled)->GetValue(), |
| - profile_->GetPrefs()->FindPreference( |
| - prefs::kDevToolsPortForwardingEnabled)->GetValue(), |
| - profile_->GetPrefs()->FindPreference( |
| - prefs::kDevToolsPortForwardingConfig)->GetValue()); |
| + // If we're not exposing bindings, we shouldn't call functions either. |
| + if (!frontend_host_) |
| + return; |
| + std::string javascript = "DevToolsAPI.devicesDiscoveryConfigChanged("; |
|
pfeldman
2017/05/08 18:38:07
Dictionary it, no backwards support needed.
|
| + std::string json; |
| + |
| + base::JSONWriter::Write( |
| + *profile_->GetPrefs() |
| + ->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled) |
| + ->GetValue(), |
| + &json); |
| + javascript.append(json); |
| + |
| + base::JSONWriter::Write( |
| + *profile_->GetPrefs() |
| + ->FindPreference(prefs::kDevToolsPortForwardingEnabled) |
| + ->GetValue(), |
| + &json); |
| + javascript.append(", ").append(json); |
| + |
| + base::JSONWriter::Write( |
| + *profile_->GetPrefs() |
| + ->FindPreference(prefs::kDevToolsPortForwardingConfig) |
| + ->GetValue(), |
| + &json); |
| + javascript.append(", ").append(json); |
| + |
| + base::JSONWriter::Write( |
| + *profile_->GetPrefs() |
| + ->FindPreference(prefs::kDevToolsDiscoverTCPTargetsEnabled) |
| + ->GetValue(), |
| + &json); |
| + javascript.append(", ").append(json); |
| + |
| + base::JSONWriter::Write( |
| + *profile_->GetPrefs() |
| + ->FindPreference(prefs::kDevToolsTCPDiscoveryConfig) |
| + ->GetValue(), |
| + &json); |
| + javascript.append(", ").append(json); |
| + |
| + javascript.append(");"); |
| + web_contents_->GetMainFrame()->ExecuteJavaScript( |
| + base::UTF8ToUTF16(javascript)); |
| } |
| void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) { |
| @@ -968,6 +1017,14 @@ void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { |
| pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, |
| base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| base::Unretained(this))); |
| + pref_change_registrar_.Add( |
| + prefs::kDevToolsDiscoverTCPTargetsEnabled, |
| + base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| + base::Unretained(this))); |
| + pref_change_registrar_.Add( |
| + prefs::kDevToolsTCPDiscoveryConfig, |
| + base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| + base::Unretained(this))); |
| port_status_serializer_.reset(new PortForwardingStatusSerializer( |
| base::Bind(&DevToolsUIBindings::SendPortForwardingStatus, |
| base::Unretained(this)), |