| Index: chrome/browser/ui/webui/tab_modal_dialog_ui.cc
|
| diff --git a/chrome/browser/ui/webui/repost_form_warning_ui.cc b/chrome/browser/ui/webui/tab_modal_dialog_ui.cc
|
| similarity index 52%
|
| rename from chrome/browser/ui/webui/repost_form_warning_ui.cc
|
| rename to chrome/browser/ui/webui/tab_modal_dialog_ui.cc
|
| index 652fdcb7e720707f7e9bebb4176fe430cc547fe3..6ef4704a38e2f20a2af126c4c94289bac68e7144 100644
|
| --- a/chrome/browser/ui/webui/repost_form_warning_ui.cc
|
| +++ b/chrome/browser/ui/webui/tab_modal_dialog_ui.cc
|
| @@ -2,19 +2,20 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/ui/webui/repost_form_warning_ui.h"
|
| +#include "chrome/browser/ui/webui/tab_modal_dialog_ui.h"
|
|
|
| #include <string>
|
|
|
| #include "base/basictypes.h"
|
| #include "base/json/json_reader.h"
|
| -#include "base/message_loop.h"
|
| +#include "base/json/json_writer.h"
|
| #include "base/string_piece.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/repost_form_warning_controller.h"
|
| +#include "chrome/browser/ui/constrained_window.h"
|
| #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "chrome/browser/ui/tab_modal_dialog_delegate.h"
|
| #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
|
| #include "chrome/browser/ui/webui/constrained_html_ui.h"
|
| #include "chrome/browser/ui/webui/html_dialog_ui.h"
|
| @@ -32,36 +33,28 @@ using std::string;
|
| namespace browser {
|
|
|
| // Declared in browser_dialogs.h so others don't have to depend on our header.
|
| -void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
|
| - TabContents* tab_contents) {
|
| - new RepostFormWarningUI(parent_window, tab_contents);
|
| +void ShowTabModalDialog(TabModalDialogDelegate* delegate,
|
| + gfx::NativeWindow parent_window,
|
| + TabContents* tab_contents) {
|
| + new TabModalDialogUI(delegate, tab_contents);
|
| }
|
|
|
| } // namespace browser
|
|
|
| -class RepostFormWarningSource : public ChromeURLDataManager::DataSource {
|
| +class TabModalDialogSource : public ChromeURLDataManager::DataSource {
|
| public:
|
| - RepostFormWarningSource()
|
| - : DataSource(chrome::kChromeUIRepostFormWarningHost,
|
| + TabModalDialogSource()
|
| + : DataSource(chrome::kChromeUITabModalDialogHost,
|
| MessageLoop::current()) {
|
| }
|
|
|
| virtual void StartDataRequest(const std::string& path,
|
| bool is_off_the_record,
|
| int request_id) OVERRIDE {
|
| - DictionaryValue dict;
|
| - dict.SetString("explanation",
|
| - l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING));
|
| - dict.SetString("resend",
|
| - l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND));
|
| - dict.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
|
| -
|
| - SetFontAndTextDirection(&dict);
|
| - base::StringPiece html =
|
| + std::string html(
|
| ResourceBundle::GetSharedInstance().GetRawDataResource(
|
| - IDR_REPOST_FORM_WARNING_HTML);
|
| - string response = jstemplate_builder::GetI18nTemplateHtml(html, &dict);
|
| - SendResponse(request_id, base::RefCountedString::TakeString(&response));
|
| + IDR_TAB_MODAL_DIALOG_HTML).as_string());
|
| + SendResponse(request_id, base::RefCountedString::TakeString(&html));
|
| }
|
|
|
| virtual string GetMimeType(const std::string& path) const OVERRIDE {
|
| @@ -70,20 +63,23 @@ class RepostFormWarningSource : public ChromeURLDataManager::DataSource {
|
|
|
| static void RegisterDataSource(Profile* profile) {
|
| ChromeURLDataManager* url_manager = profile->GetChromeURLDataManager();
|
| - url_manager->AddDataSource(new RepostFormWarningSource());
|
| + url_manager->AddDataSource(new TabModalDialogSource());
|
| }
|
|
|
| private:
|
| - virtual ~RepostFormWarningSource() {}
|
| + virtual ~TabModalDialogSource() {}
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(RepostFormWarningSource);
|
| + DISALLOW_COPY_AND_ASSIGN(TabModalDialogSource);
|
| };
|
|
|
| -class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
|
| +class TabModalDialogHtmlDelegate : public HtmlDialogUIDelegate {
|
| public:
|
| - explicit RepostFormWarningHtmlDelegate(RepostFormWarningUI* ui) : ui_(ui) {}
|
| + TabModalDialogHtmlDelegate(TabModalDialogUI* ui,
|
| + TabModalDialogDelegate* dialog_delegate)
|
| + : ui_(ui),
|
| + dialog_delegate_(dialog_delegate) {}
|
|
|
| - virtual ~RepostFormWarningHtmlDelegate() {}
|
| + virtual ~TabModalDialogHtmlDelegate() {}
|
|
|
| // HtmlDialogUIDelegate implementation.
|
| virtual bool IsDialogModal() const OVERRIDE {
|
| @@ -91,11 +87,11 @@ class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
|
| }
|
|
|
| virtual string16 GetDialogTitle() const OVERRIDE {
|
| - return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE);
|
| + return dialog_delegate_->GetTitle();
|
| }
|
|
|
| virtual GURL GetDialogContentURL() const OVERRIDE {
|
| - return GURL(chrome::kChromeUIRepostFormWarningURL);
|
| + return GURL(chrome::kChromeUITabModalDialogURL);
|
| }
|
|
|
| virtual void GetWebUIMessageHandlers(
|
| @@ -106,20 +102,26 @@ class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
|
| }
|
|
|
| virtual std::string GetDialogArgs() const OVERRIDE {
|
| - return string();
|
| + DictionaryValue dict;
|
| + dict.SetString("message", dialog_delegate_->GetMessage());
|
| + dict.SetString("accept", dialog_delegate_->GetAcceptButtonTitle());
|
| + dict.SetString("cancel", dialog_delegate_->GetCancelButtonTitle());
|
| + TabModalDialogSource::SetFontAndTextDirection(&dict);
|
| + std::string json;
|
| + base::JSONWriter::Write(&dict, false, &json);
|
| + return json;
|
| }
|
|
|
| virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE {
|
| - bool repost = false;
|
| + bool accepted = false;
|
| if (!json_retval.empty()) {
|
| base::JSONReader reader;
|
| scoped_ptr<Value> value(reader.JsonToValue(json_retval, false, false));
|
| - if (!value.get() || !value->GetAsBoolean(&repost))
|
| - NOTREACHED() << "Missing or unreadable response from dialog";
|
| + DCHECK(value.get() && value->GetAsBoolean(&accepted))
|
| + << "Missing or unreadable response from dialog";
|
| }
|
|
|
| - ui_->OnDialogClosed(repost);
|
| - ui_ = NULL;
|
| + ui_->OnDialogClosed(accepted);
|
| delete this;
|
| }
|
|
|
| @@ -132,35 +134,36 @@ class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
|
|
|
| private:
|
| static const int kDialogWidth = 400;
|
| - static const int kDialogHeight = 108;
|
| + static const int kDialogHeight = 120;
|
|
|
| - RepostFormWarningUI* ui_; // not owned
|
| + scoped_ptr<TabModalDialogUI> ui_;
|
| + // Owned by TabModalDialogUI, which we own.
|
| + TabModalDialogDelegate* dialog_delegate_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(RepostFormWarningHtmlDelegate);
|
| + DISALLOW_COPY_AND_ASSIGN(TabModalDialogHtmlDelegate);
|
| };
|
|
|
| -RepostFormWarningUI::RepostFormWarningUI(gfx::NativeWindow parent_window,
|
| - TabContents* tab_contents)
|
| - : controller_(new RepostFormWarningController(tab_contents)) {
|
| +TabModalDialogUI::TabModalDialogUI(TabModalDialogDelegate* delegate,
|
| + TabContents* tab_contents)
|
| + : delegate_(delegate) {
|
| TabContentsWrapper* wrapper =
|
| TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
|
| Profile* profile = wrapper->profile();
|
| - RepostFormWarningSource::RegisterDataSource(profile);
|
| - RepostFormWarningHtmlDelegate* html_delegate =
|
| - new RepostFormWarningHtmlDelegate(this);
|
| + TabModalDialogSource::RegisterDataSource(profile);
|
| + TabModalDialogHtmlDelegate* html_delegate =
|
| + new TabModalDialogHtmlDelegate(this, delegate);
|
| ConstrainedHtmlUIDelegate* dialog_delegate =
|
| - ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
|
| - profile, html_delegate, wrapper);
|
| - controller_->set_window(dialog_delegate->window());
|
| + ConstrainedHtmlUI::CreateConstrainedHtmlDialog(profile, html_delegate,
|
| + wrapper);
|
| + delegate_->set_window(dialog_delegate->window());
|
| }
|
|
|
| -RepostFormWarningUI::~RepostFormWarningUI() {}
|
| +TabModalDialogUI::~TabModalDialogUI() {}
|
|
|
| -void RepostFormWarningUI::OnDialogClosed(bool repost) {
|
| - controller_->set_window(NULL);
|
| - if (repost)
|
| - controller_->Continue();
|
| +void TabModalDialogUI::OnDialogClosed(bool accepted) {
|
| + delegate_->set_window(NULL);
|
| + if (accepted)
|
| + delegate_->Accept();
|
| else
|
| - controller_->Cancel();
|
| - delete this;
|
| + delegate_->Cancel();
|
| }
|
|
|