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

Unified Diff: chrome/browser/views/frame/browser_view.cc

Issue 62131: Ask for user confirmation when closing a browser with in-progress downloads (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « chrome/browser/views/frame/browser_view.h ('k') | chrome/test/test_browser_window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/frame/browser_view.cc
===================================================================
--- chrome/browser/views/frame/browser_view.cc (revision 13264)
+++ chrome/browser/views/frame/browser_view.cc (working copy)
@@ -12,6 +12,7 @@
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
+#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/encoding_menu_controller_delegate.h"
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/view_ids.h"
@@ -52,6 +53,7 @@
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
#include "chrome/views/controls/scrollbar/native_scroll_bar.h"
+#include "chrome/views/fill_layout.h"
#include "chrome/views/view.h"
#include "chrome/views/widget/hwnd_notification_source.h"
#include "chrome/views/widget/root_view.h"
@@ -189,7 +191,74 @@
DISALLOW_COPY_AND_ASSIGN(ResizeCorner);
};
+////////////////////////////////////////////////////////////////////////////////
+// DownloadInProgressConfirmDialogDelegate
+class DownloadInProgressConfirmDialogDelegate : public views::DialogDelegate,
+ public views::View {
+ public:
+ explicit DownloadInProgressConfirmDialogDelegate(Browser* browser)
+ : browser_(browser) {
+ int download_count = browser->profile()->GetDownloadManager()->
+ in_progress_count();
+ label_ = new views::Label(l10n_util::GetStringF(
+ IDS_DOWNLOAD_REMOVE_CONFIRM_TITLE, download_count));
+ label_->SetMultiLine(true);
+ label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ label_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10));
+ AddChildView(label_);
+ SetParentOwned(false);
+ SetLayoutManager(new views::FillLayout());
+ }
+
+ // View implementation:
+ virtual gfx::Size GetPreferredSize() {
+ const int kContentWidth = 400;
+ return gfx::Size(kContentWidth, label_->GetHeightForWidth(kContentWidth));
+ }
+
+ // DialogDelegate implementation:
+ virtual int GetDefaultDialogButton() const {
+ return DIALOGBUTTON_CANCEL;
+ }
+
+ virtual std::wstring GetDialogButtonLabel(DialogButton button) const {
+ if (button == DIALOGBUTTON_OK)
+ return l10n_util::GetString(IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
+
+ DCHECK_EQ(DIALOGBUTTON_CANCEL, button);
+ return l10n_util::GetString(
+ IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
+ }
+
+ virtual bool Accept() {
+ browser_->InProgressDownloadResponse(true);
+ return true;
+ }
+
+ virtual bool Cancel() {
+ browser_->InProgressDownloadResponse(false);
+ return true;
+ }
+
+ virtual void DeleteDelegate() {
+ delete this;
+ }
+
+ // WindowDelegate implementation:
+ virtual bool IsModal() const { return true; }
+
+ virtual views::View* GetContentsView() {
+ return this;
+ }
+
+ private:
+ Browser* browser_;
+ views::Label* label_;
+
+ DISALLOW_COPY_AND_ASSIGN(DownloadInProgressConfirmDialogDelegate);
+};
+
///////////////////////////////////////////////////////////////////////////////
// BrowserView, public:
@@ -818,6 +887,13 @@
NewProfileDialog::RunDialog();
}
+void BrowserView::ConfirmBrowserCloseWithPendingDownloads() {
+ DownloadInProgressConfirmDialogDelegate* delegate =
+ new DownloadInProgressConfirmDialogDelegate(browser_.get());
+ views::Window::CreateChromeWindow(GetWidget()->GetNativeView(), gfx::Rect(),
+ delegate)->Show();
+}
+
void BrowserView::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
void* parent_window) {
HWND parent_hwnd = reinterpret_cast<HWND>(parent_window);
« no previous file with comments | « chrome/browser/views/frame/browser_view.h ('k') | chrome/test/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698