summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 01:03:07 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-29 01:03:07 +0000
commitd0e08fb2ca5a534948d22533fc6968d8d073015e (patch)
tree31e09c16387d4cf9e728cb2940ff858143f59193 /chrome/browser/browser.cc
parentbb80cd0ebf646892cf0d4ae24f5ca701ab53c9d4 (diff)
downloadchromium_src-d0e08fb2ca5a534948d22533fc6968d8d073015e.zip
chromium_src-d0e08fb2ca5a534948d22533fc6968d8d073015e.tar.gz
chromium_src-d0e08fb2ca5a534948d22533fc6968d8d073015e.tar.bz2
First cut at window affinity for apps. Window affinity means that app URLs tend to open in the window associated with them, and non-app URLs tend to not open in app windows.
After playing with this first attempt, I find it is unsatisfying because spreadsheets.google.com doesn't open in the docs app (different origin) and logging out of gmail directs you back to the browser. So I'm going to fix that by adding a browse extent, separately. But I still think this is a worthwhile stepping stone to check in. Review URL: http://codereview.chromium.org/1732015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45894 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser.cc')
-rw-r--r--chrome/browser/browser.cc78
1 files changed, 75 insertions, 3 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index d06f748..4c43358 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -434,7 +434,17 @@ TabContents* Browser::OpenApplicationWindow(
Profile* profile,
Extension* extension,
Extension::LaunchContainer container,
- const GURL& url) {
+ const GURL& url_input) {
+ GURL url;
+ if (!url_input.is_empty()) {
+ if (extension)
+ DCHECK(extension->web_extent().ContainsURL(url_input));
+ url = url_input;
+ } else {
+ DCHECK(extension);
+ url = extension->GetFullLaunchURL();
+ }
+
// TODO(erikkay) this can't be correct for extensions
std::wstring app_name = web_app::GenerateApplicationNameFromURL(url);
RegisterAppPrefs(app_name);
@@ -442,8 +452,7 @@ TabContents* Browser::OpenApplicationWindow(
bool as_panel = extension && (container == Extension::LAUNCH_PANEL);
Browser* browser = Browser::CreateForApp(app_name, extension, profile,
as_panel);
- browser->AddTabWithURL(extension ? extension->GetFullLaunchURL() : url,
- GURL(), PageTransition::START_PAGE, true, -1,
+ browser->AddTabWithURL(url, GURL(), PageTransition::START_PAGE, true, -1,
false, NULL);
TabContents* tab_contents = browser->GetSelectedTabContents();
@@ -3334,6 +3343,58 @@ Browser* Browser::GetOrCreateTabbedBrowser(Profile* profile) {
return browser;
}
+bool Browser::HandleCrossAppNavigation(TabContents* source,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ // Can be null in unit tests.
+ ExtensionsService* service = profile_->GetExtensionsService();
+ if (!service)
+ return false;
+
+ // Get the destination URL's extension, if any.
+ Extension* extension = service->GetExtensionByURL(url);
+ if (!extension)
+ extension = service->GetExtensionByWebExtent(url);
+
+ if (extension) {
+ // If we're navigating to the same extension, do nothing.
+ if (extension == extension_app_)
+ return false;
+
+ // If there's already a window for the destination extension, open the URL
+ // there.
+ for (BrowserList::const_iterator iter = BrowserList::begin();
+ iter != BrowserList::end(); ++iter) {
+ if (extension == (*iter)->extension_app()) {
+ (*iter)->OpenURL(url, referrer, NEW_FOREGROUND_TAB, transition);
+ return true;
+ }
+ }
+
+ // If the extension wants to be opened in a window, but there is no
+ // existing window, create one, then open the URL there.
+ if (extension->launch_container() == Extension::LAUNCH_WINDOW) {
+ Browser::OpenApplicationWindow(profile_, extension, url,
+ false); // Don't use a panel.
+ return true;
+ }
+ }
+
+ // If the current browser is for an extension, then the destination URL must
+ // not be for that extension (otherwise, we would have caught it above). So
+ // find a normal browser and open the URL there.
+ if (extension_app_) {
+ Browser* browser = GetOrCreateTabbedBrowser(profile_);
+ browser->OpenURL(url, referrer, NEW_FOREGROUND_TAB, transition);
+ browser->window()->Show();
+ return true;
+ }
+
+ return false;
+}
+
void Browser::OpenURLAtIndex(TabContents* source,
const GURL& url,
const GURL& referrer,
@@ -3361,6 +3422,17 @@ void Browser::OpenURLAtIndex(TabContents* source,
delegate->OnUserGesture();
}
+ if (HandleCrossAppNavigation(current_tab, url, referrer, disposition,
+ transition)) {
+ // If the source tab was brand new, we can be left with an empty tab which
+ // looks ugly. Close it. It is still kinda ugly to have a tab flash visible
+ // for a second, then disappear. But I think it is better than having a
+ // dead tab just hang around.
+ if (source->controller().entry_count() == 0)
+ CloseTabContents(source);
+ return;
+ }
+
// If the URL is part of the same web site, then load it in the same
// SiteInstance (and thus the same process). This is an optimization to
// reduce process overhead; it is not necessary for compatibility. (That is,