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

Side by Side Diff: chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc

Issue 302313005: Show the Managed Bookmarks folder in the views UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on model changes Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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/extensions/api/bookmark_manager_private/bookmark_manage r_private_api.h" 5 #include "chrome/browser/extensions/api/bookmark_manager_private/bookmark_manage r_private_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 bool BookmarkManagerPrivatePasteFunction::RunOnReady() { 382 bool BookmarkManagerPrivatePasteFunction::RunOnReady() {
383 if (!EditBookmarksEnabled()) 383 if (!EditBookmarksEnabled())
384 return false; 384 return false;
385 385
386 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_)); 386 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_));
387 EXTENSION_FUNCTION_VALIDATE(params); 387 EXTENSION_FUNCTION_VALIDATE(params);
388 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 388 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
389 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 389 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
390 if (!CanBeModified(parent_node)) 390 if (!CanBeModified(parent_node))
391 return false; 391 return false;
392 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); 392 bool can_paste = bookmark_utils::CanPasteFromClipboard(model, parent_node);
393 if (!can_paste) 393 if (!can_paste)
394 return false; 394 return false;
395 395
396 // We want to use the highest index of the selected nodes as a destination. 396 // We want to use the highest index of the selected nodes as a destination.
397 std::vector<const BookmarkNode*> nodes; 397 std::vector<const BookmarkNode*> nodes;
398 // No need to test return value, if we got an empty list, we insert at end. 398 // No need to test return value, if we got an empty list, we insert at end.
399 if (params->selected_id_list) 399 if (params->selected_id_list)
400 GetNodesFromVector(model, *params->selected_id_list, &nodes); 400 GetNodesFromVector(model, *params->selected_id_list, &nodes);
401 int highest_index = -1; // -1 means insert at end of list. 401 int highest_index = -1; // -1 means insert at end of list.
402 for (size_t i = 0; i < nodes.size(); ++i) { 402 for (size_t i = 0; i < nodes.size(); ++i) {
403 // + 1 so that we insert after the selection. 403 // + 1 so that we insert after the selection.
404 int index = parent_node->GetIndexOf(nodes[i]) + 1; 404 int index = parent_node->GetIndexOf(nodes[i]) + 1;
405 if (index > highest_index) 405 if (index > highest_index)
406 highest_index = index; 406 highest_index = index;
407 } 407 }
408 408
409 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); 409 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index);
410 return true; 410 return true;
411 } 411 }
412 412
413 bool BookmarkManagerPrivateCanPasteFunction::RunOnReady() { 413 bool BookmarkManagerPrivateCanPasteFunction::RunOnReady() {
414 if (!EditBookmarksEnabled()) 414 if (!EditBookmarksEnabled())
415 return false; 415 return false;
416 416
417 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_)); 417 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_));
418 EXTENSION_FUNCTION_VALIDATE(params); 418 EXTENSION_FUNCTION_VALIDATE(params);
419 419
420 ChromeBookmarkClient* client = GetChromeBookmarkClient(); 420 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
421 const BookmarkNode* parent_node = 421 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
422 GetNodeFromString(client->model(), params->parent_id);
423 if (!parent_node) { 422 if (!parent_node) {
424 error_ = bookmark_keys::kNoParentError; 423 error_ = bookmark_keys::kNoParentError;
425 return false; 424 return false;
426 } 425 }
427 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node) && 426 bool can_paste =
428 !client->IsDescendantOfManagedNode(parent_node); 427 bookmark_utils::CanPasteFromClipboard(model, parent_node);
429 SetResult(new base::FundamentalValue(can_paste)); 428 SetResult(new base::FundamentalValue(can_paste));
430 return true; 429 return true;
431 } 430 }
432 431
433 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { 432 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() {
434 if (!EditBookmarksEnabled()) 433 if (!EditBookmarksEnabled())
435 return false; 434 return false;
436 435
437 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); 436 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_));
438 EXTENSION_FUNCTION_VALIDATE(params); 437 EXTENSION_FUNCTION_VALIDATE(params);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 CHECK(web_ui); 587 CHECK(web_ui);
589 BookmarkManagerPrivateDragEventRouter* router = 588 BookmarkManagerPrivateDragEventRouter* router =
590 web_ui->bookmark_manager_private_drag_event_router(); 589 web_ui->bookmark_manager_private_drag_event_router();
591 590
592 DCHECK(router); 591 DCHECK(router);
593 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData(); 592 const BookmarkNodeData* drag_data = router->GetBookmarkNodeData();
594 if (drag_data == NULL) { 593 if (drag_data == NULL) {
595 NOTREACHED() <<"Somehow we're dropping null bookmark data"; 594 NOTREACHED() <<"Somehow we're dropping null bookmark data";
596 return false; 595 return false;
597 } 596 }
598 chrome::DropBookmarks(GetProfile(), *drag_data, drop_parent, drop_index); 597 const bool copy = false;
598 chrome::DropBookmarks(
599 GetProfile(), *drag_data, drop_parent, drop_index, copy);
599 600
600 router->ClearBookmarkNodeData(); 601 router->ClearBookmarkNodeData();
601 return true; 602 return true;
602 } else { 603 } else {
603 NOTREACHED(); 604 NOTREACHED();
604 return false; 605 return false;
605 } 606 }
606 } 607 }
607 608
608 bool BookmarkManagerPrivateGetSubtreeFunction::RunOnReady() { 609 bool BookmarkManagerPrivateGetSubtreeFunction::RunOnReady() {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 result.enabled = undo_manager->redo_count() > 0; 792 result.enabled = undo_manager->redo_count() > 0;
792 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); 793 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel());
793 794
794 results_ = RedoInfo::Results::Create(result); 795 results_ = RedoInfo::Results::Create(result);
795 #endif // !defined(OS_ANDROID) 796 #endif // !defined(OS_ANDROID)
796 797
797 return true; 798 return true;
798 } 799 }
799 800
800 } // namespace extensions 801 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698