Chromium Code Reviews| 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 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1267 local_params.disposition = CURRENT_TAB; | 1269 local_params.disposition = CURRENT_TAB; |
| 1268 } | 1270 } |
| 1269 } | 1271 } |
| 1270 | 1272 |
| 1271 browser::Navigate(&local_params); | 1273 browser::Navigate(&local_params); |
| 1272 } | 1274 } |
| 1273 | 1275 |
| 1274 void Browser::WindowFullscreenStateChanged() { | 1276 void Browser::WindowFullscreenStateChanged() { |
| 1275 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | 1277 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 1276 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); | 1278 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| 1279 MessageLoop::current()->PostTask( | |
| 1280 FROM_HERE, method_factory_.NewRunnableMethod( | |
|
Ben Goodger (Google)
2011/08/24 18:21:49
4-space indents here
koz (OOO until 15th September)
2011/08/24 21:39:33
Done.
| |
| 1281 &Browser::NotifyFullscreenChange)); | |
| 1282 } | |
| 1283 | |
| 1284 void Browser::NotifyFullscreenChange() { | |
| 1285 NotificationService::current()->Notify( | |
| 1286 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
|
Ben Goodger (Google)
2011/08/24 18:21:49
and here
koz (OOO until 15th September)
2011/08/24 21:39:33
Done.
| |
| 1287 Source<Browser>(this), | |
| 1288 NotificationService::NoDetails()); | |
| 1277 } | 1289 } |
| 1278 | 1290 |
| 1279 /////////////////////////////////////////////////////////////////////////////// | 1291 /////////////////////////////////////////////////////////////////////////////// |
| 1280 // Browser, Assorted browser commands: | 1292 // Browser, Assorted browser commands: |
| 1281 | 1293 |
| 1282 TabContents* Browser::GetOrCloneTabForDisposition( | 1294 TabContents* Browser::GetOrCloneTabForDisposition( |
| 1283 WindowOpenDisposition disposition) { | 1295 WindowOpenDisposition disposition) { |
| 1284 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1296 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
| 1285 switch (disposition) { | 1297 switch (disposition) { |
| 1286 case NEW_FOREGROUND_TAB: | 1298 case NEW_FOREGROUND_TAB: |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1615 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); | 1627 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
| 1616 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1628 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
| 1617 TabContentsWrapper* contents = | 1629 TabContentsWrapper* contents = |
| 1618 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1630 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
| 1619 Browser* browser = Browser::Create(profile_); | 1631 Browser* browser = Browser::Create(profile_); |
| 1620 browser->tabstrip_model()->AppendTabContents(contents, true); | 1632 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1621 browser->window()->Show(); | 1633 browser->window()->Show(); |
| 1622 } | 1634 } |
| 1623 | 1635 |
| 1624 void Browser::ToggleFullscreenMode() { | 1636 void Browser::ToggleFullscreenMode() { |
| 1637 bool entering_fullscreen = !window_->IsFullscreen(); | |
| 1638 | |
| 1625 #if !defined(OS_MACOSX) | 1639 #if !defined(OS_MACOSX) |
| 1626 // In kiosk mode, we always want to be fullscreen. When the browser first | 1640 // 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. | 1641 // starts we're not yet fullscreen, so let the initial toggle go through. |
| 1628 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 1642 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| 1629 window_->IsFullscreen()) | 1643 window_->IsFullscreen()) |
| 1630 return; | 1644 return; |
| 1631 #endif | 1645 #endif |
| 1632 | 1646 |
| 1633 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | 1647 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 1634 window_->SetFullscreen(!window_->IsFullscreen()); | 1648 window_->SetFullscreen(entering_fullscreen); |
| 1635 | 1649 |
| 1636 // Once the window has become fullscreen it'll call back to | 1650 // Once the window has become fullscreen it'll call back to |
| 1637 // WindowFullscreenStateChanged(). We don't do this immediately as | 1651 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 1638 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the | 1652 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the |
| 1639 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 1653 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 1640 | 1654 |
| 1641 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 1655 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
| 1642 // the necessary state of the frame. | 1656 // the necessary state of the frame. |
| 1643 #if defined(OS_MACOSX) | 1657 #if defined(OS_MACOSX) |
| 1644 WindowFullscreenStateChanged(); | 1658 WindowFullscreenStateChanged(); |
| 1645 #endif | 1659 #endif |
| 1660 | |
| 1661 if (!entering_fullscreen) | |
| 1662 NotifyTabOfFullscreenExitIfNecessary(); | |
| 1663 } | |
| 1664 | |
| 1665 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | |
| 1666 if (fullscreened_tab_) | |
| 1667 fullscreened_tab_->ExitFullscreenMode(); | |
| 1668 fullscreened_tab_ = NULL; | |
| 1669 tab_caused_fullscreen_ = false; | |
| 1646 } | 1670 } |
| 1647 | 1671 |
| 1648 #if defined(OS_MACOSX) | 1672 #if defined(OS_MACOSX) |
| 1649 void Browser::TogglePresentationMode() { | 1673 void Browser::TogglePresentationMode() { |
| 1650 window_->SetPresentationMode(!window_->InPresentationMode()); | 1674 window_->SetPresentationMode(!window_->InPresentationMode()); |
| 1651 WindowFullscreenStateChanged(); | 1675 WindowFullscreenStateChanged(); |
| 1652 } | 1676 } |
| 1653 #endif | 1677 #endif |
| 1654 | 1678 |
| 1655 #if defined(OS_CHROMEOS) | 1679 #if defined(OS_CHROMEOS) |
| (...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2951 | 2975 |
| 2952 // Sever the TabContents' connection back to us. | 2976 // Sever the TabContents' connection back to us. |
| 2953 SetAsDelegate(contents, NULL); | 2977 SetAsDelegate(contents, NULL); |
| 2954 } | 2978 } |
| 2955 | 2979 |
| 2956 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 2980 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
| 2957 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 2981 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
| 2958 } | 2982 } |
| 2959 | 2983 |
| 2960 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 2984 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
| 2985 if (contents == fullscreened_tab_) | |
| 2986 ExitTabbedFullscreenModeIfNecessary(); | |
| 2961 if (instant()) | 2987 if (instant()) |
| 2962 instant()->DestroyPreviewContents(); | 2988 instant()->DestroyPreviewContents(); |
| 2963 | 2989 |
| 2964 // Save what the user's currently typing, so it can be restored when we | 2990 // Save what the user's currently typing, so it can be restored when we |
| 2965 // switch back to this tab. | 2991 // switch back to this tab. |
| 2966 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 2992 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
| 2967 } | 2993 } |
| 2968 | 2994 |
| 2969 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 2995 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
| 2970 TabContentsWrapper* new_contents, | 2996 TabContentsWrapper* new_contents, |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3545 | 3571 |
| 3546 void Browser::DidNavigateToPendingEntry(TabContents* tab) { | 3572 void Browser::DidNavigateToPendingEntry(TabContents* tab) { |
| 3547 if (tab == GetSelectedTabContents()) | 3573 if (tab == GetSelectedTabContents()) |
| 3548 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 3574 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
| 3549 } | 3575 } |
| 3550 | 3576 |
| 3551 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { | 3577 content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 3552 return GetJavaScriptDialogCreatorInstance(); | 3578 return GetJavaScriptDialogCreatorInstance(); |
| 3553 } | 3579 } |
| 3554 | 3580 |
| 3581 void Browser::ToggleFullscreenModeForTab(TabContents* tab, | |
| 3582 bool enter_fullscreen) { | |
| 3583 if (tab != GetSelectedTabContents()) | |
| 3584 return; | |
| 3585 fullscreened_tab_ = enter_fullscreen ? | |
| 3586 TabContentsWrapper::GetCurrentWrapperForContents(tab) : NULL; | |
| 3587 if (enter_fullscreen && !window_->IsFullscreen()) | |
| 3588 tab_caused_fullscreen_ = true; | |
| 3589 if (tab_caused_fullscreen_) | |
| 3590 ToggleFullscreenMode(); | |
| 3591 } | |
| 3592 | |
| 3593 void Browser::ExitTabbedFullscreenModeIfNecessary() { | |
| 3594 if (tab_caused_fullscreen_) | |
| 3595 ToggleFullscreenMode(); | |
| 3596 else | |
| 3597 NotifyTabOfFullscreenExitIfNecessary(); | |
| 3598 } | |
| 3599 | |
| 3555 /////////////////////////////////////////////////////////////////////////////// | 3600 /////////////////////////////////////////////////////////////////////////////// |
| 3556 // Browser, TabContentsWrapperDelegate implementation: | 3601 // Browser, TabContentsWrapperDelegate implementation: |
| 3557 | 3602 |
| 3558 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3603 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 3559 int32 page_id) { | 3604 int32 page_id) { |
| 3560 if (GetSelectedTabContentsWrapper() != source) | 3605 if (GetSelectedTabContentsWrapper() != source) |
| 3561 return; | 3606 return; |
| 3562 | 3607 |
| 3563 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3608 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 3564 if (!entry || (entry->page_id() != page_id)) | 3609 if (!entry || (entry->page_id() != page_id)) |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4887 } | 4932 } |
| 4888 | 4933 |
| 4889 void Browser::ShowSyncSetup() { | 4934 void Browser::ShowSyncSetup() { |
| 4890 ProfileSyncService* service = | 4935 ProfileSyncService* service = |
| 4891 profile()->GetOriginalProfile()->GetProfileSyncService(); | 4936 profile()->GetOriginalProfile()->GetProfileSyncService(); |
| 4892 if (service->HasSyncSetupCompleted()) | 4937 if (service->HasSyncSetupCompleted()) |
| 4893 ShowOptionsTab(chrome::kSyncSetupSubPage); | 4938 ShowOptionsTab(chrome::kSyncSetupSubPage); |
| 4894 else | 4939 else |
| 4895 service->ShowLoginDialog(); | 4940 service->ShowLoginDialog(); |
| 4896 } | 4941 } |
| OLD | NEW |