Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/devtools/devtools_window.cc

Issue 14081036: DevTools: Replace .allow-devtools-edit file check with confirmation infobar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed code style Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 29 matching lines...) Expand all
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"
61 62
62 typedef std::vector<DevToolsWindow*> DevToolsWindowList; 63 typedef std::vector<DevToolsWindow*> DevToolsWindowList;
63 namespace { 64 namespace {
64 base::LazyInstance<DevToolsWindowList>::Leaky 65 base::LazyInstance<DevToolsWindowList>::Leaky
65 g_instances = LAZY_INSTANCE_INITIALIZER; 66 g_instances = LAZY_INSTANCE_INITIALIZER;
66 } // namespace 67 } // namespace
67 68
68 using base::Bind; 69 using base::Bind;
70 using base::Callback;
69 using content::DevToolsAgentHost; 71 using content::DevToolsAgentHost;
70 using content::DevToolsClientHost; 72 using content::DevToolsClientHost;
71 using content::DevToolsManager; 73 using content::DevToolsManager;
72 using content::FileChooserParams; 74 using content::FileChooserParams;
73 using content::NativeWebKeyboardEvent; 75 using content::NativeWebKeyboardEvent;
74 using content::NavigationController; 76 using content::NavigationController;
75 using content::NavigationEntry; 77 using content::NavigationEntry;
76 using content::OpenURLParams; 78 using content::OpenURLParams;
77 using content::RenderViewHost; 79 using content::RenderViewHost;
78 using content::WebContents; 80 using content::WebContents;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 : WebContentsObserver(web_contents) { 117 : WebContentsObserver(web_contents) {
116 } 118 }
117 private: 119 private:
118 // Overriden from contents::WebContentsObserver. 120 // Overriden from contents::WebContentsObserver.
119 virtual void AboutToNavigateRenderView( 121 virtual void AboutToNavigateRenderView(
120 RenderViewHost* render_view_host) OVERRIDE { 122 RenderViewHost* render_view_host) OVERRIDE {
121 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); 123 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host);
122 } 124 }
123 }; 125 };
124 126
127 typedef Callback<void()> InfoBarCallback;
128
129 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
130 public:
131 DevToolsConfirmInfoBarDelegate(
132 InfoBarService* infobar_service,
133 const InfoBarCallback& accept_callback,
134 const InfoBarCallback& cancel_callback,
135 string16 message)
136 : ConfirmInfoBarDelegate(infobar_service),
137 accept_callback_(accept_callback),
138 cancel_callback_(cancel_callback),
139 message_(message),
140 callback_sent(false) {
141 }
142
143 virtual string16 GetMessageText() const {
144 return message_;
145 }
146
147 virtual bool Accept() {
148 callback_sent = true;
149 accept_callback_.Run();
150 return true;
151 }
152
153 virtual bool Cancel() {
154 callback_sent = true;
155 cancel_callback_.Run();
156 return true;
157 }
158
159 private:
160 virtual ~DevToolsConfirmInfoBarDelegate() {
161 if (!callback_sent) {
162 cancel_callback_.Run();
163 }
164 }
165
166 InfoBarCallback accept_callback_;
167 InfoBarCallback cancel_callback_;
168 string16 message_;
169 bool callback_sent;
170 };
171
125 // static 172 // static
126 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { 173 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() {
127 std::string wp_key; 174 std::string wp_key;
128 wp_key.append(prefs::kBrowserWindowPlacement); 175 wp_key.append(prefs::kBrowserWindowPlacement);
129 wp_key.append("_"); 176 wp_key.append("_");
130 wp_key.append(kDevToolsApp); 177 wp_key.append(kDevToolsApp);
131 return wp_key; 178 return wp_key;
132 } 179 }
133 180
134 // static 181 // static
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 1020
974 void DevToolsWindow::RequestFileSystems() { 1021 void DevToolsWindow::RequestFileSystems() {
975 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1022 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
976 file_helper_->RequestFileSystems( 1023 file_helper_->RequestFileSystems(
977 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr())); 1024 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr()));
978 } 1025 }
979 1026
980 void DevToolsWindow::AddFileSystem() { 1027 void DevToolsWindow::AddFileSystem() {
981 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1028 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
982 file_helper_->AddFileSystem( 1029 file_helper_->AddFileSystem(
983 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr())); 1030 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()),
1031 Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar,
1032 weak_factory_.GetWeakPtr()));
984 } 1033 }
985 1034
986 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { 1035 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) {
987 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1036 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
988 file_helper_->RemoveFileSystem(file_system_path); 1037 file_helper_->RemoveFileSystem(file_system_path);
989 StringValue file_system_path_value(file_system_path); 1038 StringValue file_system_path_value(file_system_path);
990 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", 1039 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved",
991 &file_system_path_value); 1040 &file_system_path_value);
992 } 1041 }
993 1042
(...skipping 11 matching lines...) Expand all
1005 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { 1054 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) {
1006 ListValue file_systems_value; 1055 ListValue file_systems_value;
1007 for (size_t i = 0; i < file_systems.size(); ++i) { 1056 for (size_t i = 0; i < file_systems.size(); ++i) {
1008 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); 1057 file_systems_value.Append(CreateFileSystemValue(file_systems[i]));
1009 } 1058 }
1010 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", 1059 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded",
1011 &file_systems_value); 1060 &file_systems_value);
1012 } 1061 }
1013 1062
1014 void DevToolsWindow::FileSystemAdded( 1063 void DevToolsWindow::FileSystemAdded(
1015 std::string error_string,
1016 const DevToolsFileHelper::FileSystem& file_system) { 1064 const DevToolsFileHelper::FileSystem& file_system) {
1017 StringValue error_string_value(error_string); 1065 StringValue error_string_value("");
1018 DictionaryValue* file_system_value = NULL; 1066 DictionaryValue* file_system_value = NULL;
1019 if (!file_system.file_system_path.empty()) 1067 if (!file_system.file_system_path.empty())
1020 file_system_value = CreateFileSystemValue(file_system); 1068 file_system_value = CreateFileSystemValue(file_system);
1021 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", 1069 CallClientFunction("InspectorFrontendAPI.fileSystemAdded",
1022 &error_string_value, 1070 &error_string_value,
1023 file_system_value); 1071 file_system_value);
1024 if (file_system_value) 1072 if (file_system_value)
1025 delete file_system_value; 1073 delete file_system_value;
1026 } 1074 }
1027 1075
1076 void DevToolsWindow::ShowDevToolsConfirmInfoBar(
1077 const string16& message,
1078 const InfoBarCallback& accept_callback,
1079 const InfoBarCallback& cancel_callback) {
1080 InfoBarService* infobar_service = IsDocked() ?
1081 InfoBarService::FromWebContents(GetInspectedWebContents()) :
1082 InfoBarService::FromWebContents(web_contents_);
1083
1084 if (infobar_service) {
1085 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
1086 new DevToolsConfirmInfoBarDelegate(
1087 infobar_service,
1088 accept_callback,
1089 cancel_callback,
1090 message)));
1091 } else {
1092 cancel_callback.Run();
1093 }
1094 }
1095
1028 content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() { 1096 content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() {
1029 content::WebContents* inspected_web_contents = GetInspectedWebContents(); 1097 content::WebContents* inspected_web_contents = GetInspectedWebContents();
1030 if (inspected_web_contents && inspected_web_contents->GetDelegate()) { 1098 if (inspected_web_contents && inspected_web_contents->GetDelegate()) {
1031 return inspected_web_contents->GetDelegate()-> 1099 return inspected_web_contents->GetDelegate()->
1032 GetJavaScriptDialogManager(); 1100 GetJavaScriptDialogManager();
1033 } 1101 }
1034 return content::WebContentsDelegate::GetJavaScriptDialogManager(); 1102 return content::WebContentsDelegate::GetJavaScriptDialogManager();
1035 } 1103 }
1036 1104
1037 void DevToolsWindow::RunFileChooser(WebContents* web_contents, 1105 void DevToolsWindow::RunFileChooser(WebContents* web_contents,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 DevToolsDockSide DevToolsWindow::SideFromString( 1168 DevToolsDockSide DevToolsWindow::SideFromString(
1101 const std::string& dock_side) { 1169 const std::string& dock_side) {
1102 if (dock_side == kDockSideRight) 1170 if (dock_side == kDockSideRight)
1103 return DEVTOOLS_DOCK_SIDE_RIGHT; 1171 return DEVTOOLS_DOCK_SIDE_RIGHT;
1104 if (dock_side == kDockSideBottom) 1172 if (dock_side == kDockSideBottom)
1105 return DEVTOOLS_DOCK_SIDE_BOTTOM; 1173 return DEVTOOLS_DOCK_SIDE_BOTTOM;
1106 if (dock_side == kDockSideMinimized) 1174 if (dock_side == kDockSideMinimized)
1107 return DEVTOOLS_DOCK_SIDE_MINIMIZED; 1175 return DEVTOOLS_DOCK_SIDE_MINIMIZED;
1108 return DEVTOOLS_DOCK_SIDE_UNDOCKED; 1176 return DEVTOOLS_DOCK_SIDE_UNDOCKED;
1109 } 1177 }
OLDNEW
« chrome/browser/devtools/devtools_file_helper.h ('K') | « chrome/browser/devtools/devtools_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698