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/settings/settings_cookies_view_handler.cc

Issue 2248683006: Site Settings Desktop: Implement individual cookie removal and RemoveAll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 4 years, 4 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
« no previous file with comments | « chrome/browser/ui/webui/settings/settings_cookies_view_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 20 matching lines...) Expand all
31 #include "content/public/browser/site_instance.h" 31 #include "content/public/browser/site_instance.h"
32 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
33 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
34 34
35 namespace storage { 35 namespace storage {
36 class FileSystemContext; 36 class FileSystemContext;
37 } 37 }
38 38
39 namespace settings { 39 namespace settings {
40 40
41 const char kId[] = "id";
42 const char kChildren[] = "children";
43 const char kStart[] = "start";
44 const char kCount[] = "count";
45
41 CookiesViewHandler::CookiesViewHandler() 46 CookiesViewHandler::CookiesViewHandler()
42 : batch_update_(false), 47 : batch_update_(false),
43 model_util_(new CookiesTreeModelUtil) { 48 model_util_(new CookiesTreeModelUtil) {
44 } 49 }
45 50
46 CookiesViewHandler::~CookiesViewHandler() { 51 CookiesViewHandler::~CookiesViewHandler() {
47 } 52 }
48 53
49 void CookiesViewHandler::OnJavascriptAllowed() { 54 void CookiesViewHandler::OnJavascriptAllowed() {
50 } 55 }
(...skipping 28 matching lines...) Expand all
79 return; 84 return;
80 85
81 AllowJavascript(); 86 AllowJavascript();
82 87
83 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); 88 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
84 CookieTreeNode* parent_node = tree_model->AsNode(parent); 89 CookieTreeNode* parent_node = tree_model->AsNode(parent);
85 90
86 std::unique_ptr<base::ListValue> children(new base::ListValue); 91 std::unique_ptr<base::ListValue> children(new base::ListValue);
87 model_util_->GetChildNodeList(parent_node, start, count, children.get()); 92 model_util_->GetChildNodeList(parent_node, start, count, children.get());
88 93
89 base::ListValue args; 94 base::DictionaryValue args;
90 if (parent == tree_model->GetRoot()) 95 if (parent == tree_model->GetRoot())
91 args.Append(base::Value::CreateNullValue()); 96 args.Set(kId, base::Value::CreateNullValue());
92 else 97 else
93 args.AppendString(model_util_->GetTreeNodeId(parent_node)); 98 args.SetString(kId, model_util_->GetTreeNodeId(parent_node));
94 args.AppendInteger(start); 99 args.SetInteger(kStart, start);
95 args.Append(std::move(children)); 100 args.Set(kChildren, std::move(children));
96 CallJavascriptFunction("cr.webUIListenerCallback", 101 CallJavascriptFunction("cr.webUIListenerCallback",
97 base::StringValue("onTreeItemAdded"), 102 base::StringValue("onTreeItemAdded"),
98 args); 103 args);
99 } 104 }
100 105
101 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, 106 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model,
102 ui::TreeModelNode* parent, 107 ui::TreeModelNode* parent,
103 int start, 108 int start,
104 int count) { 109 int count) {
105 // Skip if there is a batch update in progress. 110 // Skip if there is a batch update in progress.
106 if (batch_update_) 111 if (batch_update_)
107 return; 112 return;
108 113
109 AllowJavascript(); 114 AllowJavascript();
110 115
111 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); 116 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
112 117
113 base::ListValue args; 118 base::DictionaryValue args;
114 if (parent == tree_model->GetRoot()) 119 if (parent == tree_model->GetRoot())
115 args.Append(base::Value::CreateNullValue()); 120 args.Set(kId, base::Value::CreateNullValue());
116 else 121 else
117 args.AppendString(model_util_->GetTreeNodeId(tree_model->AsNode(parent))); 122 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent)));
118 args.AppendInteger(start); 123 args.SetInteger(kStart, start);
119 args.AppendInteger(count); 124 args.SetInteger(kCount, count);
120 CallJavascriptFunction("cr.webUIListenerCallback", 125 CallJavascriptFunction("cr.webUIListenerCallback",
121 base::StringValue("onTreeItemRemoved"), 126 base::StringValue("onTreeItemRemoved"),
122 args); 127 args);
123 } 128 }
124 129
125 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { 130 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) {
126 DCHECK(!batch_update_); // There should be no nested batch begin. 131 DCHECK(!batch_update_); // There should be no nested batch begin.
127 batch_update_ = true; 132 batch_update_ = true;
128 } 133 }
129 134
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 base::string16 query; 175 base::string16 query;
171 if (!args->GetString(0, &query)) 176 if (!args->GetString(0, &query))
172 return; 177 return;
173 178
174 EnsureCookiesTreeModelCreated(); 179 EnsureCookiesTreeModelCreated();
175 180
176 cookies_tree_model_->UpdateSearchResults(query); 181 cookies_tree_model_->UpdateSearchResults(query);
177 } 182 }
178 183
179 void CookiesViewHandler::RemoveAll(const base::ListValue* args) { 184 void CookiesViewHandler::RemoveAll(const base::ListValue* args) {
185 CHECK_EQ(1U, args->GetSize());
186 CHECK(args->GetString(0, &callback_id_));
187
180 EnsureCookiesTreeModelCreated(); 188 EnsureCookiesTreeModelCreated();
181 cookies_tree_model_->DeleteAllStoredObjects(); 189 cookies_tree_model_->DeleteAllStoredObjects();
182 } 190 }
183 191
184 void CookiesViewHandler::Remove(const base::ListValue* args) { 192 void CookiesViewHandler::Remove(const base::ListValue* args) {
185 std::string node_path; 193 std::string node_path;
186 if (!args->GetString(0, &node_path)) 194 if (!args->GetString(0, &node_path))
187 return; 195 return;
188 196
189 EnsureCookiesTreeModelCreated(); 197 EnsureCookiesTreeModelCreated();
190 198
191 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( 199 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
192 cookies_tree_model_->GetRoot(), node_path); 200 cookies_tree_model_->GetRoot(), node_path);
193 if (node) 201 if (node)
194 cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node)); 202 cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node));
195 } 203 }
196 204
197 void CookiesViewHandler::LoadChildren(const base::ListValue* args) { 205 void CookiesViewHandler::LoadChildren(const base::ListValue* args) {
206 CHECK_LT(0U, args->GetSize());
207 CHECK(args->GetString(0, &callback_id_));
208
198 std::string node_path; 209 std::string node_path;
199 if (!args->GetString(0, &node_path)) 210 if (!args->GetString(1, &node_path))
200 return; 211 return;
201 212
202 EnsureCookiesTreeModelCreated(); 213 EnsureCookiesTreeModelCreated();
203 214
204 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( 215 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
205 cookies_tree_model_->GetRoot(), node_path); 216 cookies_tree_model_->GetRoot(), node_path);
206 if (node) 217 if (node)
207 SendChildren(node); 218 SendChildren(node);
208 } 219 }
209 220
210 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { 221 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) {
211 AllowJavascript(); 222 AllowJavascript();
212 223
213 std::unique_ptr<base::ListValue> children(new base::ListValue); 224 std::unique_ptr<base::ListValue> children(new base::ListValue);
214 model_util_->GetChildNodeList(parent, 0, parent->child_count(), 225 model_util_->GetChildNodeList(parent, 0, parent->child_count(),
215 children.get()); 226 children.get());
216 227
217 base::ListValue args; 228 base::DictionaryValue args;
218 if (parent == cookies_tree_model_->GetRoot()) 229 if (parent == cookies_tree_model_->GetRoot())
219 args.Append(base::Value::CreateNullValue()); 230 args.Set(kId, base::Value::CreateNullValue());
220 else 231 else
221 args.AppendString(model_util_->GetTreeNodeId(parent)); 232 args.SetString(kId, model_util_->GetTreeNodeId(parent));
222 args.Append(std::move(children)); 233 args.Set(kChildren, std::move(children));
223 234
224 CallJavascriptFunction("cr.webUIListenerCallback", 235 ResolveJavascriptCallback(base::StringValue(callback_id_), args);
225 base::StringValue("loadChildren"), 236 callback_id_ = "";
226 args);
227 } 237 }
228 238
229 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { 239 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) {
240 CHECK_EQ(1U, args->GetSize());
241 CHECK(args->GetString(0, &callback_id_));
242
230 cookies_tree_model_.reset(); 243 cookies_tree_model_.reset();
231 244
232 EnsureCookiesTreeModelCreated(); 245 EnsureCookiesTreeModelCreated();
233 } 246 }
234 247
235 } // namespace settings 248 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/settings_cookies_view_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698