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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h" |
17 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" |
18 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 19 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
19 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
20 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 21 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
21 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" | 22 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" |
22 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 23 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 std::unique_ptr<base::ListValue> children(new base::ListValue); | 97 std::unique_ptr<base::ListValue> children(new base::ListValue); |
97 // Passing false for |include_quota_nodes| since they don't reflect reality | 98 // Passing false for |include_quota_nodes| since they don't reflect reality |
98 // until bug http://crbug.com/642955 is fixed and local/session storage is | 99 // until bug http://crbug.com/642955 is fixed and local/session storage is |
99 // counted against the total. | 100 // counted against the total. |
100 model_util_->GetChildNodeList( | 101 model_util_->GetChildNodeList( |
101 parent_node, start, count, /*include_quota_nodes=*/false, children.get()); | 102 parent_node, start, count, /*include_quota_nodes=*/false, children.get()); |
102 | 103 |
103 base::DictionaryValue args; | 104 base::DictionaryValue args; |
104 if (parent == tree_model->GetRoot()) | 105 if (parent == tree_model->GetRoot()) |
105 args.Set(kId, base::Value::CreateNullValue()); | 106 args.Set(kId, base::MakeUnique<base::Value>()); |
106 else | 107 else |
107 args.SetString(kId, model_util_->GetTreeNodeId(parent_node)); | 108 args.SetString(kId, model_util_->GetTreeNodeId(parent_node)); |
108 args.SetInteger(kStart, start); | 109 args.SetInteger(kStart, start); |
109 args.Set(kChildren, std::move(children)); | 110 args.Set(kChildren, std::move(children)); |
110 CallJavascriptFunction("cr.webUIListenerCallback", | 111 CallJavascriptFunction("cr.webUIListenerCallback", |
111 base::Value("onTreeItemAdded"), args); | 112 base::Value("onTreeItemAdded"), args); |
112 } | 113 } |
113 | 114 |
114 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 115 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
115 ui::TreeModelNode* parent, | 116 ui::TreeModelNode* parent, |
116 int start, | 117 int start, |
117 int count) { | 118 int count) { |
118 // Skip if there is a batch update in progress. | 119 // Skip if there is a batch update in progress. |
119 if (batch_update_) | 120 if (batch_update_) |
120 return; | 121 return; |
121 | 122 |
122 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 123 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
123 | 124 |
124 base::DictionaryValue args; | 125 base::DictionaryValue args; |
125 if (parent == tree_model->GetRoot()) | 126 if (parent == tree_model->GetRoot()) |
126 args.Set(kId, base::Value::CreateNullValue()); | 127 args.Set(kId, base::MakeUnique<base::Value>()); |
127 else | 128 else |
128 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent))); | 129 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent))); |
129 args.SetInteger(kStart, start); | 130 args.SetInteger(kStart, start); |
130 args.SetInteger(kCount, count); | 131 args.SetInteger(kCount, count); |
131 CallJavascriptFunction("cr.webUIListenerCallback", | 132 CallJavascriptFunction("cr.webUIListenerCallback", |
132 base::Value("onTreeItemRemoved"), args); | 133 base::Value("onTreeItemRemoved"), args); |
133 } | 134 } |
134 | 135 |
135 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 136 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
136 DCHECK(!batch_update_); // There should be no nested batch begin. | 137 DCHECK(!batch_update_); // There should be no nested batch begin. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 CHECK_EQ(2U, args->GetSize()); | 191 CHECK_EQ(2U, args->GetSize()); |
191 CHECK(args->GetString(0, &callback_id_)); | 192 CHECK(args->GetString(0, &callback_id_)); |
192 std::string site; | 193 std::string site; |
193 CHECK(args->GetString(1, &site)); | 194 CHECK(args->GetString(1, &site)); |
194 | 195 |
195 AllowJavascript(); | 196 AllowJavascript(); |
196 const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle( | 197 const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle( |
197 cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site)); | 198 cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site)); |
198 | 199 |
199 if (!node) { | 200 if (!node) { |
200 RejectJavascriptCallback(base::Value(callback_id_), | 201 RejectJavascriptCallback(base::Value(callback_id_), base::Value()); |
201 *base::Value::CreateNullValue()); | |
202 callback_id_.clear(); | 202 callback_id_.clear(); |
203 return; | 203 return; |
204 } | 204 } |
205 | 205 |
206 SendCookieDetails(node); | 206 SendCookieDetails(node); |
207 } | 207 } |
208 | 208 |
209 void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) { | 209 void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) { |
210 CHECK_EQ(1U, args->GetSize()); | 210 CHECK_EQ(1U, args->GetSize()); |
211 CHECK(args->GetString(0, &callback_id_)); | 211 CHECK(args->GetString(0, &callback_id_)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { | 248 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { |
249 std::unique_ptr<base::ListValue> children(new base::ListValue); | 249 std::unique_ptr<base::ListValue> children(new base::ListValue); |
250 // Passing false for |include_quota_nodes| since they don't reflect reality | 250 // Passing false for |include_quota_nodes| since they don't reflect reality |
251 // until bug http://crbug.com/642955 is fixed and local/session storage is | 251 // until bug http://crbug.com/642955 is fixed and local/session storage is |
252 // counted against the total. | 252 // counted against the total. |
253 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(), | 253 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(), |
254 /*include_quota_nodes=*/false, children.get()); | 254 /*include_quota_nodes=*/false, children.get()); |
255 | 255 |
256 base::DictionaryValue args; | 256 base::DictionaryValue args; |
257 if (parent == cookies_tree_model_->GetRoot()) | 257 if (parent == cookies_tree_model_->GetRoot()) |
258 args.Set(kId, base::Value::CreateNullValue()); | 258 args.Set(kId, base::MakeUnique<base::Value>()); |
259 else | 259 else |
260 args.SetString(kId, model_util_->GetTreeNodeId(parent)); | 260 args.SetString(kId, model_util_->GetTreeNodeId(parent)); |
261 args.Set(kChildren, std::move(children)); | 261 args.Set(kChildren, std::move(children)); |
262 | 262 |
263 ResolveJavascriptCallback(base::Value(callback_id_), args); | 263 ResolveJavascriptCallback(base::Value(callback_id_), args); |
264 callback_id_.clear(); | 264 callback_id_.clear(); |
265 } | 265 } |
266 | 266 |
267 void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) { | 267 void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) { |
268 std::unique_ptr<base::ListValue> children(new base::ListValue); | 268 std::unique_ptr<base::ListValue> children(new base::ListValue); |
269 // 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 |
270 // 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 |
271 // counted against the total. | 271 // counted against the total. |
272 model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(), | 272 model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(), |
273 /*include_quota_nodes=*/false, | 273 /*include_quota_nodes=*/false, |
274 children.get()); | 274 children.get()); |
275 | 275 |
276 base::DictionaryValue args; | 276 base::DictionaryValue args; |
277 if (parent == cookies_tree_model_->GetRoot()) | 277 if (parent == cookies_tree_model_->GetRoot()) |
278 args.Set(kId, base::Value::CreateNullValue()); | 278 args.Set(kId, base::MakeUnique<base::Value>()); |
279 else | 279 else |
280 args.SetString(kId, model_util_->GetTreeNodeId(parent)); | 280 args.SetString(kId, model_util_->GetTreeNodeId(parent)); |
281 args.Set(kChildren, std::move(children)); | 281 args.Set(kChildren, std::move(children)); |
282 | 282 |
283 ResolveJavascriptCallback(base::Value(callback_id_), args); | 283 ResolveJavascriptCallback(base::Value(callback_id_), args); |
284 callback_id_.clear(); | 284 callback_id_.clear(); |
285 } | 285 } |
286 | 286 |
287 } // namespace settings | 287 } // namespace settings |
OLD | NEW |