diff options
author | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-12 05:01:49 +0000 |
---|---|---|
committer | jrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-12 05:01:49 +0000 |
commit | 450bf05cbcbaa12b5bfbed1e34799a8867e504a4 (patch) | |
tree | 3b1344f31ac69c7aa356af4004b9bc593a0b9334 /chrome | |
parent | 72c577ec85d5311721d2794b8d5e684f4d5b89a0 (diff) | |
download | chromium_src-450bf05cbcbaa12b5bfbed1e34799a8867e504a4.zip chromium_src-450bf05cbcbaa12b5bfbed1e34799a8867e504a4.tar.gz chromium_src-450bf05cbcbaa12b5bfbed1e34799a8867e504a4.tar.bz2 |
Cancel drag if the bookmark model changes.
When we rebuild the bookmark bar (e.g. something changed), clear the
dragging pasteboard to avoid stale pointers.
BUG=34522
TEST=see bug; it's quite clear.
Review URL: http://codereview.chromium.org/836004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/cocoa/bookmark_bar_controller.mm | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/chrome/browser/cocoa/bookmark_bar_controller.mm b/chrome/browser/cocoa/bookmark_bar_controller.mm index e3e9e39..1958ac1 100644 --- a/chrome/browser/cocoa/bookmark_bar_controller.mm +++ b/chrome/browser/cocoa/bookmark_bar_controller.mm @@ -940,7 +940,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { if (![item isKindOfClass:[NSMenuItem class]]) return YES; - BookmarkNode* node = [self nodeFromMenuItem:item]; + const BookmarkNode* node = [self nodeFromMenuItem:item]; // If this is the bar menu, we only have things to do if there are // buttons. If this is a folder button menu, we only have things to @@ -1173,22 +1173,22 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { // -[BookmarkButtonCell menu]. - (IBAction)openBookmarkInNewForegroundTab:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openURL:node->GetURL() disposition:NEW_FOREGROUND_TAB]; } - (IBAction)openBookmarkInNewWindow:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openURL:node->GetURL() disposition:NEW_WINDOW]; } - (IBAction)openBookmarkInIncognitoWindow:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openURL:node->GetURL() disposition:OFF_THE_RECORD]; } - (IBAction)editBookmark:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; if (node->is_folder()) { BookmarkNameFolderController* controller = @@ -1216,14 +1216,14 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } - (IBAction)copyBookmark:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; NSPasteboard* pboard = [NSPasteboard generalPasteboard]; [self copyBookmarkNode:node toPasteboard:pboard]; } - (IBAction)deleteBookmark:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; bookmarkModel_->Remove(node->GetParent(), node->GetParent()->IndexOfChild(node)); // TODO(jrg): don't close; rebuild. @@ -1232,10 +1232,10 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } // An ObjC version of bookmark_utils::OpenAllImpl(). -- (void)openBookmarkNodesRecursive:(BookmarkNode*)node +- (void)openBookmarkNodesRecursive:(const BookmarkNode*)node disposition:(WindowOpenDisposition)disposition { for (int i = 0; i < node->GetChildCount(); i++) { - BookmarkNode* child = node->GetChild(i); + const BookmarkNode* child = node->GetChild(i); if (child->is_url()) { [self openURL:child->GetURL() disposition:disposition]; // We revert to a basic disposition in case the initial @@ -1248,27 +1248,30 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { } // Return the BookmarkNode associated with the given NSMenuItem. -- (BookmarkNode*)nodeFromMenuItem:(id)sender { +- (const BookmarkNode*)nodeFromMenuItem:(id)sender { + const BookmarkNode* node = NULL; BookmarkMenu* menu = (BookmarkMenu*)[sender menu]; - if ([menu isKindOfClass:[BookmarkMenu class]]) - return const_cast<BookmarkNode*>([menu node]); - return NULL; + if ([menu isKindOfClass:[BookmarkMenu class]]) { + int64 id = [menu id]; + node = bookmarkModel_->GetNodeByID(id); + } + return node; } - (IBAction)openAllBookmarks:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openBookmarkNodesRecursive:node disposition:NEW_FOREGROUND_TAB]; UserMetrics::RecordAction("OpenAllBookmarks", browser_->profile()); } - (IBAction)openAllBookmarksNewWindow:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openBookmarkNodesRecursive:node disposition:NEW_WINDOW]; UserMetrics::RecordAction("OpenAllBookmarksNewWindow", browser_->profile()); } - (IBAction)openAllBookmarksIncognitoWindow:(id)sender { - BookmarkNode* node = [self nodeFromMenuItem:sender]; + const BookmarkNode* node = [self nodeFromMenuItem:sender]; [self openBookmarkNodesRecursive:node disposition:OFF_THE_RECORD]; UserMetrics::RecordAction("OpenAllBookmarksIncognitoWindow", browser_->profile()); } @@ -1309,6 +1312,19 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { [self clearMenuTagMap]; needToRebuildOffTheSideMenu_ = YES; bookmarkBarDisplayedButtons_ = 0; + + // Make sure there are no stale pointers in the pasteboard. This + // can be important if a bookmark is deleted (via bookmark sync) + // while in the middle of a drag. The "drag completed" code + // (e.g. [BookmarkBarView performDragOperationForBookmark:]) is + // careful enough to bail if there is no data found at "drop" time. + // + // Unfortunately the clearContents selector is 10.6 only. The best + // we can do is make sure something else is present in place of the + // stale bookmark. + NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; + [pboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:self]; + [pboard setString:@"" forType:NSStringPboardType]; } // Return an autoreleased NSCell suitable for a bookmark button. @@ -1524,7 +1540,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { DCHECK(model == bookmarkModel_); if (!model->IsLoaded()) return; - // Else brute force nuke and build. + // Brute force nuke and build. savedFrameWidth_ = NSWidth([[self view] frame]); const BookmarkNode* node = model->GetBookmarkBarNode(); [self clearBookmarkBar]; @@ -1543,7 +1559,10 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { - (void)setNodeForBarMenu { const BookmarkNode* node = bookmarkModel_->GetBookmarkBarNode(); BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); - [menu setRepresentedObject:[NSValue valueWithPointer:node]]; + + // Make sure types are compatible + DCHECK(sizeof(long long) == sizeof(int64)); + [menu setRepresentedObject:[NSNumber numberWithLongLong:node->id()]]; } - (void)beingDeleted:(BookmarkModel*)model { |