| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(model, parent_node); | 392 bool can_paste = bookmark_utils::CanPasteFromClipboard(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 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 420 ChromeBookmarkClient* client = GetChromeBookmarkClient(); |
| 421 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); | 421 const BookmarkNode* parent_node = |
| 422 GetNodeFromString(client->model(), params->parent_id); |
| 422 if (!parent_node) { | 423 if (!parent_node) { |
| 423 error_ = bookmark_keys::kNoParentError; | 424 error_ = bookmark_keys::kNoParentError; |
| 424 return false; | 425 return false; |
| 425 } | 426 } |
| 426 bool can_paste = | 427 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node) && |
| 427 bookmark_utils::CanPasteFromClipboard(model, parent_node); | 428 !client->IsDescendantOfManagedNode(parent_node); |
| 428 SetResult(new base::FundamentalValue(can_paste)); | 429 SetResult(new base::FundamentalValue(can_paste)); |
| 429 return true; | 430 return true; |
| 430 } | 431 } |
| 431 | 432 |
| 432 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { | 433 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { |
| 433 if (!EditBookmarksEnabled()) | 434 if (!EditBookmarksEnabled()) |
| 434 return false; | 435 return false; |
| 435 | 436 |
| 436 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); | 437 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); |
| 437 EXTENSION_FUNCTION_VALIDATE(params); | 438 EXTENSION_FUNCTION_VALIDATE(params); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 result.enabled = undo_manager->redo_count() > 0; | 791 result.enabled = undo_manager->redo_count() > 0; |
| 791 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 792 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
| 792 | 793 |
| 793 results_ = RedoInfo::Results::Create(result); | 794 results_ = RedoInfo::Results::Create(result); |
| 794 #endif // !defined(OS_ANDROID) | 795 #endif // !defined(OS_ANDROID) |
| 795 | 796 |
| 796 return true; | 797 return true; |
| 797 } | 798 } |
| 798 | 799 |
| 799 } // namespace extensions | 800 } // namespace extensions |
| OLD | NEW |