OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1573 | 1573 |
1574 - (void)windowChangedToProfile:(Profile*)profile { | 1574 - (void)windowChangedToProfile:(Profile*)profile { |
1575 if (lastProfile_ == profile) | 1575 if (lastProfile_ == profile) |
1576 return; | 1576 return; |
1577 | 1577 |
1578 // Before tearing down the menu controller bridges, return the history menu to | 1578 // Before tearing down the menu controller bridges, return the history menu to |
1579 // its initial state. | 1579 // its initial state. |
1580 if (historyMenuBridge_) | 1580 if (historyMenuBridge_) |
1581 historyMenuBridge_->ResetMenu(); | 1581 historyMenuBridge_->ResetMenu(); |
1582 | 1582 |
1583 // Rebuild the menus with the new profile. | 1583 // Rebuild the menus with the new profile. The bookmarks submenu is cached to |
1584 // avoid slowdowns when switching between profiles with large numbers of | |
1585 // bookmarks. Before caching, store whether it is hidden, make the menu item | |
1586 // visible, and restore its original hidden state after resetting the submenu. | |
1587 // This works around an apparent AppKit bug where setting a *different* NSMenu | |
1588 // submenu on a *hidden* menu item forces the item to become visible. | |
1589 // See http://crbug/497813 for more details. | |
Robert Sesek
2015/09/04 17:33:06
nit: https://crbug.com is the proper hostname to u
dominickn
2015/09/05 00:34:02
Done.
| |
1590 NSMenuItem* item = [[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU]; | |
Robert Sesek
2015/09/04 17:33:06
naming: item is a bit vague. bookmarkItem is bette
dominickn
2015/09/05 00:34:02
Done.
| |
1591 BOOL hidden = [item isHidden]; | |
1592 [item setHidden:NO]; | |
1584 lastProfile_ = profile; | 1593 lastProfile_ = profile; |
1585 | 1594 |
1586 auto it = profileBookmarkMenuBridgeMap_.find(profile->GetPath()); | 1595 auto it = profileBookmarkMenuBridgeMap_.find(profile->GetPath()); |
1587 if (it == profileBookmarkMenuBridgeMap_.end()) { | 1596 if (it == profileBookmarkMenuBridgeMap_.end()) { |
1588 base::scoped_nsobject<NSMenu> submenu( | 1597 base::scoped_nsobject<NSMenu> submenu([[item submenu] copy]); |
1589 [[[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu] copy]); | |
1590 bookmarkMenuBridge_ = new BookmarkMenuBridge(profile, submenu); | 1598 bookmarkMenuBridge_ = new BookmarkMenuBridge(profile, submenu); |
1591 profileBookmarkMenuBridgeMap_[profile->GetPath()] = bookmarkMenuBridge_; | 1599 profileBookmarkMenuBridgeMap_[profile->GetPath()] = bookmarkMenuBridge_; |
1592 } else { | 1600 } else { |
1593 bookmarkMenuBridge_ = it->second; | 1601 bookmarkMenuBridge_ = it->second; |
1594 } | 1602 } |
1595 | 1603 |
1596 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] setSubmenu: | |
1597 bookmarkMenuBridge_->BookmarkMenu()]; | |
1598 // No need to |BuildMenu| here. It is done lazily upon menu access. | 1604 // No need to |BuildMenu| here. It is done lazily upon menu access. |
1605 [item setSubmenu:bookmarkMenuBridge_->BookmarkMenu()]; | |
1606 // Reset the hidden state to the previously saved value. | |
Robert Sesek
2015/09/04 17:33:06
Remove this comment, since it's obvious from the c
dominickn
2015/09/05 00:34:02
Done.
| |
1607 [item setHidden:hidden]; | |
1599 | 1608 |
1600 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); | 1609 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
1601 historyMenuBridge_->BuildMenu(); | 1610 historyMenuBridge_->BuildMenu(); |
1602 | 1611 |
1603 chrome::BrowserCommandController:: | 1612 chrome::BrowserCommandController:: |
1604 UpdateSharedCommandsForIncognitoAvailability( | 1613 UpdateSharedCommandsForIncognitoAvailability( |
1605 menuState_.get(), lastProfile_); | 1614 menuState_.get(), lastProfile_); |
1606 profilePrefRegistrar_.reset(new PrefChangeRegistrar()); | 1615 profilePrefRegistrar_.reset(new PrefChangeRegistrar()); |
1607 profilePrefRegistrar_->Init(lastProfile_->GetPrefs()); | 1616 profilePrefRegistrar_->Init(lastProfile_->GetPrefs()); |
1608 profilePrefRegistrar_->Add( | 1617 profilePrefRegistrar_->Add( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1712 | 1721 |
1713 //--------------------------------------------------------------------------- | 1722 //--------------------------------------------------------------------------- |
1714 | 1723 |
1715 namespace app_controller_mac { | 1724 namespace app_controller_mac { |
1716 | 1725 |
1717 bool IsOpeningNewWindow() { | 1726 bool IsOpeningNewWindow() { |
1718 return g_is_opening_new_window; | 1727 return g_is_opening_new_window; |
1719 } | 1728 } |
1720 | 1729 |
1721 } // namespace app_controller_mac | 1730 } // namespace app_controller_mac |
OLD | NEW |