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

Unified Diff: chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc

Issue 302313005: Show the Managed Bookmarks folder in the views UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on components changes CL 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc
index 5c1c3ed311cc8244f3fe728ef93dd0c6b372ab0a..557a5a6072c0adcc2095c3893962635eb735722d 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc
@@ -12,6 +12,7 @@
#include "chrome/common/pref_names.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node_data.h"
+#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/user_prefs/user_prefs.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
@@ -27,7 +28,7 @@ void DragBookmarks(Profile* profile,
ui::DragDropTypes::DragEventSource source) {
DCHECK(!nodes.empty());
- // Set up our OLE machinery
+ // Set up our OLE machinery.
ui::OSExchangeData data;
BookmarkNodeData drag_data(nodes);
drag_data.Write(profile->GetPath(), &data);
@@ -36,9 +37,11 @@ void DragBookmarks(Profile* profile,
bool was_nested = base::MessageLoop::current()->IsNested();
base::MessageLoop::current()->SetNestableTasksAllowed(true);
- int operation = ui::DragDropTypes::DRAG_COPY |
- ui::DragDropTypes::DRAG_MOVE |
- ui::DragDropTypes::DRAG_LINK;
+ int operation = ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK;
+ BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
+ if (bookmark_utils::CanAllBeEditedByUser(model->client(), nodes))
+ operation |= ui::DragDropTypes::DRAG_MOVE;
+
views::Widget* widget = views::Widget::GetWidgetForNativeView(view);
if (widget) {
@@ -55,10 +58,14 @@ void DragBookmarks(Profile* profile,
int GetBookmarkDragOperation(content::BrowserContext* browser_context,
const BookmarkNode* node) {
PrefService* prefs = user_prefs::UserPrefs::Get(browser_context);
+ Profile* profile = Profile::FromBrowserContext(browser_context);
+ BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
int move = ui::DragDropTypes::DRAG_MOVE;
- if (!prefs->GetBoolean(prefs::kEditBookmarksEnabled))
+ if (!prefs->GetBoolean(prefs::kEditBookmarksEnabled) ||
sky 2014/06/06 19:34:04 Move the pref lookup to the client.
Joao da Silva 2014/06/06 20:06:11 I'll do that in another CL, if you don't mind. I'
+ !model->client()->CanBeEditedByUser(node)) {
move = ui::DragDropTypes::DRAG_NONE;
+ }
if (node->is_url())
return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK | move;
return ui::DragDropTypes::DRAG_COPY | move;
@@ -91,10 +98,21 @@ int GetBookmarkDropOperation(Profile* profile,
if (!IsValidBookmarkDropLocation(profile, data, parent, index))
return ui::DragDropTypes::DRAG_NONE;
- if (data.GetFirstNode(BookmarkModelFactory::GetForProfile(profile),
- profile_path))
- // User is dragging from this profile: move.
+ BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
+ if (!model->client()->CanBeEditedByUser(parent))
+ return ui::DragDropTypes::DRAG_NONE;
+
+ const BookmarkNode* dragged_node =
+ data.GetFirstNode(model, profile->GetPath());
+ if (dragged_node) {
+ // User is dragging from this profile.
+ if (!model->client()->CanBeEditedByUser(dragged_node)) {
+ // Do a copy instead of a move when dragging bookmarks that the user can't
+ // modify.
+ return ui::DragDropTypes::DRAG_COPY;
+ }
return ui::DragDropTypes::DRAG_MOVE;
+ }
// User is dragging from another app, copy.
return GetPreferredBookmarkDropOperation(event.source_operations(),
@@ -113,10 +131,13 @@ bool IsValidBookmarkDropLocation(Profile* profile,
if (!data.is_valid())
return false;
+ BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile);
+ if (!model->client()->CanBeEditedByUser(drop_parent))
+ return false;
+
const base::FilePath& profile_path = profile->GetPath();
if (data.IsFromProfilePath(profile_path)) {
- std::vector<const BookmarkNode*> nodes = data.GetNodes(
- BookmarkModelFactory::GetForProfile(profile), profile_path);
+ std::vector<const BookmarkNode*> nodes = data.GetNodes(model, profile_path);
for (size_t i = 0; i < nodes.size(); ++i) {
// Don't allow the drop if the user is attempting to drop on one of the
// nodes being dragged.
@@ -132,7 +153,7 @@ bool IsValidBookmarkDropLocation(Profile* profile,
}
return true;
}
- // From the same profile, always accept.
+ // From another profile, always accept.
return true;
}

Powered by Google App Engine
This is Rietveld 408576698