OLD | NEW |
---|---|
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 : close_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, | 22 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
23 content::Source<NavigationController>(controller)); | 23 content::Source<NavigationController>(controller)); |
24 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING, | |
25 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 close_delegate_ = NULL; |
32 // Make sure everything is cleaned up. | 30 // Make sure everything is cleaned up. |
33 Cancel(); | 31 Cancel(); |
34 } | 32 } |
35 | 33 |
(...skipping 23 matching lines...) Expand all Loading... | |
59 closing_ = true; | 57 closing_ = true; |
60 OnLinkClicked(disposition); | 58 OnLinkClicked(disposition); |
61 CloseDialog(); | 59 CloseDialog(); |
62 } | 60 } |
63 | 61 |
64 void TabModalConfirmDialogDelegate::Observe( | 62 void TabModalConfirmDialogDelegate::Observe( |
65 int type, | 63 int type, |
66 const content::NotificationSource& source, | 64 const content::NotificationSource& source, |
67 const content::NotificationDetails& details) { | 65 const content::NotificationDetails& details) { |
68 // Close the dialog if we load a page (because the action might not apply to | 66 // Close the dialog if we load a page (because the action might not apply to |
69 // the same page anymore) or if the tab is closed. | 67 // the same page anymore). |
70 if (type == content::NOTIFICATION_LOAD_START || | 68 DCHECK(type == content::NOTIFICATION_LOAD_START); |
sky
2013/09/04 14:12:51
DCHECK_EQ
Mike Wittman
2013/09/04 16:59:28
Done.
| |
71 type == chrome::NOTIFICATION_TAB_CLOSING) { | 69 |
72 Close(); | 70 Close(); |
73 } else { | |
74 NOTREACHED(); | |
75 } | |
76 } | 71 } |
77 | 72 |
78 void TabModalConfirmDialogDelegate::Close() { | 73 void TabModalConfirmDialogDelegate::Close() { |
79 if (closing_) | 74 if (closing_) |
80 return; | 75 return; |
81 // Make sure we won't do anything when another action occurs. | 76 // Make sure we won't do anything when another action occurs. |
82 closing_ = true; | 77 closing_ = true; |
83 OnClosed(); | 78 OnClosed(); |
84 CloseDialog(); | 79 CloseDialog(); |
85 } | 80 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 WindowOpenDisposition disposition) { | 113 WindowOpenDisposition disposition) { |
119 } | 114 } |
120 | 115 |
121 void TabModalConfirmDialogDelegate::OnClosed() { | 116 void TabModalConfirmDialogDelegate::OnClosed() { |
122 } | 117 } |
123 | 118 |
124 void TabModalConfirmDialogDelegate::CloseDialog() { | 119 void TabModalConfirmDialogDelegate::CloseDialog() { |
125 if (close_delegate_) | 120 if (close_delegate_) |
126 close_delegate_->CloseDialog(); | 121 close_delegate_->CloseDialog(); |
127 } | 122 } |
OLD | NEW |