Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/browser/devtools/devtools_ui_bindings.cc

Issue 2864263002: [DevTools] Expose TCP targets config in frontend, use it for Node (Closed)
Patch Set: works Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/devtools/devtools_ui_bindings.h" 5 #include "chrome/browser/devtools/devtools_ui_bindings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); 911 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT);
912 } 912 }
913 913
914 void DevToolsUIBindings::ResetZoom() { 914 void DevToolsUIBindings::ResetZoom() {
915 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); 915 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET);
916 } 916 }
917 917
918 void DevToolsUIBindings::SetDevicesDiscoveryConfig( 918 void DevToolsUIBindings::SetDevicesDiscoveryConfig(
919 bool discover_usb_devices, 919 bool discover_usb_devices,
920 bool port_forwarding_enabled, 920 bool port_forwarding_enabled,
921 const std::string& port_forwarding_config) { 921 const std::string& port_forwarding_config,
922 base::DictionaryValue* config_dict = nullptr; 922 bool network_discovery_enabled,
923 std::unique_ptr<base::Value> parsed_config = 923 const std::string& network_discovery_config) {
924 base::DictionaryValue* port_forwarding_dict = nullptr;
925 std::unique_ptr<base::Value> parsed_port_forwarding =
924 base::JSONReader::Read(port_forwarding_config); 926 base::JSONReader::Read(port_forwarding_config);
925 if (!parsed_config || !parsed_config->GetAsDictionary(&config_dict)) 927 if (!parsed_port_forwarding ||
928 !parsed_port_forwarding->GetAsDictionary(&port_forwarding_dict)) {
929 return;
930 }
931
932 base::ListValue* network_list = nullptr;
933 std::unique_ptr<base::Value> parsed_network =
934 base::JSONReader::Read(network_discovery_config);
935 if (!parsed_network || !parsed_network->GetAsList(&network_list))
926 return; 936 return;
927 937
928 profile_->GetPrefs()->SetBoolean( 938 profile_->GetPrefs()->SetBoolean(
929 prefs::kDevToolsDiscoverUsbDevicesEnabled, discover_usb_devices); 939 prefs::kDevToolsDiscoverUsbDevicesEnabled, discover_usb_devices);
930 profile_->GetPrefs()->SetBoolean( 940 profile_->GetPrefs()->SetBoolean(
931 prefs::kDevToolsPortForwardingEnabled, port_forwarding_enabled); 941 prefs::kDevToolsPortForwardingEnabled, port_forwarding_enabled);
932 profile_->GetPrefs()->Set( 942 profile_->GetPrefs()->Set(prefs::kDevToolsPortForwardingConfig,
933 prefs::kDevToolsPortForwardingConfig, *config_dict); 943 *port_forwarding_dict);
944 profile_->GetPrefs()->SetBoolean(prefs::kDevToolsDiscoverTCPTargetsEnabled,
945 network_discovery_enabled);
946 profile_->GetPrefs()->Set(prefs::kDevToolsTCPDiscoveryConfig, *network_list);
934 } 947 }
935 948
936 void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() { 949 void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() {
937 CallClientFunction( 950 // If we're not exposing bindings, we shouldn't call functions either.
938 "DevToolsAPI.devicesDiscoveryConfigChanged", 951 if (!frontend_host_)
939 profile_->GetPrefs()->FindPreference( 952 return;
940 prefs::kDevToolsDiscoverUsbDevicesEnabled)->GetValue(), 953 std::string javascript = "DevToolsAPI.devicesDiscoveryConfigChanged(";
pfeldman 2017/05/08 18:38:07 Dictionary it, no backwards support needed.
941 profile_->GetPrefs()->FindPreference( 954 std::string json;
942 prefs::kDevToolsPortForwardingEnabled)->GetValue(), 955
943 profile_->GetPrefs()->FindPreference( 956 base::JSONWriter::Write(
944 prefs::kDevToolsPortForwardingConfig)->GetValue()); 957 *profile_->GetPrefs()
958 ->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled)
959 ->GetValue(),
960 &json);
961 javascript.append(json);
962
963 base::JSONWriter::Write(
964 *profile_->GetPrefs()
965 ->FindPreference(prefs::kDevToolsPortForwardingEnabled)
966 ->GetValue(),
967 &json);
968 javascript.append(", ").append(json);
969
970 base::JSONWriter::Write(
971 *profile_->GetPrefs()
972 ->FindPreference(prefs::kDevToolsPortForwardingConfig)
973 ->GetValue(),
974 &json);
975 javascript.append(", ").append(json);
976
977 base::JSONWriter::Write(
978 *profile_->GetPrefs()
979 ->FindPreference(prefs::kDevToolsDiscoverTCPTargetsEnabled)
980 ->GetValue(),
981 &json);
982 javascript.append(", ").append(json);
983
984 base::JSONWriter::Write(
985 *profile_->GetPrefs()
986 ->FindPreference(prefs::kDevToolsTCPDiscoveryConfig)
987 ->GetValue(),
988 &json);
989 javascript.append(", ").append(json);
990
991 javascript.append(");");
992 web_contents_->GetMainFrame()->ExecuteJavaScript(
993 base::UTF8ToUTF16(javascript));
945 } 994 }
946 995
947 void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) { 996 void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) {
948 CallClientFunction("DevToolsAPI.devicesPortForwardingStatusChanged", &status, 997 CallClientFunction("DevToolsAPI.devicesPortForwardingStatusChanged", &status,
949 nullptr, nullptr); 998 nullptr, nullptr);
950 } 999 }
951 1000
952 void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { 1001 void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) {
953 if (devices_updates_enabled_ == enabled) 1002 if (devices_updates_enabled_ == enabled)
954 return; 1003 return;
955 devices_updates_enabled_ = enabled; 1004 devices_updates_enabled_ = enabled;
956 if (enabled) { 1005 if (enabled) {
957 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( 1006 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb(
958 base::Bind(&DevToolsUIBindings::DevicesUpdated, 1007 base::Bind(&DevToolsUIBindings::DevicesUpdated,
959 base::Unretained(this)), 1008 base::Unretained(this)),
960 profile_); 1009 profile_);
961 pref_change_registrar_.Init(profile_->GetPrefs()); 1010 pref_change_registrar_.Init(profile_->GetPrefs());
962 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled, 1011 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled,
963 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, 1012 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated,
964 base::Unretained(this))); 1013 base::Unretained(this)));
965 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, 1014 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled,
966 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, 1015 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated,
967 base::Unretained(this))); 1016 base::Unretained(this)));
968 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, 1017 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig,
969 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, 1018 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated,
970 base::Unretained(this))); 1019 base::Unretained(this)));
1020 pref_change_registrar_.Add(
1021 prefs::kDevToolsDiscoverTCPTargetsEnabled,
1022 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated,
1023 base::Unretained(this)));
1024 pref_change_registrar_.Add(
1025 prefs::kDevToolsTCPDiscoveryConfig,
1026 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated,
1027 base::Unretained(this)));
971 port_status_serializer_.reset(new PortForwardingStatusSerializer( 1028 port_status_serializer_.reset(new PortForwardingStatusSerializer(
972 base::Bind(&DevToolsUIBindings::SendPortForwardingStatus, 1029 base::Bind(&DevToolsUIBindings::SendPortForwardingStatus,
973 base::Unretained(this)), 1030 base::Unretained(this)),
974 profile_)); 1031 profile_));
975 DevicesDiscoveryConfigUpdated(); 1032 DevicesDiscoveryConfigUpdated();
976 } else { 1033 } else {
977 remote_targets_handler_.reset(); 1034 remote_targets_handler_.reset();
978 port_status_serializer_.reset(); 1035 port_status_serializer_.reset();
979 pref_change_registrar_.RemoveAll(); 1036 pref_change_registrar_.RemoveAll();
980 SendPortForwardingStatus(base::DictionaryValue()); 1037 SendPortForwardingStatus(base::DictionaryValue());
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 void DevToolsUIBindings::FrontendLoaded() { 1429 void DevToolsUIBindings::FrontendLoaded() {
1373 if (frontend_loaded_) 1430 if (frontend_loaded_)
1374 return; 1431 return;
1375 frontend_loaded_ = true; 1432 frontend_loaded_ = true;
1376 1433
1377 // Call delegate first - it seeds importants bit of information. 1434 // Call delegate first - it seeds importants bit of information.
1378 delegate_->OnLoadCompleted(); 1435 delegate_->OnLoadCompleted();
1379 1436
1380 AddDevToolsExtensionsToClient(); 1437 AddDevToolsExtensionsToClient();
1381 } 1438 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_ui_bindings.h ('k') | third_party/WebKit/Source/devtools/front_end/devices/DevicesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698