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

Side by Side Diff: chrome/browser/repost_form_warning_controller.cc

Issue 8851007: WIP / Do not commit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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) 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 "chrome/browser/ui/constrained_window.h" 7 #if defined(TOOLKIT_USES_GTK)
8 #include <gtk/gtk.h>
9 #endif
10
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "content/browser/tab_contents/navigation_controller.h"
8 #include "content/browser/tab_contents/tab_contents.h" 14 #include "content/browser/tab_contents/tab_contents.h"
9 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
10 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h"
11 19
12 RepostFormWarningController::RepostFormWarningController( 20 RepostFormWarningController::RepostFormWarningController(
13 TabContents* tab_contents) 21 TabContents* tab_contents)
14 : tab_contents_(tab_contents), 22 : TabModalDialogDelegate(tab_contents) {
15 window_(NULL) {
16 NavigationController* controller = &tab_contents->controller();
17 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
18 content::Source<NavigationController>(controller));
19 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSING,
20 content::Source<NavigationController>(controller));
21 registrar_.Add(this, content::NOTIFICATION_REPOST_WARNING_SHOWN, 23 registrar_.Add(this, content::NOTIFICATION_REPOST_WARNING_SHOWN,
22 content::Source<NavigationController>(controller)); 24 content::Source<NavigationController>(
25 &tab_contents->controller()));
23 } 26 }
24 27
25 RepostFormWarningController::~RepostFormWarningController() { 28 RepostFormWarningController::~RepostFormWarningController() {
26 // If we end up here, the constrained window has been closed, so make sure we
27 // don't close it again.
28 window_ = NULL;
29 // Make sure everything is cleaned up.
30 Cancel();
31 } 29 }
32 30
33 void RepostFormWarningController::Cancel() { 31 string16 RepostFormWarningController::GetTitle() {
34 if (tab_contents_) { 32 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE);
35 tab_contents_->controller().CancelPendingReload();
36 CloseDialog();
37 }
38 } 33 }
39 34
40 void RepostFormWarningController::Continue() { 35 string16 RepostFormWarningController::GetMessage() {
41 if (tab_contents_) { 36 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING);
42 tab_contents_->controller().ContinuePendingReload();
43 // If we reload the page, the dialog will be closed anyway.
44 }
45 } 37 }
46 38
47 void RepostFormWarningController::Observe(int type, 39 string16 RepostFormWarningController::GetAcceptButtonTitle() {
48 const content::NotificationSource& source, 40 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND);
49 const content::NotificationDetails& details) {
50 // Close the dialog if we load a page (because reloading might not apply to
51 // the same page anymore) or if the tab is closed, because then we won't have
52 // a navigation controller anymore.
53 if (tab_contents_ &&
54 (type == content::NOTIFICATION_LOAD_START ||
55 type == content::NOTIFICATION_TAB_CLOSING ||
56 type == content::NOTIFICATION_REPOST_WARNING_SHOWN)) {
57 DCHECK_EQ(content::Source<NavigationController>(source).ptr(),
58 &tab_contents_->controller());
59 Cancel();
60 }
61 } 41 }
62 42
63 void RepostFormWarningController::CloseDialog() { 43 #if defined(TOOLKIT_USES_GTK)
64 // Make sure we won't do anything when |Cancel()| is called again. 44 const char* RepostFormWarningController::GetAcceptButtonIcon() {
65 tab_contents_ = NULL; 45 return GTK_STOCK_REFRESH;
66 if (window_) {
67 window_->CloseConstrainedWindow();
68 }
69 } 46 }
47
48 const char* RepostFormWarningController::GetCancelButtonTitleIcon() {
49 return GTK_STOCK_CANCEL;
50 }
51 #endif // defined(TOOLKIT_USES_GTK)
52
53 void RepostFormWarningController::OnAccepted() {
54 navigation_controller_->ContinuePendingReload();
55 }
56
57 void RepostFormWarningController::OnCanceled() {
58 navigation_controller_->CancelPendingReload();
59 }
60
61 void RepostFormWarningController::Observe(
62 int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) {
65 // Close the dialog if we show an additional dialog, to avoid them
66 // stacking up.
67 if (type == content::NOTIFICATION_REPOST_WARNING_SHOWN)
68 Cancel();
69 else
70 TabModalDialogDelegate::Observe(type, source, details);
71 }
OLDNEW
« no previous file with comments | « chrome/browser/repost_form_warning_controller.h ('k') | chrome/browser/resources/plugins_mac.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698