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 15 matching lines...) Expand all Loading... | |
| 26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
| 27 #include "chrome/app/chrome_command_ids.h" | 27 #include "chrome/app/chrome_command_ids.h" |
| 28 #include "chrome/browser/autofill/autofill_manager.h" | 28 #include "chrome/browser/autofill/autofill_manager.h" |
| 29 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 29 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 30 #include "chrome/browser/background/background_contents_service.h" | 30 #include "chrome/browser/background/background_contents_service.h" |
| 31 #include "chrome/browser/bookmarks/bookmark_model.h" | 31 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 32 #include "chrome/browser/bookmarks/bookmark_utils.h" | 32 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 33 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 34 #include "chrome/browser/browser_shutdown.h" | 34 #include "chrome/browser/browser_shutdown.h" |
| 35 #include "chrome/browser/character_encoding.h" | 35 #include "chrome/browser/character_encoding.h" |
| 36 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 36 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 37 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 37 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" | 38 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" |
| 38 #include "chrome/browser/debugger/devtools_toggle_action.h" | 39 #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 39 #include "chrome/browser/debugger/devtools_window.h" | 40 #include "chrome/browser/debugger/devtools_window.h" |
| 40 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 41 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 41 #include "chrome/browser/download/download_item_model.h" | 42 #include "chrome/browser/download/download_item_model.h" |
| 42 #include "chrome/browser/download/download_started_animation.h" | 43 #include "chrome/browser/download/download_started_animation.h" |
| 43 #include "chrome/browser/extensions/crx_installer.h" | 44 #include "chrome/browser/extensions/crx_installer.h" |
| 44 #include "chrome/browser/extensions/extension_browser_event_router.h" | 45 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 45 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" | 46 #include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 browser::Navigate(¶ms); | 747 browser::Navigate(¶ms); |
| 747 contents = params.target_contents->tab_contents(); | 748 contents = params.target_contents->tab_contents(); |
| 748 } | 749 } |
| 749 | 750 |
| 750 // TODO(skerner): If we are already in full screen mode, and the user | 751 // TODO(skerner): If we are already in full screen mode, and the user |
| 751 // set the app to open as a regular or pinned tab, what should happen? | 752 // set the app to open as a regular or pinned tab, what should happen? |
| 752 // Today we open the tab, but stay in full screen mode. Should we leave | 753 // Today we open the tab, but stay in full screen mode. Should we leave |
| 753 // full screen mode in this case? | 754 // full screen mode in this case? |
| 754 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && | 755 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
| 755 !browser->window()->IsFullscreen()) | 756 !browser->window()->IsFullscreen()) |
| 756 browser->ToggleFullscreenMode(); | 757 browser->ToggleFullscreenMode(false); |
| 757 | 758 |
| 758 return contents; | 759 return contents; |
| 759 } | 760 } |
| 760 | 761 |
| 761 // static | 762 // static |
| 762 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 763 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 763 Browser* browser = Browser::Create(profile); | 764 Browser* browser = Browser::Create(profile); |
| 764 browser->OpenBookmarkManager(); | 765 browser->OpenBookmarkManager(); |
| 765 browser->window()->Show(); | 766 browser->window()->Show(); |
| 766 } | 767 } |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1659 void Browser::ConvertPopupToTabbedBrowser() { | 1660 void Browser::ConvertPopupToTabbedBrowser() { |
| 1660 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); | 1661 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
| 1661 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1662 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
| 1662 TabContentsWrapper* contents = | 1663 TabContentsWrapper* contents = |
| 1663 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1664 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
| 1664 Browser* browser = Browser::Create(profile_); | 1665 Browser* browser = Browser::Create(profile_); |
| 1665 browser->tabstrip_model()->AppendTabContents(contents, true); | 1666 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1666 browser->window()->Show(); | 1667 browser->window()->Show(); |
| 1667 } | 1668 } |
| 1668 | 1669 |
| 1669 void Browser::ToggleFullscreenMode() { | 1670 // TODO Change this to an enum. |
| 1671 void Browser::ToggleFullscreenMode(bool for_tab) { | |
| 1672 bool entering_fullscreen = !window_->IsFullscreen(); | |
| 1673 | |
| 1670 #if !defined(OS_MACOSX) | 1674 #if !defined(OS_MACOSX) |
| 1671 // In kiosk mode, we always want to be fullscreen. When the browser first | 1675 // In kiosk mode, we always want to be fullscreen. When the browser first |
| 1672 // starts we're not yet fullscreen, so let the initial toggle go through. | 1676 // starts we're not yet fullscreen, so let the initial toggle go through. |
| 1673 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 1677 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| 1674 window_->IsFullscreen()) | 1678 window_->IsFullscreen()) |
| 1675 return; | 1679 return; |
| 1676 #endif | 1680 #endif |
| 1677 | 1681 |
| 1678 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | 1682 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 1679 window_->SetFullscreen(!window_->IsFullscreen()); | 1683 if (for_tab) { |
| 1684 const GURL& url = GetSelectedTabContents()->GetURL(); | |
| 1685 bool show_buttons = GetFullscreenSetting(url) == CONTENT_SETTING_ASK; | |
| 1686 window_->SetFullscreen(entering_fullscreen, url, show_buttons); | |
| 1687 } else { | |
| 1688 // TODO Replace with browser-specific fullscreen function. | |
| 1689 window_->SetFullscreen(entering_fullscreen, GURL(), false); | |
| 1690 } | |
| 1680 | 1691 |
| 1681 // Once the window has become fullscreen it'll call back to | 1692 // Once the window has become fullscreen it'll call back to |
| 1682 // WindowFullscreenStateChanged(). We don't do this immediately as | 1693 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 1683 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the | 1694 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the |
| 1684 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 1695 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 1685 | 1696 |
| 1686 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 1697 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
| 1687 // the necessary state of the frame. | 1698 // the necessary state of the frame. |
| 1688 #if defined(OS_MACOSX) | 1699 #if defined(OS_MACOSX) |
| 1689 WindowFullscreenStateChanged(); | 1700 WindowFullscreenStateChanged(); |
| 1690 #endif | 1701 #endif |
| 1691 } | 1702 } |
| 1692 | 1703 |
| 1693 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | 1704 void Browser::NotifyTabOfFullscreenExitIfNecessary() { |
| 1694 if (fullscreened_tab_) | 1705 if (fullscreened_tab_) |
| 1695 fullscreened_tab_->ExitFullscreenMode(); | 1706 fullscreened_tab_->ExitFullscreenMode(); |
| 1696 fullscreened_tab_ = NULL; | 1707 fullscreened_tab_ = NULL; |
| 1697 tab_caused_fullscreen_ = false; | 1708 tab_caused_fullscreen_ = false; |
| 1698 } | 1709 } |
| 1699 | 1710 |
| 1700 #if defined(OS_MACOSX) | 1711 #if defined(OS_MACOSX) |
| 1701 void Browser::TogglePresentationMode() { | 1712 void Browser::TogglePresentationMode(bool for_tab) { |
| 1702 window_->SetPresentationMode(!window_->InPresentationMode()); | 1713 bool entering_fullscreen = !window_->InPresentationMode(); |
| 1714 if (for_tab) { | |
| 1715 const GURL& url = GetSelectedTabContents()->GetURL(); | |
| 1716 bool show_buttons = GetFullscreenSetting(url) == CONTENT_SETTING_ASK; | |
| 1717 window_->SetPresentationMode(entering_fullscreen, url, show_buttons); | |
| 1718 } else { | |
| 1719 // TODO Replace with browser-specific fullscreen function. | |
| 1720 window_->SetFullscreen(entering_fullscreen, GURL(), false); | |
|
yzshen1
2011/10/10 19:09:30
I am not familiar with Mac implementation, but it
koz (OOO until 15th September)
2011/10/10 22:49:58
Done.
| |
| 1721 } | |
| 1703 WindowFullscreenStateChanged(); | 1722 WindowFullscreenStateChanged(); |
| 1704 } | 1723 } |
| 1705 #endif | 1724 #endif |
| 1706 | 1725 |
| 1707 #if defined(OS_CHROMEOS) | 1726 #if defined(OS_CHROMEOS) |
| 1708 void Browser::Search() { | 1727 void Browser::Search() { |
| 1709 // Exit fullscreen to show omnibox. | 1728 // Exit fullscreen to show omnibox. |
| 1710 if (window_->IsFullscreen()) { | 1729 if (window_->IsFullscreen()) { |
| 1711 ToggleFullscreenMode(); | 1730 ToggleFullscreenMode(false); |
| 1712 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1731 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1713 // visible at this point. Wait for next event cycle which toggles | 1732 // visible at this point. Wait for next event cycle which toggles |
| 1714 // the visibility of omnibox before creating new tab. | 1733 // the visibility of omnibox before creating new tab. |
| 1715 MessageLoop::current()->PostTask( | 1734 MessageLoop::current()->PostTask( |
| 1716 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); | 1735 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); |
| 1717 return; | 1736 return; |
| 1718 } | 1737 } |
| 1719 | 1738 |
| 1720 const GURL& url = GetSelectedTabContents()->GetURL(); | 1739 const GURL& url = GetSelectedTabContents()->GetURL(); |
| 1721 if (url.SchemeIs(chrome::kChromeUIScheme) && | 1740 if (url.SchemeIs(chrome::kChromeUIScheme) && |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2628 case IDC_SELECT_TAB_4: | 2647 case IDC_SELECT_TAB_4: |
| 2629 case IDC_SELECT_TAB_5: | 2648 case IDC_SELECT_TAB_5: |
| 2630 case IDC_SELECT_TAB_6: | 2649 case IDC_SELECT_TAB_6: |
| 2631 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); | 2650 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
| 2632 break; | 2651 break; |
| 2633 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; | 2652 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
| 2634 case IDC_DUPLICATE_TAB: DuplicateTab(); break; | 2653 case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
| 2635 case IDC_RESTORE_TAB: RestoreTab(); break; | 2654 case IDC_RESTORE_TAB: RestoreTab(); break; |
| 2636 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; | 2655 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
| 2637 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; | 2656 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
| 2638 case IDC_FULLSCREEN: ToggleFullscreenMode(); break; | 2657 case IDC_FULLSCREEN: ToggleFullscreenMode(false); break; |
| 2639 #if defined(OS_MACOSX) | 2658 #if defined(OS_MACOSX) |
| 2640 case IDC_PRESENTATION_MODE: TogglePresentationMode(); break; | 2659 case IDC_PRESENTATION_MODE: TogglePresentationMode(false); break; |
| 2641 #endif | 2660 #endif |
| 2642 case IDC_EXIT: Exit(); break; | 2661 case IDC_EXIT: Exit(); break; |
| 2643 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break; | 2662 case IDC_TOGGLE_VERTICAL_TABS: ToggleUseVerticalTabs(); break; |
| 2644 #if defined(OS_CHROMEOS) | 2663 #if defined(OS_CHROMEOS) |
| 2645 case IDC_SEARCH: Search(); break; | 2664 case IDC_SEARCH: Search(); break; |
| 2646 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; | 2665 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
| 2647 #endif | 2666 #endif |
| 2648 | 2667 |
| 2649 // Page-related commands | 2668 // Page-related commands |
| 2650 case IDC_SAVE_PAGE: SavePage(); break; | 2669 case IDC_SAVE_PAGE: SavePage(); break; |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3802 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); | 3821 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); |
| 3803 #else | 3822 #else |
| 3804 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); | 3823 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); |
| 3805 #endif | 3824 #endif |
| 3806 if (!in_correct_mode_for_tab_fullscreen) | 3825 if (!in_correct_mode_for_tab_fullscreen) |
| 3807 tab_caused_fullscreen_ = true; | 3826 tab_caused_fullscreen_ = true; |
| 3808 } | 3827 } |
| 3809 | 3828 |
| 3810 if (tab_caused_fullscreen_) { | 3829 if (tab_caused_fullscreen_) { |
| 3811 #if defined(OS_MACOSX) | 3830 #if defined(OS_MACOSX) |
| 3812 TogglePresentationMode(); | 3831 TogglePresentationMode(true); |
| 3813 #else | 3832 #else |
| 3814 ToggleFullscreenMode(); | 3833 ToggleFullscreenMode(true); |
| 3815 #endif | 3834 #endif |
| 3816 } else if (!enter_fullscreen) { | 3835 } else if (!enter_fullscreen) { |
| 3817 // If currently there is a tab in "tab fullscreen" mode and fullscreen was | 3836 // If currently there is a tab in "tab fullscreen" mode and fullscreen was |
| 3818 // not caused by it (i.e., previously it was in "browser fullscreen" mode), | 3837 // not caused by it (i.e., previously it was in "browser fullscreen" mode), |
| 3819 // we need to switch back to "browser fullscreen" mode. In this case, all we | 3838 // we need to switch back to "browser fullscreen" mode. In this case, all we |
| 3820 // have to do is notifying the tab that it has exited "tab fullscreen" mode. | 3839 // have to do is notifying the tab that it has exited "tab fullscreen" mode. |
| 3821 NotifyTabOfFullscreenExitIfNecessary(); | 3840 NotifyTabOfFullscreenExitIfNecessary(); |
| 3822 } | 3841 } |
| 3823 } | 3842 } |
| 3824 | 3843 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3880 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3899 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 3881 active_match_ordinal, final_update); | 3900 active_match_ordinal, final_update); |
| 3882 } | 3901 } |
| 3883 | 3902 |
| 3884 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3903 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
| 3885 CrashedPluginHelper(tab, plugin_path); | 3904 CrashedPluginHelper(tab, plugin_path); |
| 3886 } | 3905 } |
| 3887 | 3906 |
| 3888 void Browser::ExitTabbedFullscreenModeIfNecessary() { | 3907 void Browser::ExitTabbedFullscreenModeIfNecessary() { |
| 3889 if (tab_caused_fullscreen_) | 3908 if (tab_caused_fullscreen_) |
| 3890 ToggleFullscreenMode(); | 3909 ToggleFullscreenMode(false); |
| 3891 else | 3910 else |
| 3892 NotifyTabOfFullscreenExitIfNecessary(); | 3911 NotifyTabOfFullscreenExitIfNecessary(); |
| 3893 } | 3912 } |
| 3894 | 3913 |
| 3895 void Browser::UpdatePreferredSize(TabContents* source, | 3914 void Browser::UpdatePreferredSize(TabContents* source, |
| 3896 const gfx::Size& pref_size) { | 3915 const gfx::Size& pref_size) { |
| 3897 window_->UpdatePreferredSize(source, pref_size); | 3916 window_->UpdatePreferredSize(source, pref_size); |
| 3898 } | 3917 } |
| 3899 | 3918 |
| 3919 void Browser::OnAcceptFullscreenPermission(const GURL& url) { | |
|
yzshen1
2011/10/10 19:09:30
On Windows:
After clicking "Allow", restarting bro
koz (OOO until 15th September)
2011/10/10 22:49:58
No, I can't reproduce this. Can you repro if you d
| |
| 3920 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 3921 | |
| 3922 settings_map->SetContentSetting( | |
| 3923 ContentSettingsPattern::FromString(url.host()), | |
| 3924 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
| 3925 "", CONTENT_SETTING_ALLOW); | |
| 3926 } | |
| 3927 | |
| 3928 void Browser::OnDenyFullscreenPermission() { | |
| 3929 ExitTabbedFullscreenModeIfNecessary(); | |
| 3930 } | |
| 3931 | |
| 3932 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { | |
| 3933 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 3934 return settings_map->GetContentSetting(url, url, | |
| 3935 CONTENT_SETTINGS_TYPE_FULLSCREEN, ""); | |
| 3936 } | |
| 3937 | |
| 3900 /////////////////////////////////////////////////////////////////////////////// | 3938 /////////////////////////////////////////////////////////////////////////////// |
| 3901 // Browser, TabContentsWrapperDelegate implementation: | 3939 // Browser, TabContentsWrapperDelegate implementation: |
| 3902 | 3940 |
| 3903 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3941 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 3904 int32 page_id) { | 3942 int32 page_id) { |
| 3905 if (GetSelectedTabContentsWrapper() != source) | 3943 if (GetSelectedTabContentsWrapper() != source) |
| 3906 return; | 3944 return; |
| 3907 | 3945 |
| 3908 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3946 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 3909 if (!entry || (entry->page_id() != page_id)) | 3947 if (!entry || (entry->page_id() != page_id)) |
| (...skipping 1397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5307 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5345 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
| 5308 } else if (is_type_tabbed()) { | 5346 } else if (is_type_tabbed()) { |
| 5309 GlobalErrorService* service = | 5347 GlobalErrorService* service = |
| 5310 GlobalErrorServiceFactory::GetForProfile(profile()); | 5348 GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5311 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5349 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5312 if (error) { | 5350 if (error) { |
| 5313 error->ShowBubbleView(this); | 5351 error->ShowBubbleView(this); |
| 5314 } | 5352 } |
| 5315 } | 5353 } |
| 5316 } | 5354 } |
| OLD | NEW |