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

Side by Side Diff: chrome/browser/extensions/extension_bookmarks_module.cc

Issue 183020: more bookmark tests, plus fix a couple of API bugs (Closed)
Patch Set: cleanup from review comments (plus merge fallout) Created 11 years, 3 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 unified diff | Download patch
OLDNEW
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 if (recurse) { 55 if (recurse) {
56 int childCount = node->GetChildCount(); 56 int childCount = node->GetChildCount();
57 ListValue* children = new ListValue(); 57 ListValue* children = new ListValue();
58 for (int i = 0; i < childCount; ++i) { 58 for (int i = 0; i < childCount; ++i) {
59 const BookmarkNode* child = node->GetChild(i); 59 const BookmarkNode* child = node->GetChild(i);
60 DictionaryValue* dict = GetNodeDictionary(child, true); 60 DictionaryValue* dict = GetNodeDictionary(child, true);
61 children->Append(dict); 61 children->Append(dict);
62 } 62 }
63 dict->Set(keys::kChildrenKey, children); 63 if (node->is_folder())
64 dict->Set(keys::kChildrenKey, children);
64 } 65 }
65 return dict; 66 return dict;
66 } 67 }
67 68
68 // Add a JSON representation of |node| to the JSON |list|. 69 // Add a JSON representation of |node| to the JSON |list|.
69 static void AddNode(const BookmarkNode* node, ListValue* list, bool recurse) { 70 static void AddNode(const BookmarkNode* node, ListValue* list, bool recurse) {
70 DictionaryValue* dict = GetNodeDictionary(node, recurse); 71 DictionaryValue* dict = GetNodeDictionary(node, recurse);
71 list->Append(dict); 72 list->Append(dict);
72 } 73 }
73 74
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 &index)); 509 &index));
509 if (index > parent->GetChildCount() || index < 0) { 510 if (index > parent->GetChildCount() || index < 0) {
510 error_ = keys::kInvalidIndexError; 511 error_ = keys::kInvalidIndexError;
511 return false; 512 return false;
512 } 513 }
513 } else { 514 } else {
514 index = parent->GetChildCount(); 515 index = parent->GetChildCount();
515 } 516 }
516 517
517 model->Move(node, parent, index); 518 model->Move(node, parent, index);
519
520 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
521 result_.reset(ret);
522
518 return true; 523 return true;
519 } 524 }
520 525
521 bool SetBookmarkTitleFunction::RunImpl() { 526 bool UpdateBookmarkFunction::RunImpl() {
522 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_DICTIONARY)); 527 EXTENSION_FUNCTION_VALIDATE(args_->IsType(Value::TYPE_LIST));
523 DictionaryValue* json = static_cast<DictionaryValue*>(args_); 528 const ListValue* args = static_cast<const ListValue*>(args_);
524 529 int64 id;
530 std::string id_string;
531 EXTENSION_FUNCTION_VALIDATE(args->GetString(0, &id_string));
532 if (!GetBookmarkIdAsInt64(id_string, &id))
533 return false;
534 DictionaryValue* updates;
535 EXTENSION_FUNCTION_VALIDATE(args->GetDictionary(1, &updates));
525 std::wstring title; 536 std::wstring title;
526 json->GetString(keys::kTitleKey, &title); // Optional (empty is clear). 537 updates->GetString(keys::kTitleKey, &title); // Optional (empty is clear).
527 538
528 BookmarkModel* model = profile()->GetBookmarkModel(); 539 BookmarkModel* model = profile()->GetBookmarkModel();
529 int64 id = 0;
530 std::string id_string;
531 EXTENSION_FUNCTION_VALIDATE(json->GetString(keys::kIdKey, &id_string));
532 if (!GetBookmarkIdAsInt64(id_string, &id))
533 return false;
534 const BookmarkNode* node = model->GetNodeByID(id); 540 const BookmarkNode* node = model->GetNodeByID(id);
535 if (!node) { 541 if (!node) {
536 error_ = keys::kNoNodeError; 542 error_ = keys::kNoNodeError;
537 return false; 543 return false;
538 } 544 }
539 if (node == model->root_node() || 545 if (node == model->root_node() ||
540 node == model->other_node() || 546 node == model->other_node() ||
541 node == model->GetBookmarkBarNode()) { 547 node == model->GetBookmarkBarNode()) {
542 error_ = keys::kModifySpecialError; 548 error_ = keys::kModifySpecialError;
543 return false; 549 return false;
544 } 550 }
545 model->SetTitle(node, title); 551 model->SetTitle(node, title);
552
553 DictionaryValue* ret = ExtensionBookmarks::GetNodeDictionary(node, false);
554 result_.reset(ret);
555
546 return true; 556 return true;
547 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698