| OLD | NEW |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 static const char kTitleFormat[] = "Developer Tools - %s"; | 93 static const char kTitleFormat[] = "Developer Tools - %s"; |
| 94 | 94 |
| 95 static const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; | 95 static const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; |
| 96 static const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; | 96 static const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; |
| 97 | 97 |
| 98 static const char kRemotePageActionInspect[] = "inspect"; | 98 static const char kRemotePageActionInspect[] = "inspect"; |
| 99 static const char kRemotePageActionReload[] = "reload"; | 99 static const char kRemotePageActionReload[] = "reload"; |
| 100 static const char kRemotePageActionActivate[] = "activate"; | 100 static const char kRemotePageActionActivate[] = "activate"; |
| 101 static const char kRemotePageActionClose[] = "close"; | 101 static const char kRemotePageActionClose[] = "close"; |
| 102 | 102 |
| 103 static const char kConfigDiscoverUsbDevices[] = "discoverUsbDevices"; |
| 104 static const char kConfigPortForwardingEnabled[] = "portForwardingEnabled"; |
| 105 static const char kConfigPortForwardingConfig[] = "portForwardingConfig"; |
| 106 static const char kConfigNetworkDiscoveryEnabled[] = "networkDiscoveryEnabled"; |
| 107 static const char kConfigNetworkDiscoveryConfig[] = "networkDiscoveryConfig"; |
| 108 |
| 103 // This constant should be in sync with | 109 // This constant should be in sync with |
| 104 // the constant at shell_devtools_frontend.cc. | 110 // the constant at shell_devtools_frontend.cc. |
| 105 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; | 111 const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; |
| 106 | 112 |
| 107 typedef std::vector<DevToolsUIBindings*> DevToolsUIBindingsList; | 113 typedef std::vector<DevToolsUIBindings*> DevToolsUIBindingsList; |
| 108 base::LazyInstance<DevToolsUIBindingsList>::Leaky g_instances = | 114 base::LazyInstance<DevToolsUIBindingsList>::Leaky g_instances = |
| 109 LAZY_INSTANCE_INITIALIZER; | 115 LAZY_INSTANCE_INITIALIZER; |
| 110 | 116 |
| 111 std::unique_ptr<base::DictionaryValue> CreateFileSystemValue( | 117 std::unique_ptr<base::DictionaryValue> CreateFileSystemValue( |
| 112 DevToolsFileHelper::FileSystem file_system) { | 118 DevToolsFileHelper::FileSystem file_system) { |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); | 917 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_OUT); |
| 912 } | 918 } |
| 913 | 919 |
| 914 void DevToolsUIBindings::ResetZoom() { | 920 void DevToolsUIBindings::ResetZoom() { |
| 915 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); | 921 zoom::PageZoom::Zoom(web_contents(), content::PAGE_ZOOM_RESET); |
| 916 } | 922 } |
| 917 | 923 |
| 918 void DevToolsUIBindings::SetDevicesDiscoveryConfig( | 924 void DevToolsUIBindings::SetDevicesDiscoveryConfig( |
| 919 bool discover_usb_devices, | 925 bool discover_usb_devices, |
| 920 bool port_forwarding_enabled, | 926 bool port_forwarding_enabled, |
| 921 const std::string& port_forwarding_config) { | 927 const std::string& port_forwarding_config, |
| 922 base::DictionaryValue* config_dict = nullptr; | 928 bool network_discovery_enabled, |
| 923 std::unique_ptr<base::Value> parsed_config = | 929 const std::string& network_discovery_config) { |
| 930 base::DictionaryValue* port_forwarding_dict = nullptr; |
| 931 std::unique_ptr<base::Value> parsed_port_forwarding = |
| 924 base::JSONReader::Read(port_forwarding_config); | 932 base::JSONReader::Read(port_forwarding_config); |
| 925 if (!parsed_config || !parsed_config->GetAsDictionary(&config_dict)) | 933 if (!parsed_port_forwarding || |
| 934 !parsed_port_forwarding->GetAsDictionary(&port_forwarding_dict)) { |
| 935 return; |
| 936 } |
| 937 |
| 938 base::ListValue* network_list = nullptr; |
| 939 std::unique_ptr<base::Value> parsed_network = |
| 940 base::JSONReader::Read(network_discovery_config); |
| 941 if (!parsed_network || !parsed_network->GetAsList(&network_list)) |
| 926 return; | 942 return; |
| 927 | 943 |
| 928 profile_->GetPrefs()->SetBoolean( | 944 profile_->GetPrefs()->SetBoolean( |
| 929 prefs::kDevToolsDiscoverUsbDevicesEnabled, discover_usb_devices); | 945 prefs::kDevToolsDiscoverUsbDevicesEnabled, discover_usb_devices); |
| 930 profile_->GetPrefs()->SetBoolean( | 946 profile_->GetPrefs()->SetBoolean( |
| 931 prefs::kDevToolsPortForwardingEnabled, port_forwarding_enabled); | 947 prefs::kDevToolsPortForwardingEnabled, port_forwarding_enabled); |
| 932 profile_->GetPrefs()->Set( | 948 profile_->GetPrefs()->Set(prefs::kDevToolsPortForwardingConfig, |
| 933 prefs::kDevToolsPortForwardingConfig, *config_dict); | 949 *port_forwarding_dict); |
| 950 profile_->GetPrefs()->SetBoolean(prefs::kDevToolsDiscoverTCPTargetsEnabled, |
| 951 network_discovery_enabled); |
| 952 profile_->GetPrefs()->Set(prefs::kDevToolsTCPDiscoveryConfig, *network_list); |
| 934 } | 953 } |
| 935 | 954 |
| 936 void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() { | 955 void DevToolsUIBindings::DevicesDiscoveryConfigUpdated() { |
| 937 CallClientFunction( | 956 base::DictionaryValue config; |
| 938 "DevToolsAPI.devicesDiscoveryConfigChanged", | 957 config.Set(kConfigDiscoverUsbDevices, |
| 939 profile_->GetPrefs()->FindPreference( | 958 profile_->GetPrefs() |
| 940 prefs::kDevToolsDiscoverUsbDevicesEnabled)->GetValue(), | 959 ->FindPreference(prefs::kDevToolsDiscoverUsbDevicesEnabled) |
| 941 profile_->GetPrefs()->FindPreference( | 960 ->GetValue() |
| 942 prefs::kDevToolsPortForwardingEnabled)->GetValue(), | 961 ->CreateDeepCopy()); |
| 943 profile_->GetPrefs()->FindPreference( | 962 config.Set(kConfigPortForwardingEnabled, |
| 944 prefs::kDevToolsPortForwardingConfig)->GetValue()); | 963 profile_->GetPrefs() |
| 964 ->FindPreference(prefs::kDevToolsPortForwardingEnabled) |
| 965 ->GetValue() |
| 966 ->CreateDeepCopy()); |
| 967 config.Set(kConfigPortForwardingConfig, |
| 968 profile_->GetPrefs() |
| 969 ->FindPreference(prefs::kDevToolsPortForwardingConfig) |
| 970 ->GetValue() |
| 971 ->CreateDeepCopy()); |
| 972 config.Set(kConfigNetworkDiscoveryEnabled, |
| 973 profile_->GetPrefs() |
| 974 ->FindPreference(prefs::kDevToolsDiscoverTCPTargetsEnabled) |
| 975 ->GetValue() |
| 976 ->CreateDeepCopy()); |
| 977 config.Set(kConfigNetworkDiscoveryConfig, |
| 978 profile_->GetPrefs() |
| 979 ->FindPreference(prefs::kDevToolsTCPDiscoveryConfig) |
| 980 ->GetValue() |
| 981 ->CreateDeepCopy()); |
| 982 CallClientFunction("DevToolsAPI.devicesDiscoveryConfigChanged", &config, |
| 983 nullptr, nullptr); |
| 945 } | 984 } |
| 946 | 985 |
| 947 void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) { | 986 void DevToolsUIBindings::SendPortForwardingStatus(const base::Value& status) { |
| 948 CallClientFunction("DevToolsAPI.devicesPortForwardingStatusChanged", &status, | 987 CallClientFunction("DevToolsAPI.devicesPortForwardingStatusChanged", &status, |
| 949 nullptr, nullptr); | 988 nullptr, nullptr); |
| 950 } | 989 } |
| 951 | 990 |
| 952 void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { | 991 void DevToolsUIBindings::SetDevicesUpdatesEnabled(bool enabled) { |
| 953 if (devices_updates_enabled_ == enabled) | 992 if (devices_updates_enabled_ == enabled) |
| 954 return; | 993 return; |
| 955 devices_updates_enabled_ = enabled; | 994 devices_updates_enabled_ = enabled; |
| 956 if (enabled) { | 995 if (enabled) { |
| 957 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( | 996 remote_targets_handler_ = DevToolsTargetsUIHandler::CreateForAdb( |
| 958 base::Bind(&DevToolsUIBindings::DevicesUpdated, | 997 base::Bind(&DevToolsUIBindings::DevicesUpdated, |
| 959 base::Unretained(this)), | 998 base::Unretained(this)), |
| 960 profile_); | 999 profile_); |
| 961 pref_change_registrar_.Init(profile_->GetPrefs()); | 1000 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 962 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled, | 1001 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled, |
| 963 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, | 1002 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| 964 base::Unretained(this))); | 1003 base::Unretained(this))); |
| 965 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, | 1004 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, |
| 966 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, | 1005 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| 967 base::Unretained(this))); | 1006 base::Unretained(this))); |
| 968 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, | 1007 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, |
| 969 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, | 1008 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| 970 base::Unretained(this))); | 1009 base::Unretained(this))); |
| 1010 pref_change_registrar_.Add( |
| 1011 prefs::kDevToolsDiscoverTCPTargetsEnabled, |
| 1012 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| 1013 base::Unretained(this))); |
| 1014 pref_change_registrar_.Add( |
| 1015 prefs::kDevToolsTCPDiscoveryConfig, |
| 1016 base::Bind(&DevToolsUIBindings::DevicesDiscoveryConfigUpdated, |
| 1017 base::Unretained(this))); |
| 971 port_status_serializer_.reset(new PortForwardingStatusSerializer( | 1018 port_status_serializer_.reset(new PortForwardingStatusSerializer( |
| 972 base::Bind(&DevToolsUIBindings::SendPortForwardingStatus, | 1019 base::Bind(&DevToolsUIBindings::SendPortForwardingStatus, |
| 973 base::Unretained(this)), | 1020 base::Unretained(this)), |
| 974 profile_)); | 1021 profile_)); |
| 975 DevicesDiscoveryConfigUpdated(); | 1022 DevicesDiscoveryConfigUpdated(); |
| 976 } else { | 1023 } else { |
| 977 remote_targets_handler_.reset(); | 1024 remote_targets_handler_.reset(); |
| 978 port_status_serializer_.reset(); | 1025 port_status_serializer_.reset(); |
| 979 pref_change_registrar_.RemoveAll(); | 1026 pref_change_registrar_.RemoveAll(); |
| 980 SendPortForwardingStatus(base::DictionaryValue()); | 1027 SendPortForwardingStatus(base::DictionaryValue()); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 void DevToolsUIBindings::FrontendLoaded() { | 1419 void DevToolsUIBindings::FrontendLoaded() { |
| 1373 if (frontend_loaded_) | 1420 if (frontend_loaded_) |
| 1374 return; | 1421 return; |
| 1375 frontend_loaded_ = true; | 1422 frontend_loaded_ = true; |
| 1376 | 1423 |
| 1377 // Call delegate first - it seeds importants bit of information. | 1424 // Call delegate first - it seeds importants bit of information. |
| 1378 delegate_->OnLoadCompleted(); | 1425 delegate_->OnLoadCompleted(); |
| 1379 | 1426 |
| 1380 AddDevToolsExtensionsToClient(); | 1427 AddDevToolsExtensionsToClient(); |
| 1381 } | 1428 } |
| OLD | NEW |