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

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

Issue 8298019: Implement InputWindowDialog with WebUI for bookmark folder management. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 9 years, 2 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/input_window_dialog_webui.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/input_window_dialog_webui.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h"
11 #include "base/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/browser_dialogs.h"
16 #include "chrome/browser/ui/webui/html_dialog_ui.h"
17 #include "chrome/common/url_constants.h"
18 #include "content/browser/tab_contents/tab_contents.h"
19
20 namespace {
21
22 const int kInputWindowDialogWidth = 240;
23 const int kInputWindowDialogHeight = 120;
24
25 }
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // InputWindowWebUIDailog private methods
29
30 InputWindowDialogWebUI::InputWindowDialogWebUI(
31 const string16& window_title,
32 const string16& label,
33 const string16& contents,
34 InputWindowDialog::Delegate* delegate)
35 : handler_(new InputWindowDialogHandler(delegate)),
36 window_title_(window_title),
37 label_(label),
38 contents_(contents),
39 closed_(true),
40 delegate_(delegate) {
41 }
42
43 InputWindowDialogWebUI::~InputWindowDialogWebUI() {
44 }
45
46 void InputWindowDialogWebUI::Show() {
47 Browser* browser = BrowserList::GetLastActive();
48 DCHECK(browser);
49 browser->BrowserShowHtmlDialog(this, NULL);
50 closed_ = false;
51 }
52
53 void InputWindowDialogWebUI::Close() {
54 if (!closed_) {
55 DCHECK(handler_);
56 handler_->CloseDialog();
57 }
58 }
59
60 bool InputWindowDialogWebUI::IsDialogModal() const {
61 return true;
62 }
63
64 string16 InputWindowDialogWebUI::GetDialogTitle() const {
65 return window_title_;
66 }
67
68 GURL InputWindowDialogWebUI::GetDialogContentURL() const {
69 return GURL(chrome::kChromeUIInputWindowDialogURL);
70 }
71
72 void InputWindowDialogWebUI::GetWebUIMessageHandlers(
73 std::vector<WebUIMessageHandler*>* handlers) const {
74 handlers->push_back(handler_);
75 }
76
77 void InputWindowDialogWebUI::GetDialogSize(gfx::Size* size) const {
78 size->SetSize(kInputWindowDialogWidth, kInputWindowDialogHeight);
79 }
80
81 std::string InputWindowDialogWebUI::GetDialogArgs() const {
82 DictionaryValue value;
83 value.SetString("label", label_);
84 value.SetString("contents", contents_);
85 std::string json;
86 base::JSONWriter::Write(&value, false, &json);
87 return json;
88 }
89
90 void InputWindowDialogWebUI::OnDialogClosed(const std::string& json_retval) {
91 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false));
92 bool response = false;
93 ListValue* list = NULL;
94 bool accepted = false;
95 // If the dialog closes because of a button click then the json is a list
96 // containing a bool value. When OK button is clicked, a string in the text
97 // field is added to the list.
98 if (root.get() && root->GetAsList(&list) && list &&
99 list->GetBoolean(0, &response) && response) {
100 DCHECK_EQ(2U, list->GetSize());
101 string16 text;
102 if (list->GetString(1, &text)) {
103 delegate_->InputAccepted(text);
104 accepted = true;
105 }
106 }
107 if (!accepted) {
108 delegate_->InputCanceled();
109 }
110 closed_ = true;
111 }
112
113 void InputWindowDialogWebUI::OnCloseContents(TabContents* source,
114 bool* out_close_dialog) {
115 }
116
117 bool InputWindowDialogWebUI::ShouldShowDialogTitle() const {
118 return true;
119 }
120
121 ////////////////////////////////////////////////////////////////////////////////
122 // InputWindowDialogHandler methods
123
124 InputWindowDialogHandler::InputWindowDialogHandler(
125 InputWindowDialog::Delegate* delegate)
126 : delegate_(delegate) {
127 }
128
129 void InputWindowDialogHandler::CloseDialog() {
130 DCHECK(web_ui_);
131 static_cast<HtmlDialogUI*>(web_ui_)->CloseDialog(NULL);
132 }
133
134 void InputWindowDialogHandler::RegisterMessages() {
135 web_ui_->RegisterMessageCallback("validate",
136 base::Bind(&InputWindowDialogHandler::Validate,
137 base::Unretained(this)));
138 }
139
140 void InputWindowDialogHandler::Validate(const base::ListValue* args) {
141 DCHECK_EQ(1U, args->GetSize());
142 bool valid = false;
143 string16 text;
144 if (args->GetString(0, &text)) {
145 valid = delegate_->IsValid(text);
146 }
147 scoped_ptr<Value> result(Value::CreateBooleanValue(valid));
148 web_ui_->CallJavascriptFunction("inputWindowDialog.ackValidation",
149 *result);
150 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/input_window_dialog_webui.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698