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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 // static | 89 // static |
90 void DevToolsWindow::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 90 void DevToolsWindow::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
91 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, | 91 prefs->RegisterBooleanPref(prefs::kDevToolsOpenDocked, |
92 true, | 92 true, |
93 PrefServiceSyncable::UNSYNCABLE_PREF); | 93 PrefServiceSyncable::UNSYNCABLE_PREF); |
94 prefs->RegisterStringPref(prefs::kDevToolsDockSide, | 94 prefs->RegisterStringPref(prefs::kDevToolsDockSide, |
95 kDockSideBottom, | 95 kDockSideBottom, |
96 PrefServiceSyncable::UNSYNCABLE_PREF); | 96 PrefServiceSyncable::UNSYNCABLE_PREF); |
97 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, | 97 prefs->RegisterDictionaryPref(prefs::kDevToolsEditedFiles, |
98 PrefServiceSyncable::UNSYNCABLE_PREF); | 98 PrefServiceSyncable::UNSYNCABLE_PREF); |
99 prefs->RegisterDictionaryPref(prefs::kDevToolsSavedFileSystemPathes, | |
pfeldman
2012/12/24 19:01:03
Paths
| |
100 PrefServiceSyncable::UNSYNCABLE_PREF); | |
99 } | 101 } |
100 | 102 |
101 // static | 103 // static |
102 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( | 104 DevToolsWindow* DevToolsWindow::GetDockedInstanceForInspectedTab( |
103 WebContents* inspected_web_contents) { | 105 WebContents* inspected_web_contents) { |
104 if (!inspected_web_contents) | 106 if (!inspected_web_contents) |
105 return NULL; | 107 return NULL; |
106 | 108 |
107 if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost( | 109 if (!DevToolsAgentHostRegistry::HasDevToolsAgentHost( |
108 inspected_web_contents->GetRenderViewHost())) | 110 inspected_web_contents->GetRenderViewHost())) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 web_contents_(web_contents), | 211 web_contents_(web_contents), |
210 browser_(NULL), | 212 browser_(NULL), |
211 dock_side_(dock_side), | 213 dock_side_(dock_side), |
212 is_loaded_(false), | 214 is_loaded_(false), |
213 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), | 215 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), |
214 width_(-1), | 216 width_(-1), |
215 height_(-1) { | 217 height_(-1) { |
216 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost(web_contents, | 218 frontend_host_ = DevToolsClientHost::CreateDevToolsFrontendHost(web_contents, |
217 this); | 219 this); |
218 file_helper_.reset(new DevToolsFileHelper(profile, this)); | 220 file_helper_.reset(new DevToolsFileHelper(profile, this)); |
221 file_system_helper_ = new DevToolsFileSystemHelper(web_contents, | |
222 profile, | |
223 this); | |
219 | 224 |
220 g_instances.Get().push_back(this); | 225 g_instances.Get().push_back(this); |
221 // Wipe out page icon so that the default application icon is used. | 226 // Wipe out page icon so that the default application icon is used. |
222 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); | 227 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); |
223 entry->GetFavicon().image = gfx::Image(); | 228 entry->GetFavicon().image = gfx::Image(); |
224 entry->GetFavicon().valid = true; | 229 entry->GetFavicon().valid = true; |
225 | 230 |
226 // Register on-load actions. | 231 // Register on-load actions. |
227 registrar_.Add( | 232 registrar_.Add( |
228 this, | 233 this, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 } | 505 } |
501 | 506 |
502 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, | 507 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, |
503 const OpenURLParams& params) { | 508 const OpenURLParams& params) { |
504 if (inspected_web_contents_) | 509 if (inspected_web_contents_) |
505 return inspected_web_contents_->OpenURL(params); | 510 return inspected_web_contents_->OpenURL(params); |
506 return NULL; | 511 return NULL; |
507 } | 512 } |
508 | 513 |
509 void DevToolsWindow::CallClientFunction(const std::string& function_name, | 514 void DevToolsWindow::CallClientFunction(const std::string& function_name, |
510 const Value* arg) { | 515 const Value* arg1, |
511 std::string json; | 516 const Value* arg2) { |
512 if (arg) | 517 std::string params; |
513 base::JSONWriter::Write(arg, &json); | 518 if (arg1) { |
514 | 519 std::string json; |
515 string16 javascript = | 520 base::JSONWriter::Write(arg1, &json); |
516 ASCIIToUTF16(function_name + "(" + json + ");"); | 521 params.append(json); |
522 if (arg2) { | |
523 base::JSONWriter::Write(arg2, &json); | |
524 params.append(", " + json); | |
525 } | |
526 } | |
527 string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");"); | |
517 web_contents_->GetRenderViewHost()-> | 528 web_contents_->GetRenderViewHost()-> |
518 ExecuteJavascriptInWebFrame(string16(), javascript); | 529 ExecuteJavascriptInWebFrame(string16(), javascript); |
519 } | 530 } |
520 | 531 |
521 void DevToolsWindow::Observe(int type, | 532 void DevToolsWindow::Observe(int type, |
522 const content::NotificationSource& source, | 533 const content::NotificationSource& source, |
523 const content::NotificationDetails& details) { | 534 const content::NotificationDetails& details) { |
524 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { | 535 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { |
525 is_loaded_ = true; | 536 is_loaded_ = true; |
526 UpdateTheme(); | 537 UpdateTheme(); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 const std::string& content, | 826 const std::string& content, |
816 bool save_as) { | 827 bool save_as) { |
817 file_helper_->Save(url, content, save_as); | 828 file_helper_->Save(url, content, save_as); |
818 } | 829 } |
819 | 830 |
820 void DevToolsWindow::AppendToFile(const std::string& url, | 831 void DevToolsWindow::AppendToFile(const std::string& url, |
821 const std::string& content) { | 832 const std::string& content) { |
822 file_helper_->Append(url, content); | 833 file_helper_->Append(url, content); |
823 } | 834 } |
824 | 835 |
836 namespace { | |
837 | |
838 DictionaryValue* CreateFileSystemValue( | |
pfeldman
2012/12/24 19:01:03
You should also make this function static instead
| |
839 DevToolsFileSystemHelper::FileSystem file_system) { | |
840 DictionaryValue* file_system_value = new DictionaryValue(); | |
841 file_system_value->SetString("fileSystemId", file_system.filesystem_id); | |
842 file_system_value->SetString("registeredName", file_system.registered_name); | |
843 file_system_value->SetString("fileSystemPath", file_system.file_system_path); | |
844 return file_system_value; | |
845 } | |
846 | |
847 } // namespace | |
848 | |
849 void DevToolsWindow::RequestFileSystemPermissions() { | |
850 file_system_helper_->RequestPermissions(); | |
851 } | |
852 | |
853 void DevToolsWindow::SelectFolderAndGrantFileSystemPermission() { | |
854 file_system_helper_->SelectFolderAndGrantPermission(); | |
855 } | |
856 | |
857 void DevToolsWindow::RevokeFileSystemPermission( | |
858 const std::string& file_system_path) { | |
859 file_system_helper_->RevokePermission(file_system_path); | |
860 | |
861 StringValue file_system_path_value(file_system_path); | |
862 CallClientFunction("InspectorFrontendAPI.fileSystemFolderPermissionsRevoked", | |
863 &file_system_path_value); | |
864 } | |
865 | |
825 void DevToolsWindow::FileSavedAs(const std::string& url) { | 866 void DevToolsWindow::FileSavedAs(const std::string& url) { |
826 StringValue url_value(url); | 867 StringValue url_value(url); |
827 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); | 868 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); |
828 } | 869 } |
829 | 870 |
830 void DevToolsWindow::AppendedTo(const std::string& url) { | 871 void DevToolsWindow::AppendedTo(const std::string& url) { |
831 StringValue url_value(url); | 872 StringValue url_value(url); |
832 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); | 873 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); |
833 } | 874 } |
834 | 875 |
876 void DevToolsWindow::FileSystemPermissionsLoaded( | |
877 std::vector<DevToolsFileSystemHelper::FileSystem> file_systems) { | |
878 ListValue file_systems_value; | |
879 for (size_t i = 0; i < file_systems.size(); ++i) { | |
880 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); | |
881 } | |
882 CallClientFunction("InspectorFrontendAPI.fileSystemPermissionsLoaded", | |
883 &file_systems_value); | |
884 } | |
885 | |
886 void DevToolsWindow::FileSystemFolderSelected( | |
887 DevToolsFileSystemHelper::FileSystem file_system) { | |
888 DictionaryValue* file_system_value = CreateFileSystemValue(file_system); | |
889 StringValue error_string_value(""); | |
890 CallClientFunction("InspectorFrontendAPI.fileSystemFolderSelected", | |
891 &error_string_value, | |
892 file_system_value); | |
893 delete file_system_value; | |
894 } | |
895 | |
896 void DevToolsWindow::FileSystemFolderSelectionCanceled() { | |
897 CallClientFunction("InspectorFrontendAPI.fileSystemFolderSelected"); | |
898 } | |
899 | |
900 void DevToolsWindow::FileSystemFolderSelectionError(std::string error_string) { | |
901 StringValue error_string_value(error_string); | |
902 CallClientFunction("InspectorFrontendAPI.fileSystemFolderSelected", | |
903 &error_string_value); | |
904 } | |
905 | |
835 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { | 906 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { |
836 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { | 907 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { |
837 return inspected_web_contents_->GetDelegate()-> | 908 return inspected_web_contents_->GetDelegate()-> |
838 GetJavaScriptDialogCreator(); | 909 GetJavaScriptDialogCreator(); |
839 } | 910 } |
840 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); | 911 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); |
841 } | 912 } |
842 | 913 |
843 void DevToolsWindow::RunFileChooser(WebContents* web_contents, | 914 void DevToolsWindow::RunFileChooser(WebContents* web_contents, |
844 const FileChooserParams& params) { | 915 const FileChooserParams& params) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 | 973 |
903 // static | 974 // static |
904 DevToolsDockSide DevToolsWindow::SideFromString( | 975 DevToolsDockSide DevToolsWindow::SideFromString( |
905 const std::string& dock_side) { | 976 const std::string& dock_side) { |
906 if (dock_side == kDockSideRight) | 977 if (dock_side == kDockSideRight) |
907 return DEVTOOLS_DOCK_SIDE_RIGHT; | 978 return DEVTOOLS_DOCK_SIDE_RIGHT; |
908 if (dock_side == kDockSideBottom) | 979 if (dock_side == kDockSideBottom) |
909 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 980 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
910 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 981 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
911 } | 982 } |
OLD | NEW |