| 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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
| 18 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
| 19 #include "chrome/browser/fullscreen.h" | 19 #include "chrome/browser/fullscreen.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/shell_integration.h" | 21 #include "chrome/browser/shell_integration.h" |
| 22 #include "chrome/browser/sidebar/sidebar_container.h" |
| 23 #include "chrome/browser/sidebar/sidebar_manager.h" |
| 22 #include "chrome/browser/signin/signin_header_helper.h" | 24 #include "chrome/browser/signin/signin_header_helper.h" |
| 23 #include "chrome/browser/translate/chrome_translate_client.h" | 25 #include "chrome/browser/translate/chrome_translate_client.h" |
| 24 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_command_controller.h" | 27 #include "chrome/browser/ui/browser_command_controller.h" |
| 26 #include "chrome/browser/ui/browser_commands_mac.h" | 28 #include "chrome/browser/ui/browser_commands_mac.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/browser_window_state.h" | 30 #include "chrome/browser/ui/browser_window_state.h" |
| 29 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" | 31 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
| 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 31 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 33 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 [control_ setEnabled:TrimText(text).empty() ? NO : YES]; | 125 [control_ setEnabled:TrimText(text).empty() ? NO : YES]; |
| 124 } | 126 } |
| 125 @end | 127 @end |
| 126 | 128 |
| 127 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 129 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 128 BrowserWindowController* controller) | 130 BrowserWindowController* controller) |
| 129 : browser_(browser), | 131 : browser_(browser), |
| 130 controller_(controller), | 132 controller_(controller), |
| 131 initial_show_state_(ui::SHOW_STATE_DEFAULT), | 133 initial_show_state_(ui::SHOW_STATE_DEFAULT), |
| 132 attention_request_id_(0) { | 134 attention_request_id_(0) { |
| 135 registrar_.Add( |
| 136 this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 137 content::Source<SidebarManager>(SidebarManager::GetInstance())); |
| 133 | 138 |
| 134 gfx::Rect bounds; | 139 gfx::Rect bounds; |
| 135 chrome::GetSavedWindowBoundsAndShowState(browser_, | 140 chrome::GetSavedWindowBoundsAndShowState(browser_, |
| 136 &bounds, | 141 &bounds, |
| 137 &initial_show_state_); | 142 &initial_show_state_); |
| 138 | 143 |
| 139 browser_->search_model()->AddObserver(this); | 144 browser_->search_model()->AddObserver(this); |
| 140 } | 145 } |
| 141 | 146 |
| 142 BrowserWindowCocoa::~BrowserWindowCocoa() { | 147 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 void BrowserWindowCocoa::BookmarkBarStateChanged( | 310 void BrowserWindowCocoa::BookmarkBarStateChanged( |
| 306 BookmarkBar::AnimateChangeType change_type) { | 311 BookmarkBar::AnimateChangeType change_type) { |
| 307 [[controller_ bookmarkBarController] | 312 [[controller_ bookmarkBarController] |
| 308 updateState:browser_->bookmark_bar_state() | 313 updateState:browser_->bookmark_bar_state() |
| 309 changeType:change_type]; | 314 changeType:change_type]; |
| 310 } | 315 } |
| 311 | 316 |
| 312 void BrowserWindowCocoa::UpdateDevTools() { | 317 void BrowserWindowCocoa::UpdateDevTools() { |
| 313 [controller_ updateDevToolsForContents: | 318 [controller_ updateDevToolsForContents: |
| 314 browser_->tab_strip_model()->GetActiveWebContents()]; | 319 browser_->tab_strip_model()->GetActiveWebContents()]; |
| 320 UpdateSidebarForContents(browser_->tab_strip_model()->GetActiveWebContents()); |
| 315 } | 321 } |
| 316 | 322 |
| 317 void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) { | 323 void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) { |
| 318 // Do nothing on Mac. | 324 // Do nothing on Mac. |
| 319 } | 325 } |
| 320 | 326 |
| 321 void BrowserWindowCocoa::SetStarredState(bool is_starred) { | 327 void BrowserWindowCocoa::SetStarredState(bool is_starred) { |
| 322 [controller_ setStarredState:is_starred]; | 328 [controller_ setStarredState:is_starred]; |
| 323 } | 329 } |
| 324 | 330 |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 return NULL; | 781 return NULL; |
| 776 extensions::TabHelper* tab_helper = | 782 extensions::TabHelper* tab_helper = |
| 777 extensions::TabHelper::FromWebContents(web_contents); | 783 extensions::TabHelper::FromWebContents(web_contents); |
| 778 return tab_helper ? tab_helper->active_tab_permission_granter() : NULL; | 784 return tab_helper ? tab_helper->active_tab_permission_granter() : NULL; |
| 779 } | 785 } |
| 780 | 786 |
| 781 void BrowserWindowCocoa::ModelChanged(const SearchModel::State& old_state, | 787 void BrowserWindowCocoa::ModelChanged(const SearchModel::State& old_state, |
| 782 const SearchModel::State& new_state) { | 788 const SearchModel::State& new_state) { |
| 783 } | 789 } |
| 784 | 790 |
| 791 void BrowserWindowCocoa::Observe(int type, |
| 792 const content::NotificationSource& source, |
| 793 const content::NotificationDetails& details) { |
| 794 switch (type) { |
| 795 case chrome::NOTIFICATION_SIDEBAR_CHANGED: |
| 796 UpdateSidebarForContents( |
| 797 content::Details<SidebarContainer>(details)->web_contents()); |
| 798 break; |
| 799 default: |
| 800 NOTREACHED(); // we don't ask for anything else! |
| 801 break; |
| 802 } |
| 803 } |
| 804 |
| 785 void BrowserWindowCocoa::DestroyBrowser() { | 805 void BrowserWindowCocoa::DestroyBrowser() { |
| 786 [controller_ destroyBrowser]; | 806 [controller_ destroyBrowser]; |
| 787 | 807 |
| 788 // at this point the controller is dead (autoreleased), so | 808 // at this point the controller is dead (autoreleased), so |
| 789 // make sure we don't try to reference it any more. | 809 // make sure we don't try to reference it any more. |
| 790 } | 810 } |
| 791 | 811 |
| 792 NSWindow* BrowserWindowCocoa::window() const { | 812 NSWindow* BrowserWindowCocoa::window() const { |
| 793 return [controller_ window]; | 813 return [controller_ window]; |
| 794 } | 814 } |
| 795 | 815 |
| 796 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( | 816 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( |
| 797 AvatarBubbleMode mode, | 817 AvatarBubbleMode mode, |
| 798 const signin::ManageAccountsParams& manage_accounts_params) { | 818 const signin::ManageAccountsParams& manage_accounts_params) { |
| 799 AvatarBaseController* controller = [controller_ avatarButtonController]; | 819 AvatarBaseController* controller = [controller_ avatarButtonController]; |
| 800 NSView* anchor = [controller buttonView]; | 820 NSView* anchor = [controller buttonView]; |
| 801 if ([anchor isHiddenOrHasHiddenAncestor]) | 821 if ([anchor isHiddenOrHasHiddenAncestor]) |
| 802 anchor = [[controller_ toolbarController] wrenchButton]; | 822 anchor = [[controller_ toolbarController] wrenchButton]; |
| 803 [controller showAvatarBubbleAnchoredAt:anchor | 823 [controller showAvatarBubbleAnchoredAt:anchor |
| 804 withMode:mode | 824 withMode:mode |
| 805 withServiceType:manage_accounts_params.service_type]; | 825 withServiceType:manage_accounts_params.service_type]; |
| 806 } | 826 } |
| 807 | 827 |
| 808 void BrowserWindowCocoa::CloseAvatarBubbleFromAvatarButton() { | 828 void BrowserWindowCocoa::CloseAvatarBubbleFromAvatarButton() { |
| 809 [[controller_ avatarButtonController] closeAvatarBubble]; | 829 [[controller_ avatarButtonController] closeAvatarBubble]; |
| 810 } | 830 } |
| 811 | 831 |
| 832 void BrowserWindowCocoa::UpdateSidebarForContents( |
| 833 content::WebContents* tab_contents) { |
| 834 if (tab_contents == browser_->tab_strip_model()->GetActiveWebContents()) { |
| 835 [controller_ updateSidebarForContents:tab_contents]; |
| 836 } |
| 837 } |
| 838 |
| 812 int | 839 int |
| 813 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { | 840 BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { |
| 814 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 841 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
| 815 return 0; | 842 return 0; |
| 816 return 40; | 843 return 40; |
| 817 } | 844 } |
| 818 | 845 |
| 819 void BrowserWindowCocoa::ExecuteExtensionCommand( | 846 void BrowserWindowCocoa::ExecuteExtensionCommand( |
| 820 const extensions::Extension* extension, | 847 const extensions::Extension* extension, |
| 821 const extensions::Command& command) { | 848 const extensions::Command& command) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 837 void BrowserWindowCocoa::UnhideDownloadShelf() { | 864 void BrowserWindowCocoa::UnhideDownloadShelf() { |
| 838 GetDownloadShelf()->Unhide(); | 865 GetDownloadShelf()->Unhide(); |
| 839 } | 866 } |
| 840 | 867 |
| 841 void BrowserWindowCocoa::HideDownloadShelf() { | 868 void BrowserWindowCocoa::HideDownloadShelf() { |
| 842 GetDownloadShelf()->Hide(); | 869 GetDownloadShelf()->Hide(); |
| 843 StatusBubble* statusBubble = GetStatusBubble(); | 870 StatusBubble* statusBubble = GetStatusBubble(); |
| 844 if (statusBubble) | 871 if (statusBubble) |
| 845 statusBubble->Hide(); | 872 statusBubble->Hide(); |
| 846 } | 873 } |
| OLD | NEW |