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/stringprintf.h" | 10 #include "base/stringprintf.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
16 #include "chrome/browser/extensions/api/debugger/debugger_api.h" | 16 #include "chrome/browser/extensions/api/debugger/debugger_api.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
19 #include "chrome/browser/file_select_helper.h" | 19 #include "chrome/browser/file_select_helper.h" |
| 20 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
20 #include "chrome/browser/prefs/pref_service_syncable.h" | 21 #include "chrome/browser/prefs/pref_service_syncable.h" |
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/sessions/session_tab_helper.h" | 24 #include "chrome/browser/sessions/session_tab_helper.h" |
24 #include "chrome/browser/themes/theme_properties.h" | 25 #include "chrome/browser/themes/theme_properties.h" |
25 #include "chrome/browser/themes/theme_service.h" | 26 #include "chrome/browser/themes/theme_service.h" |
26 #include "chrome/browser/themes/theme_service_factory.h" | 27 #include "chrome/browser/themes/theme_service_factory.h" |
27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_iterator.h" | 29 #include "chrome/browser/ui/browser_iterator.h" |
29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
(...skipping 21 matching lines...) Expand all Loading... |
51 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
52 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
53 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
54 #include "content/public/browser/web_contents_observer.h" | 55 #include "content/public/browser/web_contents_observer.h" |
55 #include "content/public/browser/web_contents_view.h" | 56 #include "content/public/browser/web_contents_view.h" |
56 #include "content/public/common/bindings_policy.h" | 57 #include "content/public/common/bindings_policy.h" |
57 #include "content/public/common/content_client.h" | 58 #include "content/public/common/content_client.h" |
58 #include "content/public/common/page_transition_types.h" | 59 #include "content/public/common/page_transition_types.h" |
59 #include "content/public/common/url_constants.h" | 60 #include "content/public/common/url_constants.h" |
60 #include "grit/generated_resources.h" | 61 #include "grit/generated_resources.h" |
| 62 #include "ui/base/l10n/l10n_util.h" |
61 | 63 |
62 typedef std::vector<DevToolsWindow*> DevToolsWindowList; | 64 typedef std::vector<DevToolsWindow*> DevToolsWindowList; |
63 namespace { | 65 namespace { |
64 base::LazyInstance<DevToolsWindowList>::Leaky | 66 base::LazyInstance<DevToolsWindowList>::Leaky |
65 g_instances = LAZY_INSTANCE_INITIALIZER; | 67 g_instances = LAZY_INSTANCE_INITIALIZER; |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 using base::Bind; | 70 using base::Bind; |
| 71 using base::Callback; |
69 using content::DevToolsAgentHost; | 72 using content::DevToolsAgentHost; |
70 using content::DevToolsClientHost; | 73 using content::DevToolsClientHost; |
71 using content::DevToolsManager; | 74 using content::DevToolsManager; |
72 using content::FileChooserParams; | 75 using content::FileChooserParams; |
73 using content::NativeWebKeyboardEvent; | 76 using content::NativeWebKeyboardEvent; |
74 using content::NavigationController; | 77 using content::NavigationController; |
75 using content::NavigationEntry; | 78 using content::NavigationEntry; |
76 using content::OpenURLParams; | 79 using content::OpenURLParams; |
77 using content::RenderViewHost; | 80 using content::RenderViewHost; |
78 using content::WebContents; | 81 using content::WebContents; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 : WebContentsObserver(web_contents) { | 118 : WebContentsObserver(web_contents) { |
116 } | 119 } |
117 private: | 120 private: |
118 // Overriden from contents::WebContentsObserver. | 121 // Overriden from contents::WebContentsObserver. |
119 virtual void AboutToNavigateRenderView( | 122 virtual void AboutToNavigateRenderView( |
120 RenderViewHost* render_view_host) OVERRIDE { | 123 RenderViewHost* render_view_host) OVERRIDE { |
121 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); | 124 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); |
122 } | 125 } |
123 }; | 126 }; |
124 | 127 |
| 128 typedef Callback<void()> InfoBarCallback; |
| 129 |
| 130 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 131 public: |
| 132 DevToolsConfirmInfoBarDelegate( |
| 133 InfoBarService* infobar_service, |
| 134 const InfoBarCallback& accept_callback, |
| 135 const InfoBarCallback& cancel_callback, |
| 136 string16 message) |
| 137 : ConfirmInfoBarDelegate(infobar_service), |
| 138 accept_callback_(accept_callback), |
| 139 cancel_callback_(cancel_callback), |
| 140 message_(message), |
| 141 callback_sent(false) { |
| 142 } |
| 143 |
| 144 virtual string16 GetMessageText() const { |
| 145 return message_; |
| 146 } |
| 147 |
| 148 virtual bool Accept() { |
| 149 callback_sent = true; |
| 150 accept_callback_.Run(); |
| 151 return true; |
| 152 } |
| 153 |
| 154 virtual bool Cancel() { |
| 155 callback_sent = true; |
| 156 cancel_callback_.Run(); |
| 157 return true; |
| 158 } |
| 159 |
| 160 string16 GetButtonLabel(InfoBarButton button) const { |
| 161 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 162 IDS_DEV_TOOLS_CONFIRM_ALLOW_BUTTON : |
| 163 IDS_DEV_TOOLS_CONFIRM_DENY_BUTTON); |
| 164 } |
| 165 |
| 166 private: |
| 167 virtual ~DevToolsConfirmInfoBarDelegate() { |
| 168 if (!callback_sent) { |
| 169 cancel_callback_.Run(); |
| 170 } |
| 171 } |
| 172 |
| 173 InfoBarCallback accept_callback_; |
| 174 InfoBarCallback cancel_callback_; |
| 175 string16 message_; |
| 176 bool callback_sent; |
| 177 }; |
| 178 |
125 // static | 179 // static |
126 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { | 180 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { |
127 std::string wp_key; | 181 std::string wp_key; |
128 wp_key.append(prefs::kBrowserWindowPlacement); | 182 wp_key.append(prefs::kBrowserWindowPlacement); |
129 wp_key.append("_"); | 183 wp_key.append("_"); |
130 wp_key.append(kDevToolsApp); | 184 wp_key.append(kDevToolsApp); |
131 return wp_key; | 185 return wp_key; |
132 } | 186 } |
133 | 187 |
134 // static | 188 // static |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 | 1027 |
974 void DevToolsWindow::RequestFileSystems() { | 1028 void DevToolsWindow::RequestFileSystems() { |
975 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1029 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
976 file_helper_->RequestFileSystems( | 1030 file_helper_->RequestFileSystems( |
977 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr())); | 1031 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr())); |
978 } | 1032 } |
979 | 1033 |
980 void DevToolsWindow::AddFileSystem() { | 1034 void DevToolsWindow::AddFileSystem() { |
981 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1035 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
982 file_helper_->AddFileSystem( | 1036 file_helper_->AddFileSystem( |
983 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr())); | 1037 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()), |
| 1038 Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar, |
| 1039 weak_factory_.GetWeakPtr())); |
984 } | 1040 } |
985 | 1041 |
986 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { | 1042 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { |
987 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); | 1043 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); |
988 file_helper_->RemoveFileSystem(file_system_path); | 1044 file_helper_->RemoveFileSystem(file_system_path); |
989 StringValue file_system_path_value(file_system_path); | 1045 StringValue file_system_path_value(file_system_path); |
990 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", | 1046 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", |
991 &file_system_path_value); | 1047 &file_system_path_value); |
992 } | 1048 } |
993 | 1049 |
(...skipping 11 matching lines...) Expand all Loading... |
1005 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { | 1061 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { |
1006 ListValue file_systems_value; | 1062 ListValue file_systems_value; |
1007 for (size_t i = 0; i < file_systems.size(); ++i) { | 1063 for (size_t i = 0; i < file_systems.size(); ++i) { |
1008 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); | 1064 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); |
1009 } | 1065 } |
1010 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", | 1066 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", |
1011 &file_systems_value); | 1067 &file_systems_value); |
1012 } | 1068 } |
1013 | 1069 |
1014 void DevToolsWindow::FileSystemAdded( | 1070 void DevToolsWindow::FileSystemAdded( |
1015 std::string error_string, | |
1016 const DevToolsFileHelper::FileSystem& file_system) { | 1071 const DevToolsFileHelper::FileSystem& file_system) { |
1017 StringValue error_string_value(error_string); | 1072 StringValue error_string_value(""); |
1018 DictionaryValue* file_system_value = NULL; | 1073 DictionaryValue* file_system_value = NULL; |
1019 if (!file_system.file_system_path.empty()) | 1074 if (!file_system.file_system_path.empty()) |
1020 file_system_value = CreateFileSystemValue(file_system); | 1075 file_system_value = CreateFileSystemValue(file_system); |
1021 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", | 1076 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", |
1022 &error_string_value, | 1077 &error_string_value, |
1023 file_system_value); | 1078 file_system_value); |
1024 if (file_system_value) | 1079 if (file_system_value) |
1025 delete file_system_value; | 1080 delete file_system_value; |
1026 } | 1081 } |
1027 | 1082 |
| 1083 void DevToolsWindow::ShowDevToolsConfirmInfoBar( |
| 1084 const string16& message, |
| 1085 const InfoBarCallback& accept_callback, |
| 1086 const InfoBarCallback& cancel_callback) { |
| 1087 InfoBarService* infobar_service = IsDocked() ? |
| 1088 InfoBarService::FromWebContents(GetInspectedWebContents()) : |
| 1089 InfoBarService::FromWebContents(web_contents_); |
| 1090 |
| 1091 if (infobar_service) { |
| 1092 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 1093 new DevToolsConfirmInfoBarDelegate( |
| 1094 infobar_service, |
| 1095 accept_callback, |
| 1096 cancel_callback, |
| 1097 message))); |
| 1098 } else { |
| 1099 cancel_callback.Run(); |
| 1100 } |
| 1101 } |
| 1102 |
1028 content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() { | 1103 content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() { |
1029 content::WebContents* inspected_web_contents = GetInspectedWebContents(); | 1104 content::WebContents* inspected_web_contents = GetInspectedWebContents(); |
1030 if (inspected_web_contents && inspected_web_contents->GetDelegate()) { | 1105 if (inspected_web_contents && inspected_web_contents->GetDelegate()) { |
1031 return inspected_web_contents->GetDelegate()-> | 1106 return inspected_web_contents->GetDelegate()-> |
1032 GetJavaScriptDialogManager(); | 1107 GetJavaScriptDialogManager(); |
1033 } | 1108 } |
1034 return content::WebContentsDelegate::GetJavaScriptDialogManager(); | 1109 return content::WebContentsDelegate::GetJavaScriptDialogManager(); |
1035 } | 1110 } |
1036 | 1111 |
1037 void DevToolsWindow::RunFileChooser(WebContents* web_contents, | 1112 void DevToolsWindow::RunFileChooser(WebContents* web_contents, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 DevToolsDockSide DevToolsWindow::SideFromString( | 1175 DevToolsDockSide DevToolsWindow::SideFromString( |
1101 const std::string& dock_side) { | 1176 const std::string& dock_side) { |
1102 if (dock_side == kDockSideRight) | 1177 if (dock_side == kDockSideRight) |
1103 return DEVTOOLS_DOCK_SIDE_RIGHT; | 1178 return DEVTOOLS_DOCK_SIDE_RIGHT; |
1104 if (dock_side == kDockSideBottom) | 1179 if (dock_side == kDockSideBottom) |
1105 return DEVTOOLS_DOCK_SIDE_BOTTOM; | 1180 return DEVTOOLS_DOCK_SIDE_BOTTOM; |
1106 if (dock_side == kDockSideMinimized) | 1181 if (dock_side == kDockSideMinimized) |
1107 return DEVTOOLS_DOCK_SIDE_MINIMIZED; | 1182 return DEVTOOLS_DOCK_SIDE_MINIMIZED; |
1108 return DEVTOOLS_DOCK_SIDE_UNDOCKED; | 1183 return DEVTOOLS_DOCK_SIDE_UNDOCKED; |
1109 } | 1184 } |
OLD | NEW |