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/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #endif // OS_WIN | 10 #endif // OS_WIN |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 block_command_execution_(false), | 252 block_command_execution_(false), |
253 last_blocked_command_id_(-1), | 253 last_blocked_command_id_(-1), |
254 last_blocked_command_disposition_(CURRENT_TAB), | 254 last_blocked_command_disposition_(CURRENT_TAB), |
255 pending_web_app_action_(NONE), | 255 pending_web_app_action_(NONE), |
256 ALLOW_THIS_IN_INITIALIZER_LIST( | 256 ALLOW_THIS_IN_INITIALIZER_LIST( |
257 tab_restore_service_delegate_( | 257 tab_restore_service_delegate_( |
258 new BrowserTabRestoreServiceDelegate(this))), | 258 new BrowserTabRestoreServiceDelegate(this))), |
259 ALLOW_THIS_IN_INITIALIZER_LIST( | 259 ALLOW_THIS_IN_INITIALIZER_LIST( |
260 synced_window_delegate_( | 260 synced_window_delegate_( |
261 new BrowserSyncedWindowDelegate(this))), | 261 new BrowserSyncedWindowDelegate(this))), |
262 bookmark_bar_state_(BookmarkBar::HIDDEN) { | 262 bookmark_bar_state_(BookmarkBar::HIDDEN), |
| 263 fullscreened_tab_(NULL), |
| 264 tab_caused_fullscreen_(false) { |
263 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 265 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
264 NotificationService::AllSources()); | 266 NotificationService::AllSources()); |
265 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 267 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
266 NotificationService::AllSources()); | 268 NotificationService::AllSources()); |
267 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 269 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
268 NotificationService::AllSources()); | 270 NotificationService::AllSources()); |
269 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 271 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
270 NotificationService::AllSources()); | 272 NotificationService::AllSources()); |
271 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 273 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
272 NotificationService::AllSources()); | 274 NotificationService::AllSources()); |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); | 1617 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
1616 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1618 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
1617 TabContentsWrapper* contents = | 1619 TabContentsWrapper* contents = |
1618 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1620 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
1619 Browser* browser = Browser::Create(profile_); | 1621 Browser* browser = Browser::Create(profile_); |
1620 browser->tabstrip_model()->AppendTabContents(contents, true); | 1622 browser->tabstrip_model()->AppendTabContents(contents, true); |
1621 browser->window()->Show(); | 1623 browser->window()->Show(); |
1622 } | 1624 } |
1623 | 1625 |
1624 void Browser::ToggleFullscreenMode() { | 1626 void Browser::ToggleFullscreenMode() { |
| 1627 bool entering_fullscreen = !window_->IsFullscreen(); |
| 1628 |
1625 #if !defined(OS_MACOSX) | 1629 #if !defined(OS_MACOSX) |
1626 // In kiosk mode, we always want to be fullscreen. When the browser first | 1630 // In kiosk mode, we always want to be fullscreen. When the browser first |
1627 // starts we're not yet fullscreen, so let the initial toggle go through. | 1631 // starts we're not yet fullscreen, so let the initial toggle go through. |
1628 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 1632 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
1629 window_->IsFullscreen()) | 1633 window_->IsFullscreen()) |
1630 return; | 1634 return; |
1631 #endif | 1635 #endif |
1632 | 1636 |
1633 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | 1637 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
1634 window_->SetFullscreen(!window_->IsFullscreen()); | 1638 window_->SetFullscreen(entering_fullscreen); |
1635 | 1639 |
1636 // Once the window has become fullscreen it'll call back to | 1640 // Once the window has become fullscreen it'll call back to |
1637 // WindowFullscreenStateChanged(). We don't do this immediately as | 1641 // WindowFullscreenStateChanged(). We don't do this immediately as |
1638 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the | 1642 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the |
1639 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 1643 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
1640 | 1644 |
1641 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 1645 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
1642 // the necessary state of the frame. | 1646 // the necessary state of the frame. |
1643 #if defined(OS_MACOSX) | 1647 #if defined(OS_MACOSX) |
1644 WindowFullscreenStateChanged(); | 1648 WindowFullscreenStateChanged(); |
1645 #endif | 1649 #endif |
| 1650 |
| 1651 if (!entering_fullscreen) |
| 1652 NotifyTabOfFullscreenExitIfNecessary(); |
| 1653 } |
| 1654 |
| 1655 void Browser::NotifyTabOfFullscreenExitIfNecessary() { |
| 1656 if (fullscreened_tab_) |
| 1657 fullscreened_tab_->ExitFullscreenMode(); |
| 1658 fullscreened_tab_ = NULL; |
| 1659 tab_caused_fullscreen_ = false; |
1646 } | 1660 } |
1647 | 1661 |
1648 #if defined(OS_MACOSX) | 1662 #if defined(OS_MACOSX) |
1649 void Browser::TogglePresentationMode() { | 1663 void Browser::TogglePresentationMode() { |
1650 window_->SetPresentationMode(!window_->InPresentationMode()); | 1664 window_->SetPresentationMode(!window_->InPresentationMode()); |
1651 WindowFullscreenStateChanged(); | 1665 WindowFullscreenStateChanged(); |
1652 } | 1666 } |
1653 #endif | 1667 #endif |
1654 | 1668 |
1655 #if defined(OS_CHROMEOS) | 1669 #if defined(OS_CHROMEOS) |
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 | 2965 |
2952 // Sever the TabContents' connection back to us. | 2966 // Sever the TabContents' connection back to us. |
2953 SetAsDelegate(contents, NULL); | 2967 SetAsDelegate(contents, NULL); |
2954 } | 2968 } |
2955 | 2969 |
2956 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 2970 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
2957 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 2971 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
2958 } | 2972 } |
2959 | 2973 |
2960 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 2974 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
| 2975 if (contents == fullscreened_tab_) |
| 2976 ExitTabbedFullscreenModeIfNecessary(); |
2961 if (instant()) | 2977 if (instant()) |
2962 instant()->DestroyPreviewContents(); | 2978 instant()->DestroyPreviewContents(); |
2963 | 2979 |
2964 // Save what the user's currently typing, so it can be restored when we | 2980 // Save what the user's currently typing, so it can be restored when we |
2965 // switch back to this tab. | 2981 // switch back to this tab. |
2966 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 2982 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
2967 } | 2983 } |
2968 | 2984 |
2969 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 2985 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
2970 TabContentsWrapper* new_contents, | 2986 TabContentsWrapper* new_contents, |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3545 | 3561 |
3546 void Browser::DidNavigateToPendingEntry(TabContents* tab) { | 3562 void Browser::DidNavigateToPendingEntry(TabContents* tab) { |
3547 if (tab == GetSelectedTabContents()) | 3563 if (tab == GetSelectedTabContents()) |
3548 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 3564 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
3549 } | 3565 } |
3550 | 3566 |
3551 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { | 3567 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
3552 return GetJavaScriptDialogCreatorInstance(); | 3568 return GetJavaScriptDialogCreatorInstance(); |
3553 } | 3569 } |
3554 | 3570 |
| 3571 void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
| 3572 bool enter_fullscreen) { |
| 3573 if (tab != GetSelectedTabContents()) |
| 3574 return; |
| 3575 fullscreened_tab_ = enter_fullscreen ? |
| 3576 TabContentsWrapper::GetCurrentWrapperForContents(tab) : NULL; |
| 3577 if (enter_fullscreen && !window_->IsFullscreen()) |
| 3578 tab_caused_fullscreen_ = true; |
| 3579 if (tab_caused_fullscreen_) |
| 3580 ToggleFullscreenMode(); |
| 3581 } |
| 3582 |
| 3583 void Browser::ExitTabbedFullscreenModeIfNecessary() { |
| 3584 if (tab_caused_fullscreen_) |
| 3585 ToggleFullscreenMode(); |
| 3586 else |
| 3587 NotifyTabOfFullscreenExitIfNecessary(); |
| 3588 } |
| 3589 |
3555 /////////////////////////////////////////////////////////////////////////////// | 3590 /////////////////////////////////////////////////////////////////////////////// |
3556 // Browser, TabContentsWrapperDelegate implementation: | 3591 // Browser, TabContentsWrapperDelegate implementation: |
3557 | 3592 |
3558 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3593 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
3559 int32 page_id) { | 3594 int32 page_id) { |
3560 if (GetSelectedTabContentsWrapper() != source) | 3595 if (GetSelectedTabContentsWrapper() != source) |
3561 return; | 3596 return; |
3562 | 3597 |
3563 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3598 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
3564 if (!entry || (entry->page_id() != page_id)) | 3599 if (!entry || (entry->page_id() != page_id)) |
(...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4887 } | 4922 } |
4888 | 4923 |
4889 void Browser::ShowSyncSetup() { | 4924 void Browser::ShowSyncSetup() { |
4890 ProfileSyncService* service = | 4925 ProfileSyncService* service = |
4891 profile()->GetOriginalProfile()->GetProfileSyncService(); | 4926 profile()->GetOriginalProfile()->GetProfileSyncService(); |
4892 if (service->HasSyncSetupCompleted()) | 4927 if (service->HasSyncSetupCompleted()) |
4893 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4928 ShowOptionsTab(chrome::kSyncSetupSubPage); |
4894 else | 4929 else |
4895 service->ShowLoginDialog(); | 4930 service->ShowLoginDialog(); |
4896 } | 4931 } |
OLD | NEW |