| OLD | NEW |
| 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/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/prefs/public/pref_observer.h" | |
| 13 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 14 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 16 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 18 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 17 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 18 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 20 #include "chrome/browser/command_updater.h" | 19 #include "chrome/browser/command_updater.h" |
| 21 #include "chrome/browser/net/url_fixer_upper.h" | 20 #include "chrome/browser/net/url_fixer_upper.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 99 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
| 101 - (void)badgeWrenchMenuIfNeeded; | 100 - (void)badgeWrenchMenuIfNeeded; |
| 102 @end | 101 @end |
| 103 | 102 |
| 104 namespace ToolbarControllerInternal { | 103 namespace ToolbarControllerInternal { |
| 105 | 104 |
| 106 // A class registered for C++ notifications. This is used to detect changes in | 105 // A class registered for C++ notifications. This is used to detect changes in |
| 107 // preferences and upgrade available notifications. Bridges the notification | 106 // preferences and upgrade available notifications. Bridges the notification |
| 108 // back to the ToolbarController. | 107 // back to the ToolbarController. |
| 109 class NotificationBridge | 108 class NotificationBridge |
| 110 : public content::NotificationObserver, | 109 : public content::NotificationObserver { |
| 111 public PrefObserver { | |
| 112 public: | 110 public: |
| 113 explicit NotificationBridge(ToolbarController* controller) | 111 explicit NotificationBridge(ToolbarController* controller) |
| 114 : controller_(controller) { | 112 : controller_(controller) { |
| 115 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 113 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 116 content::NotificationService::AllSources()); | 114 content::NotificationService::AllSources()); |
| 117 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 115 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 118 content::Source<Profile>([controller browser]->profile())); | 116 content::Source<Profile>([controller browser]->profile())); |
| 119 } | 117 } |
| 120 | 118 |
| 121 // Overridden from content::NotificationObserver: | 119 // Overridden from content::NotificationObserver: |
| 122 virtual void Observe(int type, | 120 virtual void Observe(int type, |
| 123 const content::NotificationSource& source, | 121 const content::NotificationSource& source, |
| 124 const content::NotificationDetails& details) OVERRIDE { | 122 const content::NotificationDetails& details) OVERRIDE { |
| 125 switch (type) { | 123 switch (type) { |
| 126 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: | 124 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: |
| 127 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: | 125 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: |
| 128 [controller_ badgeWrenchMenuIfNeeded]; | 126 [controller_ badgeWrenchMenuIfNeeded]; |
| 129 break; | 127 break; |
| 130 default: | 128 default: |
| 131 NOTREACHED(); | 129 NOTREACHED(); |
| 132 } | 130 } |
| 133 } | 131 } |
| 134 | 132 |
| 135 // Overridden from PrefObserver: | 133 void OnPreferenceChanged(const std::string& pref_name) { |
| 136 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
| 137 const std::string& pref_name) OVERRIDE { | |
| 138 [controller_ prefChanged:pref_name]; | 134 [controller_ prefChanged:pref_name]; |
| 139 } | 135 } |
| 140 | 136 |
| 141 private: | 137 private: |
| 142 ToolbarController* controller_; // weak, owns us | 138 ToolbarController* controller_; // weak, owns us |
| 143 | 139 |
| 144 content::NotificationRegistrar registrar_; | 140 content::NotificationRegistrar registrar_; |
| 145 }; | 141 }; |
| 146 | 142 |
| 147 } // namespace ToolbarControllerInternal | 143 } // namespace ToolbarControllerInternal |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 locationBarView_.reset(new LocationBarViewMac(locationBar_, | 270 locationBarView_.reset(new LocationBarViewMac(locationBar_, |
| 275 commands_, toolbarModel_, | 271 commands_, toolbarModel_, |
| 276 profile_, browser_)); | 272 profile_, browser_)); |
| 277 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 273 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 278 // Register pref observers for the optional home and page/options buttons | 274 // Register pref observers for the optional home and page/options buttons |
| 279 // and then add them to the toolbar based on those prefs. | 275 // and then add them to the toolbar based on those prefs. |
| 280 notificationBridge_.reset( | 276 notificationBridge_.reset( |
| 281 new ToolbarControllerInternal::NotificationBridge(self)); | 277 new ToolbarControllerInternal::NotificationBridge(self)); |
| 282 PrefService* prefs = profile_->GetPrefs(); | 278 PrefService* prefs = profile_->GetPrefs(); |
| 283 showHomeButton_.Init(prefs::kShowHomeButton, prefs, | 279 showHomeButton_.Init(prefs::kShowHomeButton, prefs, |
| 284 notificationBridge_.get()); | 280 base::Bind(&NotificationBridge::OnPreferenceChanged, |
| 281 base::Unretained(notificationBridge_.get()))); |
| 285 [self showOptionalHomeButton]; | 282 [self showOptionalHomeButton]; |
| 286 [self installWrenchMenu]; | 283 [self installWrenchMenu]; |
| 287 | 284 |
| 288 // Create the controllers for the back/forward menus. | 285 // Create the controllers for the back/forward menus. |
| 289 backMenuController_.reset([[BackForwardMenuController alloc] | 286 backMenuController_.reset([[BackForwardMenuController alloc] |
| 290 initWithBrowser:browser_ | 287 initWithBrowser:browser_ |
| 291 modelType:BACK_FORWARD_MENU_TYPE_BACK | 288 modelType:BACK_FORWARD_MENU_TYPE_BACK |
| 292 button:backButton_]); | 289 button:backButton_]); |
| 293 forwardMenuController_.reset([[BackForwardMenuController alloc] | 290 forwardMenuController_.reset([[BackForwardMenuController alloc] |
| 294 initWithBrowser:browser_ | 291 initWithBrowser:browser_ |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 797 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 801 // Do nothing. | 798 // Do nothing. |
| 802 } | 799 } |
| 803 | 800 |
| 804 // (URLDropTargetController protocol) | 801 // (URLDropTargetController protocol) |
| 805 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 802 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 806 return drag_util::IsUnsupportedDropData(profile_, info); | 803 return drag_util::IsUnsupportedDropData(profile_, info); |
| 807 } | 804 } |
| 808 | 805 |
| 809 @end | 806 @end |
| OLD | NEW |