| 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 |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/scoped_observer.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 18 #include "chrome/app/vector_icons/vector_icons.h" | 19 #include "chrome/app/vector_icons/vector_icons.h" |
| 19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | |
| 21 #include "chrome/browser/lifetime/application_lifetime.h" | 21 #include "chrome/browser/lifetime/application_lifetime.h" |
| 22 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 22 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 23 #include "chrome/browser/profiles/avatar_menu.h" | 23 #include "chrome/browser/profiles/avatar_menu.h" |
| 24 #include "chrome/browser/profiles/avatar_menu_observer.h" | 24 #include "chrome/browser/profiles/avatar_menu_observer.h" |
| 25 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 25 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/profiles/profile_metrics.h" | 27 #include "chrome/browser/profiles/profile_metrics.h" |
| 28 #include "chrome/browser/profiles/profile_window.h" | 28 #include "chrome/browser/profiles/profile_window.h" |
| 29 #include "chrome/browser/profiles/profiles_state.h" | 29 #include "chrome/browser/profiles/profiles_state.h" |
| 30 #include "chrome/browser/signin/chrome_signin_helper.h" | 30 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 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" |
| 51 #include "chrome/browser/ui/singleton_tabs.h" | 52 #include "chrome/browser/ui/singleton_tabs.h" |
| 52 #include "chrome/browser/ui/user_manager.h" | 53 #include "chrome/browser/ui/user_manager.h" |
| 53 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 54 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 54 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 55 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 55 #include "chrome/common/pref_names.h" | 56 #include "chrome/common/pref_names.h" |
| 56 #include "chrome/common/url_constants.h" | 57 #include "chrome/common/url_constants.h" |
| 57 #include "chrome/grit/chromium_strings.h" | 58 #include "chrome/grit/chromium_strings.h" |
| 58 #include "chrome/grit/generated_resources.h" | 59 #include "chrome/grit/generated_resources.h" |
| 59 #include "chrome/grit/theme_resources.h" | 60 #include "chrome/grit/theme_resources.h" |
| 60 #include "components/browser_sync/profile_sync_service.h" | 61 #include "components/browser_sync/profile_sync_service.h" |
| 61 #include "components/prefs/pref_service.h" | 62 #include "components/prefs/pref_service.h" |
| 62 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 63 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 63 #include "components/signin/core/browser/signin_manager.h" | 64 #include "components/signin/core/browser/signin_manager.h" |
| 64 #include "components/signin/core/browser/signin_metrics.h" | 65 #include "components/signin/core/browser/signin_metrics.h" |
| 65 #include "components/signin/core/common/profile_management_switches.h" | 66 #include "components/signin/core/common/profile_management_switches.h" |
| 66 #include "content/public/browser/native_web_keyboard_event.h" | 67 #include "content/public/browser/native_web_keyboard_event.h" |
| 67 #include "content/public/browser/notification_service.h" | |
| 68 #include "content/public/browser/render_widget_host_view.h" | 68 #include "content/public/browser/render_widget_host_view.h" |
| 69 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
| 70 #include "google_apis/gaia/oauth2_token_service.h" | 70 #include "google_apis/gaia/oauth2_token_service.h" |
| 71 #include "skia/ext/skia_utils_mac.h" | 71 #include "skia/ext/skia_utils_mac.h" |
| 72 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 72 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 73 #import "ui/base/cocoa/cocoa_base_utils.h" | 73 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 74 #import "ui/base/cocoa/controls/blue_label_button.h" | 74 #import "ui/base/cocoa/controls/blue_label_button.h" |
| 75 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 75 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 76 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 76 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 77 #import "ui/base/cocoa/hover_image_button.h" | 77 #import "ui/base/cocoa/hover_image_button.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // TODO(guohui): maybe should add an accelerator for the back button. | 318 // TODO(guohui): maybe should add an accelerator for the back button. |
| 319 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT || | 319 if (chrome_command_id == IDC_CLOSE_WINDOW || chrome_command_id == IDC_EXIT || |
| 320 is_text_editing_command) { | 320 is_text_editing_command) { |
| 321 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 321 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Class that listens to changes to the OAuth2Tokens for the active profile, | 325 // Class that listens to changes to the OAuth2Tokens for the active profile, |
| 326 // changes to the avatar menu model or browser close notifications. | 326 // changes to the avatar menu model or browser close notifications. |
| 327 class ActiveProfileObserverBridge : public AvatarMenuObserver, | 327 class ActiveProfileObserverBridge : public AvatarMenuObserver, |
| 328 public content::NotificationObserver, | 328 public chrome::BrowserListObserver, |
| 329 public OAuth2TokenService::Observer { | 329 public OAuth2TokenService::Observer { |
| 330 public: | 330 public: |
| 331 ActiveProfileObserverBridge(ProfileChooserController* controller, | 331 ActiveProfileObserverBridge(ProfileChooserController* controller, |
| 332 Browser* browser) | 332 Browser* browser) |
| 333 : controller_(controller), | 333 : controller_(controller), |
| 334 browser_(browser), | 334 browser_(browser), |
| 335 browser_list_observer_(this), |
| 335 token_observer_registered_(false) { | 336 token_observer_registered_(false) { |
| 336 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 337 browser_list_observer_.Add(BrowserList::GetInstance()); |
| 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 OnBrowserClosing(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_; | 412 ScopedObserver<BrowserList, BrowserListObserver> browser_list_observer_; |
| 416 | 413 |
| 417 // The observer can be removed both when closing the browser, and by just | 414 // 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, | 415 // 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 | 416 // the avatar bubble will also be closed afterwards, resulting in a second |
| 420 // attempt to remove the observer. This ensures the observer is only | 417 // attempt to remove the observer. This ensures the observer is only |
| 421 // removed once. | 418 // removed once. |
| 422 bool token_observer_registered_; | 419 bool token_observer_registered_; |
| 423 | 420 |
| 424 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); | 421 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); |
| 425 }; | 422 }; |
| (...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2647 | 2644 |
| 2648 - (void)showWindow:(id)sender { | 2645 - (void)showWindow:(id)sender { |
| 2649 [super showWindow:sender]; | 2646 [super showWindow:sender]; |
| 2650 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2647 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2651 if (firstProfileView_ && [event type] == NSKeyDown) { | 2648 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2652 [[self window] makeFirstResponder:firstProfileView_]; | 2649 [[self window] makeFirstResponder:firstProfileView_]; |
| 2653 } | 2650 } |
| 2654 } | 2651 } |
| 2655 | 2652 |
| 2656 @end | 2653 @end |
| OLD | NEW |