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

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: . 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
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
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
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(bool)> ConfirmInfoBarCallback;
129
130 class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
131 public:
132 DevToolsConfirmInfoBarDelegate(
133 InfoBarService* infobar_service,
134 const ConfirmInfoBarCallback& callback,
135 string16 message)
136 : ConfirmInfoBarDelegate(infobar_service),
137 callback_(callback),
138 message_(message) {
139 }
140
141 virtual string16 GetMessageText() const {
142 return message_;
143 }
144
145 virtual bool Accept() {
146 callback_.Run(true);
147 callback_.Reset();
148 return true;
149 }
150
151 virtual bool Cancel() {
152 callback_.Run(false);
153 callback_.Reset();
154 return true;
155 }
156
157 string16 GetButtonLabel(InfoBarButton button) const {
158 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
159 IDS_DEV_TOOLS_CONFIRM_ALLOW_BUTTON :
160 IDS_DEV_TOOLS_CONFIRM_DENY_BUTTON);
161 }
162
163 private:
164 virtual ~DevToolsConfirmInfoBarDelegate() {
165 if (!callback_.is_null()) {
166 callback_.Run(false);
167 }
168 }
169
170 ConfirmInfoBarCallback callback_;
171 string16 message_;
172 };
173
125 // static 174 // static
126 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() { 175 std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() {
127 std::string wp_key; 176 std::string wp_key;
128 wp_key.append(prefs::kBrowserWindowPlacement); 177 wp_key.append(prefs::kBrowserWindowPlacement);
129 wp_key.append("_"); 178 wp_key.append("_");
130 wp_key.append(kDevToolsApp); 179 wp_key.append(kDevToolsApp);
131 return wp_key; 180 return wp_key;
132 } 181 }
133 182
134 // static 183 // static
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 1022
974 void DevToolsWindow::RequestFileSystems() { 1023 void DevToolsWindow::RequestFileSystems() {
975 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1024 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
976 file_helper_->RequestFileSystems( 1025 file_helper_->RequestFileSystems(
977 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr())); 1026 Bind(&DevToolsWindow::FileSystemsLoaded, weak_factory_.GetWeakPtr()));
978 } 1027 }
979 1028
980 void DevToolsWindow::AddFileSystem() { 1029 void DevToolsWindow::AddFileSystem() {
981 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1030 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
982 file_helper_->AddFileSystem( 1031 file_helper_->AddFileSystem(
983 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr())); 1032 Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()),
1033 Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar,
1034 weak_factory_.GetWeakPtr()));
984 } 1035 }
985 1036
986 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) { 1037 void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) {
987 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme)); 1038 CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
988 file_helper_->RemoveFileSystem(file_system_path); 1039 file_helper_->RemoveFileSystem(file_system_path);
989 StringValue file_system_path_value(file_system_path); 1040 StringValue file_system_path_value(file_system_path);
990 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved", 1041 CallClientFunction("InspectorFrontendAPI.fileSystemRemoved",
991 &file_system_path_value); 1042 &file_system_path_value);
992 } 1043 }
993 1044
(...skipping 11 matching lines...) Expand all
1005 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) { 1056 const std::vector<DevToolsFileHelper::FileSystem>& file_systems) {
1006 ListValue file_systems_value; 1057 ListValue file_systems_value;
1007 for (size_t i = 0; i < file_systems.size(); ++i) { 1058 for (size_t i = 0; i < file_systems.size(); ++i) {
1008 file_systems_value.Append(CreateFileSystemValue(file_systems[i])); 1059 file_systems_value.Append(CreateFileSystemValue(file_systems[i]));
1009 } 1060 }
1010 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded", 1061 CallClientFunction("InspectorFrontendAPI.fileSystemsLoaded",
1011 &file_systems_value); 1062 &file_systems_value);
1012 } 1063 }
1013 1064
1014 void DevToolsWindow::FileSystemAdded( 1065 void DevToolsWindow::FileSystemAdded(
1015 std::string error_string,
1016 const DevToolsFileHelper::FileSystem& file_system) { 1066 const DevToolsFileHelper::FileSystem& file_system) {
1017 StringValue error_string_value(error_string); 1067 StringValue error_string_value("");
1018 DictionaryValue* file_system_value = NULL; 1068 DictionaryValue* file_system_value = NULL;
1019 if (!file_system.file_system_path.empty()) 1069 if (!file_system.file_system_path.empty())
1020 file_system_value = CreateFileSystemValue(file_system); 1070 file_system_value = CreateFileSystemValue(file_system);
1021 CallClientFunction("InspectorFrontendAPI.fileSystemAdded", 1071 CallClientFunction("InspectorFrontendAPI.fileSystemAdded",
1022 &error_string_value, 1072 &error_string_value,
1023 file_system_value); 1073 file_system_value);
1024 if (file_system_value) 1074 if (file_system_value)
1025 delete file_system_value; 1075 delete file_system_value;
1026 } 1076 }
1027 1077
1078 void DevToolsWindow::ShowDevToolsConfirmInfoBar(
1079 const string16& message,
1080 const ConfirmInfoBarCallback& callback) {
1081 InfoBarService* infobar_service = IsDocked() ?
1082 InfoBarService::FromWebContents(GetInspectedWebContents()) :
1083 InfoBarService::FromWebContents(web_contents_);
1084
1085 if (infobar_service) {
1086 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
1087 new DevToolsConfirmInfoBarDelegate(
1088 infobar_service,
1089 callback,
1090 message)));
1091 } else {
1092 callback.Run(false);
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
« no previous file with comments | « chrome/browser/devtools/devtools_window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698