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

Side by Side Diff: chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc

Issue 2476753002: [MD settings] get cookie details from site without transfering cookie tree (Closed)
Patch Set: closure fix Created 4 years, 1 month 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 CookiesViewHandler::~CookiesViewHandler() { 51 CookiesViewHandler::~CookiesViewHandler() {
52 } 52 }
53 53
54 void CookiesViewHandler::OnJavascriptAllowed() { 54 void CookiesViewHandler::OnJavascriptAllowed() {
55 } 55 }
56 56
57 void CookiesViewHandler::OnJavascriptDisallowed() { 57 void CookiesViewHandler::OnJavascriptDisallowed() {
58 } 58 }
59 59
60 void CookiesViewHandler::RegisterMessages() { 60 void CookiesViewHandler::RegisterMessages() {
61 web_ui()->RegisterMessageCallback("updateCookieSearchResults", 61 EnsureCookiesTreeModelCreated();
62 base::Bind(&CookiesViewHandler::UpdateSearchResults, 62
63 web_ui()->RegisterMessageCallback(
64 "getCookieDetails",
65 base::Bind(&CookiesViewHandler::HandleGetCookieDetails,
63 base::Unretained(this))); 66 base::Unretained(this)));
64 web_ui()->RegisterMessageCallback("removeAllCookies", 67 web_ui()->RegisterMessageCallback(
65 base::Bind(&CookiesViewHandler::RemoveAll, 68 "updateCookieSearchResults",
69 base::Bind(&CookiesViewHandler::HandleUpdateSearchResults,
66 base::Unretained(this))); 70 base::Unretained(this)));
67 web_ui()->RegisterMessageCallback("removeCookie", 71 web_ui()->RegisterMessageCallback(
68 base::Bind(&CookiesViewHandler::Remove, 72 "removeAllCookies",
69 base::Unretained(this))); 73 base::Bind(&CookiesViewHandler::HandleRemoveAll, base::Unretained(this)));
70 web_ui()->RegisterMessageCallback("loadCookie", 74 web_ui()->RegisterMessageCallback(
71 base::Bind(&CookiesViewHandler::LoadChildren, 75 "removeCookie",
72 base::Unretained(this))); 76 base::Bind(&CookiesViewHandler::HandleRemove, base::Unretained(this)));
73 web_ui()->RegisterMessageCallback("reloadCookies", 77 web_ui()->RegisterMessageCallback(
74 base::Bind(&CookiesViewHandler::ReloadCookies, 78 "loadCookie", base::Bind(&CookiesViewHandler::HandleLoadChildren,
75 base::Unretained(this))); 79 base::Unretained(this)));
80 web_ui()->RegisterMessageCallback(
81 "reloadCookies", base::Bind(&CookiesViewHandler::HandleReloadCookies,
82 base::Unretained(this)));
76 } 83 }
77 84
78 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model, 85 void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model,
79 ui::TreeModelNode* parent, 86 ui::TreeModelNode* parent,
80 int start, 87 int start,
81 int count) { 88 int count) {
82 // Skip if there is a batch update in progress. 89 // Skip if there is a batch update in progress.
83 if (batch_update_) 90 if (batch_update_)
84 return; 91 return;
85 92
86 AllowJavascript();
87
88 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); 93 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
89 CookieTreeNode* parent_node = tree_model->AsNode(parent); 94 CookieTreeNode* parent_node = tree_model->AsNode(parent);
90 95
91 std::unique_ptr<base::ListValue> children(new base::ListValue); 96 std::unique_ptr<base::ListValue> children(new base::ListValue);
92 // Passing false for |include_quota_nodes| since they don't reflect reality 97 // Passing false for |include_quota_nodes| since they don't reflect reality
93 // until bug http://crbug.com/642955 is fixed and local/session storage is 98 // until bug http://crbug.com/642955 is fixed and local/session storage is
94 // counted against the total. 99 // counted against the total.
95 model_util_->GetChildNodeList( 100 model_util_->GetChildNodeList(
96 parent_node, start, count, /*include_quota_nodes=*/false, children.get()); 101 parent_node, start, count, /*include_quota_nodes=*/false, children.get());
97 102
(...skipping 10 matching lines...) Expand all
108 } 113 }
109 114
110 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, 115 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model,
111 ui::TreeModelNode* parent, 116 ui::TreeModelNode* parent,
112 int start, 117 int start,
113 int count) { 118 int count) {
114 // Skip if there is a batch update in progress. 119 // Skip if there is a batch update in progress.
115 if (batch_update_) 120 if (batch_update_)
116 return; 121 return;
117 122
118 AllowJavascript();
119
120 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); 123 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
121 124
122 base::DictionaryValue args; 125 base::DictionaryValue args;
123 if (parent == tree_model->GetRoot()) 126 if (parent == tree_model->GetRoot())
124 args.Set(kId, base::Value::CreateNullValue()); 127 args.Set(kId, base::Value::CreateNullValue());
125 else 128 else
126 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent))); 129 args.SetString(kId, model_util_->GetTreeNodeId(tree_model->AsNode(parent)));
127 args.SetInteger(kStart, start); 130 args.SetInteger(kStart, start);
128 args.SetInteger(kCount, count); 131 args.SetInteger(kCount, count);
129 CallJavascriptFunction("cr.webUIListenerCallback", 132 CallJavascriptFunction("cr.webUIListenerCallback",
130 base::StringValue("onTreeItemRemoved"), 133 base::StringValue("onTreeItemRemoved"),
131 args); 134 args);
132 } 135 }
133 136
134 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { 137 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) {
135 DCHECK(!batch_update_); // There should be no nested batch begin. 138 DCHECK(!batch_update_); // There should be no nested batch begin.
136 batch_update_ = true; 139 batch_update_ = true;
137 } 140 }
138 141
139 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { 142 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) {
140 DCHECK(batch_update_); 143 DCHECK(batch_update_);
141 batch_update_ = false; 144 batch_update_ = false;
142 145
143 SendChildren(model->GetRoot()); 146 if (IsJavascriptAllowed())
147 SendChildren(model->GetRoot());
144 } 148 }
145 149
146 void CookiesViewHandler::EnsureCookiesTreeModelCreated() { 150 void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
147 if (!cookies_tree_model_.get()) { 151 if (!cookies_tree_model_.get()) {
148 Profile* profile = Profile::FromWebUI(web_ui()); 152 Profile* profile = Profile::FromWebUI(web_ui());
149 content::StoragePartition* storage_partition = 153 content::StoragePartition* storage_partition =
150 content::BrowserContext::GetDefaultStoragePartition(profile); 154 content::BrowserContext::GetDefaultStoragePartition(profile);
151 content::IndexedDBContext* indexed_db_context = 155 content::IndexedDBContext* indexed_db_context =
152 storage_partition->GetIndexedDBContext(); 156 storage_partition->GetIndexedDBContext();
153 content::ServiceWorkerContext* service_worker_context = 157 content::ServiceWorkerContext* service_worker_context =
(...skipping 15 matching lines...) Expand all
169 new BrowsingDataCacheStorageHelper(cache_storage_context), 173 new BrowsingDataCacheStorageHelper(cache_storage_context),
170 BrowsingDataFlashLSOHelper::Create(profile), 174 BrowsingDataFlashLSOHelper::Create(profile),
171 BrowsingDataMediaLicenseHelper::Create(file_system_context)); 175 BrowsingDataMediaLicenseHelper::Create(file_system_context));
172 cookies_tree_model_.reset( 176 cookies_tree_model_.reset(
173 new CookiesTreeModel(container, 177 new CookiesTreeModel(container,
174 profile->GetExtensionSpecialStoragePolicy())); 178 profile->GetExtensionSpecialStoragePolicy()));
175 cookies_tree_model_->AddCookiesTreeObserver(this); 179 cookies_tree_model_->AddCookiesTreeObserver(this);
176 } 180 }
177 } 181 }
178 182
179 void CookiesViewHandler::UpdateSearchResults(const base::ListValue* args) { 183 void CookiesViewHandler::HandleUpdateSearchResults(
184 const base::ListValue* args) {
180 base::string16 query; 185 base::string16 query;
181 if (!args->GetString(0, &query)) 186 CHECK(args->GetString(0, &query));
182 return;
183
184 EnsureCookiesTreeModelCreated();
185 187
186 cookies_tree_model_->UpdateSearchResults(query); 188 cookies_tree_model_->UpdateSearchResults(query);
187 } 189 }
188 190
189 void CookiesViewHandler::RemoveAll(const base::ListValue* args) { 191 void CookiesViewHandler::HandleGetCookieDetails(const base::ListValue* args) {
192 CHECK_EQ(2U, args->GetSize());
193 CHECK(args->GetString(0, &callback_id_));
194 std::string site;
195 CHECK(args->GetString(1, &site));
196
197 AllowJavascript();
198 const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle(
199 cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site));
200
201 if (!node) {
202 RejectJavascriptCallback(base::StringValue(callback_id_),
203 *base::Value::CreateNullValue());
204 callback_id_.clear();
205 return;
206 }
207
208 SendCookieDetails(node);
209 }
210
211 void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) {
190 CHECK_EQ(1U, args->GetSize()); 212 CHECK_EQ(1U, args->GetSize());
191 CHECK(args->GetString(0, &callback_id_)); 213 CHECK(args->GetString(0, &callback_id_));
192 214
215 AllowJavascript();
216 cookies_tree_model_.reset();
193 EnsureCookiesTreeModelCreated(); 217 EnsureCookiesTreeModelCreated();
218 }
219
220 void CookiesViewHandler::HandleRemoveAll(const base::ListValue* args) {
221 CHECK_EQ(1U, args->GetSize());
222 CHECK(args->GetString(0, &callback_id_));
223
194 cookies_tree_model_->DeleteAllStoredObjects(); 224 cookies_tree_model_->DeleteAllStoredObjects();
195 } 225 }
196 226
197 void CookiesViewHandler::Remove(const base::ListValue* args) { 227 void CookiesViewHandler::HandleRemove(const base::ListValue* args) {
198 std::string node_path; 228 std::string node_path;
199 if (!args->GetString(0, &node_path)) 229 CHECK(args->GetString(0, &node_path));
200 return;
201
202 EnsureCookiesTreeModelCreated();
203 230
204 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( 231 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
205 cookies_tree_model_->GetRoot(), node_path); 232 cookies_tree_model_->GetRoot(), node_path);
206 if (node) 233 if (node)
207 cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node)); 234 cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node));
208 } 235 }
209 236
210 void CookiesViewHandler::LoadChildren(const base::ListValue* args) { 237 void CookiesViewHandler::HandleLoadChildren(const base::ListValue* args) {
211 CHECK_LT(0U, args->GetSize()); 238 CHECK_EQ(2U, args->GetSize());
212 CHECK(args->GetString(0, &callback_id_)); 239 CHECK(args->GetString(0, &callback_id_));
213 240
214 std::string node_path; 241 std::string node_path;
215 if (!args->GetString(1, &node_path)) 242 CHECK(args->GetString(1, &node_path));
216 return;
217
218 EnsureCookiesTreeModelCreated();
219 243
220 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( 244 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
221 cookies_tree_model_->GetRoot(), node_path); 245 cookies_tree_model_->GetRoot(), node_path);
222 if (node) 246 if (node)
223 SendChildren(node); 247 SendChildren(node);
224 } 248 }
225 249
226 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { 250 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) {
227 AllowJavascript();
228
229 std::unique_ptr<base::ListValue> children(new base::ListValue); 251 std::unique_ptr<base::ListValue> children(new base::ListValue);
230 // Passing false for |include_quota_nodes| since they don't reflect reality 252 // Passing false for |include_quota_nodes| since they don't reflect reality
231 // until bug http://crbug.com/642955 is fixed and local/session storage is 253 // until bug http://crbug.com/642955 is fixed and local/session storage is
232 // counted against the total. 254 // counted against the total.
233 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(), 255 model_util_->GetChildNodeList(parent, /*start=*/0, parent->child_count(),
234 /*include_quota_nodes=*/false, children.get()); 256 /*include_quota_nodes=*/false, children.get());
235 257
236 base::DictionaryValue args; 258 base::DictionaryValue args;
237 if (parent == cookies_tree_model_->GetRoot()) 259 if (parent == cookies_tree_model_->GetRoot())
238 args.Set(kId, base::Value::CreateNullValue()); 260 args.Set(kId, base::Value::CreateNullValue());
239 else 261 else
240 args.SetString(kId, model_util_->GetTreeNodeId(parent)); 262 args.SetString(kId, model_util_->GetTreeNodeId(parent));
241 args.Set(kChildren, std::move(children)); 263 args.Set(kChildren, std::move(children));
242 264
243 ResolveJavascriptCallback(base::StringValue(callback_id_), args); 265 ResolveJavascriptCallback(base::StringValue(callback_id_), args);
244 callback_id_ = ""; 266 callback_id_.clear();
245 } 267 }
246 268
247 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { 269 void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) {
248 CHECK_EQ(1U, args->GetSize()); 270 std::unique_ptr<base::ListValue> children(new base::ListValue);
249 CHECK(args->GetString(0, &callback_id_)); 271 // 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
273 // counted against the total.
274 model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(),
275 /*include_quota_nodes=*/false,
276 children.get());
250 277
251 cookies_tree_model_.reset(); 278 base::DictionaryValue args;
279 if (parent == cookies_tree_model_->GetRoot())
280 args.Set(kId, base::Value::CreateNullValue());
281 else
282 args.SetString(kId, model_util_->GetTreeNodeId(parent));
283 args.Set(kChildren, std::move(children));
252 284
253 EnsureCookiesTreeModelCreated(); 285 ResolveJavascriptCallback(base::StringValue(callback_id_), args);
286 callback_id_.clear();
254 } 287 }
255 288
256 } // namespace settings 289 } // 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