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

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

Issue 317333004: Added BookmarkClient::CanBeEditedByUser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added TODO 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 result.enabled = undo_manager->redo_count() > 0; 790 result.enabled = undo_manager->redo_count() > 0;
792 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); 791 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel());
793 792
794 results_ = RedoInfo::Results::Create(result); 793 results_ = RedoInfo::Results::Create(result);
795 #endif // !defined(OS_ANDROID) 794 #endif // !defined(OS_ANDROID)
796 795
797 return true; 796 return true;
798 } 797 }
799 798
800 } // namespace extensions 799 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.cc ('k') | chrome/browser/ui/bookmarks/bookmark_context_menu_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698