OLD | NEW |
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/memory/ptr_util.h" |
9 #include "chrome/browser/devtools/devtools_targets_ui.h" | 9 #include "chrome/browser/devtools/devtools_targets_ui.h" |
10 #include "chrome/browser/devtools/devtools_ui_bindings.h" | 10 #include "chrome/browser/devtools/devtools_ui_bindings.h" |
11 #include "chrome/browser/devtools/devtools_window.h" | 11 #include "chrome/browser/devtools/devtools_window.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser_navigator_params.h" | 13 #include "chrome/browser/ui/browser_navigator_params.h" |
14 #include "chrome/browser/ui/singleton_tabs.h" | 14 #include "chrome/browser/ui/singleton_tabs.h" |
15 #include "chrome/browser/ui/webui/theme_source.h" | 15 #include "chrome/browser/ui/webui/theme_source.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
18 #include "chrome/grit/browser_resources.h" | 18 #include "chrome/grit/browser_resources.h" |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 base::Unretained(this))); | 440 base::Unretained(this))); |
441 pref_change_registrar_.Add(prefs::kDevToolsTCPDiscoveryConfig, | 441 pref_change_registrar_.Add(prefs::kDevToolsTCPDiscoveryConfig, |
442 base::Bind(&InspectUI::UpdateTCPDiscoveryConfig, | 442 base::Bind(&InspectUI::UpdateTCPDiscoveryConfig, |
443 base::Unretained(this))); | 443 base::Unretained(this))); |
444 } | 444 } |
445 | 445 |
446 void InspectUI::StopListeningNotifications() { | 446 void InspectUI::StopListeningNotifications() { |
447 if (target_handlers_.empty()) | 447 if (target_handlers_.empty()) |
448 return; | 448 return; |
449 | 449 |
450 base::STLDeleteValues(&target_handlers_); | 450 target_handlers_.clear(); |
451 | 451 |
452 port_status_serializer_.reset(); | 452 port_status_serializer_.reset(); |
453 | 453 |
454 notification_registrar_.RemoveAll(); | 454 notification_registrar_.RemoveAll(); |
455 pref_change_registrar_.RemoveAll(); | 455 pref_change_registrar_.RemoveAll(); |
456 } | 456 } |
457 | 457 |
458 content::WebUIDataSource* InspectUI::CreateInspectUIHTMLSource() { | 458 content::WebUIDataSource* InspectUI::CreateInspectUIHTMLSource() { |
459 content::WebUIDataSource* source = | 459 content::WebUIDataSource* source = |
460 content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); | 460 content::WebUIDataSource::Create(chrome::kChromeUIInspectHost); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 prefs->Set(prefs::kDevToolsPortForwardingConfig, default_config); | 527 prefs->Set(prefs::kDevToolsPortForwardingConfig, default_config); |
528 } | 528 } |
529 | 529 |
530 const base::Value* InspectUI::GetPrefValue(const char* name) { | 530 const base::Value* InspectUI::GetPrefValue(const char* name) { |
531 Profile* profile = Profile::FromWebUI(web_ui()); | 531 Profile* profile = Profile::FromWebUI(web_ui()); |
532 return profile->GetPrefs()->FindPreference(name)->GetValue(); | 532 return profile->GetPrefs()->FindPreference(name)->GetValue(); |
533 } | 533 } |
534 | 534 |
535 void InspectUI::AddTargetUIHandler( | 535 void InspectUI::AddTargetUIHandler( |
536 std::unique_ptr<DevToolsTargetsUIHandler> handler) { | 536 std::unique_ptr<DevToolsTargetsUIHandler> handler) { |
537 DevToolsTargetsUIHandler* handler_ptr = handler.release(); | 537 std::string id = handler->source_id(); |
538 target_handlers_[handler_ptr->source_id()] = handler_ptr; | 538 target_handlers_[id] = std::move(handler); |
539 } | 539 } |
540 | 540 |
541 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler( | 541 DevToolsTargetsUIHandler* InspectUI::FindTargetHandler( |
542 const std::string& source_id) { | 542 const std::string& source_id) { |
543 TargetHandlerMap::iterator it = target_handlers_.find(source_id); | 543 auto it = target_handlers_.find(source_id); |
544 return it != target_handlers_.end() ? it->second : nullptr; | 544 return it != target_handlers_.end() ? it->second.get() : nullptr; |
545 } | 545 } |
546 | 546 |
547 scoped_refptr<content::DevToolsAgentHost> InspectUI::FindTarget( | 547 scoped_refptr<content::DevToolsAgentHost> InspectUI::FindTarget( |
548 const std::string& source_id, const std::string& target_id) { | 548 const std::string& source_id, const std::string& target_id) { |
549 TargetHandlerMap::iterator it = target_handlers_.find(source_id); | 549 auto it = target_handlers_.find(source_id); |
550 return it != target_handlers_.end() ? | 550 return it != target_handlers_.end() ? |
551 it->second->GetTarget(target_id) : nullptr; | 551 it->second->GetTarget(target_id) : nullptr; |
552 } | 552 } |
553 | 553 |
554 void InspectUI::PopulateTargets(const std::string& source, | 554 void InspectUI::PopulateTargets(const std::string& source, |
555 const base::ListValue& targets) { | 555 const base::ListValue& targets) { |
556 web_ui()->CallJavascriptFunctionUnsafe("populateTargets", | 556 web_ui()->CallJavascriptFunctionUnsafe("populateTargets", |
557 base::StringValue(source), targets); | 557 base::StringValue(source), targets); |
558 } | 558 } |
559 | 559 |
560 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id, | 560 void InspectUI::ForceUpdateIfNeeded(const std::string& source_id, |
561 const std::string& target_type) { | 561 const std::string& target_type) { |
562 // TODO(dgozman): remove this after moving discovery to protocol. | 562 // TODO(dgozman): remove this after moving discovery to protocol. |
563 // See crbug.com/398049. | 563 // See crbug.com/398049. |
564 if (target_type != content::DevToolsAgentHost::kTypeServiceWorker) | 564 if (target_type != content::DevToolsAgentHost::kTypeServiceWorker) |
565 return; | 565 return; |
566 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id); | 566 DevToolsTargetsUIHandler* handler = FindTargetHandler(source_id); |
567 if (handler) | 567 if (handler) |
568 handler->ForceUpdate(); | 568 handler->ForceUpdate(); |
569 } | 569 } |
570 | 570 |
571 void InspectUI::PopulatePortStatus(const base::Value& status) { | 571 void InspectUI::PopulatePortStatus(const base::Value& status) { |
572 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); | 572 web_ui()->CallJavascriptFunctionUnsafe("populatePortStatus", status); |
573 } | 573 } |
574 | 574 |
575 void InspectUI::ShowIncognitoWarning() { | 575 void InspectUI::ShowIncognitoWarning() { |
576 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); | 576 web_ui()->CallJavascriptFunctionUnsafe("showIncognitoWarning"); |
577 } | 577 } |
OLD | NEW |