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 16 matching lines...) Expand all Loading... |
27 #include "base/utf_string_conversions.h" | 27 #include "base/utf_string_conversions.h" |
28 #include "chrome/app/chrome_command_ids.h" | 28 #include "chrome/app/chrome_command_ids.h" |
29 #include "chrome/browser/autofill/autofill_manager.h" | 29 #include "chrome/browser/autofill/autofill_manager.h" |
30 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 30 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
31 #include "chrome/browser/background/background_contents_service.h" | 31 #include "chrome/browser/background/background_contents_service.h" |
32 #include "chrome/browser/bookmarks/bookmark_model.h" | 32 #include "chrome/browser/bookmarks/bookmark_model.h" |
33 #include "chrome/browser/bookmarks/bookmark_utils.h" | 33 #include "chrome/browser/bookmarks/bookmark_utils.h" |
34 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
35 #include "chrome/browser/browser_shutdown.h" | 35 #include "chrome/browser/browser_shutdown.h" |
36 #include "chrome/browser/character_encoding.h" | 36 #include "chrome/browser/character_encoding.h" |
| 37 #include "chrome/browser/content_settings/host_content_settings_map.h" |
37 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 38 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
38 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" | 39 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg
ate.h" |
39 #include "chrome/browser/debugger/devtools_toggle_action.h" | 40 #include "chrome/browser/debugger/devtools_toggle_action.h" |
40 #include "chrome/browser/debugger/devtools_window.h" | 41 #include "chrome/browser/debugger/devtools_window.h" |
41 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 42 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
42 #include "chrome/browser/download/download_item_model.h" | 43 #include "chrome/browser/download/download_item_model.h" |
43 #include "chrome/browser/download/download_service.h" | 44 #include "chrome/browser/download/download_service.h" |
44 #include "chrome/browser/download/download_service_factory.h" | 45 #include "chrome/browser/download/download_service_factory.h" |
45 #include "chrome/browser/download/download_started_animation.h" | 46 #include "chrome/browser/download/download_started_animation.h" |
46 #include "chrome/browser/extensions/crx_installer.h" | 47 #include "chrome/browser/extensions/crx_installer.h" |
(...skipping 699 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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 void Browser::ConvertPopupToTabbedBrowser() { | 1648 void Browser::ConvertPopupToTabbedBrowser() { |
1648 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); | 1649 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
1649 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1650 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
1650 TabContentsWrapper* contents = | 1651 TabContentsWrapper* contents = |
1651 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1652 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
1652 Browser* browser = Browser::Create(profile_); | 1653 Browser* browser = Browser::Create(profile_); |
1653 browser->tabstrip_model()->AppendTabContents(contents, true); | 1654 browser->tabstrip_model()->AppendTabContents(contents, true); |
1654 browser->window()->Show(); | 1655 browser->window()->Show(); |
1655 } | 1656 } |
1656 | 1657 |
1657 void Browser::ToggleFullscreenMode() { | 1658 // TODO(koz): Change |for_tab| to an enum. |
| 1659 void Browser::ToggleFullscreenMode(bool for_tab) { |
| 1660 bool entering_fullscreen = !window_->IsFullscreen(); |
| 1661 |
1658 #if !defined(OS_MACOSX) | 1662 #if !defined(OS_MACOSX) |
1659 // In kiosk mode, we always want to be fullscreen. When the browser first | 1663 // In kiosk mode, we always want to be fullscreen. When the browser first |
1660 // starts we're not yet fullscreen, so let the initial toggle go through. | 1664 // starts we're not yet fullscreen, so let the initial toggle go through. |
1661 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 1665 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
1662 window_->IsFullscreen()) | 1666 window_->IsFullscreen()) |
1663 return; | 1667 return; |
1664 #endif | 1668 #endif |
1665 | 1669 |
1666 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | 1670 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
1667 window_->SetFullscreen(!window_->IsFullscreen()); | 1671 GURL url; |
| 1672 bool ask_permission = false; |
| 1673 if (for_tab) { |
| 1674 url = GetSelectedTabContents()->GetURL(); |
| 1675 ask_permission = !url.SchemeIsFile() && |
| 1676 (GetFullscreenSetting(url) == CONTENT_SETTING_ASK); |
| 1677 } |
| 1678 if (entering_fullscreen) { |
| 1679 window_->EnterFullscreen(url, ask_permission); |
| 1680 } else { |
| 1681 window_->ExitFullscreen(); |
| 1682 } |
1668 | 1683 |
1669 // Once the window has become fullscreen it'll call back to | 1684 // Once the window has become fullscreen it'll call back to |
1670 // WindowFullscreenStateChanged(). We don't do this immediately as | 1685 // WindowFullscreenStateChanged(). We don't do this immediately as |
1671 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the | 1686 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
1672 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 1687 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
1673 | 1688 |
1674 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 1689 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
1675 // the necessary state of the frame. | 1690 // the necessary state of the frame. |
1676 #if defined(OS_MACOSX) | 1691 #if defined(OS_MACOSX) |
1677 WindowFullscreenStateChanged(); | 1692 WindowFullscreenStateChanged(); |
1678 #endif | 1693 #endif |
1679 } | 1694 } |
1680 | 1695 |
1681 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | 1696 void Browser::NotifyTabOfFullscreenExitIfNecessary() { |
1682 if (fullscreened_tab_) | 1697 if (fullscreened_tab_) |
1683 fullscreened_tab_->ExitFullscreenMode(); | 1698 fullscreened_tab_->ExitFullscreenMode(); |
1684 fullscreened_tab_ = NULL; | 1699 fullscreened_tab_ = NULL; |
1685 tab_caused_fullscreen_ = false; | 1700 tab_caused_fullscreen_ = false; |
1686 } | 1701 } |
1687 | 1702 |
1688 #if defined(OS_MACOSX) | 1703 #if defined(OS_MACOSX) |
1689 void Browser::TogglePresentationMode() { | 1704 void Browser::TogglePresentationMode(bool for_tab) { |
1690 window_->SetPresentationMode(!window_->InPresentationMode()); | 1705 bool entering_fullscreen = !window_->InPresentationMode(); |
| 1706 GURL url; |
| 1707 bool ask_permission = false; |
| 1708 if (for_tab) { |
| 1709 url = GetSelectedTabContents()->GetURL(); |
| 1710 ask_permission = !url.SchemeIsFile() && |
| 1711 (GetFullscreenSetting(url) == CONTENT_SETTING_ASK); |
| 1712 } |
| 1713 window_->SetPresentationMode(entering_fullscreen, url, ask_permission); |
1691 WindowFullscreenStateChanged(); | 1714 WindowFullscreenStateChanged(); |
1692 } | 1715 } |
1693 #endif | 1716 #endif |
1694 | 1717 |
1695 #if defined(OS_CHROMEOS) | 1718 #if defined(OS_CHROMEOS) |
1696 void Browser::Search() { | 1719 void Browser::Search() { |
1697 // Exit fullscreen to show omnibox. | 1720 // Exit fullscreen to show omnibox. |
1698 if (window_->IsFullscreen()) { | 1721 if (window_->IsFullscreen()) { |
1699 ToggleFullscreenMode(); | 1722 ToggleFullscreenMode(false); |
1700 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1723 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
1701 // visible at this point. Wait for next event cycle which toggles | 1724 // visible at this point. Wait for next event cycle which toggles |
1702 // the visibility of omnibox before creating new tab. | 1725 // the visibility of omnibox before creating new tab. |
1703 MessageLoop::current()->PostTask( | 1726 MessageLoop::current()->PostTask( |
1704 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); | 1727 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); |
1705 return; | 1728 return; |
1706 } | 1729 } |
1707 | 1730 |
1708 const GURL& url = GetSelectedTabContents()->GetURL(); | 1731 const GURL& url = GetSelectedTabContents()->GetURL(); |
1709 if (url.SchemeIs(chrome::kChromeUIScheme) && | 1732 if (url.SchemeIs(chrome::kChromeUIScheme) && |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 case IDC_SELECT_TAB_4: | 2639 case IDC_SELECT_TAB_4: |
2617 case IDC_SELECT_TAB_5: | 2640 case IDC_SELECT_TAB_5: |
2618 case IDC_SELECT_TAB_6: | 2641 case IDC_SELECT_TAB_6: |
2619 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); | 2642 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
2620 break; | 2643 break; |
2621 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; | 2644 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
2622 case IDC_DUPLICATE_TAB: DuplicateTab(); break; | 2645 case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
2623 case IDC_RESTORE_TAB: RestoreTab(); break; | 2646 case IDC_RESTORE_TAB: RestoreTab(); break; |
2624 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; | 2647 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
2625 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; | 2648 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
2626 case IDC_FULLSCREEN: ToggleFullscreenMode(); break; | 2649 case IDC_FULLSCREEN: ToggleFullscreenMode(false); break; |
2627 #if defined(OS_MACOSX) | 2650 #if defined(OS_MACOSX) |
2628 case IDC_PRESENTATION_MODE: TogglePresentationMode(); break; | 2651 case IDC_PRESENTATION_MODE: TogglePresentationMode(false); break; |
2629 #endif | 2652 #endif |
2630 case IDC_EXIT: Exit(); break; | 2653 case IDC_EXIT: Exit(); break; |
2631 #if defined(OS_CHROMEOS) | 2654 #if defined(OS_CHROMEOS) |
2632 case IDC_SEARCH: Search(); break; | 2655 case IDC_SEARCH: Search(); break; |
2633 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; | 2656 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
2634 #endif | 2657 #endif |
2635 | 2658 |
2636 // Page-related commands | 2659 // Page-related commands |
2637 case IDC_SAVE_PAGE: SavePage(); break; | 2660 case IDC_SAVE_PAGE: SavePage(); break; |
2638 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; | 2661 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3800 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); | 3823 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); |
3801 #else | 3824 #else |
3802 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); | 3825 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); |
3803 #endif | 3826 #endif |
3804 if (!in_correct_mode_for_tab_fullscreen) | 3827 if (!in_correct_mode_for_tab_fullscreen) |
3805 tab_caused_fullscreen_ = true; | 3828 tab_caused_fullscreen_ = true; |
3806 } | 3829 } |
3807 | 3830 |
3808 if (tab_caused_fullscreen_) { | 3831 if (tab_caused_fullscreen_) { |
3809 #if defined(OS_MACOSX) | 3832 #if defined(OS_MACOSX) |
3810 TogglePresentationMode(); | 3833 TogglePresentationMode(true); |
3811 #else | 3834 #else |
3812 ToggleFullscreenMode(); | 3835 ToggleFullscreenMode(true); |
3813 #endif | 3836 #endif |
3814 } else if (!enter_fullscreen) { | 3837 } else if (!enter_fullscreen) { |
3815 // If currently there is a tab in "tab fullscreen" mode and fullscreen was | 3838 // If currently there is a tab in "tab fullscreen" mode and fullscreen was |
3816 // not caused by it (i.e., previously it was in "browser fullscreen" mode), | 3839 // not caused by it (i.e., previously it was in "browser fullscreen" mode), |
3817 // we need to switch back to "browser fullscreen" mode. In this case, all we | 3840 // we need to switch back to "browser fullscreen" mode. In this case, all we |
3818 // have to do is notifying the tab that it has exited "tab fullscreen" mode. | 3841 // have to do is notifying the tab that it has exited "tab fullscreen" mode. |
3819 NotifyTabOfFullscreenExitIfNecessary(); | 3842 NotifyTabOfFullscreenExitIfNecessary(); |
3820 } | 3843 } |
3821 } | 3844 } |
3822 | 3845 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3878 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3901 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
3879 active_match_ordinal, final_update); | 3902 active_match_ordinal, final_update); |
3880 } | 3903 } |
3881 | 3904 |
3882 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3905 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
3883 CrashedPluginHelper(tab, plugin_path); | 3906 CrashedPluginHelper(tab, plugin_path); |
3884 } | 3907 } |
3885 | 3908 |
3886 void Browser::ExitTabbedFullscreenModeIfNecessary() { | 3909 void Browser::ExitTabbedFullscreenModeIfNecessary() { |
3887 if (tab_caused_fullscreen_) | 3910 if (tab_caused_fullscreen_) |
3888 ToggleFullscreenMode(); | 3911 ToggleFullscreenMode(false); |
3889 else | 3912 else |
3890 NotifyTabOfFullscreenExitIfNecessary(); | 3913 NotifyTabOfFullscreenExitIfNecessary(); |
3891 } | 3914 } |
3892 | 3915 |
3893 void Browser::UpdatePreferredSize(TabContents* source, | 3916 void Browser::UpdatePreferredSize(TabContents* source, |
3894 const gfx::Size& pref_size) { | 3917 const gfx::Size& pref_size) { |
3895 window_->UpdatePreferredSize(source, pref_size); | 3918 window_->UpdatePreferredSize(source, pref_size); |
3896 } | 3919 } |
3897 | 3920 |
| 3921 void Browser::OnAcceptFullscreenPermission(const GURL& url) { |
| 3922 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); |
| 3923 |
| 3924 settings_map->SetContentSetting( |
| 3925 ContentSettingsPattern::FromString(url.host()), |
| 3926 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 3927 std::string(), CONTENT_SETTING_ALLOW); |
| 3928 } |
| 3929 |
| 3930 void Browser::OnDenyFullscreenPermission() { |
| 3931 ExitTabbedFullscreenModeIfNecessary(); |
| 3932 } |
| 3933 |
| 3934 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { |
| 3935 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); |
| 3936 return settings_map->GetContentSetting(url, url, |
| 3937 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); |
| 3938 } |
| 3939 |
3898 /////////////////////////////////////////////////////////////////////////////// | 3940 /////////////////////////////////////////////////////////////////////////////// |
3899 // Browser, TabContentsWrapperDelegate implementation: | 3941 // Browser, TabContentsWrapperDelegate implementation: |
3900 | 3942 |
3901 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3943 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
3902 int32 page_id) { | 3944 int32 page_id) { |
3903 if (GetSelectedTabContentsWrapper() != source) | 3945 if (GetSelectedTabContentsWrapper() != source) |
3904 return; | 3946 return; |
3905 | 3947 |
3906 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3948 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
3907 if (!entry || (entry->page_id() != page_id)) | 3949 if (!entry || (entry->page_id() != page_id)) |
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5319 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5361 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
5320 } else if (is_type_tabbed()) { | 5362 } else if (is_type_tabbed()) { |
5321 GlobalErrorService* service = | 5363 GlobalErrorService* service = |
5322 GlobalErrorServiceFactory::GetForProfile(profile()); | 5364 GlobalErrorServiceFactory::GetForProfile(profile()); |
5323 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5365 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
5324 if (error) { | 5366 if (error) { |
5325 error->ShowBubbleView(this); | 5367 error->ShowBubbleView(this); |
5326 } | 5368 } |
5327 } | 5369 } |
5328 } | 5370 } |
OLD | NEW |