diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-14 21:08:36 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-14 21:08:36 +0000 |
commit | a227d09341e83f31f59383023a4031207539c0fc (patch) | |
tree | ece810f6c18505d35ce532c489d02aebd257553f /chrome | |
parent | 433475fdc35bd6c904405e1451d1b351c41e81d7 (diff) | |
download | chromium_src-a227d09341e83f31f59383023a4031207539c0fc.zip chromium_src-a227d09341e83f31f59383023a4031207539c0fc.tar.gz chromium_src-a227d09341e83f31f59383023a4031207539c0fc.tar.bz2 |
Adding a message box to confirm if the user really wants to delete all stored
passwords.
Original CL: http://codereview.chromium.org/155291
Patch contributed by: thiago.farina@gmail.com
Review URL: http://codereview.chromium.org/155513
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20658 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/generated_resources.grd | 14 | ||||
-rw-r--r-- | chrome/browser/views/confirm_message_box_dialog.cc | 83 | ||||
-rw-r--r-- | chrome/browser/views/confirm_message_box_dialog.h | 70 | ||||
-rw-r--r-- | chrome/browser/views/options/passwords_page_view.cc | 12 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
5 files changed, 180 insertions, 1 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index fd6579c..c5813bf 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2162,6 +2162,12 @@ each locale. --> <message name="IDS_PASSWORDS_PAGE_VIEW_REMOVE_ALL_BUTTON" desc="Passwords page view's 'Remove all' button text"> Remove All </message> + <message name="IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS" desc ="Passwords page view's confirmation message before removing all stored passwords"> + Are you sure you want to remove all passwords? + </message> + <message name="IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS" desc="Passwords page view's remove all confirmation message box window title"> + Remove all passwords + </message> <message name="IDS_PASSWORDS_PAGE_VIEW_SHOW_BUTTON" desc="Text for passwords page view's button to show a stored password"> Show password </message> @@ -2175,6 +2181,14 @@ each locale. --> Remove All </message> + <!-- Confirm MessageBox Dialog --> + <message name="IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL" desc="Confirm MessageBox Dialog's 'Yes' button text"> + Yes + </message> + <message name="IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL" desc="Confirm MessageBox Dialog's 'No' button text"> + No + </message> + <!-- Password Manager --> <message name="IDS_PASSWORD_MANAGER_SAVE_BUTTON" desc="Save button text for password manager"> Save password diff --git a/chrome/browser/views/confirm_message_box_dialog.cc b/chrome/browser/views/confirm_message_box_dialog.cc new file mode 100644 index 0000000..dd8cbd1 --- /dev/null +++ b/chrome/browser/views/confirm_message_box_dialog.cc @@ -0,0 +1,83 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/views/confirm_message_box_dialog.h" + +#include "app/l10n_util.h" +#include "app/message_box_flags.h" +#include "base/message_loop.h" +#include "grit/generated_resources.h" +#include "views/controls/message_box_view.h" +#include "views/widget/widget.h" +#include "views/window/window.h" + +// static +bool ConfirmMessageBoxDialog::Run(gfx::NativeWindow parent, + const std::wstring& message_text, + const std::wstring& window_title) { + ConfirmMessageBoxDialog* dialog = new ConfirmMessageBoxDialog(parent, + message_text, window_title); + MessageLoopForUI::current()->Run(dialog); + return dialog->accepted(); +} + +ConfirmMessageBoxDialog::ConfirmMessageBoxDialog(gfx::NativeWindow parent, + const std::wstring& message_text, + const std::wstring& window_title) + : message_text_(message_text), + window_title_(window_title), + accepted_(false), + is_blocking_(true) { + message_box_view_ = new MessageBoxView(MessageBoxFlags::kIsConfirmMessageBox, + message_text_, window_title_); + views::Window::CreateChromeWindow(parent, gfx::Rect(), this)->Show(); +} + +ConfirmMessageBoxDialog::~ConfirmMessageBoxDialog() { +} + +void ConfirmMessageBoxDialog::DeleteDelegate() { + delete this; +} + +int ConfirmMessageBoxDialog::GetDialogButtons() const { + return MessageBoxFlags::DIALOGBUTTON_OK | + MessageBoxFlags::DIALOGBUTTON_CANCEL; +} + +std::wstring ConfirmMessageBoxDialog::GetWindowTitle() const { + return window_title_; +} + +std::wstring ConfirmMessageBoxDialog::GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const { + if (button == MessageBoxFlags::DIALOGBUTTON_OK) { + return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL); + } + if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL) + return l10n_util::GetString(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); + return DialogDelegate::GetDialogButtonLabel(button); +} + +views::View* ConfirmMessageBoxDialog::GetContentsView() { + return message_box_view_; +} + +bool ConfirmMessageBoxDialog::Accept() { + is_blocking_ = false; + accepted_ = true; + return true; +} + +bool ConfirmMessageBoxDialog::Cancel() { + is_blocking_ = false; + accepted_ = false; + return true; +} + +bool ConfirmMessageBoxDialog::Dispatch(const MSG& msg) { + TranslateMessage(&msg); + DispatchMessage(&msg); + return is_blocking_; +} diff --git a/chrome/browser/views/confirm_message_box_dialog.h b/chrome/browser/views/confirm_message_box_dialog.h new file mode 100644 index 0000000..6792601 --- /dev/null +++ b/chrome/browser/views/confirm_message_box_dialog.h @@ -0,0 +1,70 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_CONFIRM_MESSAGE_BOX_DIALOG_H_ +#define CHROME_BROWSER_VIEWS_CONFIRM_MESSAGE_BOX_DIALOG_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/gfx/native_widget_types.h" +#include "base/message_loop.h" +#include "views/window/dialog_delegate.h" + +class MessageBoxView; + +class ConfirmMessageBoxDialog : public views::DialogDelegate, + public MessageLoopForUI::Dispatcher { + public: + // The method blocks while the dialog is showing, and returns the the value + // of the user choice, if the user click in Yes button it returns true, + // otherwise false + static bool Run(gfx::NativeWindow parent, + const std::wstring& message_text, + const std::wstring& window_title); + + virtual ~ConfirmMessageBoxDialog(); + + bool accepted() const { return accepted_; } + + // views::DialogDelegate implementation. + virtual int GetDialogButtons() const; + virtual std::wstring GetWindowTitle() const; + virtual std::wstring GetDialogButtonLabel( + MessageBoxFlags::DialogButton button) const; + virtual bool Accept(); + virtual bool Cancel(); + + // views::WindowDelegate implementation. + virtual bool IsModal() const { return true; } + virtual views::View* GetContentsView(); + virtual void DeleteDelegate(); + + // MessageLoop::Dispatcher implementation. + virtual bool Dispatch(const MSG& msg); + + private: + ConfirmMessageBoxDialog(gfx::NativeWindow parent, + const std::wstring& message_text, + const std::wstring& window_title); + + // The message which will be shown to user. + std::wstring message_text_; + + // This is the Title bar text. + std::wstring window_title_; + + MessageBoxView* message_box_view_; + + // Returns true if the user clicks in Yes button, otherwise false + bool accepted_; + + // Used to keep track of whether or not to block the message loop (still + // waiting for the user to dismiss the dialog). + bool is_blocking_; + + DISALLOW_COPY_AND_ASSIGN(ConfirmMessageBoxDialog); +}; + +#endif // CHROME_BROWSER_VIEWS_CONFIRM_MESSAGE_BOX_DIALOG_H_ diff --git a/chrome/browser/views/options/passwords_page_view.cc b/chrome/browser/views/options/passwords_page_view.cc index 4bd9648..e32ae55 100644 --- a/chrome/browser/views/options/passwords_page_view.cc +++ b/chrome/browser/views/options/passwords_page_view.cc @@ -8,6 +8,7 @@ #include "base/string_util.h" #include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/profile.h" +#include "chrome/browser/views/confirm_message_box_dialog.h" #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" #include "grit/generated_resources.h" @@ -213,7 +214,16 @@ void PasswordsPageView::OnSelectionChanged() { void PasswordsPageView::ButtonPressed(views::Button* sender) { // Close will result in our destruction. if (sender == &remove_all_button_) { - table_model_.ForgetAndRemoveAllSignons(); + bool accepted = ConfirmMessageBoxDialog::Run( + GetWindow()->GetNativeWindow(), + l10n_util::GetString(IDS_PASSWORDS_PAGE_VIEW_TEXT_DELETE_ALL_PASSWORDS), + l10n_util::GetString( + IDS_PASSWORDS_PAGE_VIEW_CAPTION_DELETE_ALL_PASSWORDS)); + + if (accepted) { + // Delete all the Passwords shown. + table_model_.ForgetAndRemoveAllSignons(); + } return; } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index d8193bf..6cb5e89 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1576,6 +1576,8 @@ 'browser/views/clear_browsing_data.h', 'browser/views/constrained_window_win.cc', 'browser/views/constrained_window_win.h', + 'browser/views/confirm_message_box_dialog.cc', + 'browser/views/confirm_message_box_dialog.h', 'browser/views/dialog_stubs_gtk.cc', 'browser/views/dom_view.cc', 'browser/views/dom_view.h', |