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/common/chrome_notification_types.h" | 7 #include "chrome/common/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, | |
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 close_delegate_ = NULL; |
32 // Make sure everything is cleaned up. | 30 // Make sure everything is cleaned up. |
33 Cancel(); | 31 Cancel(); |
(...skipping 17 matching lines...) Expand all Loading... |
51 closing_ = true; | 49 closing_ = true; |
52 OnAccepted(); | 50 OnAccepted(); |
53 CloseDialog(); | 51 CloseDialog(); |
54 } | 52 } |
55 | 53 |
56 | 54 |
57 void TabModalConfirmDialogDelegate::Observe( | 55 void TabModalConfirmDialogDelegate::Observe( |
58 int type, | 56 int type, |
59 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
60 const content::NotificationDetails& details) { | 58 const content::NotificationDetails& details) { |
61 // Close the dialog if we load a page (because the action might not apply to | 59 // Close the dialog if the tab is closed. |
62 // the same page anymore) or if the tab is closed. | 60 if (type == chrome::NOTIFICATION_TAB_CLOSING) { |
63 if (type == content::NOTIFICATION_LOAD_START || | |
64 type == chrome::NOTIFICATION_TAB_CLOSING) { | |
65 Cancel(); | 61 Cancel(); |
66 } else { | 62 } else { |
67 NOTREACHED(); | 63 NOTREACHED(); |
68 } | 64 } |
69 } | 65 } |
70 | 66 |
71 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { | 67 gfx::Image* TabModalConfirmDialogDelegate::GetIcon() { |
72 return NULL; | 68 return NULL; |
73 } | 69 } |
74 | 70 |
(...skipping 16 matching lines...) Expand all Loading... |
91 void TabModalConfirmDialogDelegate::OnAccepted() { | 87 void TabModalConfirmDialogDelegate::OnAccepted() { |
92 } | 88 } |
93 | 89 |
94 void TabModalConfirmDialogDelegate::OnCanceled() { | 90 void TabModalConfirmDialogDelegate::OnCanceled() { |
95 } | 91 } |
96 | 92 |
97 void TabModalConfirmDialogDelegate::CloseDialog() { | 93 void TabModalConfirmDialogDelegate::CloseDialog() { |
98 if (close_delegate_) | 94 if (close_delegate_) |
99 close_delegate_->CloseDialog(); | 95 close_delegate_->CloseDialog(); |
100 } | 96 } |
OLD | NEW |