diff options
Diffstat (limited to 'chrome/browser/browser.cc')
-rw-r--r-- | chrome/browser/browser.cc | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 78d43ba..70926bb 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -126,6 +126,22 @@ bool TabHasUnloadListener(TabContents* contents) { !contents->render_view_host()->SuddenTerminationAllowed(); } +// Returns true if two URLs are equal ignoring their ref (hash fragment). +static bool CompareURLsIgnoreRef(const GURL& url, const GURL& other) { + if (url == other) + return true; + // If neither has a ref than there is no point in stripping the refs and + // the URLs are different since the comparison failed in the previous if + // statement. + if (!url.has_ref() && !other.has_ref()) + return false; + url_canon::Replacements<char> replacements; + replacements.ClearRef(); + GURL url_no_ref = url.ReplaceComponents(replacements); + GURL other_no_ref = other.ReplaceComponents(replacements); + return url_no_ref == other_no_ref; +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -696,11 +712,11 @@ bool Browser::CanRestoreTab() { return service && !service->entries().empty(); } -void Browser::ShowSingleDOMUITab(const GURL& url) { +void Browser::ShowSingletonTab(const GURL& url) { // See if we already have a tab with the given URL and select it if so. for (int i = 0; i < tabstrip_model_.count(); i++) { TabContents* tc = tabstrip_model_.GetTabContentsAt(i); - if (tc->GetURL() == url) { + if (CompareURLsIgnoreRef(tc->GetURL(), url)) { tabstrip_model_.SelectTabContentsAt(i, false); return; } @@ -1265,17 +1281,17 @@ void Browser::ShowPageMenu() { void Browser::ShowHistoryTab() { UserMetrics::RecordAction("ShowHistory", profile_); - ShowSingleDOMUITab(GURL(chrome::kChromeUIHistoryURL)); + ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL)); } void Browser::ShowDownloadsTab() { UserMetrics::RecordAction("ShowDownloads", profile_); - ShowSingleDOMUITab(GURL(chrome::kChromeUIDownloadsURL)); + ShowSingletonTab(GURL(chrome::kChromeUIDownloadsURL)); } void Browser::ShowExtensionsTab() { UserMetrics::RecordAction("ShowExtensions", profile_); - ShowSingleDOMUITab(GURL(chrome::kChromeUIExtensionsURL)); + ShowSingletonTab(GURL(chrome::kChromeUIExtensionsURL)); } void Browser::OpenClearBrowsingDataDialog() { @@ -3060,7 +3076,7 @@ void Browser::OpenURLAtIndex(TabContents* source, disposition = NEW_FOREGROUND_TAB; if (disposition == SINGLETON_TAB) { - ShowSingleDOMUITab(url); + ShowSingletonTab(url); return; } else if (disposition == NEW_WINDOW) { Browser* browser = Browser::Create(profile_); |