repost_form_warning_view.cc revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
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/views/repost_form_warning_view.h"
6
7#include "app/l10n_util.h"
8#include "app/message_box_flags.h"
9#include "base/utf_string_conversions.h"
10#include "chrome/browser/browser_list.h"
11#include "chrome/browser/browser_window.h"
12#include "chrome/browser/repost_form_warning_controller.h"
13#include "chrome/browser/tab_contents/navigation_controller.h"
14#include "chrome/browser/tab_contents/tab_contents.h"
15#include "grit/generated_resources.h"
16#include "views/controls/message_box_view.h"
17#include "views/window/window.h"
18
19namespace browser {
20
21// Declared in browser_dialogs.h so others don't have to depend on our header.
22void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
23                                 TabContents* tab_contents) {
24  new RepostFormWarningView(parent_window, tab_contents);
25}
26
27}  // namespace browser
28
29//////////////////////////////////////////////////////////////////////////////
30// RepostFormWarningView, constructor & destructor:
31
32RepostFormWarningView::RepostFormWarningView(
33    gfx::NativeWindow parent_window,
34    TabContents* tab_contents)
35      : controller_(new RepostFormWarningController(tab_contents)),
36        message_box_view_(NULL) {
37  message_box_view_ = new MessageBoxView(
38      MessageBoxFlags::kIsConfirmMessageBox,
39      UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING)),
40      std::wstring());
41  controller_->Show(this);
42}
43
44RepostFormWarningView::~RepostFormWarningView() {
45}
46
47//////////////////////////////////////////////////////////////////////////////
48// RepostFormWarningView, views::DialogDelegate implementation:
49
50std::wstring RepostFormWarningView::GetWindowTitle() const {
51  return UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE));
52}
53
54std::wstring RepostFormWarningView::GetDialogButtonLabel(
55    MessageBoxFlags::DialogButton button) const {
56  if (button == MessageBoxFlags::DIALOGBUTTON_OK)
57    return UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND));
58  if (button == MessageBoxFlags::DIALOGBUTTON_CANCEL)
59    return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
60  return std::wstring();
61}
62
63views::View* RepostFormWarningView::GetContentsView() {
64  return message_box_view_;
65}
66
67bool RepostFormWarningView::Cancel() {
68  controller_->Cancel();
69  return true;
70}
71
72bool RepostFormWarningView::Accept() {
73  controller_->Continue();
74  return true;
75}
76
77///////////////////////////////////////////////////////////////////////////////
78// RepostFormWarningView, RepostFormWarning implementation:
79
80void RepostFormWarningView::DeleteDelegate() {
81  delete this;
82}
83