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

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

Issue 1233673002: Fix componentization of chrome/browser/bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments by tfarina and fix compilation Created 5 years, 5 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_bar_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/bookmarks/bookmark_stats.h" 12 #include "chrome/browser/bookmarks/bookmark_stats.h"
13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 13 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
14 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
15 #include "chrome/browser/prefs/incognito_mode_prefs.h" 14 #include "chrome/browser/prefs/incognito_mode_prefs.h"
16 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/themes/theme_properties.h" 16 #include "chrome/browser/themes/theme_properties.h"
18 #include "chrome/browser/themes/theme_service.h" 17 #include "chrome/browser/themes/theme_service.h"
19 #import "chrome/browser/themes/theme_service_factory.h" 18 #import "chrome/browser/themes/theme_service_factory.h"
20 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" 19 #include "chrome/browser/ui/bookmarks/bookmark_editor.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 20 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_list.h" 22 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/chrome_pages.h" 23 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 19 matching lines...) Expand all
44 #import "chrome/browser/ui/cocoa/view_resizer.h" 43 #import "chrome/browser/ui/cocoa/view_resizer.h"
45 #include "chrome/browser/ui/tabs/tab_strip_model.h" 44 #include "chrome/browser/ui/tabs/tab_strip_model.h"
46 #include "chrome/common/extensions/extension_constants.h" 45 #include "chrome/common/extensions/extension_constants.h"
47 #include "chrome/common/extensions/extension_metrics.h" 46 #include "chrome/common/extensions/extension_metrics.h"
48 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
49 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
50 #include "chrome/grit/generated_resources.h" 49 #include "chrome/grit/generated_resources.h"
51 #include "components/bookmarks/browser/bookmark_model.h" 50 #include "components/bookmarks/browser/bookmark_model.h"
52 #include "components/bookmarks/browser/bookmark_node_data.h" 51 #include "components/bookmarks/browser/bookmark_node_data.h"
53 #include "components/bookmarks/browser/bookmark_utils.h" 52 #include "components/bookmarks/browser/bookmark_utils.h"
53 #include "components/bookmarks/managed/managed_bookmark_service.h"
54 #include "content/public/browser/user_metrics.h" 54 #include "content/public/browser/user_metrics.h"
55 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
56 #include "extensions/browser/extension_registry.h" 56 #include "extensions/browser/extension_registry.h"
57 #include "extensions/common/extension.h" 57 #include "extensions/common/extension.h"
58 #include "extensions/common/extension_set.h" 58 #include "extensions/common/extension_set.h"
59 #include "grit/theme_resources.h" 59 #include "grit/theme_resources.h"
60 #import "ui/base/cocoa/cocoa_base_utils.h" 60 #import "ui/base/cocoa/cocoa_base_utils.h"
61 #include "ui/base/l10n/l10n_util_mac.h" 61 #include "ui/base/l10n/l10n_util_mac.h"
62 #include "ui/base/resource/resource_bundle.h" 62 #include "ui/base/resource/resource_bundle.h"
63 #include "ui/gfx/image/image.h" 63 #include "ui/gfx/image/image.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 delegate:(id<BookmarkBarControllerDelegate>)delegate 252 delegate:(id<BookmarkBarControllerDelegate>)delegate
253 resizeDelegate:(id<ViewResizer>)resizeDelegate { 253 resizeDelegate:(id<ViewResizer>)resizeDelegate {
254 if ((self = [super initWithNibName:@"BookmarkBar" 254 if ((self = [super initWithNibName:@"BookmarkBar"
255 bundle:base::mac::FrameworkBundle()])) { 255 bundle:base::mac::FrameworkBundle()])) {
256 currentState_ = BookmarkBar::HIDDEN; 256 currentState_ = BookmarkBar::HIDDEN;
257 lastState_ = BookmarkBar::HIDDEN; 257 lastState_ = BookmarkBar::HIDDEN;
258 258
259 browser_ = browser; 259 browser_ = browser;
260 initialWidth_ = initialWidth; 260 initialWidth_ = initialWidth;
261 bookmarkModel_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 261 bookmarkModel_ = BookmarkModelFactory::GetForProfile(browser_->profile());
262 bookmarkClient_ = 262 managedBookmarkService_ =
263 ChromeBookmarkClientFactory::GetForProfile(browser_->profile()); 263 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
264 buttons_.reset([[NSMutableArray alloc] init]); 264 buttons_.reset([[NSMutableArray alloc] init]);
265 delegate_ = delegate; 265 delegate_ = delegate;
266 resizeDelegate_ = resizeDelegate; 266 resizeDelegate_ = resizeDelegate;
267 folderTarget_.reset( 267 folderTarget_.reset(
268 [[BookmarkFolderTarget alloc] initWithController:self 268 [[BookmarkFolderTarget alloc] initWithController:self
269 profile:browser_->profile()]); 269 profile:browser_->profile()]);
270 270
271 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 271 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
272 folderImage_.reset( 272 folderImage_.reset(
273 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); 273 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage());
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 } 593 }
594 594
595 // In general, only show the divider when it's in the normal showing state. 595 // In general, only show the divider when it's in the normal showing state.
596 return [self isInState:BookmarkBar::SHOW] ? 0 : 1; 596 return [self isInState:BookmarkBar::SHOW] ? 0 : 1;
597 } 597 }
598 598
599 - (NSImage*)faviconForNode:(const BookmarkNode*)node { 599 - (NSImage*)faviconForNode:(const BookmarkNode*)node {
600 if (!node) 600 if (!node)
601 return defaultImage_; 601 return defaultImage_;
602 602
603 if (node == bookmarkClient_->managed_node()) { 603 if (node == managedBookmarkService_->managed_node()) {
604 // Most users never see this node, so the image is only loaded if needed. 604 // Most users never see this node, so the image is only loaded if needed.
605 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 605 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
606 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage(); 606 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage();
607 } 607 }
608 608
609 if (node == bookmarkClient_->supervised_node()) { 609 if (node == managedBookmarkService_->supervised_node()) {
610 // Most users never see this node, so the image is only loaded if needed. 610 // Most users never see this node, so the image is only loaded if needed.
611 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 611 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
612 return rb.GetNativeImageNamed( 612 return rb.GetNativeImageNamed(
613 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage(); 613 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage();
614 } 614 }
615 615
616 if (node->is_folder()) 616 if (node->is_folder())
617 return folderImage_; 617 return folderImage_;
618 618
619 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node); 619 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node);
620 if (!favicon.IsEmpty()) 620 if (!favicon.IsEmpty())
621 return favicon.ToNSImage(); 621 return favicon.ToNSImage();
622 622
623 return defaultImage_; 623 return defaultImage_;
624 } 624 }
625 625
626 - (void)closeFolderAndStopTrackingMenus { 626 - (void)closeFolderAndStopTrackingMenus {
627 showFolderMenus_ = NO; 627 showFolderMenus_ = NO;
628 [self closeAllBookmarkFolders]; 628 [self closeAllBookmarkFolders];
629 } 629 }
630 630
631 - (BOOL)canEditBookmarks { 631 - (BOOL)canEditBookmarks {
632 PrefService* prefs = browser_->profile()->GetPrefs(); 632 PrefService* prefs = browser_->profile()->GetPrefs();
633 return prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled); 633 return prefs->GetBoolean(bookmarks::prefs::kEditBookmarksEnabled);
634 } 634 }
635 635
636 - (BOOL)canEditBookmark:(const BookmarkNode*)node { 636 - (BOOL)canEditBookmark:(const BookmarkNode*)node {
637 // Don't allow edit/delete of the permanent nodes. 637 // Don't allow edit/delete of the permanent nodes.
638 if (node == nil || bookmarkModel_->is_permanent_node(node) || 638 if (node == nil || bookmarkModel_->is_permanent_node(node) ||
639 !bookmarkClient_->CanBeEditedByUser(node)) { 639 !managedBookmarkService_->CanBeEditedByUser(node)) {
640 return NO; 640 return NO;
641 } 641 }
642 return YES; 642 return YES;
643 } 643 }
644 644
645 #pragma mark Actions 645 #pragma mark Actions
646 646
647 // Helper methods called on the main thread by runMenuFlashThread. 647 // Helper methods called on the main thread by runMenuFlashThread.
648 648
649 - (void)setButtonFlashStateOn:(id)sender { 649 - (void)setButtonFlashStateOn:(id)sender {
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 // until the end of the current event loop. 1290 // until the end of the current event loop.
1291 [[button retain] autorelease]; 1291 [[button retain] autorelease];
1292 return button; 1292 return button;
1293 } 1293 }
1294 1294
1295 // Creates the button for "Managed Bookmarks", but does not position it. 1295 // Creates the button for "Managed Bookmarks", but does not position it.
1296 - (void)createManagedBookmarksButton { 1296 - (void)createManagedBookmarksButton {
1297 if (managedBookmarksButton_.get()) { 1297 if (managedBookmarksButton_.get()) {
1298 // The node's title might have changed if the user signed in or out. 1298 // The node's title might have changed if the user signed in or out.
1299 // Make sure it's up to date now. 1299 // Make sure it's up to date now.
1300 const BookmarkNode* node = bookmarkClient_->managed_node(); 1300 const BookmarkNode* node = managedBookmarkService_->managed_node();
1301 NSString* title = base::SysUTF16ToNSString(node->GetTitle()); 1301 NSString* title = base::SysUTF16ToNSString(node->GetTitle());
1302 NSCell* cell = [managedBookmarksButton_ cell]; 1302 NSCell* cell = [managedBookmarksButton_ cell];
1303 [cell setTitle:title]; 1303 [cell setTitle:title];
1304 1304
1305 // Its visibility may have changed too. 1305 // Its visibility may have changed too.
1306 [self setManagedBookmarksButtonVisibility]; 1306 [self setManagedBookmarksButtonVisibility];
1307 1307
1308 return; 1308 return;
1309 } 1309 }
1310 1310
1311 NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->managed_node()]; 1311 NSCell* cell =
1312 [self cellForBookmarkNode:managedBookmarkService_->managed_node()];
1312 managedBookmarksButton_.reset([self createCustomBookmarkButtonForCell:cell]); 1313 managedBookmarksButton_.reset([self createCustomBookmarkButtonForCell:cell]);
1313 [managedBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)]; 1314 [managedBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1314 view_id_util::SetID(managedBookmarksButton_.get(), VIEW_ID_MANAGED_BOOKMARKS); 1315 view_id_util::SetID(managedBookmarksButton_.get(), VIEW_ID_MANAGED_BOOKMARKS);
1315 [buttonView_ addSubview:managedBookmarksButton_.get()]; 1316 [buttonView_ addSubview:managedBookmarksButton_.get()];
1316 1317
1317 [self setManagedBookmarksButtonVisibility]; 1318 [self setManagedBookmarksButtonVisibility];
1318 } 1319 }
1319 1320
1320 // Creates the button for "Supervised Bookmarks", but does not position it. 1321 // Creates the button for "Supervised Bookmarks", but does not position it.
1321 - (void)createSupervisedBookmarksButton { 1322 - (void)createSupervisedBookmarksButton {
1322 if (supervisedBookmarksButton_.get()) { 1323 if (supervisedBookmarksButton_.get()) {
1323 // The button's already there, but its visibility may have changed. 1324 // The button's already there, but its visibility may have changed.
1324 [self setSupervisedBookmarksButtonVisibility]; 1325 [self setSupervisedBookmarksButtonVisibility];
1325 return; 1326 return;
1326 } 1327 }
1327 1328
1328 NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->supervised_node()]; 1329 NSCell* cell =
1330 [self cellForBookmarkNode:managedBookmarkService_->supervised_node()];
1329 supervisedBookmarksButton_.reset( 1331 supervisedBookmarksButton_.reset(
1330 [self createCustomBookmarkButtonForCell:cell]); 1332 [self createCustomBookmarkButtonForCell:cell]);
1331 [supervisedBookmarksButton_ 1333 [supervisedBookmarksButton_
1332 setAction:@selector(openBookmarkFolderFromButton:)]; 1334 setAction:@selector(openBookmarkFolderFromButton:)];
1333 view_id_util::SetID(supervisedBookmarksButton_.get(), 1335 view_id_util::SetID(supervisedBookmarksButton_.get(),
1334 VIEW_ID_SUPERVISED_BOOKMARKS); 1336 VIEW_ID_SUPERVISED_BOOKMARKS);
1335 [buttonView_ addSubview:supervisedBookmarksButton_.get()]; 1337 [buttonView_ addSubview:supervisedBookmarksButton_.get()];
1336 1338
1337 [self setSupervisedBookmarksButtonVisibility]; 1339 [self setSupervisedBookmarksButtonVisibility];
1338 } 1340 }
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 if ([button isFolder]) { 2084 if ([button isFolder]) {
2083 destParent = [button bookmarkNode]; 2085 destParent = [button bookmarkNode];
2084 // Drop it at the end. 2086 // Drop it at the end.
2085 destIndex = [button bookmarkNode]->child_count(); 2087 destIndex = [button bookmarkNode]->child_count();
2086 } else { 2088 } else {
2087 // Else we're dropping somewhere on the bar, so find the right spot. 2089 // Else we're dropping somewhere on the bar, so find the right spot.
2088 destParent = bookmarkModel_->bookmark_bar_node(); 2090 destParent = bookmarkModel_->bookmark_bar_node();
2089 destIndex = [self indexForDragToPoint:point]; 2091 destIndex = [self indexForDragToPoint:point];
2090 } 2092 }
2091 2093
2092 if (!bookmarkClient_->CanBeEditedByUser(destParent)) 2094 if (!managedBookmarkService_->CanBeEditedByUser(destParent))
2093 return NO; 2095 return NO;
2094 if (!bookmarkClient_->CanBeEditedByUser(sourceNode)) 2096 if (!managedBookmarkService_->CanBeEditedByUser(sourceNode))
2095 copy = YES; 2097 copy = YES;
2096 2098
2097 // Be sure we don't try and drop a folder into itself. 2099 // Be sure we don't try and drop a folder into itself.
2098 if (sourceNode != destParent) { 2100 if (sourceNode != destParent) {
2099 if (copy) 2101 if (copy)
2100 bookmarkModel_->Copy(sourceNode, destParent, destIndex); 2102 bookmarkModel_->Copy(sourceNode, destParent, destIndex);
2101 else 2103 else
2102 bookmarkModel_->Move(sourceNode, destParent, destIndex); 2104 bookmarkModel_->Move(sourceNode, destParent, destIndex);
2103 } 2105 }
2104 2106
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
2801 if ([button isFolder]) { 2803 if ([button isFolder]) {
2802 destParent = [button bookmarkNode]; 2804 destParent = [button bookmarkNode];
2803 // Drop it at the end. 2805 // Drop it at the end.
2804 destIndex = [button bookmarkNode]->child_count(); 2806 destIndex = [button bookmarkNode]->child_count();
2805 } else { 2807 } else {
2806 // Else we're dropping somewhere on the bar, so find the right spot. 2808 // Else we're dropping somewhere on the bar, so find the right spot.
2807 destParent = bookmarkModel_->bookmark_bar_node(); 2809 destParent = bookmarkModel_->bookmark_bar_node();
2808 destIndex = [self indexForDragToPoint:point]; 2810 destIndex = [self indexForDragToPoint:point];
2809 } 2811 }
2810 2812
2811 if (!bookmarkClient_->CanBeEditedByUser(destParent)) 2813 if (!managedBookmarkService_->CanBeEditedByUser(destParent))
2812 return NO; 2814 return NO;
2813 2815
2814 // Don't add the bookmarks if the destination index shows an error. 2816 // Don't add the bookmarks if the destination index shows an error.
2815 if (destIndex >= 0) { 2817 if (destIndex >= 0) {
2816 // Create and add the new bookmark nodes. 2818 // Create and add the new bookmark nodes.
2817 size_t urlCount = [urls count]; 2819 size_t urlCount = [urls count];
2818 for (size_t i = 0; i < urlCount; ++i) { 2820 for (size_t i = 0; i < urlCount; ++i) {
2819 GURL gurl; 2821 GURL gurl;
2820 const char* string = [[urls objectAtIndex:i] UTF8String]; 2822 const char* string = [[urls objectAtIndex:i] UTF8String];
2821 if (string) 2823 if (string)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2909 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2908 (const BookmarkNode*)node { 2910 (const BookmarkNode*)node {
2909 // See if it's in the bar, then if it is in the hierarchy of visible 2911 // See if it's in the bar, then if it is in the hierarchy of visible
2910 // folder menus. 2912 // folder menus.
2911 if (bookmarkModel_->bookmark_bar_node() == node) 2913 if (bookmarkModel_->bookmark_bar_node() == node)
2912 return self; 2914 return self;
2913 return [folderController_ controllerForNode:node]; 2915 return [folderController_ controllerForNode:node];
2914 } 2916 }
2915 2917
2916 @end 2918 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698