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/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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 return &bookmark_drag_data_; | 345 return &bookmark_drag_data_; |
346 return NULL; | 346 return NULL; |
347 } | 347 } |
348 | 348 |
349 void BookmarkManagerPrivateDragEventRouter::ClearBookmarkNodeData() { | 349 void BookmarkManagerPrivateDragEventRouter::ClearBookmarkNodeData() { |
350 bookmark_drag_data_.Clear(); | 350 bookmark_drag_data_.Clear(); |
351 } | 351 } |
352 | 352 |
353 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut, | 353 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut, |
354 const std::vector<std::string>& id_list) { | 354 const std::vector<std::string>& id_list) { |
| 355 BookmarkModel* model = GetBookmarkModel(); |
355 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 356 ChromeBookmarkClient* client = GetChromeBookmarkClient(); |
356 std::vector<const BookmarkNode*> nodes; | 357 std::vector<const BookmarkNode*> nodes; |
357 EXTENSION_FUNCTION_VALIDATE( | 358 EXTENSION_FUNCTION_VALIDATE(GetNodesFromVector(model, id_list, &nodes)); |
358 GetNodesFromVector(client->model(), id_list, &nodes)); | |
359 if (cut && client->HasDescendantsOfManagedNode(nodes)) { | 359 if (cut && client->HasDescendantsOfManagedNode(nodes)) { |
360 error_ = bookmark_keys::kModifyManagedError; | 360 error_ = bookmark_keys::kModifyManagedError; |
361 return false; | 361 return false; |
362 } | 362 } |
363 bookmark_utils::CopyToClipboard(client->model(), nodes, cut); | 363 bookmark_utils::CopyToClipboard(model, nodes, cut); |
364 return true; | 364 return true; |
365 } | 365 } |
366 | 366 |
367 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { | 367 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { |
368 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); | 368 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); |
369 EXTENSION_FUNCTION_VALIDATE(params); | 369 EXTENSION_FUNCTION_VALIDATE(params); |
370 return CopyOrCut(false, params->id_list); | 370 return CopyOrCut(false, params->id_list); |
371 } | 371 } |
372 | 372 |
373 bool BookmarkManagerPrivateCutFunction::RunOnReady() { | 373 bool BookmarkManagerPrivateCutFunction::RunOnReady() { |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 bool BookmarkManagerPrivateCanOpenNewWindowsFunction::RunOnReady() { | 728 bool BookmarkManagerPrivateCanOpenNewWindowsFunction::RunOnReady() { |
729 bool can_open_new_windows = true; | 729 bool can_open_new_windows = true; |
730 SetResult(new base::FundamentalValue(can_open_new_windows)); | 730 SetResult(new base::FundamentalValue(can_open_new_windows)); |
731 return true; | 731 return true; |
732 } | 732 } |
733 | 733 |
734 bool BookmarkManagerPrivateRemoveTreesFunction::RunOnReady() { | 734 bool BookmarkManagerPrivateRemoveTreesFunction::RunOnReady() { |
735 scoped_ptr<RemoveTrees::Params> params(RemoveTrees::Params::Create(*args_)); | 735 scoped_ptr<RemoveTrees::Params> params(RemoveTrees::Params::Create(*args_)); |
736 EXTENSION_FUNCTION_VALIDATE(params); | 736 EXTENSION_FUNCTION_VALIDATE(params); |
737 | 737 |
| 738 BookmarkModel* model = GetBookmarkModel(); |
738 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 739 ChromeBookmarkClient* client = GetChromeBookmarkClient(); |
739 #if !defined(OS_ANDROID) | 740 #if !defined(OS_ANDROID) |
740 bookmarks::ScopedGroupBookmarkActions group_deletes(client->model()); | 741 bookmarks::ScopedGroupBookmarkActions group_deletes(model); |
741 #endif | 742 #endif |
742 int64 id; | 743 int64 id; |
743 for (size_t i = 0; i < params->id_list.size(); ++i) { | 744 for (size_t i = 0; i < params->id_list.size(); ++i) { |
744 if (!GetBookmarkIdAsInt64(params->id_list[i], &id)) | 745 if (!GetBookmarkIdAsInt64(params->id_list[i], &id)) |
745 return false; | 746 return false; |
746 if (!bookmark_api_helpers::RemoveNode(client, id, true, &error_)) | 747 if (!bookmark_api_helpers::RemoveNode(model, client, id, true, &error_)) |
747 return false; | 748 return false; |
748 } | 749 } |
749 | 750 |
750 return true; | 751 return true; |
751 } | 752 } |
752 | 753 |
753 bool BookmarkManagerPrivateUndoFunction::RunOnReady() { | 754 bool BookmarkManagerPrivateUndoFunction::RunOnReady() { |
754 #if !defined(OS_ANDROID) | 755 #if !defined(OS_ANDROID) |
755 BookmarkUndoServiceFactory::GetForProfile(GetProfile())->undo_manager()-> | 756 BookmarkUndoServiceFactory::GetForProfile(GetProfile())->undo_manager()-> |
756 Undo(); | 757 Undo(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 result.enabled = undo_manager->redo_count() > 0; | 793 result.enabled = undo_manager->redo_count() > 0; |
793 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 794 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
794 | 795 |
795 results_ = RedoInfo::Results::Create(result); | 796 results_ = RedoInfo::Results::Create(result); |
796 #endif // !defined(OS_ANDROID) | 797 #endif // !defined(OS_ANDROID) |
797 | 798 |
798 return true; | 799 return true; |
799 } | 800 } |
800 | 801 |
801 } // namespace extensions | 802 } // namespace extensions |
OLD | NEW |