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

Unified Diff: chrome/browser/ui/webui/cookies_tree_model_adapter.cc

Issue 6644002: [ChromeOS] Implement collected cookies in webui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync, address evan and oshima's comemnts #1 Created 9 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/cookies_tree_model_adapter.cc
diff --git a/chrome/browser/ui/webui/cookies_tree_model_adapter.cc b/chrome/browser/ui/webui/cookies_tree_model_adapter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..edf7db3d420d75c4a853f797be974b9f350ecdc4
--- /dev/null
+++ b/chrome/browser/ui/webui/cookies_tree_model_adapter.cc
@@ -0,0 +1,141 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/webui/cookies_tree_model_adapter.h"
+
+#include "base/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/ui/webui/cookies_tree_model_util.h"
+#include "content/browser/webui/web_ui.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace {
+
+// Returns a unique callback name for |adapter|.
+std::string GetLoadCookieCallbackName(CookiesTreeModelAdapter* adapter) {
+ static const char kPrefixLoadCookie[] = "loadChildren";
+ return std::string(kPrefixLoadCookie) +
+ base::HexEncode(&adapter, sizeof(adapter));
+}
+
+} // namespace
+
+CookiesTreeModelAdapter::CookiesTreeModelAdapter()
+ : web_ui_(NULL),
+ model_(NULL),
+ batch_update_(false) {
+}
+
+CookiesTreeModelAdapter::~CookiesTreeModelAdapter() {
+ if (model_)
+ model_->RemoveCookiesTreeObserver(this);
+}
+
+void CookiesTreeModelAdapter::Init(WebUI* web_ui) {
+ web_ui_ = web_ui;
+
+ web_ui_->RegisterMessageCallback(GetLoadCookieCallbackName(this),
+ NewCallback(this, &CookiesTreeModelAdapter::LoadChildren));
+}
+
+void CookiesTreeModelAdapter::Bind(const std::string& tree_id,
+ CookiesTreeModel* model) {
+ DCHECK(web_ui_); // We should have been initialized.
+ DCHECK(tree_id_.empty() && !model_); // No existing bindings.
+
+ tree_id_ = tree_id;
+ model_ = model;
+ model_->AddCookiesTreeObserver(this);
+
+ ListValue args;
+ args.Append(Value::CreateStringValue(tree_id_));
+ args.Append(Value::CreateStringValue(GetLoadCookieCallbackName(this)));
+ web_ui_->CallJavascriptFunction("ui.CookiesTree.setCallback", args);
+
+ SendChildren(model_->GetRoot());
+}
+
+void CookiesTreeModelAdapter::TreeNodesAdded(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) {
+ // Skip if there is a batch update in progress.
+ if (batch_update_)
+ return;
+
+ CookieTreeNode* parent_node = model_->AsNode(parent);
+
+ ListValue* children = new ListValue;
+ cookies_tree_model_util::GetChildNodeList(parent_node, start, count,
+ children);
+
+ ListValue args;
+ args.Append(Value::CreateStringValue(tree_id_));
+ args.Append(parent == model_->GetRoot() ?
+ Value::CreateNullValue() :
+ Value::CreateStringValue(
+ cookies_tree_model_util::GetTreeNodeId(parent_node)));
+ args.Append(Value::CreateIntegerValue(start));
+ args.Append(children);
+ web_ui_->CallJavascriptFunction("ui.CookiesTree.onTreeItemAdded", args);
+}
+
+void CookiesTreeModelAdapter::TreeNodesRemoved(ui::TreeModel* model,
+ ui::TreeModelNode* parent,
+ int start,
+ int count) {
+ // Skip if there is a batch update in progress.
+ if (batch_update_)
+ return;
+
+ ListValue args;
+ args.Append(Value::CreateStringValue(tree_id_));
+ args.Append(parent == model_->GetRoot() ?
+ Value::CreateNullValue() :
+ Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(
+ model_->AsNode(parent))));
+ args.Append(Value::CreateIntegerValue(start));
+ args.Append(Value::CreateIntegerValue(count));
+ web_ui_->CallJavascriptFunction("ui.CookiesTree.onTreeItemRemoved",
+ args);
+}
+
+void CookiesTreeModelAdapter::TreeModelBeginBatch(CookiesTreeModel* model) {
+ DCHECK(!batch_update_); // There should be no nested batch begin.
+ batch_update_ = true;
+}
+
+void CookiesTreeModelAdapter::TreeModelEndBatch(CookiesTreeModel* model) {
+ DCHECK(batch_update_);
+ batch_update_ = false;
+
+ SendChildren(model_->GetRoot());
+}
+
+void CookiesTreeModelAdapter::LoadChildren(const ListValue* args) {
+ std::string node_path;
+ if (!args->GetString(0, &node_path))
+ return;
+
+ CookieTreeNode* node = cookies_tree_model_util::GetTreeNodeFromPath(
+ model_->GetRoot(), node_path);
+ if (node)
+ SendChildren(node);
+}
+
+void CookiesTreeModelAdapter::SendChildren(CookieTreeNode* parent) {
+ ListValue* children = new ListValue;
+ cookies_tree_model_util::GetChildNodeList(parent, 0, parent->GetChildCount(),
+ children);
+
+ ListValue args;
+ args.Append(Value::CreateStringValue(tree_id_));
+ args.Append(parent == model_->GetRoot() ?
+ Value::CreateNullValue() :
+ Value::CreateStringValue(cookies_tree_model_util::GetTreeNodeId(parent)));
+ args.Append(children);
+
+ web_ui_->CallJavascriptFunction("ui.CookiesTree.loadChildren", args);
+}

Powered by Google App Engine
This is Rietveld 408576698