OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "browser_actions_controller.h" | 5 #import "browser_actions_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/extensions/extension_browser_event_router.h" | 12 #include "chrome/browser/extensions/extension_browser_event_router.h" |
13 #include "chrome/browser/extensions/extension_host.h" | 13 #include "chrome/browser/extensions/extension_host.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 14 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/extensions/extensions_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 18 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 20 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
21 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 21 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
22 #import "chrome/browser/ui/cocoa/extensions/chevron_menu_button.h" | 22 #import "chrome/browser/ui/cocoa/extensions/chevron_menu_button.h" |
23 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 23 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
24 #import "chrome/browser/ui/cocoa/menu_button.h" | 24 #import "chrome/browser/ui/cocoa/menu_button.h" |
25 #include "chrome/common/extensions/extension_action.h" | 25 #include "chrome/common/extensions/extension_action.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 // Updates the container's grippy cursor based on the number of hidden buttons. | 170 // Updates the container's grippy cursor based on the number of hidden buttons. |
171 - (void)updateGrippyCursors; | 171 - (void)updateGrippyCursors; |
172 | 172 |
173 // Returns the ID of the currently selected tab or -1 if none exists. | 173 // Returns the ID of the currently selected tab or -1 if none exists. |
174 - (int)currentTabId; | 174 - (int)currentTabId; |
175 @end | 175 @end |
176 | 176 |
177 // A helper class to proxy extension notifications to the view controller's | 177 // A helper class to proxy extension notifications to the view controller's |
178 // appropriate methods. | 178 // appropriate methods. |
179 class ExtensionsServiceObserverBridge : public NotificationObserver, | 179 class ExtensionServiceObserverBridge : public NotificationObserver, |
180 public ExtensionToolbarModel::Observer { | 180 public ExtensionToolbarModel::Observer { |
181 public: | 181 public: |
182 ExtensionsServiceObserverBridge(BrowserActionsController* owner, | 182 ExtensionServiceObserverBridge(BrowserActionsController* owner, |
183 Profile* profile) : owner_(owner) { | 183 Profile* profile) : owner_(owner) { |
184 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 184 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
185 Source<Profile>(profile)); | 185 Source<Profile>(profile)); |
186 } | 186 } |
187 | 187 |
188 // Overridden from NotificationObserver. | 188 // Overridden from NotificationObserver. |
189 void Observe(NotificationType type, | 189 void Observe(NotificationType type, |
190 const NotificationSource& source, | 190 const NotificationSource& source, |
191 const NotificationDetails& details) { | 191 const NotificationDetails& details) { |
192 switch (type.value) { | 192 switch (type.value) { |
(...skipping 20 matching lines...) Expand all Loading... |
213 [owner_ resizeContainerAndAnimate:NO]; | 213 [owner_ resizeContainerAndAnimate:NO]; |
214 } | 214 } |
215 | 215 |
216 private: | 216 private: |
217 // The object we need to inform when we get a notification. Weak. Owns us. | 217 // The object we need to inform when we get a notification. Weak. Owns us. |
218 BrowserActionsController* owner_; | 218 BrowserActionsController* owner_; |
219 | 219 |
220 // Used for registering to receive notifications and automatic clean up. | 220 // Used for registering to receive notifications and automatic clean up. |
221 NotificationRegistrar registrar_; | 221 NotificationRegistrar registrar_; |
222 | 222 |
223 DISALLOW_COPY_AND_ASSIGN(ExtensionsServiceObserverBridge); | 223 DISALLOW_COPY_AND_ASSIGN(ExtensionServiceObserverBridge); |
224 }; | 224 }; |
225 | 225 |
226 @implementation BrowserActionsController | 226 @implementation BrowserActionsController |
227 | 227 |
228 @synthesize containerView = containerView_; | 228 @synthesize containerView = containerView_; |
229 | 229 |
230 #pragma mark - | 230 #pragma mark - |
231 #pragma mark Public Methods | 231 #pragma mark Public Methods |
232 | 232 |
233 - (id)initWithBrowser:(Browser*)browser | 233 - (id)initWithBrowser:(Browser*)browser |
234 containerView:(BrowserActionsContainerView*)container { | 234 containerView:(BrowserActionsContainerView*)container { |
235 DCHECK(browser && container); | 235 DCHECK(browser && container); |
236 | 236 |
237 if ((self = [super init])) { | 237 if ((self = [super init])) { |
238 browser_ = browser; | 238 browser_ = browser; |
239 profile_ = browser->profile(); | 239 profile_ = browser->profile(); |
240 | 240 |
241 if (!profile_->GetPrefs()->FindPreference( | 241 if (!profile_->GetPrefs()->FindPreference( |
242 prefs::kBrowserActionContainerWidth)) | 242 prefs::kBrowserActionContainerWidth)) |
243 [BrowserActionsController registerUserPrefs:profile_->GetPrefs()]; | 243 [BrowserActionsController registerUserPrefs:profile_->GetPrefs()]; |
244 | 244 |
245 observer_.reset(new ExtensionsServiceObserverBridge(self, profile_)); | 245 observer_.reset(new ExtensionServiceObserverBridge(self, profile_)); |
246 ExtensionsService* extensionsService = profile_->GetExtensionsService(); | 246 ExtensionService* extensionsService = profile_->GetExtensionService(); |
247 // |extensionsService| can be NULL in Incognito. | 247 // |extensionsService| can be NULL in Incognito. |
248 if (extensionsService) { | 248 if (extensionsService) { |
249 toolbarModel_ = extensionsService->toolbar_model(); | 249 toolbarModel_ = extensionsService->toolbar_model(); |
250 toolbarModel_->AddObserver(observer_.get()); | 250 toolbarModel_->AddObserver(observer_.get()); |
251 } | 251 } |
252 | 252 |
253 containerView_ = container; | 253 containerView_ = container; |
254 [containerView_ setPostsFrameChangedNotifications:YES]; | 254 [containerView_ setPostsFrameChangedNotifications:YES]; |
255 [[NSNotificationCenter defaultCenter] | 255 [[NSNotificationCenter defaultCenter] |
256 addObserver:self | 256 addObserver:self |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 devMode:NO]; | 740 devMode:NO]; |
741 } else { | 741 } else { |
742 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( | 742 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
743 profile_, action->extension_id(), browser_); | 743 profile_, action->extension_id(), browser_); |
744 } | 744 } |
745 } | 745 } |
746 | 746 |
747 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { | 747 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension { |
748 // Only display incognito-enabled extensions while in incognito mode. | 748 // Only display incognito-enabled extensions while in incognito mode. |
749 return (!profile_->IsOffTheRecord() || | 749 return (!profile_->IsOffTheRecord() || |
750 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 750 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); |
751 } | 751 } |
752 | 752 |
753 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { | 753 - (void)showChevronIfNecessaryInFrame:(NSRect)frame animate:(BOOL)animate { |
754 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) | 754 [self setChevronHidden:([self buttonCount] == [self visibleButtonCount]) |
755 inFrame:frame | 755 inFrame:frame |
756 animate:animate]; | 756 animate:animate]; |
757 } | 757 } |
758 | 758 |
759 - (void)updateChevronPositionInFrame:(NSRect)frame { | 759 - (void)updateChevronPositionInFrame:(NSRect)frame { |
760 CGFloat xPos = NSWidth(frame) - kChevronWidth; | 760 CGFloat xPos = NSWidth(frame) - kChevronWidth; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 if (profile_->IsOffTheRecord()) | 854 if (profile_->IsOffTheRecord()) |
855 index = toolbarModel_->IncognitoIndexToOriginal(index); | 855 index = toolbarModel_->IncognitoIndexToOriginal(index); |
856 if (index < toolbarModel_->size()) { | 856 if (index < toolbarModel_->size()) { |
857 const Extension* extension = toolbarModel_->GetExtensionByIndex(index); | 857 const Extension* extension = toolbarModel_->GetExtensionByIndex(index); |
858 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 858 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
859 } | 859 } |
860 return nil; | 860 return nil; |
861 } | 861 } |
862 | 862 |
863 @end | 863 @end |
OLD | NEW |