| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options/cookies_view_handler.h" | 5 #include "chrome/browser/ui/webui/options/cookies_view_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 ui::TreeModelNode* parent, | 134 ui::TreeModelNode* parent, |
| 135 int start, | 135 int start, |
| 136 int count) { | 136 int count) { |
| 137 // Skip if there is a batch update in progress. | 137 // Skip if there is a batch update in progress. |
| 138 if (batch_update_) | 138 if (batch_update_) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 141 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
| 142 CookieTreeNode* parent_node = tree_model->AsNode(parent); | 142 CookieTreeNode* parent_node = tree_model->AsNode(parent); |
| 143 | 143 |
| 144 base::ListValue* children = new base::ListValue; | 144 scoped_ptr<base::ListValue> children(new base::ListValue); |
| 145 model_util_->GetChildNodeList(parent_node, start, count, children); | 145 model_util_->GetChildNodeList(parent_node, start, count, children.get()); |
| 146 | 146 |
| 147 base::ListValue args; | 147 base::ListValue args; |
| 148 args.Append(parent == tree_model->GetRoot() ? | 148 if (parent == tree_model->GetRoot()) |
| 149 base::Value::CreateNullValue() : | 149 args.Append(base::Value::CreateNullValue()); |
| 150 new base::StringValue(model_util_->GetTreeNodeId(parent_node))); | 150 else |
| 151 args.Append(new base::FundamentalValue(start)); | 151 args.AppendString(model_util_->GetTreeNodeId(parent_node)); |
| 152 args.Append(children); | 152 args.AppendInteger(start); |
| 153 args.Append(children.Pass()); |
| 153 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); | 154 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemAdded", args); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, | 157 void CookiesViewHandler::TreeNodesRemoved(ui::TreeModel* model, |
| 157 ui::TreeModelNode* parent, | 158 ui::TreeModelNode* parent, |
| 158 int start, | 159 int start, |
| 159 int count) { | 160 int count) { |
| 160 // Skip if there is a batch update in progress. | 161 // Skip if there is a batch update in progress. |
| 161 if (batch_update_) | 162 if (batch_update_) |
| 162 return; | 163 return; |
| 163 | 164 |
| 164 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); | 165 CookiesTreeModel* tree_model = static_cast<CookiesTreeModel*>(model); |
| 165 | 166 |
| 166 base::ListValue args; | 167 base::ListValue args; |
| 167 args.Append(parent == tree_model->GetRoot() ? | 168 if (parent == tree_model->GetRoot()) |
| 168 base::Value::CreateNullValue() : | 169 args.Append(base::Value::CreateNullValue()); |
| 169 new base::StringValue(model_util_->GetTreeNodeId( | 170 else |
| 170 tree_model->AsNode(parent)))); | 171 args.AppendString(model_util_->GetTreeNodeId(tree_model->AsNode(parent))); |
| 171 args.Append(new base::FundamentalValue(start)); | 172 args.AppendInteger(start); |
| 172 args.Append(new base::FundamentalValue(count)); | 173 args.AppendInteger(count); |
| 173 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); | 174 web_ui()->CallJavascriptFunction("CookiesView.onTreeItemRemoved", args); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { | 177 void CookiesViewHandler::TreeModelBeginBatch(CookiesTreeModel* model) { |
| 177 DCHECK(!batch_update_); // There should be no nested batch begin. | 178 DCHECK(!batch_update_); // There should be no nested batch begin. |
| 178 batch_update_ = true; | 179 batch_update_ = true; |
| 179 } | 180 } |
| 180 | 181 |
| 181 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { | 182 void CookiesViewHandler::TreeModelEndBatch(CookiesTreeModel* model) { |
| 182 DCHECK(batch_update_); | 183 DCHECK(batch_update_); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 252 |
| 252 EnsureCookiesTreeModelCreated(); | 253 EnsureCookiesTreeModelCreated(); |
| 253 | 254 |
| 254 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( | 255 const CookieTreeNode* node = model_util_->GetTreeNodeFromPath( |
| 255 cookies_tree_model_->GetRoot(), node_path); | 256 cookies_tree_model_->GetRoot(), node_path); |
| 256 if (node) | 257 if (node) |
| 257 SendChildren(node); | 258 SendChildren(node); |
| 258 } | 259 } |
| 259 | 260 |
| 260 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { | 261 void CookiesViewHandler::SendChildren(const CookieTreeNode* parent) { |
| 261 base::ListValue* children = new base::ListValue; | 262 scoped_ptr<base::ListValue> children(new base::ListValue); |
| 262 model_util_->GetChildNodeList(parent, 0, parent->child_count(), | 263 model_util_->GetChildNodeList(parent, 0, parent->child_count(), |
| 263 children); | 264 children.get()); |
| 264 | 265 |
| 265 base::ListValue args; | 266 base::ListValue args; |
| 266 args.Append(parent == cookies_tree_model_->GetRoot() ? | 267 if (parent == cookies_tree_model_->GetRoot()) |
| 267 base::Value::CreateNullValue() : | 268 args.Append(base::Value::CreateNullValue()); |
| 268 new base::StringValue(model_util_->GetTreeNodeId(parent))); | 269 else |
| 269 args.Append(children); | 270 args.AppendString(model_util_->GetTreeNodeId(parent)); |
| 271 args.Append(children.Pass()); |
| 270 | 272 |
| 271 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); | 273 web_ui()->CallJavascriptFunction("CookiesView.loadChildren", args); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { | 276 void CookiesViewHandler::ReloadCookies(const base::ListValue* args) { |
| 275 cookies_tree_model_.reset(); | 277 cookies_tree_model_.reset(); |
| 276 | 278 |
| 277 EnsureCookiesTreeModelCreated(); | 279 EnsureCookiesTreeModelCreated(); |
| 278 } | 280 } |
| 279 | 281 |
| 280 } // namespace options | 282 } // namespace options |
| OLD | NEW |