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

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: Addressed comments 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 && bookmark_utils::HasManaged(model, nodes)) {
not at google - send to devlin 2014/06/03 18:09:16 i was considering suggesting such a function in th
358 error_ = bookmark_keys::kModifyManagedError;
359 return false;
360 }
357 bookmark_utils::CopyToClipboard(model, nodes, cut); 361 bookmark_utils::CopyToClipboard(model, nodes, cut);
358 return true; 362 return true;
359 } 363 }
360 364
361 bool BookmarkManagerPrivateCopyFunction::RunOnReady() { 365 bool BookmarkManagerPrivateCopyFunction::RunOnReady() {
362 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_)); 366 scoped_ptr<Copy::Params> params(Copy::Params::Create(*args_));
363 EXTENSION_FUNCTION_VALIDATE(params); 367 EXTENSION_FUNCTION_VALIDATE(params);
364 return CopyOrCut(false, params->id_list); 368 return CopyOrCut(false, params->id_list);
365 } 369 }
366 370
367 bool BookmarkManagerPrivateCutFunction::RunOnReady() { 371 bool BookmarkManagerPrivateCutFunction::RunOnReady() {
368 if (!EditBookmarksEnabled()) 372 if (!EditBookmarksEnabled())
369 return false; 373 return false;
370 374
371 scoped_ptr<Cut::Params> params(Cut::Params::Create(*args_)); 375 scoped_ptr<Cut::Params> params(Cut::Params::Create(*args_));
372 EXTENSION_FUNCTION_VALIDATE(params); 376 EXTENSION_FUNCTION_VALIDATE(params);
373 return CopyOrCut(true, params->id_list); 377 return CopyOrCut(true, params->id_list);
374 } 378 }
375 379
376 bool BookmarkManagerPrivatePasteFunction::RunOnReady() { 380 bool BookmarkManagerPrivatePasteFunction::RunOnReady() {
377 if (!EditBookmarksEnabled()) 381 if (!EditBookmarksEnabled())
378 return false; 382 return false;
379 383
380 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_)); 384 scoped_ptr<Paste::Params> params(Paste::Params::Create(*args_));
381 EXTENSION_FUNCTION_VALIDATE(params); 385 EXTENSION_FUNCTION_VALIDATE(params);
382 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 386 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
383 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 387 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
384 if (!parent_node) { 388 if (!CanBeModified(parent_node))
385 error_ = bookmark_keys::kNoParentError;
386 return false; 389 return false;
387 }
388 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); 390 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node);
389 if (!can_paste) 391 if (!can_paste)
390 return false; 392 return false;
391 393
392 // We want to use the highest index of the selected nodes as a destination. 394 // We want to use the highest index of the selected nodes as a destination.
393 std::vector<const BookmarkNode*> nodes; 395 std::vector<const BookmarkNode*> nodes;
394 // No need to test return value, if we got an empty list, we insert at end. 396 // No need to test return value, if we got an empty list, we insert at end.
395 if (params->selected_id_list) 397 if (params->selected_id_list)
396 GetNodesFromVector(model, *params->selected_id_list, &nodes); 398 GetNodesFromVector(model, *params->selected_id_list, &nodes);
397 int highest_index = -1; // -1 means insert at end of list. 399 int highest_index = -1; // -1 means insert at end of list.
(...skipping 14 matching lines...) Expand all
412 414
413 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_)); 415 scoped_ptr<CanPaste::Params> params(CanPaste::Params::Create(*args_));
414 EXTENSION_FUNCTION_VALIDATE(params); 416 EXTENSION_FUNCTION_VALIDATE(params);
415 417
416 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 418 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
417 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 419 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
418 if (!parent_node) { 420 if (!parent_node) {
419 error_ = bookmark_keys::kNoParentError; 421 error_ = bookmark_keys::kNoParentError;
420 return false; 422 return false;
421 } 423 }
422 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node); 424 bool can_paste = bookmark_utils::CanPasteFromClipboard(parent_node) &&
425 !model->IsManaged(parent_node);
423 SetResult(new base::FundamentalValue(can_paste)); 426 SetResult(new base::FundamentalValue(can_paste));
424 return true; 427 return true;
425 } 428 }
426 429
427 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() { 430 bool BookmarkManagerPrivateSortChildrenFunction::RunOnReady() {
428 if (!EditBookmarksEnabled()) 431 if (!EditBookmarksEnabled())
429 return false; 432 return false;
430 433
431 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_)); 434 scoped_ptr<SortChildren::Params> params(SortChildren::Params::Create(*args_));
432 EXTENSION_FUNCTION_VALIDATE(params); 435 EXTENSION_FUNCTION_VALIDATE(params);
433 436
434 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 437 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
435 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id); 438 const BookmarkNode* parent_node = GetNodeFromString(model, params->parent_id);
436 if (!parent_node) { 439 if (!CanBeModified(parent_node))
437 error_ = bookmark_keys::kNoParentError;
438 return false; 440 return false;
439 }
440 model->SortChildren(parent_node); 441 model->SortChildren(parent_node);
441 return true; 442 return true;
442 } 443 }
443 444
444 bool BookmarkManagerPrivateGetStringsFunction::RunAsync() { 445 bool BookmarkManagerPrivateGetStringsFunction::RunAsync() {
445 base::DictionaryValue* localized_strings = new base::DictionaryValue(); 446 base::DictionaryValue* localized_strings = new base::DictionaryValue();
446 447
447 localized_strings->SetString("title", 448 localized_strings->SetString("title",
448 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE)); 449 l10n_util::GetStringUTF16(IDS_BOOKMARK_MANAGER_TITLE));
449 localized_strings->SetString("search_button", 450 localized_strings->SetString("search_button",
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 bool BookmarkManagerPrivateDropFunction::RunOnReady() { 558 bool BookmarkManagerPrivateDropFunction::RunOnReady() {
558 if (!EditBookmarksEnabled()) 559 if (!EditBookmarksEnabled())
559 return false; 560 return false;
560 561
561 scoped_ptr<Drop::Params> params(Drop::Params::Create(*args_)); 562 scoped_ptr<Drop::Params> params(Drop::Params::Create(*args_));
562 EXTENSION_FUNCTION_VALIDATE(params); 563 EXTENSION_FUNCTION_VALIDATE(params);
563 564
564 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile()); 565 BookmarkModel* model = BookmarkModelFactory::GetForProfile(GetProfile());
565 566
566 const BookmarkNode* drop_parent = GetNodeFromString(model, params->parent_id); 567 const BookmarkNode* drop_parent = GetNodeFromString(model, params->parent_id);
567 if (!drop_parent) { 568 if (!CanBeModified(drop_parent))
568 error_ = bookmark_keys::kNoParentError;
569 return false; 569 return false;
570 }
571 570
572 int drop_index; 571 int drop_index;
573 if (params->index) 572 if (params->index)
574 drop_index = *params->index; 573 drop_index = *params->index;
575 else 574 else
576 drop_index = drop_parent->child_count(); 575 drop_index = drop_parent->child_count();
577 576
578 WebContents* web_contents = 577 WebContents* web_contents =
579 WebContents::FromRenderViewHost(render_view_host_); 578 WebContents::FromRenderViewHost(render_view_host_);
580 if (GetViewType(web_contents) == VIEW_TYPE_TAB_CONTENTS) { 579 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; 786 result.enabled = undo_manager->redo_count() > 0;
788 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel()); 787 result.label = base::UTF16ToUTF8(undo_manager->GetRedoLabel());
789 788
790 results_ = RedoInfo::Results::Create(result); 789 results_ = RedoInfo::Results::Create(result);
791 #endif // !defined(OS_ANDROID) 790 #endif // !defined(OS_ANDROID)
792 791
793 return true; 792 return true;
794 } 793 }
795 794
796 } // namespace extensions 795 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698