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_service.h" | 43 #include "chrome/browser/download/download_service.h" |
| 43 #include "chrome/browser/download/download_service_factory.h" | 44 #include "chrome/browser/download/download_service_factory.h" |
| 44 #include "chrome/browser/download/download_started_animation.h" | 45 #include "chrome/browser/download/download_started_animation.h" |
| 45 #include "chrome/browser/extensions/crx_installer.h" | 46 #include "chrome/browser/extensions/crx_installer.h" |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 browser::Navigate(¶ms); | 734 browser::Navigate(¶ms); |
| 734 contents = params.target_contents->tab_contents(); | 735 contents = params.target_contents->tab_contents(); |
| 735 } | 736 } |
| 736 | 737 |
| 737 // TODO(skerner): If we are already in full screen mode, and the user | 738 // TODO(skerner): If we are already in full screen mode, and the user |
| 738 // set the app to open as a regular or pinned tab, what should happen? | 739 // set the app to open as a regular or pinned tab, what should happen? |
| 739 // Today we open the tab, but stay in full screen mode. Should we leave | 740 // Today we open the tab, but stay in full screen mode. Should we leave |
| 740 // full screen mode in this case? | 741 // full screen mode in this case? |
| 741 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && | 742 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
| 742 !browser->window()->IsFullscreen()) | 743 !browser->window()->IsFullscreen()) |
| 743 browser->ToggleFullscreenMode(); | 744 browser->ToggleFullscreenMode(false); |
| 744 | 745 |
| 745 return contents; | 746 return contents; |
| 746 } | 747 } |
| 747 | 748 |
| 748 // static | 749 // static |
| 749 void Browser::OpenBookmarkManagerWindow(Profile* profile) { | 750 void Browser::OpenBookmarkManagerWindow(Profile* profile) { |
| 750 Browser* browser = Browser::Create(profile); | 751 Browser* browser = Browser::Create(profile); |
| 751 browser->OpenBookmarkManager(); | 752 browser->OpenBookmarkManager(); |
| 752 browser->window()->Show(); | 753 browser->window()->Show(); |
| 753 } | 754 } |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1629 void Browser::ConvertPopupToTabbedBrowser() { | 1630 void Browser::ConvertPopupToTabbedBrowser() { |
| 1630 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); | 1631 UserMetrics::RecordAction(UserMetricsAction("ShowAsTab")); |
| 1631 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); | 1632 int tab_strip_index = tab_handler_->GetTabStripModel()->active_index(); |
| 1632 TabContentsWrapper* contents = | 1633 TabContentsWrapper* contents = |
| 1633 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); | 1634 tab_handler_->GetTabStripModel()->DetachTabContentsAt(tab_strip_index); |
| 1634 Browser* browser = Browser::Create(profile_); | 1635 Browser* browser = Browser::Create(profile_); |
| 1635 browser->tabstrip_model()->AppendTabContents(contents, true); | 1636 browser->tabstrip_model()->AppendTabContents(contents, true); |
| 1636 browser->window()->Show(); | 1637 browser->window()->Show(); |
| 1637 } | 1638 } |
| 1638 | 1639 |
| 1639 void Browser::ToggleFullscreenMode() { | 1640 // TODO(koz): Change |for_tab| to an enum. |
| 1641 void Browser::ToggleFullscreenMode(bool for_tab) { | |
| 1642 bool entering_fullscreen = !window_->IsFullscreen(); | |
| 1643 | |
| 1640 #if !defined(OS_MACOSX) | 1644 #if !defined(OS_MACOSX) |
| 1641 // In kiosk mode, we always want to be fullscreen. When the browser first | 1645 // In kiosk mode, we always want to be fullscreen. When the browser first |
| 1642 // starts we're not yet fullscreen, so let the initial toggle go through. | 1646 // starts we're not yet fullscreen, so let the initial toggle go through. |
| 1643 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && | 1647 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode) && |
| 1644 window_->IsFullscreen()) | 1648 window_->IsFullscreen()) |
| 1645 return; | 1649 return; |
| 1646 #endif | 1650 #endif |
| 1647 | 1651 |
| 1648 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); | 1652 UserMetrics::RecordAction(UserMetricsAction("ToggleFullscreen")); |
| 1649 window_->SetFullscreen(!window_->IsFullscreen()); | 1653 GURL url; |
| 1654 bool ask_permission = false; | |
| 1655 if (for_tab) { | |
| 1656 url = GetSelectedTabContents()->GetURL(); | |
| 1657 ask_permission = !url.SchemeIsFile() && | |
| 1658 (GetFullscreenSetting(url) == CONTENT_SETTING_ASK); | |
| 1659 } | |
| 1660 if (entering_fullscreen) { | |
|
Peter Kasting
2011/10/13 23:48:06
Nit: No {}
koz (OOO until 15th September)
2011/10/14 00:35:16
Done.
| |
| 1661 window_->EnterFullscreen(url, ask_permission); | |
| 1662 } else { | |
| 1663 window_->ExitFullscreen(); | |
| 1664 } | |
| 1650 | 1665 |
| 1651 // Once the window has become fullscreen it'll call back to | 1666 // Once the window has become fullscreen it'll call back to |
| 1652 // WindowFullscreenStateChanged(). We don't do this immediately as | 1667 // WindowFullscreenStateChanged(). We don't do this immediately as |
| 1653 // BrowserWindow::SetFullscreen() asks for bookmark_bar_state_, so we let the | 1668 // BrowserWindow::EnterFullscreen() asks for bookmark_bar_state_, so we let |
| 1654 // BrowserWindow invoke WindowFullscreenStateChanged when appropriate. | 1669 // the BrowserWindow invoke WindowFullscreenStateChanged when appropriate. |
| 1655 | 1670 |
| 1656 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates | 1671 // TODO: convert mac to invoke WindowFullscreenStateChanged once it updates |
| 1657 // the necessary state of the frame. | 1672 // the necessary state of the frame. |
| 1658 #if defined(OS_MACOSX) | 1673 #if defined(OS_MACOSX) |
| 1659 WindowFullscreenStateChanged(); | 1674 WindowFullscreenStateChanged(); |
| 1660 #endif | 1675 #endif |
| 1661 } | 1676 } |
| 1662 | 1677 |
| 1663 void Browser::NotifyTabOfFullscreenExitIfNecessary() { | 1678 void Browser::NotifyTabOfFullscreenExitIfNecessary() { |
| 1664 if (fullscreened_tab_) | 1679 if (fullscreened_tab_) |
| 1665 fullscreened_tab_->ExitFullscreenMode(); | 1680 fullscreened_tab_->ExitFullscreenMode(); |
| 1666 fullscreened_tab_ = NULL; | 1681 fullscreened_tab_ = NULL; |
| 1667 tab_caused_fullscreen_ = false; | 1682 tab_caused_fullscreen_ = false; |
| 1668 } | 1683 } |
| 1669 | 1684 |
| 1670 #if defined(OS_MACOSX) | 1685 #if defined(OS_MACOSX) |
| 1671 void Browser::TogglePresentationMode() { | 1686 void Browser::TogglePresentationMode(bool for_tab) { |
| 1672 window_->SetPresentationMode(!window_->InPresentationMode()); | 1687 bool entering_fullscreen = !window_->InPresentationMode(); |
| 1688 GURL url; | |
| 1689 bool ask_permission = false; | |
| 1690 if (for_tab) { | |
| 1691 url = GetSelectedTabContents()->GetURL(); | |
| 1692 ask_permission = !url.SchemeIsFile() && | |
| 1693 (GetFullscreenSetting(url) == CONTENT_SETTING_ASK); | |
| 1694 } | |
| 1695 window_->SetPresentationMode(entering_fullscreen, url, ask_permission); | |
| 1673 WindowFullscreenStateChanged(); | 1696 WindowFullscreenStateChanged(); |
| 1674 } | 1697 } |
| 1675 #endif | 1698 #endif |
| 1676 | 1699 |
| 1677 #if defined(OS_CHROMEOS) | 1700 #if defined(OS_CHROMEOS) |
| 1678 void Browser::Search() { | 1701 void Browser::Search() { |
| 1679 // Exit fullscreen to show omnibox. | 1702 // Exit fullscreen to show omnibox. |
| 1680 if (window_->IsFullscreen()) { | 1703 if (window_->IsFullscreen()) { |
| 1681 ToggleFullscreenMode(); | 1704 ToggleFullscreenMode(false); |
| 1682 // ToggleFullscreenMode is asynchronous, so we don't have omnibox | 1705 // ToggleFullscreenMode is asynchronous, so we don't have omnibox |
| 1683 // visible at this point. Wait for next event cycle which toggles | 1706 // visible at this point. Wait for next event cycle which toggles |
| 1684 // the visibility of omnibox before creating new tab. | 1707 // the visibility of omnibox before creating new tab. |
| 1685 MessageLoop::current()->PostTask( | 1708 MessageLoop::current()->PostTask( |
| 1686 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); | 1709 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::Search)); |
| 1687 return; | 1710 return; |
| 1688 } | 1711 } |
| 1689 | 1712 |
| 1690 const GURL& url = GetSelectedTabContents()->GetURL(); | 1713 const GURL& url = GetSelectedTabContents()->GetURL(); |
| 1691 if (url.SchemeIs(chrome::kChromeUIScheme) && | 1714 if (url.SchemeIs(chrome::kChromeUIScheme) && |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2598 case IDC_SELECT_TAB_4: | 2621 case IDC_SELECT_TAB_4: |
| 2599 case IDC_SELECT_TAB_5: | 2622 case IDC_SELECT_TAB_5: |
| 2600 case IDC_SELECT_TAB_6: | 2623 case IDC_SELECT_TAB_6: |
| 2601 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); | 2624 case IDC_SELECT_TAB_7: SelectNumberedTab(id - IDC_SELECT_TAB_0); |
| 2602 break; | 2625 break; |
| 2603 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; | 2626 case IDC_SELECT_LAST_TAB: SelectLastTab(); break; |
| 2604 case IDC_DUPLICATE_TAB: DuplicateTab(); break; | 2627 case IDC_DUPLICATE_TAB: DuplicateTab(); break; |
| 2605 case IDC_RESTORE_TAB: RestoreTab(); break; | 2628 case IDC_RESTORE_TAB: RestoreTab(); break; |
| 2606 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; | 2629 case IDC_COPY_URL: WriteCurrentURLToClipboard(); break; |
| 2607 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; | 2630 case IDC_SHOW_AS_TAB: ConvertPopupToTabbedBrowser(); break; |
| 2608 case IDC_FULLSCREEN: ToggleFullscreenMode(); break; | 2631 case IDC_FULLSCREEN: ToggleFullscreenMode(false); break; |
| 2609 #if defined(OS_MACOSX) | 2632 #if defined(OS_MACOSX) |
| 2610 case IDC_PRESENTATION_MODE: TogglePresentationMode(); break; | 2633 case IDC_PRESENTATION_MODE: TogglePresentationMode(false); break; |
| 2611 #endif | 2634 #endif |
| 2612 case IDC_EXIT: Exit(); break; | 2635 case IDC_EXIT: Exit(); break; |
| 2613 #if defined(OS_CHROMEOS) | 2636 #if defined(OS_CHROMEOS) |
| 2614 case IDC_SEARCH: Search(); break; | 2637 case IDC_SEARCH: Search(); break; |
| 2615 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; | 2638 case IDC_SHOW_KEYBOARD_OVERLAY: ShowKeyboardOverlay(); break; |
| 2616 #endif | 2639 #endif |
| 2617 | 2640 |
| 2618 // Page-related commands | 2641 // Page-related commands |
| 2619 case IDC_SAVE_PAGE: SavePage(); break; | 2642 case IDC_SAVE_PAGE: SavePage(); break; |
| 2620 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; | 2643 case IDC_BOOKMARK_PAGE: BookmarkCurrentPage(); break; |
| (...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3774 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); | 3797 in_correct_mode_for_tab_fullscreen = window_->InPresentationMode(); |
| 3775 #else | 3798 #else |
| 3776 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); | 3799 in_correct_mode_for_tab_fullscreen = window_->IsFullscreen(); |
| 3777 #endif | 3800 #endif |
| 3778 if (!in_correct_mode_for_tab_fullscreen) | 3801 if (!in_correct_mode_for_tab_fullscreen) |
| 3779 tab_caused_fullscreen_ = true; | 3802 tab_caused_fullscreen_ = true; |
| 3780 } | 3803 } |
| 3781 | 3804 |
| 3782 if (tab_caused_fullscreen_) { | 3805 if (tab_caused_fullscreen_) { |
| 3783 #if defined(OS_MACOSX) | 3806 #if defined(OS_MACOSX) |
| 3784 TogglePresentationMode(); | 3807 TogglePresentationMode(true); |
| 3785 #else | 3808 #else |
| 3786 ToggleFullscreenMode(); | 3809 ToggleFullscreenMode(true); |
| 3787 #endif | 3810 #endif |
| 3788 } else if (!enter_fullscreen) { | 3811 } else if (!enter_fullscreen) { |
| 3789 // If currently there is a tab in "tab fullscreen" mode and fullscreen was | 3812 // If currently there is a tab in "tab fullscreen" mode and fullscreen was |
| 3790 // not caused by it (i.e., previously it was in "browser fullscreen" mode), | 3813 // not caused by it (i.e., previously it was in "browser fullscreen" mode), |
| 3791 // we need to switch back to "browser fullscreen" mode. In this case, all we | 3814 // we need to switch back to "browser fullscreen" mode. In this case, all we |
| 3792 // have to do is notifying the tab that it has exited "tab fullscreen" mode. | 3815 // have to do is notifying the tab that it has exited "tab fullscreen" mode. |
| 3793 NotifyTabOfFullscreenExitIfNecessary(); | 3816 NotifyTabOfFullscreenExitIfNecessary(); |
| 3794 } | 3817 } |
| 3795 } | 3818 } |
| 3796 | 3819 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3852 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, | 3875 FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 3853 active_match_ordinal, final_update); | 3876 active_match_ordinal, final_update); |
| 3854 } | 3877 } |
| 3855 | 3878 |
| 3856 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { | 3879 void Browser::CrashedPlugin(TabContents* tab, const FilePath& plugin_path) { |
| 3857 CrashedPluginHelper(tab, plugin_path); | 3880 CrashedPluginHelper(tab, plugin_path); |
| 3858 } | 3881 } |
| 3859 | 3882 |
| 3860 void Browser::ExitTabbedFullscreenModeIfNecessary() { | 3883 void Browser::ExitTabbedFullscreenModeIfNecessary() { |
| 3861 if (tab_caused_fullscreen_) | 3884 if (tab_caused_fullscreen_) |
| 3862 ToggleFullscreenMode(); | 3885 ToggleFullscreenMode(false); |
| 3863 else | 3886 else |
| 3864 NotifyTabOfFullscreenExitIfNecessary(); | 3887 NotifyTabOfFullscreenExitIfNecessary(); |
| 3865 } | 3888 } |
| 3866 | 3889 |
| 3867 void Browser::UpdatePreferredSize(TabContents* source, | 3890 void Browser::UpdatePreferredSize(TabContents* source, |
| 3868 const gfx::Size& pref_size) { | 3891 const gfx::Size& pref_size) { |
| 3869 window_->UpdatePreferredSize(source, pref_size); | 3892 window_->UpdatePreferredSize(source, pref_size); |
| 3870 } | 3893 } |
| 3871 | 3894 |
| 3895 void Browser::OnAcceptFullscreenPermission(const GURL& url) { | |
| 3896 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 3897 | |
| 3898 settings_map->SetContentSetting( | |
| 3899 ContentSettingsPattern::FromString(url.host()), | |
| 3900 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_FULLSCREEN, | |
| 3901 std::string(), CONTENT_SETTING_ALLOW); | |
| 3902 } | |
| 3903 | |
| 3904 void Browser::OnDenyFullscreenPermission() { | |
| 3905 ExitTabbedFullscreenModeIfNecessary(); | |
| 3906 } | |
| 3907 | |
| 3908 ContentSetting Browser::GetFullscreenSetting(const GURL& url) { | |
| 3909 HostContentSettingsMap* settings_map = profile()->GetHostContentSettingsMap(); | |
| 3910 return settings_map->GetContentSetting(url, url, | |
| 3911 CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()); | |
| 3912 } | |
| 3913 | |
| 3872 /////////////////////////////////////////////////////////////////////////////// | 3914 /////////////////////////////////////////////////////////////////////////////// |
| 3873 // Browser, TabContentsWrapperDelegate implementation: | 3915 // Browser, TabContentsWrapperDelegate implementation: |
| 3874 | 3916 |
| 3875 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, | 3917 void Browser::OnDidGetApplicationInfo(TabContentsWrapper* source, |
| 3876 int32 page_id) { | 3918 int32 page_id) { |
| 3877 if (GetSelectedTabContentsWrapper() != source) | 3919 if (GetSelectedTabContentsWrapper() != source) |
| 3878 return; | 3920 return; |
| 3879 | 3921 |
| 3880 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); | 3922 NavigationEntry* entry = source->controller().GetLastCommittedEntry(); |
| 3881 if (!entry || (entry->page_id() != page_id)) | 3923 if (!entry || (entry->page_id() != page_id)) |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5276 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); | 5318 window_->GetLocationBar()->ShowFirstRunBubble(bubble_type); |
| 5277 } else if (is_type_tabbed()) { | 5319 } else if (is_type_tabbed()) { |
| 5278 GlobalErrorService* service = | 5320 GlobalErrorService* service = |
| 5279 GlobalErrorServiceFactory::GetForProfile(profile()); | 5321 GlobalErrorServiceFactory::GetForProfile(profile()); |
| 5280 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); | 5322 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 5281 if (error) { | 5323 if (error) { |
| 5282 error->ShowBubbleView(this); | 5324 error->ShowBubbleView(this); |
| 5283 } | 5325 } |
| 5284 } | 5326 } |
| 5285 } | 5327 } |
| OLD | NEW |