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

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

Issue 1203713002: Limit access to ChromeBookmarkClient to bookmarks code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_bookmark_client
Patch Set: Rebase Created 5 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
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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
10 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h" 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_sync_promo_controller.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 14 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
16 #include "chrome/browser/ui/sync/sync_promo_ui.h" 15 #include "chrome/browser/ui/sync/sync_promo_ui.h"
17 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
18 #include "components/bookmarks/browser/bookmark_model.h" 17 #include "components/bookmarks/browser/bookmark_model.h"
19 #include "components/bookmarks/browser/bookmark_utils.h" 18 #include "components/bookmarks/browser/bookmark_utils.h"
(...skipping 27 matching lines...) Expand all
47 // Singleton object to act as a representedObject for the "choose another 46 // Singleton object to act as a representedObject for the "choose another
48 // folder" item in the pop up. 47 // folder" item in the pop up.
49 static ChooseAnotherFolder* object = nil; 48 static ChooseAnotherFolder* object = nil;
50 if (!object) { 49 if (!object) {
51 object = [[ChooseAnotherFolder alloc] init]; 50 object = [[ChooseAnotherFolder alloc] init];
52 } 51 }
53 return object; 52 return object;
54 } 53 }
55 54
56 - (id)initWithParentWindow:(NSWindow*)parentWindow 55 - (id)initWithParentWindow:(NSWindow*)parentWindow
57 client:(ChromeBookmarkClient*)client
58 model:(BookmarkModel*)model 56 model:(BookmarkModel*)model
59 node:(const BookmarkNode*)node 57 node:(const BookmarkNode*)node
60 alreadyBookmarked:(BOOL)alreadyBookmarked { 58 alreadyBookmarked:(BOOL)alreadyBookmarked {
61 DCHECK(client); 59 DCHECK(model);
62 DCHECK(node); 60 DCHECK(node);
63 if ((self = [super initWithWindowNibPath:@"BookmarkBubble" 61 if ((self = [super initWithWindowNibPath:@"BookmarkBubble"
64 parentWindow:parentWindow 62 parentWindow:parentWindow
65 anchoredAt:NSZeroPoint])) { 63 anchoredAt:NSZeroPoint])) {
66 client_ = client;
67 model_ = model; 64 model_ = model;
68 node_ = node; 65 node_ = node;
69 alreadyBookmarked_ = alreadyBookmarked; 66 alreadyBookmarked_ = alreadyBookmarked;
70 } 67 }
71 return self; 68 return self;
72 } 69 }
73 70
74 - (void)awakeFromNib { 71 - (void)awakeFromNib {
75 [super awakeFromNib]; 72 [super awakeFromNib];
76 73
(...skipping 23 matching lines...) Expand all
100 [[self window] setFrame:bubbleFrame display:YES]; 97 [[self window] setFrame:bubbleFrame display:YES];
101 } 98 }
102 } 99 }
103 100
104 // If this is a new bookmark somewhere visible (e.g. on the bookmark 101 // If this is a new bookmark somewhere visible (e.g. on the bookmark
105 // bar), pulse it. Else, call ourself recursively with our parent 102 // bar), pulse it. Else, call ourself recursively with our parent
106 // until we find something visible to pulse. 103 // until we find something visible to pulse.
107 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node { 104 - (void)startPulsingBookmarkButton:(const BookmarkNode*)node {
108 while (node) { 105 while (node) {
109 if ((node->parent() == model_->bookmark_bar_node()) || 106 if ((node->parent() == model_->bookmark_bar_node()) ||
110 (node->parent() == client_->managed_node()) || 107 (node->parent() == model_->managed_node()) ||
111 (node->parent() == client_->supervised_node()) || 108 (node->parent() == model_->supervised_node()) ||
112 (node == model_->other_node())) { 109 (node == model_->other_node())) {
113 pulsingBookmarkNode_ = node; 110 pulsingBookmarkNode_ = node;
114 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_); 111 bookmarkObserver_->StartObservingNode(pulsingBookmarkNode_);
115 NSValue *value = [NSValue valueWithPointer:node]; 112 NSValue *value = [NSValue valueWithPointer:node];
116 NSDictionary *dict = [NSDictionary 113 NSDictionary *dict = [NSDictionary
117 dictionaryWithObjectsAndKeys:value, 114 dictionaryWithObjectsAndKeys:value,
118 bookmark_button::kBookmarkKey, 115 bookmark_button::kBookmarkKey,
119 [NSNumber numberWithBool:YES], 116 [NSNumber numberWithBool:YES],
120 bookmark_button::kBookmarkPulseFlagKey, 117 bookmark_button::kBookmarkPulseFlagKey,
121 nil]; 118 nil];
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 NSMenuItem* item = [menu addItemWithTitle:title 370 NSMenuItem* item = [menu addItemWithTitle:title
374 action:NULL 371 action:NULL
375 keyEquivalent:@""]; 372 keyEquivalent:@""];
376 [item setRepresentedObject:[NSValue valueWithPointer:parent]]; 373 [item setRepresentedObject:[NSValue valueWithPointer:parent]];
377 [item setIndentationLevel:indentation]; 374 [item setIndentationLevel:indentation];
378 ++indentation; 375 ++indentation;
379 } 376 }
380 for (int i = 0; i < parent->child_count(); i++) { 377 for (int i = 0; i < parent->child_count(); i++) {
381 const BookmarkNode* child = parent->GetChild(i); 378 const BookmarkNode* child = parent->GetChild(i);
382 if (child->is_folder() && child->IsVisible() && 379 if (child->is_folder() && child->IsVisible() &&
383 client_->CanBeEditedByUser(child)) { 380 model_->CanBeEditedByUser(child)) {
384 [self addFolderNodes:child 381 [self addFolderNodes:child
385 toPopUpButton:button 382 toPopUpButton:button
386 indentation:indentation]; 383 indentation:indentation];
387 } 384 }
388 } 385 }
389 } 386 }
390 387
391 - (void)setTitle:(NSString*)title parentFolder:(const BookmarkNode*)parent { 388 - (void)setTitle:(NSString*)title parentFolder:(const BookmarkNode*)parent {
392 [nameTextField_ setStringValue:title]; 389 [nameTextField_ setStringValue:title];
393 [self setParentFolderSelection:parent]; 390 [self setParentFolderSelection:parent];
394 } 391 }
395 392
396 // Pick a specific parent node in the selection by finding the right 393 // Pick a specific parent node in the selection by finding the right
397 // pop up button index. 394 // pop up button index.
398 - (void)setParentFolderSelection:(const BookmarkNode*)parent { 395 - (void)setParentFolderSelection:(const BookmarkNode*)parent {
399 // Expectation: There is a parent mapping for all items in the 396 // Expectation: There is a parent mapping for all items in the
400 // folderPopUpButton except the last one ("Choose another folder..."). 397 // folderPopUpButton except the last one ("Choose another folder...").
401 NSMenu* menu = [folderPopUpButton_ menu]; 398 NSMenu* menu = [folderPopUpButton_ menu];
402 NSValue* parentValue = [NSValue valueWithPointer:parent]; 399 NSValue* parentValue = [NSValue valueWithPointer:parent];
403 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue]; 400 NSInteger idx = [menu indexOfItemWithRepresentedObject:parentValue];
404 DCHECK(idx != -1); 401 DCHECK(idx != -1);
405 [folderPopUpButton_ selectItemAtIndex:idx]; 402 [folderPopUpButton_ selectItemAtIndex:idx];
406 } 403 }
407 404
408 - (NSPopUpButton*)folderPopUpButton { 405 - (NSPopUpButton*)folderPopUpButton {
409 return folderPopUpButton_; 406 return folderPopUpButton_;
410 } 407 }
411 408
412 @end // implementation BookmarkBubbleController(ExposedForUnitTesting) 409 @end // implementation BookmarkBubbleController(ExposedForUnitTesting)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698