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

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

Issue 308273002: Made the bookmarks extension APIs aware of managed bookmarks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 void BookmarkManagerPrivateDragEventRouter::ClearBookmarkNodeData() { 348 void BookmarkManagerPrivateDragEventRouter::ClearBookmarkNodeData() {
349 bookmark_drag_data_.Clear(); 349 bookmark_drag_data_.Clear();
350 } 350 }
351 351
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 = BookmarkModelFactory::GetForProfile(GetProfile()); 354 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
355 std::vector<const BookmarkNode*> nodes; 355 std::vector<const BookmarkNode*> nodes;
356 EXTENSION_FUNCTION_VALIDATE(GetNodesFromVector(model, id_list, &nodes)); 356 EXTENSION_FUNCTION_VALIDATE(GetNodesFromVector(model, id_list, &nodes));
357 if (cut) {
358 for (size_t i = 0; i < nodes.size(); ++i) {
359 if (model->IsManaged(nodes[i])) {
360 error_ = bookmark_keys::kModifyManagedError;
361 return false;
362 }
363 }
364 }
357 bookmark_utils::CopyToClipboard(model, nodes, cut); 365 bookmark_utils::CopyToClipboard(model, nodes, cut);
358 return true; 366 return true;
359 } 367 }
360 368
361 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { 369 bool BookmarkManagerPrivateCopyFunction::RunOnReady() {
362 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); 370 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_));
363 EXTENSION_FUNCTION_VALIDATE(params); 371 EXTENSION_FUNCTION_VALIDATE(params);
364 return CopyOrCut(false, params->id_list); 372 return CopyOrCut(false, params->id_list);
365 } 373 }
366 374
(...skipping 11 matching lines...) Expand all
378 return false; 386 return false;
379 387
380 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_)); 388 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_));
381 EXTENSION_FUNCTION_VALIDATE(params); 389 EXTENSION_FUNCTION_VALIDATE(params);
382 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 390 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
383 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 391 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
384 if (!parent_node) { 392 if (!parent_node) {
385 error_ = bookmark_keys::kNoParentError; 393 error_ = bookmark_keys::kNoParentError;
386 return false; 394 return false;
387 } 395 }
396 if (model->IsManaged(parent_node)) {
397 error_ = bookmark_keys::kModifyManagedError;
398 return false;
399 }
388 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); 400 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node);
389 if (!can_paste) 401 if (!can_paste)
390 return false; 402 return false;
391 403
392 // We want to use the highest index of the selected nodes as a destination. 404 // We want to use the highest index of the selected nodes as a destination.
393 std::vector<const BookmarkNode*> nodes; 405 std::vector<const BookmarkNode*> nodes;
394 // No need to test return value, if we got an empty list, we insert at end. 406 // No need to test return value, if we got an empty list, we insert at end.
395 if (params->selected_id_list) 407 if (params->selected_id_list)
396 GetNodesFromVector(model, *params->selected_id_list, &nodes); 408 GetNodesFromVector(model, *params->selected_id_list, &nodes);
397 int highest_index = -1; // -1 means insert at end of list. 409 int highest_index = -1; // -1 means insert at end of list.
(...skipping 14 matching lines...) Expand all
412 424
413 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_)); 425 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_));
414 EXTENSION_FUNCTION_VALIDATE(params); 426 EXTENSION_FUNCTION_VALIDATE(params);
415 427
416 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 428 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
417 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 429 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
418 if (!parent_node) { 430 if (!parent_node) {
419 error_ = bookmark_keys::kNoParentError; 431 error_ = bookmark_keys::kNoParentError;
420 return false; 432 return false;
421 } 433 }
422 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); 434 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node) &&
435 !model->IsManaged(parent_node);
423 SetResult(new base::FundamentalValue(can_paste)); 436 SetResult(new base::FundamentalValue(can_paste));
424 return true; 437 return true;
425 } 438 }
426 439
427 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { 440 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() {
428 if (!EditBookmarksEnabled()) 441 if (!EditBookmarksEnabled())
429 return false; 442 return false;
430 443
431 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); 444 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_));
432 EXTENSION_FUNCTION_VALIDATE(params); 445 EXTENSION_FUNCTION_VALIDATE(params);
433 446
434 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 447 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
435 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 448 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
436 if (!parent_node) { 449 if (!parent_node) {
437 error_ = bookmark_keys::kNoParentError; 450 error_ = bookmark_keys::kNoParentError;
438 return false; 451 return false;
439 } 452 }
453 if (model->IsManaged(parent_node)) {
454 error_ = bookmark_keys::kModifyManagedError;
455 return false;
456 }
440 model->SortChildren(parent_node); 457 model->SortChildren(parent_node);
441 return true; 458 return true;
442 } 459 }
443 460
444 bool BookmarkManagerPrivateGetStringsFunction::RunAsync() { 461 bool BookmarkManagerPrivateGetStringsFunction::RunAsync() {
445 base::DictionaryValue* localized_strings = new base::DictionaryValue(); 462 base::DictionaryValue* localized_strings = new base::DictionaryValue();
446 463
447 localized_strings->SetString("title", 464 localized_strings->SetString("title",
448 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE)); 465 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE));
449 localized_strings->SetString("search_button", 466 localized_strings->SetString("search_button",
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 scoped_ptr<Drop::Params> params(Drop::Params::Create(*args_)); 578 scoped_ptr<Drop::Params> params(Drop::Params::Create(*args_));
562 EXTENSION_FUNCTION_VALIDATE(params); 579 EXTENSION_FUNCTION_VALIDATE(params);
563 580
564 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 581 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
565 582
566 const BookmarkNode* drop_parent = GetNodeFromString(model, params->parent_id); 583 const BookmarkNode* drop_parent = GetNodeFromString(model, params->parent_id);
567 if (!drop_parent) { 584 if (!drop_parent) {
568 error_ = bookmark_keys::kNoParentError; 585 error_ = bookmark_keys::kNoParentError;
569 return false; 586 return false;
570 } 587 }
588 if (model->IsManaged(drop_parent)) {
589 error_ = bookmark_keys::kModifyManagedError;
590 return false;
591 }
571 592
572 int drop_index; 593 int drop_index;
573 if (params->index) 594 if (params->index)
574 drop_index = *params->index; 595 drop_index = *params->index;
575 else 596 else
576 drop_index = drop_parent->child_count(); 597 drop_index = drop_parent->child_count();
577 598
578 WebContents* web_contents = 599 WebContents* web_contents =
579 WebContents::FromRenderViewHost(render_view_host_); 600 WebContents::FromRenderViewHost(render_view_host_);
580 if (GetViewType(web_contents) == VIEW_TYPE_TAB_CONTENTS) { 601 if (GetViewType(web_contents) == VIEW_TYPE_TAB_CONTENTS) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 result.enabled = undo_manager->redo_count() > 0; 808 result.enabled = undo_manager->redo_count() > 0;
788 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); 809 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel());
789 810
790 results_ = RedoInfo::Results::Create(result); 811 results_ = RedoInfo::Results::Create(result);
791 #endif // !defined(OS_ANDROID) 812 #endif // !defined(OS_ANDROID)
792 813
793 return true; 814 return true;
794 } 815 }
795 816
796 } // namespace extensions 817 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698