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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.mm

Issue 8404022: Fix yet another crash with bookmarks drag&drop on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h"
6 6
7 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" 7 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info { 215 - (BOOL)performDragOperationForBookmarkButton:(id<NSDraggingInfo>)info {
216 BOOL rtn = NO; 216 BOOL rtn = NO;
217 NSData* data = [[info draggingPasteboard] 217 NSData* data = [[info draggingPasteboard]
218 dataForType:kBookmarkButtonDragType]; 218 dataForType:kBookmarkButtonDragType];
219 // [info draggingSource] is nil if not the same application. 219 // [info draggingSource] is nil if not the same application.
220 if (data && [info draggingSource]) { 220 if (data && [info draggingSource]) {
221 BookmarkButton* button = nil; 221 BookmarkButton* button = nil;
222 [data getBytes:&button length:sizeof(button)]; 222 [data getBytes:&button length:sizeof(button)];
223 223
224 // If we're dragging from one profile to another, disallow moving (only 224 // If we're dragging from one profile to another, disallow moving (only
225 // allow copying). Note that we need to call |GetOriginalProfile()| to make 225 // allow copying). Each profile has its own bookmark model, so one way to
226 // sure that Incognito profiles are handled correctly. 226 // check whether we are dragging across profiles is to see if the
227 NSWindow* source_window = [[button delegate] browserWindow]; 227 // |BookmarkNode| corresponding to |button| exists in this profile. If it
228 BrowserWindowController* source_window_controller = 228 // does, we're dragging within a profile; otherwise, we're dragging across
229 [BrowserWindowController 229 // profiles.
230 browserWindowControllerForWindow:source_window]; 230 const BookmarkModel* const model = [[self controller] bookmarkModel];
231 const Profile* source_profile = 231 const BookmarkNode* const source_node = [button bookmarkNode];
232 [source_window_controller profile]->GetOriginalProfile(); 232 const BookmarkNode* const target_node =
233 const Profile* target_profile = 233 model->GetNodeByID(source_node->id());
234 [controller_ bookmarkModel]->profile()->GetOriginalProfile();
235 234
236 BOOL copy = 235 BOOL copy =
237 !([info draggingSourceOperationMask] & NSDragOperationMove) || 236 !([info draggingSourceOperationMask] & NSDragOperationMove) ||
238 source_profile != target_profile; 237 (source_node != target_node);
239 rtn = [controller_ dragButton:button 238 rtn = [controller_ dragButton:button
240 to:[info draggingLocation] 239 to:[info draggingLocation]
241 copy:copy]; 240 copy:copy];
242 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_DragEnd")); 241 UserMetrics::RecordAction(UserMetricsAction("BookmarkBar_DragEnd"));
243 } 242 }
244 return rtn; 243 return rtn;
245 } 244 }
246 245
247 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info { 246 - (BOOL)performDragOperation:(id<NSDraggingInfo>)info {
248 if ([controller_ dragBookmarkData:info]) 247 if ([controller_ dragBookmarkData:info])
(...skipping 13 matching lines...) Expand all
262 261
263 - (void)setController:(id)controller { 262 - (void)setController:(id)controller {
264 controller_ = controller; 263 controller_ = controller;
265 } 264 }
266 265
267 - (ViewID)viewID { 266 - (ViewID)viewID {
268 return VIEW_ID_BOOKMARK_BAR; 267 return VIEW_ID_BOOKMARK_BAR;
269 } 268 }
270 269
271 @end // @implementation BookmarkBarView 270 @end // @implementation BookmarkBarView
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698