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

Side by Side Diff: chrome/browser/download/download_danger_prompt.cc

Issue 18179004: Dismiss action in tab modal dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make the tests pass with GTK and Cocoa Created 7 years, 5 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
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 "chrome/browser/download/download_danger_prompt.h" 5 #include "chrome/browser/download/download_danger_prompt.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/download/chrome_download_manager_delegate.h" 8 #include "chrome/browser/download/chrome_download_manager_delegate.h"
9 #include "chrome/browser/ui/tab_modal_confirm_dialog.h" 9 #include "chrome/browser/ui/tab_modal_confirm_dialog.h"
10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
(...skipping 23 matching lines...) Expand all
34 // content::DownloadItem::Observer 34 // content::DownloadItem::Observer
35 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; 35 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
36 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; 36 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE;
37 37
38 // TabModalConfirmDialogDelegate 38 // TabModalConfirmDialogDelegate
39 virtual string16 GetTitle() OVERRIDE; 39 virtual string16 GetTitle() OVERRIDE;
40 virtual string16 GetMessage() OVERRIDE; 40 virtual string16 GetMessage() OVERRIDE;
41 virtual string16 GetAcceptButtonTitle() OVERRIDE; 41 virtual string16 GetAcceptButtonTitle() OVERRIDE;
42 virtual void OnAccepted() OVERRIDE; 42 virtual void OnAccepted() OVERRIDE;
43 virtual void OnCanceled() OVERRIDE; 43 virtual void OnCanceled() OVERRIDE;
44 virtual void OnClosed() OVERRIDE;
44 45
45 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents 46 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents
46 // this object from responding to state changes in |download_| that might 47 // this object from responding to state changes in |download_| that might
47 // result from invoking the callback. |callback| must refer to either 48 // result from invoking the callback. |callback| must refer to either
48 // |accepted_| or |canceled_|. 49 // |accepted_| or |canceled_|.
49 void RunCallback(const base::Closure& callback); 50 void RunCallback(const base::Closure& callback);
50 51
51 // Resets |accepted_|, |canceled_| and removes the observer from |download_|, 52 // Resets |accepted_|, |canceled_| and removes the observer from |download_|,
52 // in preparation for closing the prompt. 53 // in preparation for closing the prompt.
53 void PrepareToClose(); 54 void PrepareToClose();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 137 }
137 138
138 void DownloadDangerPromptImpl::OnAccepted() { 139 void DownloadDangerPromptImpl::OnAccepted() {
139 RunCallback(accepted_); 140 RunCallback(accepted_);
140 } 141 }
141 142
142 void DownloadDangerPromptImpl::OnCanceled() { 143 void DownloadDangerPromptImpl::OnCanceled() {
143 RunCallback(canceled_); 144 RunCallback(canceled_);
144 } 145 }
145 146
147 void DownloadDangerPromptImpl::OnClosed() {
148 RunCallback(canceled_);
149 }
150
146 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) { 151 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) {
147 // Invoking the callback can cause the download item state to change or cause 152 // Invoking the callback can cause the download item state to change or cause
148 // the constrained window to close, and |callback| refers to a member 153 // the constrained window to close, and |callback| refers to a member
149 // variable. 154 // variable.
150 base::Closure callback_copy = callback; 155 base::Closure callback_copy = callback;
151 PrepareToClose(); 156 PrepareToClose();
152 if (!callback_copy.is_null()) 157 if (!callback_copy.is_null())
153 callback_copy.Run(); 158 callback_copy.Run();
154 } 159 }
155 160
(...skipping 14 matching lines...) Expand all
170 content::WebContents* web_contents, 175 content::WebContents* web_contents,
171 bool show_context, 176 bool show_context,
172 const base::Closure& accepted, 177 const base::Closure& accepted,
173 const base::Closure& canceled) { 178 const base::Closure& canceled) {
174 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( 179 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl(
175 item, show_context, accepted, canceled); 180 item, show_context, accepted, canceled);
176 // |prompt| will be deleted when the dialog is done. 181 // |prompt| will be deleted when the dialog is done.
177 TabModalConfirmDialog::Create(prompt, web_contents); 182 TabModalConfirmDialog::Create(prompt, web_contents);
178 return prompt; 183 return prompt;
179 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698