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

Side by Side Diff: chrome/browser/ui/webui/repost_form_warning_ui.cc

Issue 7828065: chromeos: Add WebUI implementation of form repost dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 9 years, 3 months 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
« no previous file with comments | « chrome/browser/ui/webui/repost_form_warning_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/webui/repost_form_warning_ui.h"
6
7 #include <string>
8
9 #include "base/basictypes.h"
10 #include "base/json/json_reader.h"
11 #include "base/string_piece.h"
12 #include "base/utf_string_conversions.h"
13 #include "base/values.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/repost_form_warning_controller.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
17 #include "chrome/browser/ui/webui/constrained_html_ui.h"
18 #include "chrome/browser/ui/webui/html_dialog_ui.h"
19 #include "chrome/common/jstemplate_builder.h"
20 #include "chrome/common/url_constants.h"
21 #include "content/browser/tab_contents/tab_contents.h"
22 #include "grit/browser_resources.h"
23 #include "grit/generated_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/size.h"
27
28 using std::string;
29
30 namespace browser {
31
32 // Declared in browser_dialogs.h so others don't have to depend on our header.
33 void ShowRepostFormWarningDialog(gfx::NativeWindow parent_window,
34 TabContents* tab_contents) {
35 new RepostFormWarningUI(parent_window, tab_contents);
36 }
37
38 } // namespace browser
39
40 class RepostFormWarningSource : public ChromeURLDataManager::DataSource {
41 public:
42 RepostFormWarningSource()
43 : DataSource(chrome::kChromeUIRepostFormWarningHost,
44 MessageLoop::current()) {
45 }
46
47 virtual void StartDataRequest(const std::string& path,
48 bool is_off_the_record,
49 int request_id) OVERRIDE {
50 DictionaryValue dict;
51 dict.SetString("explanation",
52 l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING));
53 dict.SetString("resend",
54 l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_RESEND));
55 dict.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL));
56
57 SetFontAndTextDirection(&dict);
58 base::StringPiece html =
59 ResourceBundle::GetSharedInstance().GetRawDataResource(
60 IDR_REPOST_FORM_WARNING_HTML);
61 string response = jstemplate_builder::GetI18nTemplateHtml(html, &dict);
62 SendResponse(request_id, base::RefCountedString::TakeString(&response));
63 }
64
65 virtual string GetMimeType(const std::string& path) const OVERRIDE {
66 return "text/html";
67 }
68
69 static void RegisterDataSource(Profile* profile) {
70 ChromeURLDataManager* url_manager = profile->GetChromeURLDataManager();
71 url_manager->AddDataSource(new RepostFormWarningSource());
72 }
73
74 private:
75 virtual ~RepostFormWarningSource() {}
76
77 DISALLOW_COPY_AND_ASSIGN(RepostFormWarningSource);
78 };
79
80 class RepostFormWarningHtmlDelegate : public HtmlDialogUIDelegate {
81 public:
82 explicit RepostFormWarningHtmlDelegate(RepostFormWarningUI* ui) : ui_(ui) {}
83
84 virtual ~RepostFormWarningHtmlDelegate() {}
85
86 // HtmlDialogUIDelegate implementation.
87 virtual bool IsDialogModal() const OVERRIDE {
88 return true;
89 }
90
91 virtual string16 GetDialogTitle() const OVERRIDE {
92 return l10n_util::GetStringUTF16(IDS_HTTP_POST_WARNING_TITLE);
93 }
94
95 virtual GURL GetDialogContentURL() const OVERRIDE {
96 return GURL(chrome::kChromeUIRepostFormWarningURL);
97 }
98
99 virtual void GetWebUIMessageHandlers(
100 std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {}
101
102 virtual void GetDialogSize(gfx::Size* size) const OVERRIDE {
103 size->SetSize(kDialogWidth, kDialogHeight);
104 }
105
106 virtual std::string GetDialogArgs() const OVERRIDE {
107 return string();
108 }
109
110 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE {
111 LOG(ERROR) << "XXX OnDialogClosed: json_retval=\"" << json_retval << "\"";
arv (Not doing code reviews) 2011/09/08 01:56:25 Do you want to remove this before submit?
112 bool repost = false;
113 if (!json_retval.empty()) {
114 base::JSONReader reader;
115 scoped_ptr<Value> value(reader.JsonToValue(json_retval, false, false));
116 if (!value.get() || !value->GetAsBoolean(&repost))
117 NOTREACHED() << "Missing or unreadable response from dialog";
118 }
119
120 ui_->OnDialogClosed(repost);
121 ui_ = NULL;
122 delete this;
123 }
124
125 virtual void OnCloseContents(TabContents* source,
126 bool* out_close_dialog) OVERRIDE {}
127
128 virtual bool ShouldShowDialogTitle() const OVERRIDE {
129 return true;
130 }
131
132 private:
133 static const int kDialogWidth = 400;
134 static const int kDialogHeight = 108;
135
136 RepostFormWarningUI* ui_; // not owned
137
138 DISALLOW_COPY_AND_ASSIGN(RepostFormWarningHtmlDelegate);
139 };
140
141 RepostFormWarningUI::RepostFormWarningUI(gfx::NativeWindow parent_window,
142 TabContents* tab_contents)
143 : controller_(new RepostFormWarningController(tab_contents)) {
144 Profile* profile =
145 Profile::FromBrowserContext(tab_contents->browser_context());
146 RepostFormWarningSource::RegisterDataSource(profile);
147 RepostFormWarningHtmlDelegate* delegate =
148 new RepostFormWarningHtmlDelegate(this);
149 ConstrainedHtmlUI::CreateConstrainedHtmlDialog(
150 profile, delegate, tab_contents);
151 }
152
153 RepostFormWarningUI::~RepostFormWarningUI() {}
154
155 void RepostFormWarningUI::OnDialogClosed(bool repost) {
156 if (repost)
157 controller_->Continue();
158 else
159 controller_->Cancel();
160 delete this;
161 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/repost_form_warning_ui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698