OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webui/settings/settings_cookies_view_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_cookies_view_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 parent_node, start, count, /*include_quota_nodes=*/false, children.get()); | 101 parent_node, start, count, /*include_quota_nodes=*/false, children.get()); |
102 | 102 |
103 base::DictionaryValue args; | 103 base::DictionaryValue args; |
104 if (parent == tree_model->GetRoot()) | 104 if (parent == tree_model->GetRoot()) |
105 args.Set(kId, base::Value::CreateNullValue()); | 105 args.Set(kId, base::Value::CreateNullValue()); |
106 else | 106 else |
107 args.SetString(kId, model_util_->GetTreeNodeId(parent_node)); | 107 args.SetString(kId, model_util_->GetTreeNodeId(parent_node)); |
108 args.SetInteger(kStart, start); | 108 args.SetInteger(kStart, start); |
109 args.Set(kChildren, std::move(children)); | 109 args.Set(kChildren, std::move(children)); |
110 CallJavascriptFunction("cr.webUIListenerCallback", | 110 CallJavascriptFunction("cr.webUIListenerCallback", |
111 base::StringValue("onTreeItemAdded"), | 111 base::Value("onTreeItemAdded"), args); |
112 args); | |
113 } | 112 } |
114 | 113 |
115 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 114 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
116 ui::TreeModelNode* parent, | 115 ui::TreeModelNode* parent, |
117 int start, | 116 int start, |
118 int count) { | 117 int count) { |
119 // Skip if there is a batch update in progress. | 118 // Skip if there is a batch update in progress. |
120 if (batch_update_) | 119 if (batch_update_) |
121 return; | 120 return; |
122 | 121 |
123 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 122 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
124 | 123 |
125 base::DictionaryValue args; | 124 base::DictionaryValue args; |
126 if (parent == tree_model->GetRoot()) | 125 if (parent == tree_model->GetRoot()) |
127 args.Set(kId, base::Value::CreateNullValue()); | 126 args.Set(kId, base::Value::CreateNullValue()); |
128 else | 127 else |
129 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent))); | 128 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent))); |
130 args.SetInteger(kStart, start); | 129 args.SetInteger(kStart, start); |
131 args.SetInteger(kCount, count); | 130 args.SetInteger(kCount, count); |
132 CallJavascriptFunction("cr.webUIListenerCallback", | 131 CallJavascriptFunction("cr.webUIListenerCallback", |
133 base::StringValue("onTreeItemRemoved"), | 132 base::Value("onTreeItemRemoved"), args); |
134 args); | |
135 } | 133 } |
136 | 134 |
137 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 135 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
138 DCHECK(!batch_update_); // There should be no nested batch begin. | 136 DCHECK(!batch_update_); // There should be no nested batch begin. |
139 batch_update_ = true; | 137 batch_update_ = true; |
140 } | 138 } |
141 | 139 |
142 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { | 140 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
143 DCHECK(batch_update_); | 141 DCHECK(batch_update_); |
144 batch_update_ = false; | 142 batch_update_ = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 CHECK_EQ(2U, args->GetSize()); | 190 CHECK_EQ(2U, args->GetSize()); |
193 CHECK(args->GetString(0, &callback_id_)); | 191 CHECK(args->GetString(0, &callback_id_)); |
194 std::string site; | 192 std::string site; |
195 CHECK(args->GetString(1, &site)); | 193 CHECK(args->GetString(1, &site)); |
196 | 194 |
197 AllowJavascript(); | 195 AllowJavascript(); |
198 const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle( | 196 const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle( |
199 cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site)); | 197 cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site)); |
200 | 198 |
201 if (!node) { | 199 if (!node) { |
202 RejectJavascriptCallback(base::StringValue(callback_id_), | 200 RejectJavascriptCallback(base::Value(callback_id_), |
203 *base::Value::CreateNullValue()); | 201 *base::Value::CreateNullValue()); |
204 callback_id_.clear(); | 202 callback_id_.clear(); |
205 return; | 203 return; |
206 } | 204 } |
207 | 205 |
208 SendCookieDetails(node); | 206 SendCookieDetails(node); |
209 } | 207 } |
210 | 208 |
211 void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) { | 209 void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) { |
212 CHECK_EQ(1U, args->GetSize()); | 210 CHECK_EQ(1U, args->GetSize()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(), | 253 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(), |
256 /*include_quota_nodes=*/false, children.get()); | 254 /*include_quota_nodes=*/false, children.get()); |
257 | 255 |
258 base::DictionaryValue args; | 256 base::DictionaryValue args; |
259 if (parent == cookies_tree_model_->GetRoot()) | 257 if (parent == cookies_tree_model_->GetRoot()) |
260 args.Set(kId, base::Value::CreateNullValue()); | 258 args.Set(kId, base::Value::CreateNullValue()); |
261 else | 259 else |
262 args.SetString(kId, model_util_->GetTreeNodeId(parent)); | 260 args.SetString(kId, model_util_->GetTreeNodeId(parent)); |
263 args.Set(kChildren, std::move(children)); | 261 args.Set(kChildren, std::move(children)); |
264 | 262 |
265 ResolveJavascriptCallback(base::StringValue(callback_id_), args); | 263 ResolveJavascriptCallback(base::Value(callback_id_), args); |
266 callback_id_.clear(); | 264 callback_id_.clear(); |
267 } | 265 } |
268 | 266 |
269 void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) { | 267 void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) { |
270 std::unique_ptr<base::ListValue> children(new base::ListValue); | 268 std::unique_ptr<base::ListValue> children(new base::ListValue); |
271 // Passing false for |include_quota_nodes| since they don't reflect reality | 269 // Passing false for |include_quota_nodes| since they don't reflect reality |
272 // until bug http://crbug.com/642955 is fixed and local/session storage is | 270 // until bug http://crbug.com/642955 is fixed and local/session storage is |
273 // counted against the total. | 271 // counted against the total. |
274 model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(), | 272 model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(), |
275 /*include_quota_nodes=*/false, | 273 /*include_quota_nodes=*/false, |
276 children.get()); | 274 children.get()); |
277 | 275 |
278 base::DictionaryValue args; | 276 base::DictionaryValue args; |
279 if (parent == cookies_tree_model_->GetRoot()) | 277 if (parent == cookies_tree_model_->GetRoot()) |
280 args.Set(kId, base::Value::CreateNullValue()); | 278 args.Set(kId, base::Value::CreateNullValue()); |
281 else | 279 else |
282 args.SetString(kId, model_util_->GetTreeNodeId(parent)); | 280 args.SetString(kId, model_util_->GetTreeNodeId(parent)); |
283 args.Set(kChildren, std::move(children)); | 281 args.Set(kChildren, std::move(children)); |
284 | 282 |
285 ResolveJavascriptCallback(base::StringValue(callback_id_), args); | 283 ResolveJavascriptCallback(base::Value(callback_id_), args); |
286 callback_id_.clear(); | 284 callback_id_.clear(); |
287 } | 285 } |
288 | 286 |
289 } // namespace settings | 287 } // namespace settings |
OLD | NEW |