| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extensions/extension_bookmarks_module.h" | 5 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| 6 | 6 |
| 7 #include "base/json_writer.h" | 7 #include "base/json_writer.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_codec.h" | 9 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 const BookmarkNode* node = parent->GetChild(index); | 196 const BookmarkNode* node = parent->GetChild(index); |
| 197 args.Append(new StringValue(Int64ToString(node->id()))); | 197 args.Append(new StringValue(Int64ToString(node->id()))); |
| 198 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); | 198 DictionaryValue* obj = ExtensionBookmarks::GetNodeDictionary(node, false); |
| 199 | 199 |
| 200 // Remove id since it's already being passed as the first argument. | 200 // Remove id since it's already being passed as the first argument. |
| 201 obj->Remove(keys::kIdKey, NULL); | 201 obj->Remove(keys::kIdKey, NULL); |
| 202 args.Append(obj); | 202 args.Append(obj); |
| 203 | 203 |
| 204 std::string json_args; | 204 std::string json_args; |
| 205 JSONWriter::Write(&args, false, &json_args); | 205 JSONWriter::Write(&args, false, &json_args); |
| 206 DispatchEvent(model->profile(), keys::kOnBookmarkAdded, json_args); | 206 DispatchEvent(model->profile(), keys::kOnBookmarkCreated, json_args); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( | 209 void ExtensionBookmarkEventRouter::BookmarkNodeRemoved( |
| 210 BookmarkModel* model, | 210 BookmarkModel* model, |
| 211 const BookmarkNode* parent, | 211 const BookmarkNode* parent, |
| 212 int index, | 212 int index, |
| 213 const BookmarkNode* node) { | 213 const BookmarkNode* node) { |
| 214 ListValue args; | 214 ListValue args; |
| 215 args.Append(new StringValue(Int64ToString(node->id()))); | 215 args.Append(new StringValue(Int64ToString(node->id()))); |
| 216 DictionaryValue* object_args = new DictionaryValue(); | 216 DictionaryValue* object_args = new DictionaryValue(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 BookmarkModel* model, const BookmarkNode* node) { | 251 BookmarkModel* model, const BookmarkNode* node) { |
| 252 ListValue args; | 252 ListValue args; |
| 253 args.Append(new StringValue(Int64ToString(node->id()))); | 253 args.Append(new StringValue(Int64ToString(node->id()))); |
| 254 int childCount = node->GetChildCount(); | 254 int childCount = node->GetChildCount(); |
| 255 ListValue* children = new ListValue(); | 255 ListValue* children = new ListValue(); |
| 256 for (int i = 0; i < childCount; ++i) { | 256 for (int i = 0; i < childCount; ++i) { |
| 257 const BookmarkNode* child = node->GetChild(i); | 257 const BookmarkNode* child = node->GetChild(i); |
| 258 Value* child_id = new StringValue(Int64ToString(child->id())); | 258 Value* child_id = new StringValue(Int64ToString(child->id())); |
| 259 children->Append(child_id); | 259 children->Append(child_id); |
| 260 } | 260 } |
| 261 args.Append(children); | 261 DictionaryValue* reorder_info = new DictionaryValue(); |
| 262 reorder_info->Set(keys::kChildIdsKey, children); |
| 263 args.Append(reorder_info); |
| 262 | 264 |
| 263 std::string json_args; | 265 std::string json_args; |
| 264 JSONWriter::Write(&args, false, &json_args); | 266 JSONWriter::Write(&args, false, &json_args); |
| 265 DispatchEvent(model->profile(), | 267 DispatchEvent(model->profile(), |
| 266 keys::kOnBookmarkChildrenReordered, | 268 keys::kOnBookmarkChildrenReordered, |
| 267 json_args); | 269 json_args); |
| 268 } | 270 } |
| 269 | 271 |
| 270 bool GetBookmarksFunction::RunImpl() { | 272 bool GetBookmarksFunction::RunImpl() { |
| 271 BookmarkModel* model = profile()->GetBookmarkModel(); | 273 BookmarkModel* model = profile()->GetBookmarkModel(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 538 } |
| 537 if (node == model->root_node() || | 539 if (node == model->root_node() || |
| 538 node == model->other_node() || | 540 node == model->other_node() || |
| 539 node == model->GetBookmarkBarNode()) { | 541 node == model->GetBookmarkBarNode()) { |
| 540 error_ = keys::kModifySpecialError; | 542 error_ = keys::kModifySpecialError; |
| 541 return false; | 543 return false; |
| 542 } | 544 } |
| 543 model->SetTitle(node, title); | 545 model->SetTitle(node, title); |
| 544 return true; | 546 return true; |
| 545 } | 547 } |
| OLD | NEW |