Home | History | Annotate | Download | only in views
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/repost_form_warning_view.h"
      6 
      7 #include "base/utf_string_conversions.h"
      8 #include "chrome/browser/repost_form_warning_controller.h"
      9 #include "chrome/browser/ui/browser_list.h"
     10 #include "chrome/browser/ui/browser_window.h"
     11 #include "content/browser/tab_contents/navigation_controller.h"
     12 #include "content/browser/tab_contents/tab_contents.h"
     13 #include "grit/generated_resources.h"
     14 #include "ui/base/l10n/l10n_util.h"
     15 #include "ui/base/message_box_flags.h"
     16 #include "views/controls/message_box_view.h"
     17 #include "views/window/window.h"
     18 
     19 namespace browser {
     20 
     21 // Declared in browser_dialogs.h so others don't have to depend on our header.
     22 void 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 
     32 RepostFormWarningView::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 views::MessageBoxView(
     38       ui::MessageBoxFlags::kIsConfirmMessageBox,
     39       UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING)),
     40       std::wstring());
     41   controller_->Show(this);
     42 }
     43 
     44 RepostFormWarningView::~RepostFormWarningView() {
     45 }
     46 
     47 //////////////////////////////////////////////////////////////////////////////
     48 // RepostFormWarningView, views::DialogDelegate implementation:
     49 
     50 std::wstring RepostFormWarningView::GetWindowTitle() const {
     51   return UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE));
     52 }
     53 
     54 std::wstring RepostFormWarningView::GetDialogButtonLabel(
     55     ui::MessageBoxFlags::DialogButton button) const {
     56   if (button == ui::MessageBoxFlags::DIALOGBUTTON_OK)
     57     return UTF16ToWide(l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND));
     58   if (button == ui::MessageBoxFlags::DIALOGBUTTON_CANCEL)
     59     return UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANCEL));
     60   return std::wstring();
     61 }
     62 
     63 views::View* RepostFormWarningView::GetContentsView() {
     64   return message_box_view_;
     65 }
     66 
     67 bool RepostFormWarningView::Cancel() {
     68   controller_->Cancel();
     69   return true;
     70 }
     71 
     72 bool RepostFormWarningView::Accept() {
     73   controller_->Continue();
     74   return true;
     75 }
     76 
     77 ///////////////////////////////////////////////////////////////////////////////
     78 // RepostFormWarningView, RepostFormWarning implementation:
     79 
     80 void RepostFormWarningView::DeleteDelegate() {
     81   delete this;
     82 }
     83