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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 last_blocked_command_id_(-1), | 309 last_blocked_command_id_(-1), |
310 last_blocked_command_disposition_(CURRENT_TAB), | 310 last_blocked_command_disposition_(CURRENT_TAB), |
311 pending_web_app_action_(NONE), | 311 pending_web_app_action_(NONE), |
312 ALLOW_THIS_IN_INITIALIZER_LIST( | 312 ALLOW_THIS_IN_INITIALIZER_LIST( |
313 tab_restore_service_delegate_( | 313 tab_restore_service_delegate_( |
314 new BrowserTabRestoreServiceDelegate(this))), | 314 new BrowserTabRestoreServiceDelegate(this))), |
315 ALLOW_THIS_IN_INITIALIZER_LIST( | 315 ALLOW_THIS_IN_INITIALIZER_LIST( |
316 synced_window_delegate_( | 316 synced_window_delegate_( |
317 new BrowserSyncedWindowDelegate(this))), | 317 new BrowserSyncedWindowDelegate(this))), |
318 bookmark_bar_state_(BookmarkBar::HIDDEN), | 318 bookmark_bar_state_(BookmarkBar::HIDDEN), |
319 fullscreened_tab_(NULL), | |
320 tab_caused_fullscreen_(false), | |
321 tab_fullscreen_accepted_(false), | |
322 mouse_lock_state_(MOUSELOCK_NOT_REQUESTED), | |
323 window_has_shown_(false) { | 319 window_has_shown_(false) { |
324 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, | 320 registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
325 content::NotificationService::AllSources()); | 321 content::NotificationService::AllSources()); |
326 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, | 322 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
327 content::Source<Profile>(profile_)); | 323 content::Source<Profile>(profile_)); |
328 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 324 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
329 content::Source<Profile>(profile_)); | 325 content::Source<Profile>(profile_)); |
330 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 326 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
331 content::Source<Profile>(profile_)); | 327 content::Source<Profile>(profile_)); |
332 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 328 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 423 } |
428 | 424 |
429 // There may be pending file dialogs, we need to tell them that we've gone | 425 // There may be pending file dialogs, we need to tell them that we've gone |
430 // away so they don't try and call back to us. | 426 // away so they don't try and call back to us. |
431 if (select_file_dialog_.get()) | 427 if (select_file_dialog_.get()) |
432 select_file_dialog_->ListenerDestroyed(); | 428 select_file_dialog_->ListenerDestroyed(); |
433 | 429 |
434 TabRestoreServiceDestroyed(tab_restore_service_); | 430 TabRestoreServiceDestroyed(tab_restore_service_); |
435 } | 431 } |
436 | 432 |
| 433 bool Browser::IsFullscreenForTab() const { |
| 434 return fullscreen_controller_->IsFullscreenForTab(); |
| 435 } |
| 436 |
437 // static | 437 // static |
438 Browser* Browser::Create(Profile* profile) { | 438 Browser* Browser::Create(Profile* profile) { |
439 Browser* browser = new Browser(TYPE_TABBED, profile); | 439 Browser* browser = new Browser(TYPE_TABBED, profile); |
440 browser->InitBrowserWindow(); | 440 browser->InitBrowserWindow(); |
441 return browser; | 441 return browser; |
442 } | 442 } |
443 | 443 |
444 // static | 444 // static |
445 Browser* Browser::CreateWithParams(const CreateParams& params) { | 445 Browser* Browser::CreateWithParams(const CreateParams& params) { |
446 Browser* browser = new Browser(params.type, params.profile); | 446 Browser* browser = new Browser(params.type, params.profile); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 CreateParams params(TYPE_POPUP, profile); | 501 CreateParams params(TYPE_POPUP, profile); |
502 #endif | 502 #endif |
503 params.app_name = DevToolsWindow::kDevToolsApp; | 503 params.app_name = DevToolsWindow::kDevToolsApp; |
504 return CreateWithParams(params); | 504 return CreateWithParams(params); |
505 } | 505 } |
506 | 506 |
507 void Browser::InitBrowserWindow() { | 507 void Browser::InitBrowserWindow() { |
508 DCHECK(!window_); | 508 DCHECK(!window_); |
509 | 509 |
510 window_ = CreateBrowserWindow(); | 510 window_ = CreateBrowserWindow(); |
| 511 fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
511 | 512 |
512 #if defined(OS_WIN) && !defined(USE_AURA) | 513 #if defined(OS_WIN) && !defined(USE_AURA) |
513 { | 514 { |
514 // TODO: This might hit the disk | 515 // TODO: This might hit the disk |
515 // http://code.google.com/p/chromium/issues/detail?id=61638 | 516 // http://code.google.com/p/chromium/issues/detail?id=61638 |
516 base::ThreadRestrictions::ScopedAllowIO allow_io; | 517 base::ThreadRestrictions::ScopedAllowIO allow_io; |
517 | 518 |
518 // Set the app user model id for this application to that of the application | 519 // Set the app user model id for this application to that of the application |
519 // name. See http://crbug.com/7028. | 520 // name. See http://crbug.com/7028. |
520 ui::win::SetAppIdForWindow( | 521 ui::win::SetAppIdForWindow( |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 contents_url == GURL(chrome::kAboutBlankURL)) && | 1368 contents_url == GURL(chrome::kAboutBlankURL)) && |
1368 browser::GetIndexOfSingletonTab(&local_params) < 0) { | 1369 browser::GetIndexOfSingletonTab(&local_params) < 0) { |
1369 local_params.disposition = CURRENT_TAB; | 1370 local_params.disposition = CURRENT_TAB; |
1370 } | 1371 } |
1371 } | 1372 } |
1372 | 1373 |
1373 browser::Navigate(&local_params); | 1374 browser::Navigate(&local_params); |
1374 } | 1375 } |
1375 | 1376 |
1376 void Browser::WindowFullscreenStateChanged() { | 1377 void Browser::WindowFullscreenStateChanged() { |
1377 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); | 1378 fullscreen_controller_->WindowFullscreenStateChanged(); |
1378 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); | |
1379 MessageLoop::current()->PostTask( | |
1380 FROM_HERE, method_factory_.NewRunnableMethod( | |
1381 &Browser::NotifyFullscreenChange)); | |
1382 bool notify_tab_of_exit; | |
1383 #if defined(OS_MACOSX) | |
1384 notify_tab_of_exit = !window_->InPresentationMode(); | |
1385 #else | |
1386 notify_tab_of_exit = !window_->IsFullscreen(); | |
1387 #endif | |
1388 if (notify_tab_of_exit) | |
1389 NotifyTabOfFullscreenExitIfNecessary(); | |
1390 } | |
1391 | |
1392 void Browser::NotifyFullscreenChange() { | |
1393 content::NotificationService::current()->Notify( | |
1394 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
1395 content::Source<Browser>(this), | |
1396 content::NotificationService::NoDetails()); | |
1397 } | 1379 } |
1398 | 1380 |
1399 /////////////////////////////////////////////////////////////////////////////// | 1381 /////////////////////////////////////////////////////////////////////////////// |
1400 // Browser, Assorted browser commands: | 1382 // Browser, Assorted browser commands: |
1401 | 1383 |
1402 TabContents* Browser::GetOrCloneTabForDisposition( | 1384 TabContents* Browser::GetOrCloneTabForDisposition( |
1403 WindowOpenDisposition disposition) { | 1385 WindowOpenDisposition disposition) { |
1404 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); | 1386 TabContentsWrapper* current_tab = GetSelectedTabContentsWrapper(); |
1405 switch (disposition) { | 1387 switch (disposition) { |
1406 case NEW_FOREGROUND_TAB: | 1388 case NEW_FOREGROUND_TAB: |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1709 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
1728 TabContentsWrapper* contents = | 1710 TabContentsWrapper* contents = |
1729 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1711 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
1730 Browser* browser = Browser::Create(profile_); | 1712 Browser* browser = Browser::Create(profile_); |
1731 browser->tabstrip_model()->AppendTabContents(contents, true); | 1713 browser->tabstrip_model()->AppendTabContents(contents, true); |
1732 browser->window()->Show(); | 1714 browser->window()->Show(); |
1733 } | 1715 } |
1734 | 1716 |
1735 // TODO(koz): Change |for_tab| to an enum. | 1717 // TODO(koz): Change |for_tab| to an enum. |
1736 void Browser::ToggleFullscreenMode(bool for_tab) { | 1718 void Browser::ToggleFullscreenMode(bool for_tab) { |
1737 bool entering_fullscreen = !window_->IsFullscreen(); | 1719 fullscreen_controller_->ToggleFullscreenMode(for_tab); |
1738 | |
1739 #if !defined(OS_MACOSX) | |
1740 // In kiosk mode, we always want to be fullscreen. When the browser first | |
1741 // starts we're not yet fullscreen, so let the initial toggle go through. | |
1742 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | |
1743 window_->IsFullscreen()) | |
1744 return; | |
1745 #endif | |
1746 | |
1747 GURL url; | |
1748 if (for_tab) { | |
1749 url = GetSelectedTabContents()->GetURL(); | |
1750 tab_fullscreen_accepted_ = entering_fullscreen && | |
1751 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
1752 } else { | |
1753 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | |
1754 } | |
1755 if (entering_fullscreen) | |
1756 window_->EnterFullscreen(url, GetFullscreenExitBubbleType()); | |
1757 else | |
1758 window_->ExitFullscreen(); | |
1759 | |
1760 // Once the window has become fullscreen it'll call back to | |
1761 // WindowFullscreenStateChanged(). We don't do this immediately as | |
1762 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let | |
1763 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | |
1764 | |
1765 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | |
1766 // the necessary state of the frame. | |
1767 #if defined(OS_MACOSX) | |
1768 WindowFullscreenStateChanged(); | |
1769 #endif | |
1770 } | |
1771 | |
1772 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | |
1773 if (fullscreened_tab_) | |
1774 fullscreened_tab_->ExitFullscreenMode(); | |
1775 else | |
1776 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); | |
1777 | |
1778 fullscreened_tab_ = NULL; | |
1779 tab_caused_fullscreen_ = false; | |
1780 tab_fullscreen_accepted_ = false; | |
1781 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
1782 | |
1783 UpdateFullscreenExitBubbleContent(); | |
1784 } | 1720 } |
1785 | 1721 |
1786 #if defined(OS_MACOSX) | 1722 #if defined(OS_MACOSX) |
1787 void Browser::TogglePresentationMode(bool for_tab) { | 1723 void Browser::TogglePresentationMode(bool for_tab) { |
1788 bool entering_fullscreen = !window_->InPresentationMode(); | 1724 fullscreen_controller_->TogglePresentationMode(for_tab); |
1789 GURL url; | |
1790 if (for_tab) { | |
1791 url = GetSelectedTabContents()->GetURL(); | |
1792 tab_fullscreen_accepted_ = entering_fullscreen && | |
1793 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
1794 } | |
1795 if (entering_fullscreen) | |
1796 window_->EnterPresentationMode(url, GetFullscreenExitBubbleType()); | |
1797 else | |
1798 window_->ExitPresentationMode(); | |
1799 WindowFullscreenStateChanged(); | |
1800 } | 1725 } |
1801 #endif | 1726 #endif |
1802 | 1727 |
1803 #if defined(OS_CHROMEOS) | 1728 #if defined(OS_CHROMEOS) |
1804 void Browser::Search() { | 1729 void Browser::Search() { |
1805 // Exit fullscreen to show omnibox. | 1730 // Exit fullscreen to show omnibox. |
1806 if (window_->IsFullscreen()) { | 1731 if (window_->IsFullscreen()) { |
1807 ToggleFullscreenMode(false); | 1732 ToggleFullscreenMode(false); |
1808 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1733 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
1809 // visible at this point. Wait for next event cycle which toggles | 1734 // visible at this point. Wait for next event cycle which toggles |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3236 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, | 3161 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DISCONNECTED, |
3237 content::Source<TabContents>(contents->tab_contents())); | 3162 content::Source<TabContents>(contents->tab_contents())); |
3238 | 3163 |
3239 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, | 3164 registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
3240 content::Source<TabContents>(contents->tab_contents())); | 3165 content::Source<TabContents>(contents->tab_contents())); |
3241 } | 3166 } |
3242 | 3167 |
3243 void Browser::TabClosingAt(TabStripModel* tab_strip_model, | 3168 void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
3244 TabContentsWrapper* contents, | 3169 TabContentsWrapper* contents, |
3245 int index) { | 3170 int index) { |
3246 if (fullscreened_tab_ == contents) { | 3171 fullscreen_controller_->OnTabClosing(contents->tab_contents()); |
3247 ExitTabbedFullscreenModeIfNecessary(); | |
3248 // The call to exit fullscreen may result in asynchronous notification of | |
3249 // fullscreen state change (e.g., on Linux). We don't want to rely on it | |
3250 // to call NotifyTabOfFullscreenExitIfNecessary(), because at that point | |
3251 // |fullscreen_tab_| may not be valid. Instead, we call it here to clean up | |
3252 // tab fullscreen related state. | |
3253 NotifyTabOfFullscreenExitIfNecessary(); | |
3254 } | |
3255 content::NotificationService::current()->Notify( | 3172 content::NotificationService::current()->Notify( |
3256 content::NOTIFICATION_TAB_CLOSING, | 3173 content::NOTIFICATION_TAB_CLOSING, |
3257 content::Source<NavigationController>(&contents->controller()), | 3174 content::Source<NavigationController>(&contents->controller()), |
3258 content::NotificationService::NoDetails()); | 3175 content::NotificationService::NoDetails()); |
3259 | 3176 |
3260 // Sever the TabContents' connection back to us. | 3177 // Sever the TabContents' connection back to us. |
3261 SetAsDelegate(contents, NULL); | 3178 SetAsDelegate(contents, NULL); |
3262 } | 3179 } |
3263 | 3180 |
3264 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { | 3181 void Browser::TabDetachedAt(TabContentsWrapper* contents, int index) { |
3265 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); | 3182 TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
3266 } | 3183 } |
3267 | 3184 |
3268 void Browser::TabDeactivated(TabContentsWrapper* contents) { | 3185 void Browser::TabDeactivated(TabContentsWrapper* contents) { |
3269 if (contents == fullscreened_tab_) | 3186 fullscreen_controller_->OnTabDeactivated(contents); |
3270 ExitTabbedFullscreenModeIfNecessary(); | |
3271 if (instant()) | 3187 if (instant()) |
3272 instant()->Hide(); | 3188 instant()->Hide(); |
3273 | 3189 |
3274 // Save what the user's currently typing, so it can be restored when we | 3190 // Save what the user's currently typing, so it can be restored when we |
3275 // switch back to this tab. | 3191 // switch back to this tab. |
3276 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); | 3192 window_->GetLocationBar()->SaveStateToContents(contents->tab_contents()); |
3277 } | 3193 } |
3278 | 3194 |
3279 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, | 3195 void Browser::ActiveTabChanged(TabContentsWrapper* old_contents, |
3280 TabContentsWrapper* new_contents, | 3196 TabContentsWrapper* new_contents, |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3783 DCHECK(source); | 3699 DCHECK(source); |
3784 int index = tabstrip_model()->GetWrapperIndex(source); | 3700 int index = tabstrip_model()->GetWrapperIndex(source); |
3785 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); | 3701 TabContentsWrapper* wrapper = tabstrip_model()->GetTabContentsAt(index); |
3786 ViewSource(wrapper, frame_url, frame_content_state); | 3702 ViewSource(wrapper, frame_url, frame_content_state); |
3787 } | 3703 } |
3788 | 3704 |
3789 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 3705 bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
3790 bool* is_keyboard_shortcut) { | 3706 bool* is_keyboard_shortcut) { |
3791 // Escape exits tabbed fullscreen mode. | 3707 // Escape exits tabbed fullscreen mode. |
3792 // TODO(koz): Write a test for this http://crbug.com/100441. | 3708 // TODO(koz): Write a test for this http://crbug.com/100441. |
3793 if (event.windowsKeyCode == 27 && fullscreened_tab_) { | 3709 if (event.windowsKeyCode == 27 && |
3794 ExitTabbedFullscreenModeIfNecessary(); | 3710 fullscreen_controller_->HandleUserPressedEscape()) { |
3795 return true; | 3711 return true; |
3796 } | 3712 } |
3797 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); | 3713 return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
3798 } | 3714 } |
3799 | 3715 |
3800 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | 3716 void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
3801 window()->HandleKeyboardEvent(event); | 3717 window()->HandleKeyboardEvent(event); |
3802 } | 3718 } |
3803 | 3719 |
3804 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { | 3720 void Browser::ShowRepostFormWarningDialog(TabContents *tab_contents) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3887 const ViewHostMsg_RunFileChooser_Params& params) { | 3803 const ViewHostMsg_RunFileChooser_Params& params) { |
3888 RunFileChooserHelper(tab, params); | 3804 RunFileChooserHelper(tab, params); |
3889 } | 3805 } |
3890 | 3806 |
3891 void Browser::EnumerateDirectory(TabContents* tab, int request_id, | 3807 void Browser::EnumerateDirectory(TabContents* tab, int request_id, |
3892 const FilePath& path) { | 3808 const FilePath& path) { |
3893 EnumerateDirectoryHelper(tab, request_id, path); | 3809 EnumerateDirectoryHelper(tab, request_id, path); |
3894 } | 3810 } |
3895 | 3811 |
3896 void Browser::ToggleFullscreenModeForTab(TabContents* tab, | 3812 void Browser::ToggleFullscreenModeForTab(TabContents* tab, |
3897 bool enter_fullscreen) { | 3813 bool enter_fullscreen) { |
3898 if (tab != GetSelectedTabContents()) | 3814 fullscreen_controller_->ToggleFullscreenModeForTab(tab, enter_fullscreen); |
3899 return; | |
3900 | |
3901 bool in_browser_or_tab_fullscreen_mode; | |
3902 #if defined(OS_MACOSX) | |
3903 in_browser_or_tab_fullscreen_mode = window_->InPresentationMode(); | |
3904 #else | |
3905 in_browser_or_tab_fullscreen_mode = window_->IsFullscreen(); | |
3906 #endif | |
3907 | |
3908 if (enter_fullscreen) { | |
3909 fullscreened_tab_ = TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
3910 if (!in_browser_or_tab_fullscreen_mode) { | |
3911 tab_caused_fullscreen_ = true; | |
3912 #if defined(OS_MACOSX) | |
3913 TogglePresentationMode(true); | |
3914 #else | |
3915 ToggleFullscreenMode(true); | |
3916 #endif | |
3917 } else { | |
3918 // We need to update the fullscreen exit bubble, e.g., going from browser | |
3919 // fullscreen to tab fullscreen will need to show different content. | |
3920 const GURL& url = tab->GetURL(); | |
3921 if (!tab_fullscreen_accepted_) { | |
3922 tab_fullscreen_accepted_ = | |
3923 GetFullscreenSetting(url) == CONTENT_SETTING_ALLOW; | |
3924 } | |
3925 UpdateFullscreenExitBubbleContent(); | |
3926 } | |
3927 } else { | |
3928 if (in_browser_or_tab_fullscreen_mode) { | |
3929 if (tab_caused_fullscreen_) { | |
3930 #if defined(OS_MACOSX) | |
3931 TogglePresentationMode(true); | |
3932 #else | |
3933 ToggleFullscreenMode(true); | |
3934 #endif | |
3935 } else { | |
3936 // If currently there is a tab in "tab fullscreen" mode and fullscreen | |
3937 // was not caused by it (i.e., previously it was in "browser fullscreen" | |
3938 // mode), we need to switch back to "browser fullscreen" mode. In this | |
3939 // case, all we have to do is notifying the tab that it has exited "tab | |
3940 // fullscreen" mode. | |
3941 NotifyTabOfFullscreenExitIfNecessary(); | |
3942 } | |
3943 } | |
3944 } | |
3945 } | 3815 } |
3946 | 3816 |
3947 bool Browser::IsFullscreenForTab(const TabContents* tab) const { | 3817 bool Browser::IsFullscreenForTab(const TabContents* tab) const { |
3948 const TabContentsWrapper* wrapper = | 3818 return fullscreen_controller_->IsFullscreenForTab(tab); |
3949 TabContentsWrapper::GetCurrentWrapperForContents(tab); | |
3950 bool result = wrapper && wrapper == fullscreened_tab_; | |
3951 DCHECK(!result || tab == GetSelectedTabContents()); | |
3952 DCHECK(!result || window_->IsFullscreen()); | |
3953 | |
3954 return result; | |
3955 } | 3819 } |
3956 | 3820 |
3957 void Browser::JSOutOfMemory(TabContents* tab) { | 3821 void Browser::JSOutOfMemory(TabContents* tab) { |
3958 JSOutOfMemoryHelper(tab); | 3822 JSOutOfMemoryHelper(tab); |
3959 } | 3823 } |
3960 | 3824 |
3961 void Browser::RegisterProtocolHandler(TabContents* tab, | 3825 void Browser::RegisterProtocolHandler(TabContents* tab, |
3962 const std::string& protocol, | 3826 const std::string& protocol, |
3963 const GURL& url, | 3827 const GURL& url, |
3964 const string16& title) { | 3828 const string16& title) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3997 int active_match_ordinal, | 3861 int active_match_ordinal, |
3998 bool final_update) { | 3862 bool final_update) { |
3999 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3863 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
4000 active_match_ordinal, final_update); | 3864 active_match_ordinal, final_update); |
4001 } | 3865 } |
4002 | 3866 |
4003 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3867 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
4004 CrashedPluginHelper(tab, plugin_path); | 3868 CrashedPluginHelper(tab, plugin_path); |
4005 } | 3869 } |
4006 | 3870 |
4007 void Browser::ExitTabbedFullscreenModeIfNecessary() { | |
4008 if (tab_caused_fullscreen_) | |
4009 ToggleFullscreenMode(false); | |
4010 else | |
4011 NotifyTabOfFullscreenExitIfNecessary(); | |
4012 } | |
4013 | |
4014 void Browser::UpdatePreferredSize(TabContents* source, | 3871 void Browser::UpdatePreferredSize(TabContents* source, |
4015 const gfx::Size& pref_size) { | 3872 const gfx::Size& pref_size) { |
4016 window_->UpdatePreferredSize(source, pref_size); | 3873 window_->UpdatePreferredSize(source, pref_size); |
4017 } | 3874 } |
4018 | 3875 |
4019 void Browser::RequestToLockMouse(TabContents* tab) { | 3876 void Browser::RequestToLockMouse(TabContents* tab) { |
4020 // Mouse Lock is only permitted when browser is in tab fullscreen. | 3877 fullscreen_controller_->RequestToLockMouse(tab); |
4021 if (!IsFullscreenForTab(tab)) { | |
4022 tab->GotResponseToLockMouseRequest(false); | |
4023 return; | |
4024 } | |
4025 | |
4026 if (mouse_lock_state_ == MOUSELOCK_ACCEPTED) { | |
4027 tab->GotResponseToLockMouseRequest(true); | |
4028 return; | |
4029 } | |
4030 | |
4031 switch (GetMouseLockSetting(tab->GetURL())) { | |
4032 case CONTENT_SETTING_ALLOW: | |
4033 mouse_lock_state_ = MOUSELOCK_ACCEPTED; | |
4034 tab->GotResponseToLockMouseRequest(true); | |
4035 break; | |
4036 case CONTENT_SETTING_BLOCK: | |
4037 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
4038 tab->GotResponseToLockMouseRequest(false); | |
4039 break; | |
4040 case CONTENT_SETTING_ASK: | |
4041 mouse_lock_state_ = MOUSELOCK_REQUESTED; | |
4042 break; | |
4043 default: | |
4044 NOTREACHED(); | |
4045 } | |
4046 UpdateFullscreenExitBubbleContent(); | |
4047 } | 3878 } |
4048 | 3879 |
4049 void Browser::LostMouseLock() { | 3880 void Browser::LostMouseLock() { |
4050 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | 3881 fullscreen_controller_->LostMouseLock(); |
4051 UpdateFullscreenExitBubbleContent(); | |
4052 } | 3882 } |
4053 | 3883 |
4054 void Browser::OnAcceptFullscreenPermission( | 3884 void Browser::OnAcceptFullscreenPermission( |
4055 const GURL& url, | 3885 const GURL& url, |
4056 FullscreenExitBubbleType bubble_type) { | 3886 FullscreenExitBubbleType bubble_type) { |
4057 bool mouse_lock = false; | 3887 fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
4058 bool fullscreen = false; | |
4059 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
4060 &mouse_lock); | |
4061 DCHECK(fullscreened_tab_); | |
4062 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
4063 | |
4064 HostContentSettingsMap* settings_map = | |
4065 profile()->GetHostContentSettingsMap(); | |
4066 if (mouse_lock) { | |
4067 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
4068 settings_map->SetContentSetting( | |
4069 ContentSettingsPattern::FromURL(url), | |
4070 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MOUSELOCK, | |
4071 std::string(), CONTENT_SETTING_ALLOW); | |
4072 mouse_lock_state_ = | |
4073 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(true) ? | |
4074 MOUSELOCK_ACCEPTED : MOUSELOCK_NOT_REQUESTED; | |
4075 } | |
4076 if (!tab_fullscreen_accepted_) { | |
4077 settings_map->SetContentSetting( | |
4078 ContentSettingsPattern::FromURL(url), | |
4079 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
4080 std::string(), CONTENT_SETTING_ALLOW); | |
4081 tab_fullscreen_accepted_ = true; | |
4082 } | |
4083 UpdateFullscreenExitBubbleContent(); | |
4084 } | 3888 } |
4085 | 3889 |
4086 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { | 3890 void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
4087 bool mouse_lock = false; | 3891 fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
4088 bool fullscreen = false; | |
4089 fullscreen_bubble::PermissionRequestedByType(bubble_type, &fullscreen, | |
4090 &mouse_lock); | |
4091 DCHECK(fullscreened_tab_); | |
4092 DCHECK_NE(tab_fullscreen_accepted_, fullscreen); | |
4093 | |
4094 if (mouse_lock) { | |
4095 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_REQUESTED); | |
4096 mouse_lock_state_ = MOUSELOCK_NOT_REQUESTED; | |
4097 fullscreened_tab_->tab_contents()->GotResponseToLockMouseRequest(false); | |
4098 if (!fullscreen) | |
4099 UpdateFullscreenExitBubbleContent(); | |
4100 } | |
4101 | |
4102 if (fullscreen) | |
4103 ExitTabbedFullscreenModeIfNecessary(); | |
4104 } | 3892 } |
4105 | 3893 |
4106 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { | |
4107 if (url.SchemeIsFile()) | |
4108 return CONTENT_SETTING_ALLOW; | |
4109 | |
4110 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
4111 return settings_map->GetContentSetting(url, url, | |
4112 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | |
4113 } | |
4114 | |
4115 ContentSetting Browser::GetMouseLockSetting(const GURL& url) { | |
4116 if (url.SchemeIsFile()) | |
4117 return CONTENT_SETTING_ALLOW; | |
4118 | |
4119 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
4120 return settings_map->GetContentSetting(url, url, | |
4121 CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()); | |
4122 } | |
4123 | 3894 |
4124 /////////////////////////////////////////////////////////////////////////////// | 3895 /////////////////////////////////////////////////////////////////////////////// |
4125 // Browser, TabContentsWrapperDelegate implementation: | 3896 // Browser, TabContentsWrapperDelegate implementation: |
4126 | 3897 |
4127 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3898 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
4128 int32 page_id) { | 3899 int32 page_id) { |
4129 if (GetSelectedTabContentsWrapper() != source) | 3900 if (GetSelectedTabContentsWrapper() != source) |
4130 return; | 3901 return; |
4131 | 3902 |
4132 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3903 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4357 if (location_bar) | 4128 if (location_bar) |
4358 location_bar->UpdateContentSettingsIcons(); | 4129 location_bar->UpdateContentSettingsIcons(); |
4359 } | 4130 } |
4360 break; | 4131 break; |
4361 } | 4132 } |
4362 | 4133 |
4363 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: | 4134 case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
4364 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); | 4135 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
4365 break; | 4136 break; |
4366 | 4137 |
| 4138 case chrome::NOTIFICATION_FULLSCREEN_CHANGED: |
| 4139 UpdateCommandsForFullscreenMode(window_->IsFullscreen()); |
| 4140 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
| 4141 break; |
| 4142 |
4367 default: | 4143 default: |
4368 NOTREACHED() << "Got a notification we didn't register for."; | 4144 NOTREACHED() << "Got a notification we didn't register for."; |
4369 } | 4145 } |
4370 } | 4146 } |
4371 | 4147 |
4372 /////////////////////////////////////////////////////////////////////////////// | 4148 /////////////////////////////////////////////////////////////////////////////// |
4373 // Browser, ProfileSyncServiceObserver implementation: | 4149 // Browser, ProfileSyncServiceObserver implementation: |
4374 | 4150 |
4375 void Browser::OnStateChanged() { | 4151 void Browser::OnStateChanged() { |
4376 DCHECK(profile_->GetProfileSyncService()); | 4152 DCHECK(profile_->GetProfileSyncService()); |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5496 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5272 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
5497 } else if (is_type_tabbed()) { | 5273 } else if (is_type_tabbed()) { |
5498 GlobalErrorService* service = | 5274 GlobalErrorService* service = |
5499 GlobalErrorServiceFactory::GetForProfile(profile()); | 5275 GlobalErrorServiceFactory::GetForProfile(profile()); |
5500 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5276 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
5501 if (error) { | 5277 if (error) { |
5502 error->ShowBubbleView(this); | 5278 error->ShowBubbleView(this); |
5503 } | 5279 } |
5504 } | 5280 } |
5505 } | 5281 } |
5506 | |
5507 FullscreenExitBubbleType Browser::GetFullscreenExitBubbleType() const { | |
5508 bool tab_fullscreen_requested = | |
5509 fullscreened_tab_ && !tab_fullscreen_accepted_; | |
5510 if (!tab_fullscreen_requested && !tab_fullscreen_accepted_) { | |
5511 DCHECK_EQ(mouse_lock_state_, MOUSELOCK_NOT_REQUESTED); | |
5512 return FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; | |
5513 } | |
5514 if (tab_fullscreen_requested) { | |
5515 DCHECK_NE(mouse_lock_state_, MOUSELOCK_ACCEPTED); | |
5516 return mouse_lock_state_ == MOUSELOCK_REQUESTED ? | |
5517 FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS : FEB_TYPE_FULLSCREEN_BUTTONS; | |
5518 } | |
5519 if (mouse_lock_state_ == MOUSELOCK_REQUESTED) | |
5520 return FEB_TYPE_MOUSELOCK_BUTTONS; | |
5521 return mouse_lock_state_ == MOUSELOCK_ACCEPTED ? | |
5522 FEB_TYPE_FULLSCREEN_MOUSELOCK_EXIT_INSTRUCTION : | |
5523 FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION; | |
5524 } | |
5525 | |
5526 void Browser::UpdateFullscreenExitBubbleContent() { | |
5527 GURL url; | |
5528 if (fullscreened_tab_) | |
5529 url = fullscreened_tab_->tab_contents()->GetURL(); | |
5530 | |
5531 window_->UpdateFullscreenExitBubbleContent( | |
5532 url, GetFullscreenExitBubbleType()); | |
5533 } | |
OLD | NEW |