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