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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "content/public/browser/favicon_status.h" | 39 #include "content/public/browser/favicon_status.h" |
40 #include "content/public/browser/load_notification_details.h" | 40 #include "content/public/browser/load_notification_details.h" |
41 #include "content/public/browser/navigation_controller.h" | 41 #include "content/public/browser/navigation_controller.h" |
42 #include "content/public/browser/navigation_entry.h" | 42 #include "content/public/browser/navigation_entry.h" |
43 #include "content/public/browser/notification_source.h" | 43 #include "content/public/browser/notification_source.h" |
44 #include "content/public/browser/render_process_host.h" | 44 #include "content/public/browser/render_process_host.h" |
45 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
47 #include "content/public/browser/web_contents_view.h" | 47 #include "content/public/browser/web_contents_view.h" |
48 #include "content/public/common/bindings_policy.h" | 48 #include "content/public/common/bindings_policy.h" |
| 49 #include "content/public/common/content_client.h" |
49 #include "content/public/common/page_transition_types.h" | 50 #include "content/public/common/page_transition_types.h" |
50 #include "grit/generated_resources.h" | 51 #include "grit/generated_resources.h" |
51 | 52 |
52 typedef std::vector<DevToolsWindow*> DevToolsWindowList; | 53 typedef std::vector<DevToolsWindow*> DevToolsWindowList; |
53 namespace { | 54 namespace { |
54 base::LazyInstance<DevToolsWindowList>::Leaky | 55 base::LazyInstance<DevToolsWindowList>::Leaky |
55 g_instances = LAZY_INSTANCE_INITIALIZER; | 56 g_instances = LAZY_INSTANCE_INITIALIZER; |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 using base::Bind; | 59 using base::Bind; |
(...skipping 30 matching lines...) Expand all Loading... |
89 // static | 90 // static |
90 void DevToolsWindow::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 91 void DevToolsWindow::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
91 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, | 92 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, |
92 true, | 93 true, |
93 PrefServiceSyncable::UNSYNCABLE_PREF); | 94 PrefServiceSyncable::UNSYNCABLE_PREF); |
94 prefs->RegisterStringPref(prefs::kDevToolsDockSide, | 95 prefs->RegisterStringPref(prefs::kDevToolsDockSide, |
95 kDockSideBottom, | 96 kDockSideBottom, |
96 PrefServiceSyncable::UNSYNCABLE_PREF); | 97 PrefServiceSyncable::UNSYNCABLE_PREF); |
97 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, | 98 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, |
98 PrefServiceSyncable::UNSYNCABLE_PREF); | 99 PrefServiceSyncable::UNSYNCABLE_PREF); |
| 100 prefs->RegisterDictionaryPref(prefs::kDevToolsFilesystemPaths, |
| 101 PrefServiceSyncable::UNSYNCABLE_PREF); |
99 } | 102 } |
100 | 103 |
101 // static | 104 // static |
102 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( | 105 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( |
103 WebContents* inspected_web_contents) { | 106 WebContents* inspected_web_contents) { |
104 if (!inspected_web_contents) | 107 if (!inspected_web_contents) |
105 return NULL; | 108 return NULL; |
106 | 109 |
107 if (!DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) | 110 if (!DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) |
108 return NULL; | 111 return NULL; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 web_contents_(web_contents), | 211 web_contents_(web_contents), |
209 browser_(NULL), | 212 browser_(NULL), |
210 dock_side_(dock_side), | 213 dock_side_(dock_side), |
211 is_loaded_(false), | 214 is_loaded_(false), |
212 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), | 215 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), |
213 weak_factory_(this), | 216 weak_factory_(this), |
214 width_(-1), | 217 width_(-1), |
215 height_(-1) { | 218 height_(-1) { |
216 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost(web_contents, | 219 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost(web_contents, |
217 this); | 220 this); |
218 file_helper_.reset(new DevToolsFileHelper(profile)); | 221 file_helper_.reset(new DevToolsFileHelper(web_contents, profile)); |
219 | 222 |
220 g_instances.Get().push_back(this); | 223 g_instances.Get().push_back(this); |
221 // Wipe out page icon so that the default application icon is used. | 224 // Wipe out page icon so that the default application icon is used. |
222 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); | 225 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); |
223 entry->GetFavicon().image = gfx::Image(); | 226 entry->GetFavicon().image = gfx::Image(); |
224 entry->GetFavicon().valid = true; | 227 entry->GetFavicon().valid = true; |
225 | 228 |
226 // Register on-load actions. | 229 // Register on-load actions. |
227 registrar_.Add( | 230 registrar_.Add( |
228 this, | 231 this, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 } | 503 } |
501 | 504 |
502 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, | 505 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, |
503 const OpenURLParams& params) { | 506 const OpenURLParams& params) { |
504 if (inspected_web_contents_) | 507 if (inspected_web_contents_) |
505 return inspected_web_contents_->OpenURL(params); | 508 return inspected_web_contents_->OpenURL(params); |
506 return NULL; | 509 return NULL; |
507 } | 510 } |
508 | 511 |
509 void DevToolsWindow::CallClientFunction(const std::string& function_name, | 512 void DevToolsWindow::CallClientFunction(const std::string& function_name, |
510 const Value* arg) { | 513 const Value* arg1, |
511 std::string json; | 514 const Value* arg2) { |
512 if (arg) | 515 std::string params; |
513 base::JSONWriter::Write(arg, &json); | 516 if (arg1) { |
514 | 517 std::string json; |
515 string16 javascript = | 518 base::JSONWriter::Write(arg1, &json); |
516 ASCIIToUTF16(function_name + "(" + json + ");"); | 519 params.append(json); |
| 520 if (arg2) { |
| 521 base::JSONWriter::Write(arg2, &json); |
| 522 params.append(", " + json); |
| 523 } |
| 524 } |
| 525 string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");"); |
517 web_contents_->GetRenderViewHost()-> | 526 web_contents_->GetRenderViewHost()-> |
518 ExecuteJavascriptInWebFrame(string16(), javascript); | 527 ExecuteJavascriptInWebFrame(string16(), javascript); |
519 } | 528 } |
520 | 529 |
521 void DevToolsWindow::Observe(int type, | 530 void DevToolsWindow::Observe(int type, |
522 const content::NotificationSource& source, | 531 const content::NotificationSource& source, |
523 const content::NotificationDetails& details) { | 532 const content::NotificationDetails& details) { |
524 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { | 533 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { |
525 is_loaded_ = true; | 534 is_loaded_ = true; |
526 UpdateTheme(); | 535 UpdateTheme(); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 url)); | 828 url)); |
820 } | 829 } |
821 | 830 |
822 void DevToolsWindow::AppendToFile(const std::string& url, | 831 void DevToolsWindow::AppendToFile(const std::string& url, |
823 const std::string& content) { | 832 const std::string& content) { |
824 file_helper_->Append(url, content, Bind(&DevToolsWindow::AppendedTo, | 833 file_helper_->Append(url, content, Bind(&DevToolsWindow::AppendedTo, |
825 weak_factory_.GetWeakPtr(), | 834 weak_factory_.GetWeakPtr(), |
826 url)); | 835 url)); |
827 } | 836 } |
828 | 837 |
| 838 namespace { |
| 839 |
| 840 DictionaryValue* CreateFilesystemValue( |
| 841 DevToolsFileHelper::Filesystem filesystem) { |
| 842 DictionaryValue* filesystem_value = new DictionaryValue(); |
| 843 filesystem_value->SetString("filesystemId", filesystem.filesystem_id); |
| 844 filesystem_value->SetString("registeredName", filesystem.registered_name); |
| 845 filesystem_value->SetString("filesystemPath", filesystem.filesystem_path); |
| 846 return filesystem_value; |
| 847 } |
| 848 |
| 849 } // namespace |
| 850 |
| 851 void DevToolsWindow::RequestFilesystems() { |
| 852 CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL())); |
| 853 file_helper_->RequestFilesystems( |
| 854 Bind(&DevToolsWindow::FilesystemsLoaded, weak_factory_.GetWeakPtr())); |
| 855 } |
| 856 |
| 857 void DevToolsWindow::AddFilesystem() { |
| 858 CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL())); |
| 859 file_helper_->AddFilesystem( |
| 860 Bind(&DevToolsWindow::FilesystemAdded, weak_factory_.GetWeakPtr())); |
| 861 } |
| 862 |
| 863 void DevToolsWindow::RemoveFilesystem(const std::string& filesystem_path) { |
| 864 CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL())); |
| 865 file_helper_->RemoveFilesystem(filesystem_path); |
| 866 StringValue filesystem_path_value(filesystem_path); |
| 867 CallClientFunction("InspectorFrontendAPI.filesystemRemoved", |
| 868 &filesystem_path_value); |
| 869 } |
| 870 |
829 void DevToolsWindow::FileSavedAs(const std::string& url) { | 871 void DevToolsWindow::FileSavedAs(const std::string& url) { |
830 StringValue url_value(url); | 872 StringValue url_value(url); |
831 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); | 873 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); |
832 } | 874 } |
833 | 875 |
834 void DevToolsWindow::AppendedTo(const std::string& url) { | 876 void DevToolsWindow::AppendedTo(const std::string& url) { |
835 StringValue url_value(url); | 877 StringValue url_value(url); |
836 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); | 878 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); |
837 } | 879 } |
838 | 880 |
| 881 void DevToolsWindow::FilesystemsLoaded( |
| 882 const std::vector<DevToolsFileHelper::Filesystem>& filesystems) { |
| 883 ListValue filesystems_value; |
| 884 for (size_t i = 0; i < filesystems.size(); ++i) { |
| 885 filesystems_value.Append(CreateFilesystemValue(filesystems[i])); |
| 886 } |
| 887 CallClientFunction("InspectorFrontendAPI.filesystemsLoaded", |
| 888 &filesystems_value); |
| 889 } |
| 890 |
| 891 void DevToolsWindow::FilesystemAdded( |
| 892 std::string error_string, |
| 893 const DevToolsFileHelper::Filesystem& filesystem) { |
| 894 StringValue error_string_value(error_string); |
| 895 DictionaryValue* filesystem_value = NULL; |
| 896 if (!filesystem.filesystem_path.empty()) |
| 897 filesystem_value = CreateFilesystemValue(filesystem); |
| 898 CallClientFunction("InspectorFrontendAPI.filesystemAdded", |
| 899 &error_string_value, |
| 900 filesystem_value); |
| 901 if (filesystem_value) |
| 902 delete filesystem_value; |
| 903 } |
| 904 |
839 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { | 905 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { |
840 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { | 906 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { |
841 return inspected_web_contents_->GetDelegate()-> | 907 return inspected_web_contents_->GetDelegate()-> |
842 GetJavaScriptDialogCreator(); | 908 GetJavaScriptDialogCreator(); |
843 } | 909 } |
844 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); | 910 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); |
845 } | 911 } |
846 | 912 |
847 void DevToolsWindow::RunFileChooser(WebContents* web_contents, | 913 void DevToolsWindow::RunFileChooser(WebContents* web_contents, |
848 const FileChooserParams& params) { | 914 const FileChooserParams& params) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 | 972 |
907 // static | 973 // static |
908 DevToolsDockSide DevToolsWindow::SideFromString( | 974 DevToolsDockSide DevToolsWindow::SideFromString( |
909 const std::string& dock_side) { | 975 const std::string& dock_side) { |
910 if (dock_side == kDockSideRight) | 976 if (dock_side == kDockSideRight) |
911 return DEVTOOLS_DOCK_SIDE_RIGHT; | 977 return DEVTOOLS_DOCK_SIDE_RIGHT; |
912 if (dock_side == kDockSideBottom) | 978 if (dock_side == kDockSideBottom) |
913 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 979 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
914 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 980 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
915 } | 981 } |
OLD | NEW |