| 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/ui/views/repost_form_warning_view.h" | 5 #include "chrome/browser/ui/views/tab_modal_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/repost_form_warning_controller.h" | |
| 9 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 11 #include "chrome/browser/ui/tab_modal_dialog_delegate.h" |
| 12 #include "chrome/browser/ui/views/constrained_window_views.h" | 12 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 13 #include "content/browser/tab_contents/navigation_controller.h" | 13 #include "content/browser/tab_contents/navigation_controller.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 14 #include "content/browser/tab_contents/tab_contents.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/views/controls/message_box_view.h" | 17 #include "ui/views/controls/message_box_view.h" |
| 18 | 18 |
| 19 namespace browser { | 19 namespace browser { |
| 20 | 20 |
| 21 // Declared in browser_dialogs.h so others don't have to depend on our header. | 21 // Declared in browser_dialogs.h so others don't have to depend on our header. |
| 22 void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window, | 22 void ShowTabModalDialog(TabModalDialogDelegate* delegate, |
| 23 TabContents* tab_contents) { | 23 gfx::NativeWindow parent_window, |
| 24 new RepostFormWarningView(parent_window, tab_contents); | 24 TabContents* tab_contents) { |
| 25 new TabModalDialogDelegateView(delegate, parent_window, tab_contents); |
| 25 } | 26 } |
| 26 | 27 |
| 27 } // namespace browser | 28 } // namespace browser |
| 28 | 29 |
| 29 ////////////////////////////////////////////////////////////////////////////// | 30 ////////////////////////////////////////////////////////////////////////////// |
| 30 // RepostFormWarningView, constructor & destructor: | 31 // TabModalDialogDelegateView, constructor & destructor: |
| 31 | 32 |
| 32 RepostFormWarningView::RepostFormWarningView( | 33 TabModalDialogDelegateView::TabModalDialogDelegateView( |
| 34 TabModalDialogDelegate* delegate, |
| 33 gfx::NativeWindow parent_window, | 35 gfx::NativeWindow parent_window, |
| 34 TabContents* tab_contents) | 36 TabContents* tab_contents) |
| 35 : controller_(new RepostFormWarningController(tab_contents)), | 37 : delegate_(delegate), |
| 36 message_box_view_(NULL) { | 38 message_box_view_(NULL) { |
| 37 message_box_view_ = new views::MessageBoxView( | 39 message_box_view_ = new views::MessageBoxView( |
| 38 views::MessageBoxView::NO_OPTIONS, | 40 views::MessageBoxView::NO_OPTIONS, |
| 39 l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING), | 41 delegate->GetMessage(), |
| 40 string16()); | 42 string16()); |
| 41 TabContentsWrapper* wrapper = | 43 TabContentsWrapper* wrapper = |
| 42 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | 44 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 43 controller_->set_window(new ConstrainedWindowViews(wrapper, this)); | 45 delegate_->set_window(new ConstrainedWindowViews(wrapper, this)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 RepostFormWarningView::~RepostFormWarningView() { | 48 TabModalDialogDelegateView::~TabModalDialogDelegateView() { |
| 47 } | 49 } |
| 48 | 50 |
| 49 ////////////////////////////////////////////////////////////////////////////// | 51 ////////////////////////////////////////////////////////////////////////////// |
| 50 // RepostFormWarningView, views::DialogDelegate implementation: | 52 // TabModalDialogDelegateView, views::DialogDelegate implementation: |
| 51 | 53 |
| 52 string16 RepostFormWarningView::GetWindowTitle() const { | 54 string16 TabModalDialogDelegateView::GetWindowTitle() const { |
| 53 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE); | 55 return delegate_->GetTitle(); |
| 54 } | 56 } |
| 55 | 57 |
| 56 string16 RepostFormWarningView::GetDialogButtonLabel( | 58 string16 TabModalDialogDelegateView::GetDialogButtonLabel( |
| 57 ui::DialogButton button) const { | 59 ui::DialogButton button) const { |
| 58 if (button == ui::DIALOG_BUTTON_OK) | 60 if (button == ui::DIALOG_BUTTON_OK) |
| 59 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND); | 61 return delegate_->GetAcceptButtonTitle(); |
| 60 if (button == ui::DIALOG_BUTTON_CANCEL) | 62 if (button == ui::DIALOG_BUTTON_CANCEL) |
| 61 return l10n_util::GetStringUTF16(IDS_CANCEL); | 63 return delegate_->GetCancelButtonTitle(); |
| 62 return string16(); | 64 return string16(); |
| 63 } | 65 } |
| 64 | 66 |
| 65 views::View* RepostFormWarningView::GetContentsView() { | 67 bool TabModalDialogDelegateView::Cancel() { |
| 66 return message_box_view_; | 68 delegate_->Cancel(); |
| 67 } | |
| 68 | |
| 69 views::Widget* RepostFormWarningView::GetWidget() { | |
| 70 return message_box_view_->GetWidget(); | |
| 71 } | |
| 72 | |
| 73 const views::Widget* RepostFormWarningView::GetWidget() const { | |
| 74 return message_box_view_->GetWidget(); | |
| 75 } | |
| 76 | |
| 77 bool RepostFormWarningView::Cancel() { | |
| 78 controller_->Cancel(); | |
| 79 return true; | 69 return true; |
| 80 } | 70 } |
| 81 | 71 |
| 82 bool RepostFormWarningView::Accept() { | 72 bool TabModalDialogDelegateView::Accept() { |
| 83 controller_->Continue(); | 73 delegate_->Accept(); |
| 84 return true; | 74 return true; |
| 85 } | 75 } |
| 86 | 76 |
| 87 /////////////////////////////////////////////////////////////////////////////// | 77 /////////////////////////////////////////////////////////////////////////////// |
| 88 // RepostFormWarningView, RepostFormWarning implementation: | 78 // TabModalDialogDelegateView, views::WidgetDelegate implementation: |
| 89 | 79 |
| 90 void RepostFormWarningView::DeleteDelegate() { | 80 views::View* TabModalDialogDelegateView::GetContentsView() { |
| 81 return message_box_view_; |
| 82 } |
| 83 |
| 84 views::Widget* TabModalDialogDelegateView::GetWidget() { |
| 85 return message_box_view_->GetWidget(); |
| 86 } |
| 87 |
| 88 const views::Widget* TabModalDialogDelegateView::GetWidget() const { |
| 89 return message_box_view_->GetWidget(); |
| 90 } |
| 91 |
| 92 void TabModalDialogDelegateView::DeleteDelegate() { |
| 91 delete this; | 93 delete this; |
| 92 } | 94 } |
| OLD | NEW |