[email protected] | ebbbb9f | 2011-03-09 13:16:14 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/repost_form_warning_controller.h" | ||||
6 | |||||
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 7 | #if defined(TOOLKIT_GTK) |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 8 | #include <gtk/gtk.h> |
9 | #endif | ||||
10 | |||||
11 | #include "base/bind.h" | ||||
12 | #include "base/bind_helpers.h" | ||||
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 13 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 14 | #include "content/public/browser/notification_source.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 15 | #include "content/public/browser/notification_types.h" |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 16 | #include "content/public/browser/web_contents.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 17 | #include "grit/generated_resources.h" |
18 | #include "ui/base/l10n/l10n_util.h" | ||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 19 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 20 | using content::NavigationController; |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 21 | using content::WebContents; |
22 | |||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 23 | RepostFormWarningController::RepostFormWarningController( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 24 | WebContents* web_contents) |
25 | : TabModalConfirmDialogDelegate(web_contents), | ||||
26 | navigation_controller_(&web_contents->GetController()) { | ||||
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 27 | registrar_.Add(this, content::NOTIFICATION_REPOST_WARNING_SHOWN, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 28 | content::Source<NavigationController>( |
[email protected] | cca0f1e | 2012-01-03 18:27:46 | [diff] [blame] | 29 | navigation_controller_)); |
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 30 | } |
31 | |||||
32 | RepostFormWarningController::~RepostFormWarningController() { | ||||
33 | } | ||||
34 | |||||
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 35 | string16 RepostFormWarningController::GetTitle() { |
36 | return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE); | ||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 37 | } |
38 | |||||
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 39 | string16 RepostFormWarningController::GetMessage() { |
40 | return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING); | ||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 41 | } |
42 | |||||
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 43 | string16 RepostFormWarningController::GetAcceptButtonTitle() { |
44 | return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND); | ||||
45 | } | ||||
46 | |||||
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 47 | #if defined(TOOLKIT_GTK) |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 48 | const char* RepostFormWarningController::GetAcceptButtonIcon() { |
49 | return GTK_STOCK_REFRESH; | ||||
50 | } | ||||
51 | |||||
52 | const char* RepostFormWarningController::GetCancelButtonIcon() { | ||||
53 | return GTK_STOCK_CANCEL; | ||||
54 | } | ||||
[email protected] | a13283cc | 2012-04-05 00:21:22 | [diff] [blame] | 55 | #endif // defined(TOOLKIT_GTK) |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 56 | |
57 | void RepostFormWarningController::OnAccepted() { | ||||
58 | navigation_controller_->ContinuePendingReload(); | ||||
59 | } | ||||
60 | |||||
61 | void RepostFormWarningController::OnCanceled() { | ||||
62 | navigation_controller_->CancelPendingReload(); | ||||
63 | } | ||||
64 | |||||
65 | void RepostFormWarningController::Observe( | ||||
66 | int type, | ||||
67 | const content::NotificationSource& source, | ||||
68 | const content::NotificationDetails& details) { | ||||
69 | // Close the dialog if we show an additional dialog, to avoid them | ||||
70 | // stacking up. | ||||
71 | if (type == content::NOTIFICATION_REPOST_WARNING_SHOWN) | ||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 72 | Cancel(); |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 73 | else |
74 | TabModalConfirmDialogDelegate::Observe(type, source, details); | ||||
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 75 | } |