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

Side by Side Diff: chrome/browser/ui/webui/inspect_ui.cc

Issue 2248133002: [DevTools] Add UI for adding remote targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 (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 "chrome/browser/ui/webui/inspect_ui.h" 5 #include "chrome/browser/ui/webui/inspect_ui.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/devtools/devtools_target_impl.h" 9 #include "chrome/browser/devtools/devtools_target_impl.h"
10 #include "chrome/browser/devtools/devtools_targets_ui.h" 10 #include "chrome/browser/devtools/devtools_targets_ui.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const char kReloadCommand[] = "reload"; 43 const char kReloadCommand[] = "reload";
44 const char kOpenCommand[] = "open"; 44 const char kOpenCommand[] = "open";
45 const char kInspectBrowser[] = "inspect-browser"; 45 const char kInspectBrowser[] = "inspect-browser";
46 const char kLocalHost[] = "localhost"; 46 const char kLocalHost[] = "localhost";
47 47
48 const char kDiscoverUsbDevicesEnabledCommand[] = 48 const char kDiscoverUsbDevicesEnabledCommand[] =
49 "set-discover-usb-devices-enabled"; 49 "set-discover-usb-devices-enabled";
50 const char kPortForwardingEnabledCommand[] = 50 const char kPortForwardingEnabledCommand[] =
51 "set-port-forwarding-enabled"; 51 "set-port-forwarding-enabled";
52 const char kPortForwardingConfigCommand[] = "set-port-forwarding-config"; 52 const char kPortForwardingConfigCommand[] = "set-port-forwarding-config";
53 const char kTargetDiscoveryConfigCommand[] = "set-target-discovery-config";
53 54
54 const char kPortForwardingDefaultPort[] = "8080"; 55 const char kPortForwardingDefaultPort[] = "8080";
55 const char kPortForwardingDefaultLocation[] = "localhost:8080"; 56 const char kPortForwardingDefaultLocation[] = "localhost:8080";
56 57
57 // InspectMessageHandler -------------------------------------------- 58 // InspectMessageHandler --------------------------------------------
58 59
59 class InspectMessageHandler : public WebUIMessageHandler { 60 class InspectMessageHandler : public WebUIMessageHandler {
60 public: 61 public:
61 explicit InspectMessageHandler(InspectUI* inspect_ui) 62 explicit InspectMessageHandler(InspectUI* inspect_ui)
62 : inspect_ui_(inspect_ui) {} 63 : inspect_ui_(inspect_ui) {}
63 ~InspectMessageHandler() override {} 64 ~InspectMessageHandler() override {}
64 65
65 private: 66 private:
66 // WebUIMessageHandler implementation. 67 // WebUIMessageHandler implementation.
67 void RegisterMessages() override; 68 void RegisterMessages() override;
68 69
69 void HandleInitUICommand(const base::ListValue* args); 70 void HandleInitUICommand(const base::ListValue* args);
70 void HandleInspectCommand(const base::ListValue* args); 71 void HandleInspectCommand(const base::ListValue* args);
71 void HandleActivateCommand(const base::ListValue* args); 72 void HandleActivateCommand(const base::ListValue* args);
72 void HandleCloseCommand(const base::ListValue* args); 73 void HandleCloseCommand(const base::ListValue* args);
73 void HandleReloadCommand(const base::ListValue* args); 74 void HandleReloadCommand(const base::ListValue* args);
74 void HandleOpenCommand(const base::ListValue* args); 75 void HandleOpenCommand(const base::ListValue* args);
75 void HandleInspectBrowserCommand(const base::ListValue* args); 76 void HandleInspectBrowserCommand(const base::ListValue* args);
76 void HandleBooleanPrefChanged(const char* pref_name, 77 void HandleBooleanPrefChanged(const char* pref_name,
77 const base::ListValue* args); 78 const base::ListValue* args);
78 void HandlePortForwardingConfigCommand(const base::ListValue* args); 79 void HandlePortForwardingConfigCommand(const base::ListValue* args);
80 void HandleTargetDiscoveryConfigCommand(const base::ListValue* args);
79 81
80 InspectUI* inspect_ui_; 82 InspectUI* inspect_ui_;
81 83
82 DISALLOW_COPY_AND_ASSIGN(InspectMessageHandler); 84 DISALLOW_COPY_AND_ASSIGN(InspectMessageHandler);
83 }; 85 };
84 86
85 void InspectMessageHandler::RegisterMessages() { 87 void InspectMessageHandler::RegisterMessages() {
86 web_ui()->RegisterMessageCallback(kInitUICommand, 88 web_ui()->RegisterMessageCallback(kInitUICommand,
87 base::Bind(&InspectMessageHandler::HandleInitUICommand, 89 base::Bind(&InspectMessageHandler::HandleInitUICommand,
88 base::Unretained(this))); 90 base::Unretained(this)));
(...skipping 10 matching lines...) Expand all
99 base::Bind(&InspectMessageHandler::HandleBooleanPrefChanged, 101 base::Bind(&InspectMessageHandler::HandleBooleanPrefChanged,
100 base::Unretained(this), 102 base::Unretained(this),
101 &prefs::kDevToolsDiscoverUsbDevicesEnabled[0])); 103 &prefs::kDevToolsDiscoverUsbDevicesEnabled[0]));
102 web_ui()->RegisterMessageCallback(kPortForwardingEnabledCommand, 104 web_ui()->RegisterMessageCallback(kPortForwardingEnabledCommand,
103 base::Bind(&InspectMessageHandler::HandleBooleanPrefChanged, 105 base::Bind(&InspectMessageHandler::HandleBooleanPrefChanged,
104 base::Unretained(this), 106 base::Unretained(this),
105 &prefs::kDevToolsPortForwardingEnabled[0])); 107 &prefs::kDevToolsPortForwardingEnabled[0]));
106 web_ui()->RegisterMessageCallback(kPortForwardingConfigCommand, 108 web_ui()->RegisterMessageCallback(kPortForwardingConfigCommand,
107 base::Bind(&InspectMessageHandler::HandlePortForwardingConfigCommand, 109 base::Bind(&InspectMessageHandler::HandlePortForwardingConfigCommand,
108 base::Unretained(this))); 110 base::Unretained(this)));
111 web_ui()->RegisterMessageCallback(kTargetDiscoveryConfigCommand,
112 base::Bind(&InspectMessageHandler::HandleTargetDiscoveryConfigCommand,
113 base::Unretained(this)));
109 web_ui()->RegisterMessageCallback(kReloadCommand, 114 web_ui()->RegisterMessageCallback(kReloadCommand,
110 base::Bind(&InspectMessageHandler::HandleReloadCommand, 115 base::Bind(&InspectMessageHandler::HandleReloadCommand,
111 base::Unretained(this))); 116 base::Unretained(this)));
112 web_ui()->RegisterMessageCallback(kOpenCommand, 117 web_ui()->RegisterMessageCallback(kOpenCommand,
113 base::Bind(&InspectMessageHandler::HandleOpenCommand, 118 base::Bind(&InspectMessageHandler::HandleOpenCommand,
114 base::Unretained(this))); 119 base::Unretained(this)));
115 web_ui()->RegisterMessageCallback(kInspectBrowser, 120 web_ui()->RegisterMessageCallback(kInspectBrowser,
116 base::Bind(&InspectMessageHandler::HandleInspectBrowserCommand, 121 base::Bind(&InspectMessageHandler::HandleInspectBrowserCommand,
117 base::Unretained(this))); 122 base::Unretained(this)));
118 } 123 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const base::ListValue* args) { 199 const base::ListValue* args) {
195 Profile* profile = Profile::FromWebUI(web_ui()); 200 Profile* profile = Profile::FromWebUI(web_ui());
196 if (!profile) 201 if (!profile)
197 return; 202 return;
198 203
199 const base::DictionaryValue* dict_src; 204 const base::DictionaryValue* dict_src;
200 if (args->GetSize() == 1 && args->GetDictionary(0, &dict_src)) 205 if (args->GetSize() == 1 && args->GetDictionary(0, &dict_src))
201 profile->GetPrefs()->Set(prefs::kDevToolsPortForwardingConfig, *dict_src); 206 profile->GetPrefs()->Set(prefs::kDevToolsPortForwardingConfig, *dict_src);
202 } 207 }
203 208
209 void InspectMessageHandler::HandleTargetDiscoveryConfigCommand(
210 const base::ListValue* args) {
211 Profile* profile = Profile::FromWebUI(web_ui());
212 if (!profile)
213 return;
214
215 const base::ListValue* list_src;
216 if (args->GetSize() == 1 && args->GetList(0, &list_src))
217 profile->GetPrefs()->Set(prefs::kDevToolsTargetDiscoveryConfig, *list_src);
218 }
219
204 // DevToolsUIBindingsEnabler ---------------------------------------- 220 // DevToolsUIBindingsEnabler ----------------------------------------
205 221
206 class DevToolsUIBindingsEnabler 222 class DevToolsUIBindingsEnabler
207 : public content::WebContentsObserver { 223 : public content::WebContentsObserver {
208 public: 224 public:
209 DevToolsUIBindingsEnabler(WebContents* web_contents, 225 DevToolsUIBindingsEnabler(WebContents* web_contents,
210 const GURL& url); 226 const GURL& url);
211 ~DevToolsUIBindingsEnabler() override {} 227 ~DevToolsUIBindingsEnabler() override {}
212 228
213 DevToolsUIBindings* GetBindings(); 229 DevToolsUIBindings* GetBindings();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 InspectUI::~InspectUI() { 281 InspectUI::~InspectUI() {
266 StopListeningNotifications(); 282 StopListeningNotifications();
267 } 283 }
268 284
269 void InspectUI::InitUI() { 285 void InspectUI::InitUI() {
270 SetPortForwardingDefaults(); 286 SetPortForwardingDefaults();
271 StartListeningNotifications(); 287 StartListeningNotifications();
272 UpdateDiscoverUsbDevicesEnabled(); 288 UpdateDiscoverUsbDevicesEnabled();
273 UpdatePortForwardingEnabled(); 289 UpdatePortForwardingEnabled();
274 UpdatePortForwardingConfig(); 290 UpdatePortForwardingConfig();
291 UpdateTargetDiscoveryConfig();
275 } 292 }
276 293
277 void InspectUI::Inspect(const std::string& source_id, 294 void InspectUI::Inspect(const std::string& source_id,
278 const std::string& target_id) { 295 const std::string& target_id) {
279 DevToolsTargetImpl* target = FindTarget(source_id, target_id); 296 DevToolsTargetImpl* target = FindTarget(source_id, target_id);
280 if (target) { 297 if (target) {
281 const std::string target_type = target->GetType(); 298 const std::string target_type = target->GetType();
282 target->Inspect(Profile::FromWebUI(web_ui())); 299 target->Inspect(Profile::FromWebUI(web_ui()));
283 ForceUpdateIfNeeded(source_id, target_type); 300 ForceUpdateIfNeeded(source_id, target_type);
284 } 301 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 pref_change_registrar_.Init(profile->GetPrefs()); 420 pref_change_registrar_.Init(profile->GetPrefs());
404 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled, 421 pref_change_registrar_.Add(prefs::kDevToolsDiscoverUsbDevicesEnabled,
405 base::Bind(&InspectUI::UpdateDiscoverUsbDevicesEnabled, 422 base::Bind(&InspectUI::UpdateDiscoverUsbDevicesEnabled,
406 base::Unretained(this))); 423 base::Unretained(this)));
407 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, 424 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled,
408 base::Bind(&InspectUI::UpdatePortForwardingEnabled, 425 base::Bind(&InspectUI::UpdatePortForwardingEnabled,
409 base::Unretained(this))); 426 base::Unretained(this)));
410 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, 427 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig,
411 base::Bind(&InspectUI::UpdatePortForwardingConfig, 428 base::Bind(&InspectUI::UpdatePortForwardingConfig,
412 base::Unretained(this))); 429 base::Unretained(this)));
430 pref_change_registrar_.Add(prefs::kDevToolsTargetDiscoveryConfig,
431 base::Bind(&InspectUI::UpdateTargetDiscoveryConfig,
432 base::Unretained(this)));
413 } 433 }
414 434
415 void InspectUI::StopListeningNotifications() { 435 void InspectUI::StopListeningNotifications() {
416 if (target_handlers_.empty()) 436 if (target_handlers_.empty())
417 return; 437 return;
418 438
419 base::STLDeleteValues(&target_handlers_); 439 base::STLDeleteValues(&target_handlers_);
420 440
421 port_status_serializer_.reset(); 441 port_status_serializer_.reset();
422 442
(...skipping 21 matching lines...) Expand all
444 "updatePortForwardingEnabled", 464 "updatePortForwardingEnabled",
445 *GetPrefValue(prefs::kDevToolsPortForwardingEnabled)); 465 *GetPrefValue(prefs::kDevToolsPortForwardingEnabled));
446 } 466 }
447 467
448 void InspectUI::UpdatePortForwardingConfig() { 468 void InspectUI::UpdatePortForwardingConfig() {
449 web_ui()->CallJavascriptFunctionUnsafe( 469 web_ui()->CallJavascriptFunctionUnsafe(
450 "updatePortForwardingConfig", 470 "updatePortForwardingConfig",
451 *GetPrefValue(prefs::kDevToolsPortForwardingConfig)); 471 *GetPrefValue(prefs::kDevToolsPortForwardingConfig));
452 } 472 }
453 473
474 void InspectUI::UpdateTargetDiscoveryConfig() {
475 web_ui()->CallJavascriptFunctionUnsafe(
476 "updateTargetDiscoveryConfig",
477 *GetPrefValue(prefs::kDevToolsTargetDiscoveryConfig));
478 }
479
454 void InspectUI::SetPortForwardingDefaults() { 480 void InspectUI::SetPortForwardingDefaults() {
455 Profile* profile = Profile::FromWebUI(web_ui()); 481 Profile* profile = Profile::FromWebUI(web_ui());
456 PrefService* prefs = profile->GetPrefs(); 482 PrefService* prefs = profile->GetPrefs();
457 483
458 bool default_set; 484 bool default_set;
459 if (!GetPrefValue(prefs::kDevToolsPortForwardingDefaultSet)-> 485 if (!GetPrefValue(prefs::kDevToolsPortForwardingDefaultSet)->
460 GetAsBoolean(&default_set) || default_set) { 486 GetAsBoolean(&default_set) || default_set) {
461 return; 487 return;
462 } 488 }
463 489
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 handler->ForceUpdate(); 551 handler->ForceUpdate();
526 } 552 }
527 553
528 void InspectUI::PopulatePortStatus(const base::Value& status) { 554 void InspectUI::PopulatePortStatus(const base::Value& status) {
529 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); 555 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status);
530 } 556 }
531 557
532 void InspectUI::ShowIncognitoWarning() { 558 void InspectUI::ShowIncognitoWarning() {
533 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); 559 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning");
534 } 560 }
OLDNEW
« chrome/browser/resources/inspect/inspect.js ('K') | « chrome/browser/ui/webui/inspect_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698