summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-31 00:10:31 +0000
committerarv@chromium.org <arv@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-31 00:10:31 +0000
commit71d6e77d7dfb71c8db3430e16f1777fb33ee2681 (patch)
treeecfc530e3ba0dd855f7208b69afd03e8e2658729
parentbe6fca6c1f6e90be5a1d513130433a2434fadf64 (diff)
downloadchromium_src-71d6e77d7dfb71c8db3430e16f1777fb33ee2681.zip
chromium_src-71d6e77d7dfb71c8db3430e16f1777fb33ee2681.tar.gz
chromium_src-71d6e77d7dfb71c8db3430e16f1777fb33ee2681.tar.bz2
Ignore ref (hash fragment) in URL when opening singleton tabs based on URLs.
I renamed the method name in preparation of using this for opening the bookmark manager extension. BUG=None TEST=Open History. Do a search and open history again. We should not create a new tab but go to the existing one. Review URL: http://codereview.chromium.org/553151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37651 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/back_forward_menu_model.cc2
-rw-r--r--chrome/browser/browser.cc28
-rw-r--r--chrome/browser/browser.h8
3 files changed, 27 insertions, 11 deletions
diff --git a/chrome/browser/back_forward_menu_model.cc b/chrome/browser/back_forward_menu_model.cc
index 6ceede4..7d54e94 100644
--- a/chrome/browser/back_forward_menu_model.cc
+++ b/chrome/browser/back_forward_menu_model.cc
@@ -135,7 +135,7 @@ void BackForwardMenuModel::ActivatedAt(int index) {
if (index == GetItemCount() - 1) {
UserMetrics::RecordComputedAction(BuildActionName("ShowFullHistory", -1),
controller.profile());
- browser_->ShowSingleDOMUITab(GURL(chrome::kChromeUIHistoryURL));
+ browser_->ShowSingletonTab(GURL(chrome::kChromeUIHistoryURL));
return;
}
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_);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 5b43a6b..4058632 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -315,10 +315,10 @@ class Browser : public TabStripModelDelegate,
// Returns true if a tab can be restored.
virtual bool CanRestoreTab();
- // Show a DOMUI tab given a URL. If a tab with the same URL is already
- // visible in this browser, it becomes selected. Otherwise a new tab is
- // created.
- void ShowSingleDOMUITab(const GURL& url);
+ // Show a given a URL. If a tab with the same URL (ignoring the ref) is
+ // already visible in this browser, it becomes selected. Otherwise a new tab
+ // is created.
+ void ShowSingletonTab(const GURL& url);
// Update commands whose state depends on whether the window is in fullscreen
// mode. This is a public function because on Linux, fullscreen mode is an