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

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: 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 24 matching lines...) Expand all
35 // content::DownloadItem::Observer 35 // content::DownloadItem::Observer
36 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; 36 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE;
37 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE; 37 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE;
38 38
39 // TabModalConfirmDialogDelegate 39 // TabModalConfirmDialogDelegate
40 virtual string16 GetTitle() OVERRIDE; 40 virtual string16 GetTitle() OVERRIDE;
41 virtual string16 GetMessage() OVERRIDE; 41 virtual string16 GetMessage() OVERRIDE;
42 virtual string16 GetAcceptButtonTitle() OVERRIDE; 42 virtual string16 GetAcceptButtonTitle() OVERRIDE;
43 virtual void OnAccepted() OVERRIDE; 43 virtual void OnAccepted() OVERRIDE;
44 virtual void OnCanceled() OVERRIDE; 44 virtual void OnCanceled() OVERRIDE;
45 virtual void OnDismissed() OVERRIDE;
45 46
46 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents 47 // Runs |callback|. PrepareToClose() is called beforehand. Doing so prevents
47 // this object from responding to state changes in |download_| that might 48 // this object from responding to state changes in |download_| that might
48 // result from invoking the callback. |callback| must refer to either 49 // result from invoking the callback. |callback| must refer to either
49 // |accepted_| or |canceled_|. 50 // |accepted_| or |canceled_|.
50 void RunCallback(const base::Closure& callback); 51 void RunCallback(const base::Closure& callback);
51 52
52 // Resets |accepted_|, |canceled_| and removes the observer from |download_|, 53 // Resets |accepted_|, |canceled_| and removes the observer from |download_|,
53 // in preparation for closing the prompt. 54 // in preparation for closing the prompt.
54 void PrepareToClose(); 55 void PrepareToClose();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 140 }
140 141
141 void DownloadDangerPromptImpl::OnAccepted() { 142 void DownloadDangerPromptImpl::OnAccepted() {
142 RunCallback(accepted_); 143 RunCallback(accepted_);
143 } 144 }
144 145
145 void DownloadDangerPromptImpl::OnCanceled() { 146 void DownloadDangerPromptImpl::OnCanceled() {
146 RunCallback(canceled_); 147 RunCallback(canceled_);
147 } 148 }
148 149
150 void DownloadDangerPromptImpl::OnDismissed() {
151 RunCallback(canceled_);
fdoray 2013/06/28 15:32:59 Should I call OnCanceled here to avoid code duplic
benjhayden 2013/06/28 16:05:46 I have a slight preference for calling RunCallback
152 }
153
149 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) { 154 void DownloadDangerPromptImpl::RunCallback(const base::Closure& callback) {
150 // Invoking the callback can cause the download item state to change or cause 155 // Invoking the callback can cause the download item state to change or cause
151 // the constrained window to close, and |callback| refers to a member 156 // the constrained window to close, and |callback| refers to a member
152 // variable. 157 // variable.
153 base::Closure callback_copy = callback; 158 base::Closure callback_copy = callback;
154 PrepareToClose(); 159 PrepareToClose();
155 if (!callback_copy.is_null()) 160 if (!callback_copy.is_null())
156 callback_copy.Run(); 161 callback_copy.Run();
157 } 162 }
158 163
(...skipping 14 matching lines...) Expand all
173 content::WebContents* web_contents, 178 content::WebContents* web_contents,
174 bool show_context, 179 bool show_context,
175 const base::Closure& accepted, 180 const base::Closure& accepted,
176 const base::Closure& canceled) { 181 const base::Closure& canceled) {
177 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl( 182 DownloadDangerPromptImpl* prompt = new DownloadDangerPromptImpl(
178 item, web_contents, show_context, accepted, canceled); 183 item, web_contents, show_context, accepted, canceled);
179 // |prompt| will be deleted when the dialog is done. 184 // |prompt| will be deleted when the dialog is done.
180 TabModalConfirmDialog::Create(prompt, web_contents); 185 TabModalConfirmDialog::Create(prompt, web_contents);
181 return prompt; 186 return prompt;
182 } 187 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/repost_form_warning_controller.h » ('j') | chrome/browser/ui/tab_modal_confirm_dialog_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698