| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/repost_form_warning_controller.h" | 5 #include "chrome/browser/repost_form_warning_controller.h" |
| 6 | 6 |
| 7 #include "content/browser/tab_contents/tab_contents.h" | 7 #include "content/browser/tab_contents/tab_contents.h" |
| 8 #include "content/common/notification_source.h" | 8 #include "content/common/notification_source.h" |
| 9 | 9 |
| 10 RepostFormWarningController::RepostFormWarningController( | 10 RepostFormWarningController::RepostFormWarningController( |
| 11 TabContents* tab_contents) | 11 TabContents* tab_contents) |
| 12 : tab_contents_(tab_contents), | 12 : tab_contents_(tab_contents), |
| 13 window_(NULL) { | 13 window_(NULL) { |
| 14 NavigationController* controller = &tab_contents->controller(); | 14 NavigationController* controller = &tab_contents->controller(); |
| 15 registrar_.Add(this, NotificationType::LOAD_START, | 15 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 16 Source<NavigationController>(controller)); | 16 Source<NavigationController>(controller)); |
| 17 registrar_.Add(this, NotificationType::TAB_CLOSING, | 17 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING, |
| 18 Source<NavigationController>(controller)); | 18 Source<NavigationController>(controller)); |
| 19 registrar_.Add(this, NotificationType::REPOST_WARNING_SHOWN, | 19 registrar_.Add(this, content::NOTIFICATION_REPOST_WARNING_SHOWN, |
| 20 Source<NavigationController>(controller)); | 20 Source<NavigationController>(controller)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 RepostFormWarningController::~RepostFormWarningController() { | 23 RepostFormWarningController::~RepostFormWarningController() { |
| 24 // If we end up here, the constrained window has been closed, so make sure we | 24 // If we end up here, the constrained window has been closed, so make sure we |
| 25 // don't close it again. | 25 // don't close it again. |
| 26 window_ = NULL; | 26 window_ = NULL; |
| 27 // Make sure everything is cleaned up. | 27 // Make sure everything is cleaned up. |
| 28 Cancel(); | 28 Cancel(); |
| 29 } | 29 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 | 42 |
| 43 void RepostFormWarningController::Continue() { | 43 void RepostFormWarningController::Continue() { |
| 44 if (tab_contents_) { | 44 if (tab_contents_) { |
| 45 tab_contents_->controller().ContinuePendingReload(); | 45 tab_contents_->controller().ContinuePendingReload(); |
| 46 // If we reload the page, the dialog will be closed anyway. | 46 // If we reload the page, the dialog will be closed anyway. |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void RepostFormWarningController::Observe(NotificationType type, | 50 void RepostFormWarningController::Observe(int type, |
| 51 const NotificationSource& source, | 51 const NotificationSource& source, |
| 52 const NotificationDetails& details) { | 52 const NotificationDetails& details) { |
| 53 // Close the dialog if we load a page (because reloading might not apply to | 53 // Close the dialog if we load a page (because reloading might not apply to |
| 54 // the same page anymore) or if the tab is closed, because then we won't have | 54 // the same page anymore) or if the tab is closed, because then we won't have |
| 55 // a navigation controller anymore. | 55 // a navigation controller anymore. |
| 56 if (tab_contents_ && | 56 if (tab_contents_ && |
| 57 (type == NotificationType::LOAD_START || | 57 (type == content::NOTIFICATION_LOAD_START || |
| 58 type == NotificationType::TAB_CLOSING || | 58 type == content::NOTIFICATION_TAB_CLOSING || |
| 59 type == NotificationType::REPOST_WARNING_SHOWN)) { | 59 type == content::NOTIFICATION_REPOST_WARNING_SHOWN)) { |
| 60 DCHECK_EQ(Source<NavigationController>(source).ptr(), | 60 DCHECK_EQ(Source<NavigationController>(source).ptr(), |
| 61 &tab_contents_->controller()); | 61 &tab_contents_->controller()); |
| 62 Cancel(); | 62 Cancel(); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RepostFormWarningController::CloseDialog() { | 66 void RepostFormWarningController::CloseDialog() { |
| 67 // Make sure we won't do anything when |Cancel()| is called again. | 67 // Make sure we won't do anything when |Cancel()| is called again. |
| 68 tab_contents_ = NULL; | 68 tab_contents_ = NULL; |
| 69 if (window_) { | 69 if (window_) { |
| 70 window_->CloseConstrainedWindow(); | 70 window_->CloseConstrainedWindow(); |
| 71 } | 71 } |
| 72 } | 72 } |
| OLD | NEW |