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

Unified 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: Comments addressed 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/devtools/devtools_window.cc
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index bc28c3e88e8e2e082353ea752c82e5fcac877854..1247abf465898dfd0af499e45e95ccb25e634819 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/file_select_helper.h"
+#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
@@ -58,6 +59,7 @@
#include "content/public/common/page_transition_types.h"
#include "content/public/common/url_constants.h"
#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
typedef std::vector<DevToolsWindow*> DevToolsWindowList;
namespace {
@@ -66,6 +68,7 @@ base::LazyInstance<DevToolsWindowList>::Leaky
} // namespace
using base::Bind;
+using base::Callback;
using content::DevToolsAgentHost;
using content::DevToolsClientHost;
using content::DevToolsManager;
@@ -122,6 +125,57 @@ class DevToolsWindow::FrontendWebContentsObserver
}
};
+typedef Callback<void()> InfoBarCallback;
+
+class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ DevToolsConfirmInfoBarDelegate(
+ InfoBarService* infobar_service,
+ const InfoBarCallback& accept_callback,
+ const InfoBarCallback& cancel_callback,
+ string16 message)
+ : ConfirmInfoBarDelegate(infobar_service),
+ accept_callback_(accept_callback),
+ cancel_callback_(cancel_callback),
+ message_(message),
+ callback_sent(false) {
+ }
+
+ virtual string16 GetMessageText() const {
+ return message_;
+ }
+
+ virtual bool Accept() {
+ callback_sent = true;
+ accept_callback_.Run();
+ return true;
+ }
+
+ virtual bool Cancel() {
+ callback_sent = true;
+ cancel_callback_.Run();
+ return true;
+ }
+
+ string16 GetButtonLabel(InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_DEV_TOOLS_CONFIRM_ALLOW_BUTTON :
+ IDS_DEV_TOOLS_CONFIRM_DENY_BUTTON);
+ }
+
+ private:
+ virtual ~DevToolsConfirmInfoBarDelegate() {
+ if (!callback_sent) {
+ cancel_callback_.Run();
+ }
+ }
+
+ InfoBarCallback accept_callback_;
+ InfoBarCallback cancel_callback_;
+ string16 message_;
+ bool callback_sent;
+};
+
// static
std::string DevToolsWindow::GetDevToolsWindowPlacementPrefKey() {
std::string wp_key;
@@ -980,7 +1034,9 @@ void DevToolsWindow::RequestFileSystems() {
void DevToolsWindow::AddFileSystem() {
CHECK(web_contents_->GetURL().SchemeIs(chrome::kChromeDevToolsScheme));
file_helper_->AddFileSystem(
- Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()));
+ Bind(&DevToolsWindow::FileSystemAdded, weak_factory_.GetWeakPtr()),
+ Bind(&DevToolsWindow::ShowDevToolsConfirmInfoBar,
+ weak_factory_.GetWeakPtr()));
}
void DevToolsWindow::RemoveFileSystem(const std::string& file_system_path) {
@@ -1012,9 +1068,8 @@ void DevToolsWindow::FileSystemsLoaded(
}
void DevToolsWindow::FileSystemAdded(
- std::string error_string,
const DevToolsFileHelper::FileSystem& file_system) {
- StringValue error_string_value(error_string);
+ StringValue error_string_value("");
DictionaryValue* file_system_value = NULL;
if (!file_system.file_system_path.empty())
file_system_value = CreateFileSystemValue(file_system);
@@ -1025,6 +1080,26 @@ void DevToolsWindow::FileSystemAdded(
delete file_system_value;
}
+void DevToolsWindow::ShowDevToolsConfirmInfoBar(
+ const string16& message,
+ const InfoBarCallback& accept_callback,
+ const InfoBarCallback& cancel_callback) {
+ InfoBarService* infobar_service = IsDocked() ?
+ InfoBarService::FromWebContents(GetInspectedWebContents()) :
+ InfoBarService::FromWebContents(web_contents_);
+
+ if (infobar_service) {
+ infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
+ new DevToolsConfirmInfoBarDelegate(
+ infobar_service,
+ accept_callback,
+ cancel_callback,
+ message)));
+ } else {
+ cancel_callback.Run();
+ }
+}
+
content::JavaScriptDialogManager* DevToolsWindow::GetJavaScriptDialogManager() {
content::WebContents* inspected_web_contents = GetInspectedWebContents();
if (inspected_web_contents && inspected_web_contents->GetDelegate()) {
« 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