| 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" |
| 39 #import "chrome/browser/ui/cocoa/browser/avatar_base_controller.h" |
| 38 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" | 40 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
| 41 #import "chrome/browser/ui/cocoa/browser/avatar_icon_controller.h" |
| 39 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 42 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 40 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" | 43 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h" |
| 41 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 44 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 42 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" | 45 #import "chrome/browser/ui/cocoa/dev_tools_controller.h" |
| 43 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 46 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
| 44 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 47 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
| 45 #import "chrome/browser/ui/cocoa/fast_resize_view.h" | 48 #import "chrome/browser/ui/cocoa/fast_resize_view.h" |
| 46 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 49 #import "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 47 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" | 50 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h" |
| 48 #import "chrome/browser/ui/cocoa/framed_browser_window.h" | 51 #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" | 64 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 62 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 65 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 63 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 66 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 64 #include "chrome/browser/ui/omnibox/location_bar.h" | 67 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 65 #include "chrome/browser/ui/tabs/dock_info.h" | 68 #include "chrome/browser/ui/tabs/dock_info.h" |
| 66 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 69 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 67 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" | 70 #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" |
| 68 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 71 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 69 #include "chrome/browser/ui/window_sizer/window_sizer.h" | 72 #include "chrome/browser/ui/window_sizer/window_sizer.h" |
| 70 #include "chrome/common/chrome_switches.h" | 73 #include "chrome/common/chrome_switches.h" |
| 74 #include "chrome/common/profile_management_switches.h" |
| 71 #include "chrome/common/url_constants.h" | 75 #include "chrome/common/url_constants.h" |
| 72 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 76 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 73 #include "content/public/browser/render_view_host.h" | 77 #include "content/public/browser/render_view_host.h" |
| 74 #include "content/public/browser/render_widget_host_view.h" | 78 #include "content/public/browser/render_widget_host_view.h" |
| 75 #include "content/public/browser/web_contents.h" | 79 #include "content/public/browser/web_contents.h" |
| 76 #include "content/public/browser/web_contents_view.h" | 80 #include "content/public/browser/web_contents_view.h" |
| 77 #include "content/public/common/content_switches.h" | 81 #include "content/public/common/content_switches.h" |
| 78 #include "grit/chromium_strings.h" | 82 #include "grit/chromium_strings.h" |
| 79 #include "grit/generated_resources.h" | 83 #include "grit/generated_resources.h" |
| 80 #include "grit/locale_settings.h" | 84 #include "grit/locale_settings.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 520 } |
| 517 | 521 |
| 518 - (OverlayableContentsController*)overlayableContentsController { | 522 - (OverlayableContentsController*)overlayableContentsController { |
| 519 return overlayableContentsController_; | 523 return overlayableContentsController_; |
| 520 } | 524 } |
| 521 | 525 |
| 522 - (Profile*)profile { | 526 - (Profile*)profile { |
| 523 return browser_->profile(); | 527 return browser_->profile(); |
| 524 } | 528 } |
| 525 | 529 |
| 526 - (AvatarButtonController*)avatarButtonController { | 530 - (AvatarBaseController*)avatarButtonController { |
| 527 return avatarButtonController_.get(); | 531 return avatarButtonController_.get(); |
| 528 } | 532 } |
| 529 | 533 |
| 530 - (void)destroyBrowser { | 534 - (void)destroyBrowser { |
| 531 [NSApp removeWindowsItem:[self window]]; | 535 [NSApp removeWindowsItem:[self window]]; |
| 532 | 536 |
| 533 // We need the window to go away now. | 537 // We need the window to go away now. |
| 534 // We can't actually use |-autorelease| here because there's an embedded | 538 // We can't actually use |-autorelease| here because there's an embedded |
| 535 // run loop in the |-performClose:| which contains its own autorelease pool. | 539 // 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 | 540 // Instead call it after a zero-length delay, which gets us back to the main |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 ProfileInfoCache& cache = | 1494 ProfileInfoCache& cache = |
| 1491 g_browser_process->profile_manager()->GetProfileInfoCache(); | 1495 g_browser_process->profile_manager()->GetProfileInfoCache(); |
| 1492 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == | 1496 if (cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()) == |
| 1493 std::string::npos) { | 1497 std::string::npos) { |
| 1494 return NO; | 1498 return NO; |
| 1495 } | 1499 } |
| 1496 | 1500 |
| 1497 return AvatarMenu::ShouldShowAvatarMenu(); | 1501 return AvatarMenu::ShouldShowAvatarMenu(); |
| 1498 } | 1502 } |
| 1499 | 1503 |
| 1504 - (BOOL)shouldUseNewAvatarButton { |
| 1505 return switches::IsNewProfileManagement() && |
| 1506 profiles::IsRegularOrGuestSession(browser_.get()); |
| 1507 } |
| 1508 |
| 1500 - (BOOL)isBookmarkBarVisible { | 1509 - (BOOL)isBookmarkBarVisible { |
| 1501 return [bookmarkBarController_ isVisible]; | 1510 return [bookmarkBarController_ isVisible]; |
| 1502 } | 1511 } |
| 1503 | 1512 |
| 1504 - (BOOL)isBookmarkBarAnimating { | 1513 - (BOOL)isBookmarkBarAnimating { |
| 1505 return [bookmarkBarController_ isAnimationRunning]; | 1514 return [bookmarkBarController_ isAnimationRunning]; |
| 1506 } | 1515 } |
| 1507 | 1516 |
| 1508 - (BookmarkBarController*)bookmarkBarController { | 1517 - (BookmarkBarController*)bookmarkBarController { |
| 1509 return bookmarkBarController_; | 1518 return bookmarkBarController_; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1703 BookmarkEditor::EditDetails::EditNode(node), | 1712 BookmarkEditor::EditDetails::EditNode(node), |
| 1704 BookmarkEditor::SHOW_TREE); | 1713 BookmarkEditor::SHOW_TREE); |
| 1705 } | 1714 } |
| 1706 } | 1715 } |
| 1707 | 1716 |
| 1708 // If the browser is in incognito mode or has multi-profiles, install the image | 1717 // 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 | 1718 // view to decorate the window at the upper right. Use the same base y |
| 1710 // coordinate as the tab strip. | 1719 // coordinate as the tab strip. |
| 1711 - (void)installAvatar { | 1720 - (void)installAvatar { |
| 1712 // Install the image into the badge view. Hide it for now; positioning and | 1721 // 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 | 1722 // sizing will be done by the layout code. The AvatarIcon will choose which |
| 1714 // image to display based on the browser. | 1723 // image to display based on the browser. The AvatarButton will display |
| 1715 avatarButtonController_.reset( | 1724 // the browser profile's name unless the browser is incognito. |
| 1725 NSView* view; |
| 1726 if ([self shouldUseNewAvatarButton]) { |
| 1727 avatarButtonController_.reset( |
| 1716 [[AvatarButtonController alloc] initWithBrowser:browser_.get()]); | 1728 [[AvatarButtonController alloc] initWithBrowser:browser_.get()]); |
| 1717 | 1729 } else { |
| 1718 NSView* view = [avatarButtonController_ view]; | 1730 avatarButtonController_.reset( |
| 1731 [[AvatarIconController alloc] initWithBrowser:browser_.get()]); |
| 1732 } |
| 1733 view = [avatarButtonController_ view]; |
| 1719 [view setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 1734 [view setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 1720 [view setHidden:![self shouldShowAvatar]]; | 1735 [view setHidden:![self shouldShowAvatar]]; |
| 1721 | 1736 |
| 1722 // Install the view. | 1737 // Install the view. |
| 1723 [[[[self window] contentView] superview] addSubview:view]; | 1738 [[[[self window] contentView] superview] addSubview:view]; |
| 1724 } | 1739 } |
| 1725 | 1740 |
| 1726 // Called when we get a three-finger swipe. | 1741 // Called when we get a three-finger swipe. |
| 1727 - (void)swipeWithEvent:(NSEvent*)event { | 1742 - (void)swipeWithEvent:(NSEvent*)event { |
| 1728 CGFloat deltaX = [event deltaX]; | 1743 CGFloat deltaX = [event deltaX]; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2228 | 2243 |
| 2229 - (BOOL)supportsBookmarkBar { | 2244 - (BOOL)supportsBookmarkBar { |
| 2230 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2245 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2231 } | 2246 } |
| 2232 | 2247 |
| 2233 - (BOOL)isTabbedWindow { | 2248 - (BOOL)isTabbedWindow { |
| 2234 return browser_->is_type_tabbed(); | 2249 return browser_->is_type_tabbed(); |
| 2235 } | 2250 } |
| 2236 | 2251 |
| 2237 @end // @implementation BrowserWindowController(WindowType) | 2252 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |