| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif // OS_WIN | 10 #endif // OS_WIN |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 bool Browser::NavigateToIndexWithDisposition(int index, | 1030 bool Browser::NavigateToIndexWithDisposition(int index, |
| 1031 WindowOpenDisposition disp) { | 1031 WindowOpenDisposition disp) { |
| 1032 NavigationController& controller = | 1032 NavigationController& controller = |
| 1033 GetOrCloneTabForDisposition(disp)->controller(); | 1033 GetOrCloneTabForDisposition(disp)->controller(); |
| 1034 if (index < 0 || index >= controller.entry_count()) | 1034 if (index < 0 || index >= controller.entry_count()) |
| 1035 return false; | 1035 return false; |
| 1036 controller.GoToIndex(index); | 1036 controller.GoToIndex(index); |
| 1037 return true; | 1037 return true; |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 void Browser::ShowSingletonTab(const GURL& url) { | 1040 void Browser::ShowSingletonTab(const GURL& url, bool ignore_path) { |
| 1041 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); | 1041 browser::NavigateParams params(this, url, PageTransition::AUTO_BOOKMARK); |
| 1042 params.disposition = SINGLETON_TAB; | 1042 params.disposition = SINGLETON_TAB; |
| 1043 params.show_window = true; | 1043 params.show_window = true; |
| 1044 params.ignore_path = ignore_path; |
| 1044 browser::Navigate(¶ms); | 1045 browser::Navigate(¶ms); |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { | 1048 void Browser::UpdateCommandsForFullscreenMode(bool is_fullscreen) { |
| 1048 #if !defined(OS_MACOSX) | 1049 #if !defined(OS_MACOSX) |
| 1049 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; | 1050 const bool show_main_ui = (type() == TYPE_NORMAL) && !is_fullscreen; |
| 1050 #else | 1051 #else |
| 1051 const bool show_main_ui = (type() == TYPE_NORMAL); | 1052 const bool show_main_ui = (type() == TYPE_NORMAL); |
| 1052 #endif | 1053 #endif |
| 1053 | 1054 |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 ShowBookmarkManagerTab(); | 1715 ShowBookmarkManagerTab(); |
| 1715 } | 1716 } |
| 1716 | 1717 |
| 1717 void Browser::ShowAppMenu() { | 1718 void Browser::ShowAppMenu() { |
| 1718 UserMetrics::RecordAction(UserMetricsAction("ShowAppMenu"), profile_); | 1719 UserMetrics::RecordAction(UserMetricsAction("ShowAppMenu"), profile_); |
| 1719 window_->ShowAppMenu(); | 1720 window_->ShowAppMenu(); |
| 1720 } | 1721 } |
| 1721 | 1722 |
| 1722 void Browser::ShowBookmarkManagerTab() { | 1723 void Browser::ShowBookmarkManagerTab() { |
| 1723 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarks"), profile_); | 1724 UserMetrics::RecordAction(UserMetricsAction("ShowBookmarks"), profile_); |
| 1724 ShowSingletonTab(GURL(chrome::kChromeUIBookmarksURL)); | 1725 ShowSingletonTab(GURL(chrome::kChromeUIBookmarksURL), false); |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 void Browser::ShowHistoryTab() { | 1728 void Browser::ShowHistoryTab() { |
| 1728 UserMetrics::RecordAction(UserMetricsAction("ShowHistory"), profile_); | 1729 UserMetrics::RecordAction(UserMetricsAction("ShowHistory"), profile_); |
| 1729 ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL)); | 1730 ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL), false); |
| 1730 } | 1731 } |
| 1731 | 1732 |
| 1732 void Browser::ShowDownloadsTab() { | 1733 void Browser::ShowDownloadsTab() { |
| 1733 UserMetrics::RecordAction(UserMetricsAction("ShowDownloads"), profile_); | 1734 UserMetrics::RecordAction(UserMetricsAction("ShowDownloads"), profile_); |
| 1734 ShowSingletonTab(GURL(chrome::kChromeUIDownloadsURL)); | 1735 ShowSingletonTab(GURL(chrome::kChromeUIDownloadsURL), false); |
| 1735 } | 1736 } |
| 1736 | 1737 |
| 1737 void Browser::ShowExtensionsTab() { | 1738 void Browser::ShowExtensionsTab() { |
| 1738 UserMetrics::RecordAction(UserMetricsAction("ShowExtensions"), profile_); | 1739 UserMetrics::RecordAction(UserMetricsAction("ShowExtensions"), profile_); |
| 1739 ShowSingletonTab(GURL(chrome::kChromeUIExtensionsURL)); | 1740 ShowSingletonTab(GURL(chrome::kChromeUIExtensionsURL), false); |
| 1740 } | 1741 } |
| 1741 | 1742 |
| 1742 void Browser::ShowAboutConflictsTab() { | 1743 void Browser::ShowAboutConflictsTab() { |
| 1743 UserMetrics::RecordAction(UserMetricsAction("AboutConflicts"), profile_); | 1744 UserMetrics::RecordAction(UserMetricsAction("AboutConflicts"), profile_); |
| 1744 ShowSingletonTab(GURL(chrome::kChromeUIConflictsURL)); | 1745 ShowSingletonTab(GURL(chrome::kChromeUIConflictsURL), false); |
| 1745 } | 1746 } |
| 1746 | 1747 |
| 1747 void Browser::ShowBrokenPageTab(TabContents* contents) { | 1748 void Browser::ShowBrokenPageTab(TabContents* contents) { |
| 1748 UserMetrics::RecordAction(UserMetricsAction("ReportBug"), profile_); | 1749 UserMetrics::RecordAction(UserMetricsAction("ReportBug"), profile_); |
| 1749 string16 page_title = contents->GetTitle(); | 1750 string16 page_title = contents->GetTitle(); |
| 1750 NavigationEntry* entry = contents->controller().GetActiveEntry(); | 1751 NavigationEntry* entry = contents->controller().GetActiveEntry(); |
| 1751 if (!entry) | 1752 if (!entry) |
| 1752 return; | 1753 return; |
| 1753 std::string page_url = entry->url().spec(); | 1754 std::string page_url = entry->url().spec(); |
| 1754 std::vector<std::string> subst; | 1755 std::vector<std::string> subst; |
| 1755 subst.push_back(UTF16ToASCII(page_title)); | 1756 subst.push_back(UTF16ToASCII(page_title)); |
| 1756 subst.push_back(page_url); | 1757 subst.push_back(page_url); |
| 1757 std::string report_page_url = | 1758 std::string report_page_url = |
| 1758 ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); | 1759 ReplaceStringPlaceholders(kBrokenPageUrl, subst, NULL); |
| 1759 ShowSingletonTab(GURL(report_page_url)); | 1760 ShowSingletonTab(GURL(report_page_url), false); |
| 1760 } | 1761 } |
| 1761 | 1762 |
| 1762 void Browser::ShowOptionsTab(const std::string& sub_page) { | 1763 void Browser::ShowOptionsTab(const std::string& sub_page) { |
| 1763 GURL url(chrome::kChromeUISettingsURL + sub_page); | 1764 GURL url(chrome::kChromeUISettingsURL + sub_page); |
| 1764 | 1765 ShowSingletonTab(url, true); |
| 1765 // See if there is already an options tab open that we can use. | |
| 1766 TabStripModel* model = tab_handler_->GetTabStripModel(); | |
| 1767 for (int i = 0; i < model->count(); i++) { | |
| 1768 TabContents* tc = model->GetTabContentsAt(i); | |
| 1769 const GURL& tab_url = tc->GetURL(); | |
| 1770 | |
| 1771 if (tab_url.scheme() == url.scheme() && tab_url.host() == url.host()) { | |
| 1772 // We found an existing options tab, load the URL in this tab. (Note: | |
| 1773 // this may cause us to unnecessarily reload the same page. We can't | |
| 1774 // really detect that unless the options page is permitted to change the | |
| 1775 // URL in the address bar, but security policy doesn't allow that. | |
| 1776 browser::NavigateParams params(this, url, PageTransition::GENERATED); | |
| 1777 params.source_contents = tc; | |
| 1778 browser::Navigate(¶ms); | |
| 1779 model->SelectTabContentsAt(i, false); | |
| 1780 return; | |
| 1781 } | |
| 1782 } | |
| 1783 | |
| 1784 // No options tab found, so create a new one. | |
| 1785 AddSelectedTabWithURL(url, PageTransition::AUTO_BOOKMARK); | |
| 1786 } | 1766 } |
| 1787 | 1767 |
| 1788 void Browser::OpenClearBrowsingDataDialog() { | 1768 void Browser::OpenClearBrowsingDataDialog() { |
| 1789 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg"), | 1769 UserMetrics::RecordAction(UserMetricsAction("ClearBrowsingData_ShowDlg"), |
| 1790 profile_); | 1770 profile_); |
| 1791 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1771 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1792 switches::kEnableTabbedOptions)) { | 1772 switches::kEnableTabbedOptions)) { |
| 1793 ShowOptionsTab( | 1773 ShowOptionsTab( |
| 1794 chrome::kAdvancedOptionsSubPage + std::string(kHashMark) + | 1774 chrome::kAdvancedOptionsSubPage + std::string(kHashMark) + |
| 1795 chrome::kClearBrowserDataSubPage); | 1775 chrome::kClearBrowserDataSubPage); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1841 | 1821 |
| 1842 #if defined(ENABLE_REMOTING) | 1822 #if defined(ENABLE_REMOTING) |
| 1843 void Browser::OpenRemotingSetupDialog() { | 1823 void Browser::OpenRemotingSetupDialog() { |
| 1844 RemotingSetupFlow::OpenDialog(profile_); | 1824 RemotingSetupFlow::OpenDialog(profile_); |
| 1845 } | 1825 } |
| 1846 #endif | 1826 #endif |
| 1847 | 1827 |
| 1848 void Browser::OpenAboutChromeDialog() { | 1828 void Browser::OpenAboutChromeDialog() { |
| 1849 UserMetrics::RecordAction(UserMetricsAction("AboutChrome"), profile_); | 1829 UserMetrics::RecordAction(UserMetricsAction("AboutChrome"), profile_); |
| 1850 #if defined(OS_CHROMEOS) | 1830 #if defined(OS_CHROMEOS) |
| 1851 ShowSingletonTab(GURL(chrome::kChromeUIAboutURL)); | 1831 ShowSingletonTab(GURL(chrome::kChromeUIAboutURL), false); |
| 1852 #else | 1832 #else |
| 1853 window_->ShowAboutChromeDialog(); | 1833 window_->ShowAboutChromeDialog(); |
| 1854 #endif | 1834 #endif |
| 1855 } | 1835 } |
| 1856 | 1836 |
| 1857 void Browser::OpenUpdateChromeDialog() { | 1837 void Browser::OpenUpdateChromeDialog() { |
| 1858 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); | 1838 UserMetrics::RecordAction(UserMetricsAction("UpdateChrome"), profile_); |
| 1859 window_->ShowUpdateChromeDialog(); | 1839 window_->ShowUpdateChromeDialog(); |
| 1860 } | 1840 } |
| 1861 | 1841 |
| (...skipping 2231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4093 NOTREACHED(); | 4073 NOTREACHED(); |
| 4094 return false; | 4074 return false; |
| 4095 } | 4075 } |
| 4096 | 4076 |
| 4097 void Browser::CreateInstantIfNecessary() { | 4077 void Browser::CreateInstantIfNecessary() { |
| 4098 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && | 4078 if (type() == TYPE_NORMAL && InstantController::IsEnabled(profile()) && |
| 4099 !profile()->IsOffTheRecord()) { | 4079 !profile()->IsOffTheRecord()) { |
| 4100 instant_.reset(new InstantController(profile_, this)); | 4080 instant_.reset(new InstantController(profile_, this)); |
| 4101 } | 4081 } |
| 4102 } | 4082 } |
| OLD | NEW |