OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <numeric> | 8 #include <numeric> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #import "base/mac/sdk_forward_declarations.h" | 13 #import "base/mac/sdk_forward_declarations.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/app/chrome_command_ids.h" // IDC_* | 16 #include "chrome/app/chrome_command_ids.h" // IDC_* |
17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/devtools/devtools_window.h" | 19 #include "chrome/browser/devtools/devtools_window.h" |
20 #include "chrome/browser/fullscreen.h" | 20 #include "chrome/browser/fullscreen.h" |
21 #include "chrome/browser/profiles/avatar_menu.h" | 21 #include "chrome/browser/profiles/avatar_menu.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_info_cache.h" | 23 #include "chrome/browser/profiles/profile_info_cache.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/profiles/profiles_state.h" |
25 #include "chrome/browser/signin/signin_ui_util.h" | 26 #include "chrome/browser/signin/signin_ui_util.h" |
26 #include "chrome/browser/themes/theme_service.h" | 27 #include "chrome/browser/themes/theme_service.h" |
27 #include "chrome/browser/themes/theme_service_factory.h" | 28 #include "chrome/browser/themes/theme_service_factory.h" |
28 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" | 29 #include "chrome/browser/ui/bookmarks/bookmark_editor.h" |
29 #include "chrome/browser/ui/browser.h" | 30 #include "chrome/browser/ui/browser.h" |
30 #include "chrome/browser/ui/browser_command_controller.h" | 31 #include "chrome/browser/ui/browser_command_controller.h" |
31 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
32 #include "chrome/browser/ui/browser_instant_controller.h" | 33 #include "chrome/browser/ui/browser_instant_controller.h" |
33 #include "chrome/browser/ui/browser_list.h" | 34 #include "chrome/browser/ui/browser_list.h" |
34 #include "chrome/browser/ui/browser_window_state.h" | 35 #include "chrome/browser/ui/browser_window_state.h" |
35 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 36 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
36 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
38 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" | 39 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
| 40 #import "chrome/browser/ui/cocoa/browser/new_avatar_button_controller.h" |
39 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 41 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
40 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 42 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
41 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 43 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
42 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 44 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
43 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 45 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
44 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 46 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
45 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 47 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
46 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 48 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
47 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 49 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
48 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 50 #import "chrome/browser/ui/cocoa/framed_browser_window.h" |
(...skipping 12 matching lines...) Expand all Loading... |
61 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 63 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
62 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 64 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
63 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 65 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
64 #include "chrome/browser/ui/omnibox/location_bar.h" | 66 #include "chrome/browser/ui/omnibox/location_bar.h" |
65 #include "chrome/browser/ui/tabs/dock_info.h" | 67 #include "chrome/browser/ui/tabs/dock_info.h" |
66 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 68 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
67 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 69 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
68 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 70 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
69 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 71 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
70 #include "chrome/common/chrome_switches.h" | 72 #include "chrome/common/chrome_switches.h" |
| 73 #include "chrome/common/profile_management_switches.h" |
71 #include "chrome/common/url_constants.h" | 74 #include "chrome/common/url_constants.h" |
72 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 75 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
73 #include "content/public/browser/render_view_host.h" | 76 #include "content/public/browser/render_view_host.h" |
74 #include "content/public/browser/render_widget_host_view.h" | 77 #include "content/public/browser/render_widget_host_view.h" |
75 #include "content/public/browser/web_contents.h" | 78 #include "content/public/browser/web_contents.h" |
76 #include "content/public/browser/web_contents_view.h" | 79 #include "content/public/browser/web_contents_view.h" |
77 #include "content/public/common/content_switches.h" | 80 #include "content/public/common/content_switches.h" |
78 #include "grit/chromium_strings.h" | 81 #include "grit/chromium_strings.h" |
79 #include "grit/generated_resources.h" | 82 #include "grit/generated_resources.h" |
80 #include "grit/locale_settings.h" | 83 #include "grit/locale_settings.h" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 } | 523 } |
521 | 524 |
522 - (Profile*)profile { | 525 - (Profile*)profile { |
523 return browser_->profile(); | 526 return browser_->profile(); |
524 } | 527 } |
525 | 528 |
526 - (AvatarButtonController*)avatarButtonController { | 529 - (AvatarButtonController*)avatarButtonController { |
527 return avatarButtonController_.get(); | 530 return avatarButtonController_.get(); |
528 } | 531 } |
529 | 532 |
| 533 - (NewAvatarButtonController*)newAvatarButtonController { |
| 534 return newAvatarButtonController_.get(); |
| 535 } |
| 536 |
530 - (void)destroyBrowser { | 537 - (void)destroyBrowser { |
531 [NSApp removeWindowsItem:[self window]]; | 538 [NSApp removeWindowsItem:[self window]]; |
532 | 539 |
533 // We need the window to go away now. | 540 // We need the window to go away now. |
534 // We can't actually use |-autorelease| here because there's an embedded | 541 // We can't actually use |-autorelease| here because there's an embedded |
535 // run loop in the |-performClose:| which contains its own autorelease pool. | 542 // run loop in the |-performClose:| which contains its own autorelease pool. |
536 // Instead call it after a zero-length delay, which gets us back to the main | 543 // Instead call it after a zero-length delay, which gets us back to the main |
537 // event loop. | 544 // event loop. |
538 [self performSelector:@selector(autorelease) | 545 [self performSelector:@selector(autorelease) |
539 withObject:nil | 546 withObject:nil |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1490 ProfileInfoCache& cache = | 1497 ProfileInfoCache& cache = |
1491 g_browser_process->profile_manager()->GetProfileInfoCache(); | 1498 g_browser_process->profile_manager()->GetProfileInfoCache(); |
1492 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == | 1499 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == |
1493 std::string::npos) { | 1500 std::string::npos) { |
1494 return NO; | 1501 return NO; |
1495 } | 1502 } |
1496 | 1503 |
1497 return AvatarMenu::ShouldShowAvatarMenu(); | 1504 return AvatarMenu::ShouldShowAvatarMenu(); |
1498 } | 1505 } |
1499 | 1506 |
| 1507 - (BOOL)shouldUseNewAvatarButton { |
| 1508 return switches::IsNewProfileManagement() && |
| 1509 profiles::IsRegularOrGuestSession(browser_.get()); |
| 1510 } |
| 1511 |
1500 - (BOOL)isBookmarkBarVisible { | 1512 - (BOOL)isBookmarkBarVisible { |
1501 return [bookmarkBarController_ isVisible]; | 1513 return [bookmarkBarController_ isVisible]; |
1502 } | 1514 } |
1503 | 1515 |
1504 - (BOOL)isBookmarkBarAnimating { | 1516 - (BOOL)isBookmarkBarAnimating { |
1505 return [bookmarkBarController_ isAnimationRunning]; | 1517 return [bookmarkBarController_ isAnimationRunning]; |
1506 } | 1518 } |
1507 | 1519 |
1508 - (BookmarkBarController*)bookmarkBarController { | 1520 - (BookmarkBarController*)bookmarkBarController { |
1509 return bookmarkBarController_; | 1521 return bookmarkBarController_; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 BookmarkEditor::SHOW_TREE); | 1716 BookmarkEditor::SHOW_TREE); |
1705 } | 1717 } |
1706 } | 1718 } |
1707 | 1719 |
1708 // If the browser is in incognito mode or has multi-profiles, install the image | 1720 // If the browser is in incognito mode or has multi-profiles, install the image |
1709 // view to decorate the window at the upper right. Use the same base y | 1721 // view to decorate the window at the upper right. Use the same base y |
1710 // coordinate as the tab strip. | 1722 // coordinate as the tab strip. |
1711 - (void)installAvatar { | 1723 - (void)installAvatar { |
1712 // Install the image into the badge view. Hide it for now; positioning and | 1724 // Install the image into the badge view. Hide it for now; positioning and |
1713 // sizing will be done by the layout code. The AvatarButton will choose which | 1725 // sizing will be done by the layout code. The AvatarButton will choose which |
1714 // image to display based on the browser. | 1726 // image to display based on the browser. The NewAvatarButton will display |
1715 avatarButtonController_.reset( | 1727 // the browser profile's name unless the browser is incognito. |
| 1728 NSView* view; |
| 1729 if ([self shouldUseNewAvatarButton]) { |
| 1730 newAvatarButtonController_.reset( |
| 1731 [[NewAvatarButtonController alloc] initWithBrowser:browser_.get()]); |
| 1732 view = [newAvatarButtonController_ view]; |
| 1733 } else { |
| 1734 avatarButtonController_.reset( |
1716 [[AvatarButtonController alloc] initWithBrowser:browser_.get()]); | 1735 [[AvatarButtonController alloc] initWithBrowser:browser_.get()]); |
| 1736 view = [avatarButtonController_ view]; |
| 1737 } |
1717 | 1738 |
1718 NSView* view = [avatarButtonController_ view]; | |
1719 [view setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 1739 [view setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
1720 [view setHidden:![self shouldShowAvatar]]; | 1740 [view setHidden:![self shouldShowAvatar]]; |
1721 | 1741 |
1722 // Install the view. | 1742 // Install the view. |
1723 [[[[self window] contentView] superview] addSubview:view]; | 1743 [[[[self window] contentView] superview] addSubview:view]; |
1724 } | 1744 } |
1725 | 1745 |
1726 // Called when we get a three-finger swipe. | 1746 // Called when we get a three-finger swipe. |
1727 - (void)swipeWithEvent:(NSEvent*)event { | 1747 - (void)swipeWithEvent:(NSEvent*)event { |
1728 CGFloat deltaX = [event deltaX]; | 1748 CGFloat deltaX = [event deltaX]; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2228 | 2248 |
2229 - (BOOL)supportsBookmarkBar { | 2249 - (BOOL)supportsBookmarkBar { |
2230 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2250 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
2231 } | 2251 } |
2232 | 2252 |
2233 - (BOOL)isTabbedWindow { | 2253 - (BOOL)isTabbedWindow { |
2234 return browser_->is_type_tabbed(); | 2254 return browser_->is_type_tabbed(); |
2235 } | 2255 } |
2236 | 2256 |
2237 @end // @implementation BrowserWindowController(WindowType) | 2257 @end // @implementation BrowserWindowController(WindowType) |
OLD | NEW |