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::kDevToolsFilesystemPaths, | |
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 (!DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) | 109 if (!DevToolsAgentHost::HasFor(inspected_web_contents->GetRenderViewHost())) |
108 return NULL; | 110 return NULL; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 web_contents_(web_contents), | 210 web_contents_(web_contents), |
209 browser_(NULL), | 211 browser_(NULL), |
210 dock_side_(dock_side), | 212 dock_side_(dock_side), |
211 is_loaded_(false), | 213 is_loaded_(false), |
212 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), | 214 action_on_load_(DEVTOOLS_TOGGLE_ACTION_SHOW), |
213 weak_factory_(this), | 215 weak_factory_(this), |
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)); | 220 file_helper_.reset(new DevToolsFileHelper(web_contents, profile)); |
219 | 221 |
220 g_instances.Get().push_back(this); | 222 g_instances.Get().push_back(this); |
221 // Wipe out page icon so that the default application icon is used. | 223 // Wipe out page icon so that the default application icon is used. |
222 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); | 224 NavigationEntry* entry = web_contents->GetController().GetActiveEntry(); |
223 entry->GetFavicon().image = gfx::Image(); | 225 entry->GetFavicon().image = gfx::Image(); |
224 entry->GetFavicon().valid = true; | 226 entry->GetFavicon().valid = true; |
225 | 227 |
226 // Register on-load actions. | 228 // Register on-load actions. |
227 registrar_.Add( | 229 registrar_.Add( |
228 this, | 230 this, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 } | 502 } |
501 | 503 |
502 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, | 504 WebContents* DevToolsWindow::OpenURLFromTab(WebContents* source, |
503 const OpenURLParams& params) { | 505 const OpenURLParams& params) { |
504 if (inspected_web_contents_) | 506 if (inspected_web_contents_) |
505 return inspected_web_contents_->OpenURL(params); | 507 return inspected_web_contents_->OpenURL(params); |
506 return NULL; | 508 return NULL; |
507 } | 509 } |
508 | 510 |
509 void DevToolsWindow::CallClientFunction(const std::string& function_name, | 511 void DevToolsWindow::CallClientFunction(const std::string& function_name, |
510 const Value* arg) { | 512 const Value* arg1, |
511 std::string json; | 513 const Value* arg2) { |
512 if (arg) | 514 std::string params; |
513 base::JSONWriter::Write(arg, &json); | 515 if (arg1) { |
514 | 516 std::string json; |
515 string16 javascript = | 517 base::JSONWriter::Write(arg1, &json); |
516 ASCIIToUTF16(function_name + "(" + json + ");"); | 518 params.append(json); |
519 if (arg2) { | |
520 base::JSONWriter::Write(arg2, &json); | |
521 params.append(", " + json); | |
522 } | |
523 } | |
524 string16 javascript = ASCIIToUTF16(function_name + "(" + params + ");"); | |
517 web_contents_->GetRenderViewHost()-> | 525 web_contents_->GetRenderViewHost()-> |
518 ExecuteJavascriptInWebFrame(string16(), javascript); | 526 ExecuteJavascriptInWebFrame(string16(), javascript); |
519 } | 527 } |
520 | 528 |
521 void DevToolsWindow::Observe(int type, | 529 void DevToolsWindow::Observe(int type, |
522 const content::NotificationSource& source, | 530 const content::NotificationSource& source, |
523 const content::NotificationDetails& details) { | 531 const content::NotificationDetails& details) { |
524 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { | 532 if (type == content::NOTIFICATION_LOAD_STOP && !is_loaded_) { |
525 is_loaded_ = true; | 533 is_loaded_ = true; |
526 UpdateTheme(); | 534 UpdateTheme(); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
819 url)); | 827 url)); |
820 } | 828 } |
821 | 829 |
822 void DevToolsWindow::AppendToFile(const std::string& url, | 830 void DevToolsWindow::AppendToFile(const std::string& url, |
823 const std::string& content) { | 831 const std::string& content) { |
824 file_helper_->Append(url, content, Bind(&DevToolsWindow::AppendedTo, | 832 file_helper_->Append(url, content, Bind(&DevToolsWindow::AppendedTo, |
825 weak_factory_.GetWeakPtr(), | 833 weak_factory_.GetWeakPtr(), |
826 url)); | 834 url)); |
827 } | 835 } |
828 | 836 |
837 namespace { | |
838 | |
839 DictionaryValue* CreateFilesystemValue( | |
840 DevToolsFileHelper::Filesystem filesystem) { | |
841 DictionaryValue* filesystem_value = new DictionaryValue(); | |
842 filesystem_value->SetString("filesystemId", filesystem.filesystem_id); | |
843 filesystem_value->SetString("registeredName", filesystem.registered_name); | |
844 filesystem_value->SetString("filesystemPath", filesystem.filesystem_path); | |
845 return filesystem_value; | |
846 } | |
847 | |
848 } // namespace | |
849 | |
850 void DevToolsWindow::RequestFilesystems() { | |
851 file_helper_->RequestFilesystems( | |
pfeldman
2012/12/29 10:23:02
RestoreFilesystems
new DevToolsFileHelper(web_con
| |
852 Bind(&DevToolsWindow::FilesystemsLoaded, weak_factory_.GetWeakPtr())); | |
853 } | |
854 | |
855 void DevToolsWindow::AddFilesystem() { | |
856 file_helper_->AddFilesystem( | |
857 Bind(&DevToolsWindow::FilesystemAdded, weak_factory_.GetWeakPtr())); | |
858 } | |
859 | |
860 void DevToolsWindow::RemoveFilesystem(const std::string& filesystem_path) { | |
861 file_helper_->RemoveFilesystem(filesystem_path); | |
862 StringValue filesystem_path_value(filesystem_path); | |
863 CallClientFunction("InspectorFrontendAPI.filesystemRemoved", | |
864 &filesystem_path_value); | |
865 } | |
866 | |
829 void DevToolsWindow::FileSavedAs(const std::string& url) { | 867 void DevToolsWindow::FileSavedAs(const std::string& url) { |
830 StringValue url_value(url); | 868 StringValue url_value(url); |
831 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); | 869 CallClientFunction("InspectorFrontendAPI.savedURL", &url_value); |
832 } | 870 } |
833 | 871 |
834 void DevToolsWindow::AppendedTo(const std::string& url) { | 872 void DevToolsWindow::AppendedTo(const std::string& url) { |
835 StringValue url_value(url); | 873 StringValue url_value(url); |
836 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); | 874 CallClientFunction("InspectorFrontendAPI.appendedToURL", &url_value); |
837 } | 875 } |
838 | 876 |
877 void DevToolsWindow::FilesystemsLoaded( | |
878 const std::vector<DevToolsFileHelper::Filesystem>& filesystems) { | |
879 ListValue filesystems_value; | |
880 for (size_t i = 0; i < filesystems.size(); ++i) { | |
881 filesystems_value.Append(CreateFilesystemValue(filesystems[i])); | |
882 } | |
883 CallClientFunction("InspectorFrontendAPI.filesystemsLoaded", | |
884 &filesystems_value); | |
885 } | |
886 | |
887 void DevToolsWindow::FilesystemAdded( | |
888 std::string error_string, | |
889 const DevToolsFileHelper::Filesystem& filesystem) { | |
890 StringValue error_string_value(error_string); | |
891 DictionaryValue* filesystem_value = NULL; | |
892 if (!filesystem.filesystem_path.empty()) | |
893 filesystem_value = CreateFilesystemValue(filesystem); | |
894 CallClientFunction("InspectorFrontendAPI.filesystemAdded", | |
895 &error_string_value, | |
896 filesystem_value); | |
897 if (filesystem_value) | |
898 delete filesystem_value; | |
899 } | |
900 | |
839 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { | 901 content::JavaScriptDialogCreator* DevToolsWindow::GetJavaScriptDialogCreator() { |
840 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { | 902 if (inspected_web_contents_ && inspected_web_contents_->GetDelegate()) { |
841 return inspected_web_contents_->GetDelegate()-> | 903 return inspected_web_contents_->GetDelegate()-> |
842 GetJavaScriptDialogCreator(); | 904 GetJavaScriptDialogCreator(); |
843 } | 905 } |
844 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); | 906 return content::WebContentsDelegate::GetJavaScriptDialogCreator(); |
845 } | 907 } |
846 | 908 |
847 void DevToolsWindow::RunFileChooser(WebContents* web_contents, | 909 void DevToolsWindow::RunFileChooser(WebContents* web_contents, |
848 const FileChooserParams& params) { | 910 const FileChooserParams& params) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
906 | 968 |
907 // static | 969 // static |
908 DevToolsDockSide DevToolsWindow::SideFromString( | 970 DevToolsDockSide DevToolsWindow::SideFromString( |
909 const std::string& dock_side) { | 971 const std::string& dock_side) { |
910 if (dock_side == kDockSideRight) | 972 if (dock_side == kDockSideRight) |
911 return DEVTOOLS_DOCK_SIDE_RIGHT; | 973 return DEVTOOLS_DOCK_SIDE_RIGHT; |
912 if (dock_side == kDockSideBottom) | 974 if (dock_side == kDockSideBottom) |
913 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 975 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
914 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 976 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
915 } | 977 } |
OLD | NEW |