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); | |
Tom Sepez
2013/01/11 18:34:17
Good. Syncing across systems can't be allowed.
| |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 Profile* profile, | 206 Profile* profile, |
204 RenderViewHost* inspected_rvh, | 207 RenderViewHost* inspected_rvh, |
205 DevToolsDockSide dock_side) | 208 DevToolsDockSide dock_side) |
206 : profile_(profile), | 209 : profile_(profile), |
207 inspected_web_contents_(NULL), | 210 inspected_web_contents_(NULL), |
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 ALLOW_THIS_IN_INITIALIZER_LIST(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 file_system) { | |
842 DictionaryValue* file_system_value = new DictionaryValue(); | |
843 file_system_value->SetString("fileSystemId", file_system.file_system_id); | |
844 file_system_value->SetString("registeredName", file_system.registered_name); | |
845 file_system_value->SetString("fileSystemPath", file_system.file_system_path); | |
846 return file_system_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& file_system_path) { | |
864 CHECK(content::GetContentClient()->HasWebUIScheme(web_contents_->GetURL())); | |
865 file_helper_->RemoveFileSystem(file_system_path); | |
866 StringValue file_system_path_value(file_system_path); | |
867 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", | |
868 &file_system_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>& file_systems) { | |
883 ListValue file_systems_value; | |
884 for (size_t i = 0; i < file_systems.size(); ++i) { | |
885 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); | |
886 } | |
887 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", | |
888 &file_systems_value); | |
889 } | |
890 | |
891 void DevToolsWindow::FileSystemAdded( | |
892 std::string error_string, | |
893 const DevToolsFileHelper::FileSystem& file_system) { | |
894 StringValue error_string_value(error_string); | |
895 DictionaryValue* file_system_value = NULL; | |
896 if (!file_system.file_system_path.empty()) | |
897 file_system_value = CreateFileSystemValue(file_system); | |
898 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", | |
899 &error_string_value, | |
900 file_system_value); | |
901 if (file_system_value) | |
902 delete file_system_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 |