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

Side by Side Diff: chrome/browser/ui/tab_modal_confirm_dialog_delegate.cc

Issue 17500003: Close web contents modal dialogs on content load start (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compilation fixes, change "inhibit" variable names 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 | Annotate | Revision Log
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/ui/tab_modal_confirm_dialog_delegate.h" 5 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "content/public/browser/navigation_controller.h" 8 #include "content/public/browser/navigation_controller.h"
9 #include "content/public/browser/notification_source.h" 9 #include "content/public/browser/notification_source.h"
10 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 13
14 using content::NavigationController; 14 using content::NavigationController;
15 using content::WebContents; 15 using content::WebContents;
16 16
17 TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate( 17 TabModalConfirmDialogDelegate::TabModalConfirmDialogDelegate(
18 WebContents* web_contents) 18 WebContents* web_contents)
19 : close_delegate_(NULL), 19 : operations_delegate_(NULL),
20 closing_(false) { 20 closing_(false) {
21 NavigationController* controller = &web_contents->GetController(); 21 NavigationController* controller = &web_contents->GetController();
22 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
23 content::Source<NavigationController>(controller));
24 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, 22 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING,
25 content::Source<NavigationController>(controller)); 23 content::Source<NavigationController>(controller));
26 } 24 }
27 25
28 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() { 26 TabModalConfirmDialogDelegate::~TabModalConfirmDialogDelegate() {
29 // If we end up here, the window has been closed, so make sure we don't close 27 // If we end up here, the window has been closed, so make sure we don't close
30 // it again. 28 // it again.
31 close_delegate_ = NULL; 29 operations_delegate_ = NULL;
32 // Make sure everything is cleaned up. 30 // Make sure everything is cleaned up.
33 Cancel(); 31 Cancel();
34 } 32 }
35 33
36 void TabModalConfirmDialogDelegate::Cancel() { 34 void TabModalConfirmDialogDelegate::Cancel() {
37 if (closing_) 35 if (closing_)
38 return; 36 return;
39 // Make sure we won't do anything when |Cancel()| or |Accept()| is called 37 // Make sure we won't do anything when |Cancel()| or |Accept()| is called
40 // again. 38 // again.
41 closing_ = true; 39 closing_ = true;
(...skipping 18 matching lines...) Expand all
60 // Make sure we won't do anything when another action occurs. 58 // Make sure we won't do anything when another action occurs.
61 closing_ = true; 59 closing_ = true;
62 OnLinkClicked(disposition); 60 OnLinkClicked(disposition);
63 CloseDialog(); 61 CloseDialog();
64 } 62 }
65 63
66 void TabModalConfirmDialogDelegate::Observe( 64 void TabModalConfirmDialogDelegate::Observe(
67 int type, 65 int type,
68 const content::NotificationSource& source, 66 const content::NotificationSource& source,
69 const content::NotificationDetails& details) { 67 const content::NotificationDetails& details) {
70 // Close the dialog if we load a page (because the action might not apply to 68 // Close the dialog if the tab is closed.
71 // the same page anymore) or if the tab is closed. 69 if (type == chrome::NOTIFICATION_TAB_CLOSING) {
72 if (type == content::NOTIFICATION_LOAD_START ||
73 type == chrome::NOTIFICATION_TAB_CLOSING) {
74 Cancel(); 70 Cancel();
75 } else { 71 } else {
76 NOTREACHED(); 72 NOTREACHED();
77 } 73 }
78 } 74 }
79 75
80 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { 76 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() {
81 return NULL; 77 return NULL;
82 } 78 }
83 79
(...skipping 21 matching lines...) Expand all
105 } 101 }
106 102
107 void TabModalConfirmDialogDelegate::OnCanceled() { 103 void TabModalConfirmDialogDelegate::OnCanceled() {
108 } 104 }
109 105
110 void TabModalConfirmDialogDelegate::OnLinkClicked( 106 void TabModalConfirmDialogDelegate::OnLinkClicked(
111 WindowOpenDisposition disposition) { 107 WindowOpenDisposition disposition) {
112 } 108 }
113 109
114 void TabModalConfirmDialogDelegate::CloseDialog() { 110 void TabModalConfirmDialogDelegate::CloseDialog() {
115 if (close_delegate_) 111 if (operations_delegate_)
116 close_delegate_->CloseDialog(); 112 operations_delegate_->CloseDialog();
117 } 113 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tab_modal_confirm_dialog_delegate.h ('k') | chrome/browser/ui/views/autofill/autofill_dialog_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698