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/devtools/devtools_window.h" | 5 #include "chrome/browser/devtools/devtools_window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 18 #include "chrome/browser/devtools/list_value_parser.h" |
17 #include "chrome/browser/extensions/api/debugger/debugger_api.h" | 19 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
20 #include "chrome/browser/file_select_helper.h" | 22 #include "chrome/browser/file_select_helper.h" |
21 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 23 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
22 #include "chrome/browser/prefs/pref_service_syncable.h" | 24 #include "chrome/browser/prefs/pref_service_syncable.h" |
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 25 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/sessions/session_tab_helper.h" | 27 #include "chrome/browser/sessions/session_tab_helper.h" |
26 #include "chrome/browser/themes/theme_properties.h" | 28 #include "chrome/browser/themes/theme_properties.h" |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, nav_controller_source); | 577 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, nav_controller_source); |
576 registrar_.Add( | 578 registrar_.Add( |
577 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 579 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
578 content::Source<ThemeService>( | 580 content::Source<ThemeService>( |
579 ThemeServiceFactory::GetForProfile(profile_))); | 581 ThemeServiceFactory::GetForProfile(profile_))); |
580 | 582 |
581 // There is no inspected_rvh in case of shared workers. | 583 // There is no inspected_rvh in case of shared workers. |
582 if (inspected_rvh) | 584 if (inspected_rvh) |
583 inspected_contents_observer_.reset(new InspectedWebContentsObserver( | 585 inspected_contents_observer_.reset(new InspectedWebContentsObserver( |
584 content::WebContents::FromRenderViewHost(inspected_rvh))); | 586 content::WebContents::FromRenderViewHost(inspected_rvh))); |
| 587 |
| 588 RegisterFrontendMessageHandler("bringToFront", |
| 589 BindToListParser(base::Bind(&DevToolsWindow::ActivateWindow, |
| 590 base::Unretained(this)))); |
| 591 RegisterFrontendMessageHandler("closeWindow", |
| 592 BindToListParser(base::Bind(&DevToolsWindow::CloseWindow, |
| 593 base::Unretained(this)))); |
| 594 RegisterFrontendMessageHandler("moveWindowBy", |
| 595 BindToListParser(base::Bind(&DevToolsWindow::MoveWindow, |
| 596 base::Unretained(this)))); |
| 597 RegisterFrontendMessageHandler("requestSetDockSide", |
| 598 BindToListParser(base::Bind(&DevToolsWindow::SetDockSide, |
| 599 base::Unretained(this)))); |
| 600 RegisterFrontendMessageHandler("openInNewTab", |
| 601 BindToListParser(base::Bind(&DevToolsWindow::OpenInNewTab, |
| 602 base::Unretained(this)))); |
| 603 RegisterFrontendMessageHandler("save", |
| 604 BindToListParser(base::Bind(&DevToolsWindow::SaveToFile, |
| 605 base::Unretained(this)))); |
| 606 RegisterFrontendMessageHandler("append", |
| 607 BindToListParser(base::Bind(&DevToolsWindow::AppendToFile, |
| 608 base::Unretained(this)))); |
| 609 RegisterFrontendMessageHandler("requestFileSystems", |
| 610 BindToListParser(base::Bind(&DevToolsWindow::RequestFileSystems, |
| 611 base::Unretained(this)))); |
| 612 RegisterFrontendMessageHandler("addFileSystem", |
| 613 BindToListParser(base::Bind(&DevToolsWindow::AddFileSystem, |
| 614 base::Unretained(this)))); |
| 615 RegisterFrontendMessageHandler("removeFileSystem", |
| 616 BindToListParser(base::Bind(&DevToolsWindow::RemoveFileSystem, |
| 617 base::Unretained(this)))); |
| 618 RegisterFrontendMessageHandler("indexPath", |
| 619 BindToListParser(base::Bind(&DevToolsWindow::IndexPath, |
| 620 base::Unretained(this)))); |
| 621 RegisterFrontendMessageHandler("stopIndexing", |
| 622 BindToListParser(base::Bind(&DevToolsWindow::StopIndexing, |
| 623 base::Unretained(this)))); |
| 624 RegisterFrontendMessageHandler("searchInPath", |
| 625 BindToListParser(base::Bind(&DevToolsWindow::SearchInPath, |
| 626 base::Unretained(this)))); |
585 } | 627 } |
586 | 628 |
587 // static | 629 // static |
588 DevToolsWindow* DevToolsWindow::Create( | 630 DevToolsWindow* DevToolsWindow::Create( |
589 Profile* profile, | 631 Profile* profile, |
590 const GURL& frontend_url, | 632 const GURL& frontend_url, |
591 content::RenderViewHost* inspected_rvh, | 633 content::RenderViewHost* inspected_rvh, |
592 DevToolsDockSide dock_side, | 634 DevToolsDockSide dock_side, |
593 bool shared_worker_frontend) { | 635 bool shared_worker_frontend) { |
594 // Create WebContents with devtools. | 636 // Create WebContents with devtools. |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 } | 857 } |
816 | 858 |
817 void DevToolsWindow::WebContentsFocused(content::WebContents* contents) { | 859 void DevToolsWindow::WebContentsFocused(content::WebContents* contents) { |
818 Browser* inspected_browser = NULL; | 860 Browser* inspected_browser = NULL; |
819 int inspected_tab_index = -1; | 861 int inspected_tab_index = -1; |
820 if (IsDocked() && FindInspectedBrowserAndTabIndex(&inspected_browser, | 862 if (IsDocked() && FindInspectedBrowserAndTabIndex(&inspected_browser, |
821 &inspected_tab_index)) | 863 &inspected_tab_index)) |
822 inspected_browser->window()->WebContentsFocused(contents); | 864 inspected_browser->window()->WebContentsFocused(contents); |
823 } | 865 } |
824 | 866 |
| 867 static const char kFrontendHostMethod[] = "method"; |
| 868 static const char kFrontendHostParams[] = "params"; |
| 869 |
| 870 void DevToolsWindow::DispatchOnFrontendHost(const std::string& message) { |
| 871 std::string method; |
| 872 base::ListValue empty_params; |
| 873 base::ListValue* params = &empty_params; |
| 874 |
| 875 base::DictionaryValue* dict; |
| 876 scoped_ptr<base::Value> parsed_message(base::JSONReader::Read(message)); |
| 877 if (!parsed_message || |
| 878 !parsed_message->GetAsDictionary(&dict) || |
| 879 !dict->GetString(kFrontendHostMethod, &method) || |
| 880 (dict->HasKey(kFrontendHostParams) && |
| 881 !dict->GetList(kFrontendHostParams, ¶ms))) { |
| 882 LOG(ERROR) << "Cannot parse frontend host message: " << message; |
| 883 return; |
| 884 } |
| 885 |
| 886 FrontendMessageHandlerMap::iterator it = |
| 887 frontend_message_handlers_.find(method); |
| 888 if (it == frontend_message_handlers_.end()) { |
| 889 LOG(ERROR) << "Unsupported frontend host method: " << message; |
| 890 return; |
| 891 } |
| 892 |
| 893 if (!it->second.Run(*params)) { |
| 894 LOG(ERROR) << "Invalid frontend host message parameters: " << message; |
| 895 } else { |
| 896 LOG(ERROR) << "DevToolsWindow dispatched: " << message; |
| 897 } |
| 898 } |
| 899 |
| 900 void DevToolsWindow::RegisterFrontendMessageHandler( |
| 901 const std::string& method, |
| 902 const FrontendMessageHandler& handler) { |
| 903 frontend_message_handlers_[method] = handler; |
| 904 } |
| 905 |
825 void DevToolsWindow::ActivateWindow() { | 906 void DevToolsWindow::ActivateWindow() { |
826 if (IsDocked() && GetInspectedBrowserWindow()) | 907 if (IsDocked() && GetInspectedBrowserWindow()) |
827 web_contents_->GetView()->Focus(); | 908 web_contents_->GetView()->Focus(); |
828 else if (!IsDocked() && !browser_->window()->IsActive()) | 909 else if (!IsDocked() && !browser_->window()->IsActive()) |
829 browser_->window()->Activate(); | 910 browser_->window()->Activate(); |
830 } | 911 } |
831 | 912 |
832 void DevToolsWindow::ChangeAttachedWindowHeight(unsigned height) { | |
833 NOTREACHED(); // TODO(dgozman): This is not used anymore, remove. | |
834 } | |
835 | |
836 void DevToolsWindow::CloseWindow() { | 913 void DevToolsWindow::CloseWindow() { |
837 DCHECK(IsDocked()); | 914 DCHECK(IsDocked()); |
838 content::DevToolsManager::GetInstance()->ClientHostClosing( | 915 content::DevToolsManager::GetInstance()->ClientHostClosing( |
839 frontend_host_.get()); | 916 frontend_host_.get()); |
840 Hide(); | 917 Hide(); |
841 } | 918 } |
842 | 919 |
843 void DevToolsWindow::MoveWindow(int x, int y) { | 920 void DevToolsWindow::MoveWindow(int x, int y) { |
844 if (!IsDocked()) { | 921 if (!IsDocked()) { |
845 gfx::Rect bounds = browser_->window()->GetBounds(); | 922 gfx::Rect bounds = browser_->window()->GetBounds(); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 | 1395 |
1319 void DevToolsWindow::Restore() { | 1396 void DevToolsWindow::Restore() { |
1320 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) | 1397 if (dock_side_ == DEVTOOLS_DOCK_SIDE_MINIMIZED) |
1321 SetDockSide(SideToString(dock_side_before_minimized_)); | 1398 SetDockSide(SideToString(dock_side_before_minimized_)); |
1322 } | 1399 } |
1323 | 1400 |
1324 content::WebContents* DevToolsWindow::GetInspectedWebContents() { | 1401 content::WebContents* DevToolsWindow::GetInspectedWebContents() { |
1325 return inspected_contents_observer_ ? | 1402 return inspected_contents_observer_ ? |
1326 inspected_contents_observer_->web_contents() : NULL; | 1403 inspected_contents_observer_->web_contents() : NULL; |
1327 } | 1404 } |
OLD | NEW |