| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 46 #include "ui/base/l10n/l10n_util_mac.h" | 46 #include "ui/base/l10n/l10n_util_mac.h" |
| 47 #include "ui/gfx/rect.h" | 47 #include "ui/gfx/rect.h" |
| 48 | 48 |
| 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 50 BrowserWindowController* controller, | 50 BrowserWindowController* controller, |
| 51 NSWindow* window) | 51 NSWindow* window) |
| 52 : browser_(browser), | 52 : browser_(browser), |
| 53 controller_(controller), | 53 controller_(controller), |
| 54 confirm_close_factory_(browser) { | 54 confirm_close_factory_(browser) { |
| 55 // This pref applies to all windows, so all must watch for it. | 55 // Listen for bookmark bar visibility changes and set the initial state; we |
| 56 // need to listen to all profiles because of normal profile/incognito issues. |
| 56 registrar_.Add(this, | 57 registrar_.Add(this, |
| 57 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 58 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 58 NotificationService::AllSources()); | 59 NotificationService::AllBrowserContextsAndSources()); |
| 59 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 60 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 60 NotificationService::AllSources()); | 61 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 61 } | 62 } |
| 62 | 63 |
| 63 BrowserWindowCocoa::~BrowserWindowCocoa() { | 64 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 64 } | 65 } |
| 65 | 66 |
| 66 void BrowserWindowCocoa::Show() { | 67 void BrowserWindowCocoa::Show() { |
| 67 // The Browser associated with this browser window must become the active | 68 // The Browser associated with this browser window must become the active |
| 68 // browser at the time |Show()| is called. This is the natural behaviour under | 69 // browser at the time |Show()| is called. This is the natural behaviour under |
| 69 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 70 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 70 // until we return to the runloop. Therefore any calls to | 71 // until we return to the runloop. Therefore any calls to |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 return bridge; | 602 return bridge; |
| 602 } | 603 } |
| 603 | 604 |
| 604 void BrowserWindowCocoa::Observe(int type, | 605 void BrowserWindowCocoa::Observe(int type, |
| 605 const NotificationSource& source, | 606 const NotificationSource& source, |
| 606 const NotificationDetails& details) { | 607 const NotificationDetails& details) { |
| 607 switch (type) { | 608 switch (type) { |
| 608 // Only the key window gets a direct toggle from the menu. | 609 // Only the key window gets a direct toggle from the menu. |
| 609 // Other windows hear about it from the notification. | 610 // Other windows hear about it from the notification. |
| 610 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 611 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: |
| 611 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 612 if (browser_->profile()->IsSameProfile(Source<Profile>(source).ptr())) |
| 613 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
| 612 break; | 614 break; |
| 613 case chrome::NOTIFICATION_SIDEBAR_CHANGED: | 615 case chrome::NOTIFICATION_SIDEBAR_CHANGED: |
| 614 UpdateSidebarForContents( | 616 UpdateSidebarForContents( |
| 615 Details<SidebarContainer>(details)->tab_contents()); | 617 Details<SidebarContainer>(details)->tab_contents()); |
| 616 break; | 618 break; |
| 617 default: | 619 default: |
| 618 NOTREACHED(); // we don't ask for anything else! | 620 NOTREACHED(); // we don't ask for anything else! |
| 619 break; | 621 break; |
| 620 } | 622 } |
| 621 } | 623 } |
| 622 | 624 |
| 623 void BrowserWindowCocoa::DestroyBrowser() { | 625 void BrowserWindowCocoa::DestroyBrowser() { |
| 624 [controller_ destroyBrowser]; | 626 [controller_ destroyBrowser]; |
| 625 | 627 |
| 626 // at this point the controller is dead (autoreleased), so | 628 // at this point the controller is dead (autoreleased), so |
| 627 // make sure we don't try to reference it any more. | 629 // make sure we don't try to reference it any more. |
| 628 } | 630 } |
| 629 | 631 |
| 630 NSWindow* BrowserWindowCocoa::window() const { | 632 NSWindow* BrowserWindowCocoa::window() const { |
| 631 return [controller_ window]; | 633 return [controller_ window]; |
| 632 } | 634 } |
| 633 | 635 |
| 634 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 636 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 635 if (tab_contents == browser_->GetSelectedTabContents()) { | 637 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 636 [controller_ updateSidebarForContents:tab_contents]; | 638 [controller_ updateSidebarForContents:tab_contents]; |
| 637 } | 639 } |
| 638 } | 640 } |
| OLD | NEW |