| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 namespace { | 65 namespace { |
| 66 | 66 |
| 67 // Returns a single bookmark node from the argument ID. | 67 // Returns a single bookmark node from the argument ID. |
| 68 // This returns NULL in case of failure. | 68 // This returns NULL in case of failure. |
| 69 const BookmarkNode* GetNodeFromString(BookmarkModel* model, | 69 const BookmarkNode* GetNodeFromString(BookmarkModel* model, |
| 70 const std::string& id_string) { | 70 const std::string& id_string) { |
| 71 int64 id; | 71 int64 id; |
| 72 if (!base::StringToInt64(id_string, &id)) | 72 if (!base::StringToInt64(id_string, &id)) |
| 73 return NULL; | 73 return NULL; |
| 74 return GetBookmarkNodeByID(model, id); | 74 return bookmarks::GetBookmarkNodeByID(model, id); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Gets a vector of bookmark nodes from the argument list of IDs. | 77 // Gets a vector of bookmark nodes from the argument list of IDs. |
| 78 // This returns false in the case of failure. | 78 // This returns false in the case of failure. |
| 79 bool GetNodesFromVector(BookmarkModel* model, | 79 bool GetNodesFromVector(BookmarkModel* model, |
| 80 const std::vector<std::string>& id_strings, | 80 const std::vector<std::string>& id_strings, |
| 81 std::vector<const BookmarkNode*>* nodes) { | 81 std::vector<const BookmarkNode*>* nodes) { |
| 82 if (id_strings.empty()) | 82 if (id_strings.empty()) |
| 83 return false; | 83 return false; |
| 84 | 84 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut, | 352 bool ClipboardBookmarkManagerFunction::CopyOrCut(bool cut, |
| 353 const std::vector<std::string>& id_list) { | 353 const std::vector<std::string>& id_list) { |
| 354 BookmarkModel* model = GetBookmarkModel(); | 354 BookmarkModel* model = GetBookmarkModel(); |
| 355 ChromeBookmarkClient* client = GetChromeBookmarkClient(); | 355 ChromeBookmarkClient* client = GetChromeBookmarkClient(); |
| 356 std::vector<const BookmarkNode*> nodes; | 356 std::vector<const BookmarkNode*> nodes; |
| 357 EXTENSION_FUNCTION_VALIDATE(GetNodesFromVector(model, id_list, &nodes)); | 357 EXTENSION_FUNCTION_VALIDATE(GetNodesFromVector(model, id_list, &nodes)); |
| 358 if (cut && client->HasDescendantsOfManagedNode(nodes)) { | 358 if (cut && client->HasDescendantsOfManagedNode(nodes)) { |
| 359 error_ = bookmark_keys::kModifyManagedError; | 359 error_ = bookmark_keys::kModifyManagedError; |
| 360 return false; | 360 return false; |
| 361 } | 361 } |
| 362 bookmark_utils::CopyToClipboard(model, nodes, cut); | 362 bookmarks::CopyToClipboard(model, nodes, cut); |
| 363 return true; | 363 return true; |
| 364 } | 364 } |
| 365 | 365 |
| 366 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { | 366 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { |
| 367 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); | 367 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); |
| 368 EXTENSION_FUNCTION_VALIDATE(params); | 368 EXTENSION_FUNCTION_VALIDATE(params); |
| 369 return CopyOrCut(false, params->id_list); | 369 return CopyOrCut(false, params->id_list); |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool BookmarkManagerPrivateCutFunction::RunOnReady() { | 372 bool BookmarkManagerPrivateCutFunction::RunOnReady() { |
| 373 if (!EditBookmarksEnabled()) | 373 if (!EditBookmarksEnabled()) |
| 374 return false; | 374 return false; |
| 375 | 375 |
| 376 scoped_ptr<Cut::Params> params(Cut::Params::Create(*args_)); | 376 scoped_ptr<Cut::Params> params(Cut::Params::Create(*args_)); |
| 377 EXTENSION_FUNCTION_VALIDATE(params); | 377 EXTENSION_FUNCTION_VALIDATE(params); |
| 378 return CopyOrCut(true, params->id_list); | 378 return CopyOrCut(true, params->id_list); |
| 379 } | 379 } |
| 380 | 380 |
| 381 bool BookmarkManagerPrivatePasteFunction::RunOnReady() { | 381 bool BookmarkManagerPrivatePasteFunction::RunOnReady() { |
| 382 if (!EditBookmarksEnabled()) | 382 if (!EditBookmarksEnabled()) |
| 383 return false; | 383 return false; |
| 384 | 384 |
| 385 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_)); | 385 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_)); |
| 386 EXTENSION_FUNCTION_VALIDATE(params); | 386 EXTENSION_FUNCTION_VALIDATE(params); |
| 387 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 387 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
| 388 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); | 388 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); |
| 389 if (!CanBeModified(parent_node)) | 389 if (!CanBeModified(parent_node)) |
| 390 return false; | 390 return false; |
| 391 bool can_paste = bookmark_utils::CanPasteFromClipboard(model, parent_node); | 391 bool can_paste = bookmarks::CanPasteFromClipboard(model, parent_node); |
| 392 if (!can_paste) | 392 if (!can_paste) |
| 393 return false; | 393 return false; |
| 394 | 394 |
| 395 // We want to use the highest index of the selected nodes as a destination. | 395 // We want to use the highest index of the selected nodes as a destination. |
| 396 std::vector<const BookmarkNode*> nodes; | 396 std::vector<const BookmarkNode*> nodes; |
| 397 // No need to test return value, if we got an empty list, we insert at end. | 397 // No need to test return value, if we got an empty list, we insert at end. |
| 398 if (params->selected_id_list) | 398 if (params->selected_id_list) |
| 399 GetNodesFromVector(model, *params->selected_id_list, &nodes); | 399 GetNodesFromVector(model, *params->selected_id_list, &nodes); |
| 400 int highest_index = -1; // -1 means insert at end of list. | 400 int highest_index = -1; // -1 means insert at end of list. |
| 401 for (size_t i = 0; i < nodes.size(); ++i) { | 401 for (size_t i = 0; i < nodes.size(); ++i) { |
| 402 // + 1 so that we insert after the selection. | 402 // + 1 so that we insert after the selection. |
| 403 int index = parent_node->GetIndexOf(nodes[i]) + 1; | 403 int index = parent_node->GetIndexOf(nodes[i]) + 1; |
| 404 if (index > highest_index) | 404 if (index > highest_index) |
| 405 highest_index = index; | 405 highest_index = index; |
| 406 } | 406 } |
| 407 | 407 |
| 408 bookmark_utils::PasteFromClipboard(model, parent_node, highest_index); | 408 bookmarks::PasteFromClipboard(model, parent_node, highest_index); |
| 409 return true; | 409 return true; |
| 410 } | 410 } |
| 411 | 411 |
| 412 bool BookmarkManagerPrivateCanPasteFunction::RunOnReady() { | 412 bool BookmarkManagerPrivateCanPasteFunction::RunOnReady() { |
| 413 if (!EditBookmarksEnabled()) | 413 if (!EditBookmarksEnabled()) |
| 414 return false; | 414 return false; |
| 415 | 415 |
| 416 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_)); | 416 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_)); |
| 417 EXTENSION_FUNCTION_VALIDATE(params); | 417 EXTENSION_FUNCTION_VALIDATE(params); |
| 418 | 418 |
| 419 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); | 419 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); |
| 420 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); | 420 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); |
| 421 if (!parent_node) { | 421 if (!parent_node) { |
| 422 error_ = bookmark_keys::kNoParentError; | 422 error_ = bookmark_keys::kNoParentError; |
| 423 return false; | 423 return false; |
| 424 } | 424 } |
| 425 bool can_paste = | 425 bool can_paste = bookmarks::CanPasteFromClipboard(model, parent_node); |
| 426 bookmark_utils::CanPasteFromClipboard(model, parent_node); | |
| 427 SetResult(new base::FundamentalValue(can_paste)); | 426 SetResult(new base::FundamentalValue(can_paste)); |
| 428 return true; | 427 return true; |
| 429 } | 428 } |
| 430 | 429 |
| 431 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { | 430 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { |
| 432 if (!EditBookmarksEnabled()) | 431 if (!EditBookmarksEnabled()) |
| 433 return false; | 432 return false; |
| 434 | 433 |
| 435 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); | 434 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); |
| 436 EXTENSION_FUNCTION_VALIDATE(params); | 435 EXTENSION_FUNCTION_VALIDATE(params); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 799 |
| 801 RedoInfo::Results::Result result; | 800 RedoInfo::Results::Result result; |
| 802 result.enabled = undo_manager->redo_count() > 0; | 801 result.enabled = undo_manager->redo_count() > 0; |
| 803 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); | 802 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); |
| 804 | 803 |
| 805 results_ = RedoInfo::Results::Create(result); | 804 results_ = RedoInfo::Results::Create(result); |
| 806 return true; | 805 return true; |
| 807 } | 806 } |
| 808 | 807 |
| 809 } // namespace extensions | 808 } // namespace extensions |
| OLD | NEW |