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

Unified 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: touchups 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc
diff --git a/chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc b/chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc
index 841fc8774b9af1b102789e9e5b84465b6ac0b5d2..744ea90adb7477599b2c1685754ddbb4c52f6715 100644
--- a/chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc
+++ b/chrome/browser/ui/webui/settings/settings_cookies_view_handler.cc
@@ -58,21 +58,28 @@ void CookiesViewHandler::OnJavascriptDisallowed() {
}
void CookiesViewHandler::RegisterMessages() {
- web_ui()->RegisterMessageCallback("updateCookieSearchResults",
- base::Bind(&CookiesViewHandler::UpdateSearchResults,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback("removeAllCookies",
- base::Bind(&CookiesViewHandler::RemoveAll,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback("removeCookie",
- base::Bind(&CookiesViewHandler::Remove,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback("loadCookie",
- base::Bind(&CookiesViewHandler::LoadChildren,
+ EnsureCookiesTreeModelCreated();
+
+ web_ui()->RegisterMessageCallback(
+ "getCookieDetails",
+ base::Bind(&CookiesViewHandler::HandleGetCookieDetails,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback("reloadCookies",
- base::Bind(&CookiesViewHandler::ReloadCookies,
+ web_ui()->RegisterMessageCallback(
+ "updateCookieSearchResults",
+ base::Bind(&CookiesViewHandler::HandleUpdateSearchResults,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "removeAllCookies",
+ base::Bind(&CookiesViewHandler::HandleRemoveAll, base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "removeCookie",
+ base::Bind(&CookiesViewHandler::HandleRemove, base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "loadCookie", base::Bind(&CookiesViewHandler::HandleLoadChildren,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "reloadCookies", base::Bind(&CookiesViewHandler::HandleReloadCookies,
+ base::Unretained(this)));
}
void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model,
@@ -83,8 +90,6 @@ void CookiesViewHandler::TreeNodesAdded(ui::TreeModel* model,
if (batch_update_)
return;
- AllowJavascript();
-
CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
CookieTreeNode* parent_node = tree_model->AsNode(parent);
@@ -115,8 +120,6 @@ void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model,
if (batch_update_)
return;
- AllowJavascript();
-
CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model);
base::DictionaryValue args;
@@ -140,7 +143,8 @@ void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) {
DCHECK(batch_update_);
batch_update_ = false;
- SendChildren(model->GetRoot());
+ if (IsJavascriptAllowed())
+ SendChildren(model->GetRoot());
}
void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
@@ -176,38 +180,64 @@ void CookiesViewHandler::EnsureCookiesTreeModelCreated() {
}
}
-void CookiesViewHandler::UpdateSearchResults(const base::ListValue* args) {
+void CookiesViewHandler::HandleUpdateSearchResults(
+ const base::ListValue* args) {
base::string16 query;
if (!args->GetString(0, &query))
return;
- EnsureCookiesTreeModelCreated();
-
cookies_tree_model_->UpdateSearchResults(query);
}
-void CookiesViewHandler::RemoveAll(const base::ListValue* args) {
+void CookiesViewHandler::HandleGetCookieDetails(const base::ListValue* args) {
+ CHECK_EQ(2U, args->GetSize());
+ CHECK(args->GetString(0, &callback_id_));
+ std::string site;
+ if (!args->GetString(1, &site))
Dan Beam 2016/11/04 00:35:32 should you still be settings callback_id_ if getti
dschuyler 2016/11/04 00:50:44 Done.
+ return;
+
+ AllowJavascript();
Dan Beam 2016/11/04 00:35:31 shouldn't we call this even if !GetString(1)
dschuyler 2016/11/04 00:50:44 Done.
+ const CookieTreeNode* node = model_util_->GetTreeNodeFromTitle(
+ cookies_tree_model_->GetRoot(), base::UTF8ToUTF16(site));
+
+ if (!node) {
+ RejectJavascriptCallback(base::StringValue(callback_id_),
+ *base::Value::CreateNullValue());
+ callback_id_ = "";
Dan Beam 2016/11/04 00:35:32 callback_id_.clear();
dschuyler 2016/11/04 00:50:44 Done.
+ return;
+ }
+
+ SendCookieDetails(node);
+}
+
+void CookiesViewHandler::HandleReloadCookies(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
CHECK(args->GetString(0, &callback_id_));
+ AllowJavascript();
+ cookies_tree_model_.reset();
EnsureCookiesTreeModelCreated();
+}
+
+void CookiesViewHandler::HandleRemoveAll(const base::ListValue* args) {
+ CHECK_EQ(1U, args->GetSize());
+ CHECK(args->GetString(0, &callback_id_));
+
cookies_tree_model_->DeleteAllStoredObjects();
}
-void CookiesViewHandler::Remove(const base::ListValue* args) {
+void CookiesViewHandler::HandleRemove(const base::ListValue* args) {
std::string node_path;
if (!args->GetString(0, &node_path))
return;
- EnsureCookiesTreeModelCreated();
-
const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
cookies_tree_model_->GetRoot(), node_path);
if (node)
cookies_tree_model_->DeleteCookieNode(const_cast<CookieTreeNode*>(node));
}
-void CookiesViewHandler::LoadChildren(const base::ListValue* args) {
+void CookiesViewHandler::HandleLoadChildren(const base::ListValue* args) {
CHECK_LT(0U, args->GetSize());
CHECK(args->GetString(0, &callback_id_));
@@ -215,8 +245,6 @@ void CookiesViewHandler::LoadChildren(const base::ListValue* args) {
if (!args->GetString(1, &node_path))
return;
- EnsureCookiesTreeModelCreated();
-
const CookieTreeNode* node = model_util_->GetTreeNodeFromPath(
cookies_tree_model_->GetRoot(), node_path);
if (node)
@@ -224,8 +252,6 @@ void CookiesViewHandler::LoadChildren(const base::ListValue* args) {
}
void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) {
- AllowJavascript();
-
std::unique_ptr<base::ListValue> children(new base::ListValue);
// Passing false for |include_quota_nodes| since they don't reflect reality
// until bug http://crbug.com/642955 is fixed and local/session storage is
@@ -244,13 +270,24 @@ void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) {
callback_id_ = "";
}
-void CookiesViewHandler::ReloadCookies(const base::ListValue* args) {
- CHECK_EQ(1U, args->GetSize());
- CHECK(args->GetString(0, &callback_id_));
+void CookiesViewHandler::SendCookieDetails(const CookieTreeNode* parent) {
+ std::unique_ptr<base::ListValue> children(new base::ListValue);
+ // Passing false for |include_quota_nodes| since they don't reflect reality
+ // until bug http://crbug.com/642955 is fixed and local/session storage is
+ // counted against the total.
+ model_util_->GetChildNodeDetails(parent, /*start=*/0, parent->child_count(),
+ /*include_quota_nodes=*/false,
+ children.get());
- cookies_tree_model_.reset();
+ base::DictionaryValue args;
+ if (parent == cookies_tree_model_->GetRoot())
+ args.Set(kId, base::Value::CreateNullValue());
+ else
+ args.SetString(kId, model_util_->GetTreeNodeId(parent));
+ args.Set(kChildren, std::move(children));
- EnsureCookiesTreeModelCreated();
+ ResolveJavascriptCallback(base::StringValue(callback_id_), args);
+ callback_id_ = "";
Dan Beam 2016/11/04 00:35:32 callback_id_.clear();
dschuyler 2016/11/04 00:50:44 Done.
}
} // namespace settings

Powered by Google App Engine
This is Rietveld 408576698