| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_chooser_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 6 | 6 |
| 7 #import <Carbon/Carbon.h> // kVK_Return. | 7 #import <Carbon/Carbon.h> // kVK_Return. |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 31 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 32 #include "chrome/browser/signin/signin_error_controller_factory.h" | 32 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 33 #include "chrome/browser/signin/signin_manager_factory.h" | 33 #include "chrome/browser/signin/signin_manager_factory.h" |
| 34 #include "chrome/browser/signin/signin_promo.h" | 34 #include "chrome/browser/signin/signin_promo.h" |
| 35 #include "chrome/browser/signin/signin_ui_util.h" | 35 #include "chrome/browser/signin/signin_ui_util.h" |
| 36 #include "chrome/browser/sync/profile_sync_service_factory.h" | 36 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 37 #include "chrome/browser/sync/sync_ui_util.h" | 37 #include "chrome/browser/sync/sync_ui_util.h" |
| 38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 39 #include "chrome/browser/ui/browser_commands.h" | 39 #include "chrome/browser/ui/browser_commands.h" |
| 40 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 41 #include "chrome/browser/ui/browser_list_observer.h" |
| 41 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
| 42 #include "chrome/browser/ui/chrome_pages.h" | 43 #include "chrome/browser/ui/chrome_pages.h" |
| 43 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 44 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 44 #include "chrome/browser/ui/cocoa/chrome_style.h" | 45 #include "chrome/browser/ui/cocoa/chrome_style.h" |
| 45 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 46 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 46 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 47 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 47 #include "chrome/browser/ui/cocoa/l10n_util.h" | 48 #include "chrome/browser/ui/cocoa/l10n_util.h" |
| 48 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" | 49 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" |
| 49 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | 50 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
| 50 #include "chrome/browser/ui/profile_chooser_constants.h" | 51 #include "chrome/browser/ui/profile_chooser_constants.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // TODO(guohui): maybe should add an accelerator for the back button. | 319 // TODO(guohui): maybe should add an accelerator for the back button. |
| 319 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT || | 320 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT || |
| 320 is_text_editing_command) { | 321 is_text_editing_command) { |
| 321 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 322 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 322 } | 323 } |
| 323 } | 324 } |
| 324 | 325 |
| 325 // Class that listens to changes to the OAuth2Tokens for the active profile, | 326 // Class that listens to changes to the OAuth2Tokens for the active profile, |
| 326 // changes to the avatar menu model or browser close notifications. | 327 // changes to the avatar menu model or browser close notifications. |
| 327 class ActiveProfileObserverBridge : public AvatarMenuObserver, | 328 class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| 328 public content::NotificationObserver, | 329 public chrome::BrowserListObserver, |
| 329 public OAuth2TokenService::Observer { | 330 public OAuth2TokenService::Observer { |
| 330 public: | 331 public: |
| 331 ActiveProfileObserverBridge(ProfileChooserController* controller, | 332 ActiveProfileObserverBridge(ProfileChooserController* controller, |
| 332 Browser* browser) | 333 Browser* browser) |
| 333 : controller_(controller), | 334 : controller_(controller), |
| 334 browser_(browser), | 335 browser_(browser), |
| 335 token_observer_registered_(false) { | 336 token_observer_registered_(false) { |
| 336 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 337 BrowserList::AddObserver(this); |
| 337 content::NotificationService::AllSources()); | |
| 338 if (!browser_->profile()->IsGuestSession()) | 338 if (!browser_->profile()->IsGuestSession()) |
| 339 AddTokenServiceObserver(); | 339 AddTokenServiceObserver(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 ~ActiveProfileObserverBridge() override { RemoveTokenServiceObserver(); } | 342 ~ActiveProfileObserverBridge() override { RemoveTokenServiceObserver(); } |
| 343 | 343 |
| 344 private: | 344 private: |
| 345 void AddTokenServiceObserver() { | 345 void AddTokenServiceObserver() { |
| 346 ProfileOAuth2TokenService* oauth2_token_service = | 346 ProfileOAuth2TokenService* oauth2_token_service = |
| 347 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); | 347 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 // AvatarMenuObserver: | 388 // AvatarMenuObserver: |
| 389 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override { | 389 void OnAvatarMenuChanged(AvatarMenu* avatar_menu) override { |
| 390 profiles::BubbleViewMode viewMode = [controller_ viewMode]; | 390 profiles::BubbleViewMode viewMode = [controller_ viewMode]; |
| 391 if (viewMode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 391 if (viewMode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || |
| 392 viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 392 viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 393 [controller_ initMenuContentsWithView:viewMode]; | 393 [controller_ initMenuContentsWithView:viewMode]; |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 // content::NotificationObserver: | 397 // chrome::BrowserListObserver: |
| 398 void Observe(int type, | 398 void OnBrowserCloseStarted(Browser* browser) override { |
| 399 const content::NotificationSource& source, | 399 if (browser_ == browser) { |
| 400 const content::NotificationDetails& details) override { | |
| 401 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_CLOSING, type); | |
| 402 if (browser_ == content::Source<Browser>(source).ptr()) { | |
| 403 RemoveTokenServiceObserver(); | 400 RemoveTokenServiceObserver(); |
| 404 // Clean up the bubble's WebContents (used by the Gaia embedded view), to | 401 // Clean up the bubble's WebContents (used by the Gaia embedded view), to |
| 405 // make sure the guest profile doesn't have any dangling host renderers. | 402 // make sure the guest profile doesn't have any dangling host renderers. |
| 406 // This can happen if Chrome is quit using Command-Q while the bubble is | 403 // This can happen if Chrome is quit using Command-Q while the bubble is |
| 407 // still open, which won't give the bubble a chance to be closed and | 404 // still open, which won't give the bubble a chance to be closed and |
| 408 // clean up the WebContents itself. | 405 // clean up the WebContents itself. |
| 409 [controller_ cleanUpEmbeddedViewContents]; | 406 [controller_ cleanUpEmbeddedViewContents]; |
| 410 } | 407 } |
| 411 } | 408 } |
| 412 | 409 |
| 413 ProfileChooserController* controller_; // Weak; owns this. | 410 ProfileChooserController* controller_; // Weak; owns this. |
| 414 Browser* browser_; // Weak. | 411 Browser* browser_; // Weak. |
| 415 content::NotificationRegistrar registrar_; | |
| 416 | 412 |
| 417 // The observer can be removed both when closing the browser, and by just | 413 // The observer can be removed both when closing the browser, and by just |
| 418 // closing the avatar bubble. However, in the case of closing the browser, | 414 // closing the avatar bubble. However, in the case of closing the browser, |
| 419 // the avatar bubble will also be closed afterwards, resulting in a second | 415 // the avatar bubble will also be closed afterwards, resulting in a second |
| 420 // attempt to remove the observer. This ensures the observer is only | 416 // attempt to remove the observer. This ensures the observer is only |
| 421 // removed once. | 417 // removed once. |
| 422 bool token_observer_registered_; | 418 bool token_observer_registered_; |
| 423 | 419 |
| 424 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); | 420 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); |
| 425 }; | 421 }; |
| (...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2676 | 2672 |
| 2677 - (void)showWindow:(id)sender { | 2673 - (void)showWindow:(id)sender { |
| 2678 [super showWindow:sender]; | 2674 [super showWindow:sender]; |
| 2679 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2675 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2680 if (firstProfileView_ && [event type] == NSKeyDown) { | 2676 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2681 [[self window] makeFirstResponder:firstProfileView_]; | 2677 [[self window] makeFirstResponder:firstProfileView_]; |
| 2682 } | 2678 } |
| 2683 } | 2679 } |
| 2684 | 2680 |
| 2685 @end | 2681 @end |
| OLD | NEW |