summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 14:44:53 +0000
committerjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 14:44:53 +0000
commit9b2ef45f3f252eb67e29f3075d8341bc32160be3 (patch)
tree71e7e2ef359ea2a3bd2a11bb03f51138661e490b
parent63d5bdec81228ba936be0fb268c5b83434a74b9b (diff)
downloadchromium_src-9b2ef45f3f252eb67e29f3075d8341bc32160be3.zip
chromium_src-9b2ef45f3f252eb67e29f3075d8341bc32160be3.tar.gz
chromium_src-9b2ef45f3f252eb67e29f3075d8341bc32160be3.tar.bz2
Merge 62560 - Launch apps directly into NTP
Applications that are configured to be launched in a tab are now opened directly in the NTP, rather than opening a new tab and closing the NTP. BUG=57476 TEST=Try launching an application from the new tab page. If it's set to open as a tab, a pinned tab, or full-screen, the application should launch directly into the existing new tab page. The new tab page should close when opening an application with panel launch type. Review URL: http://codereview.chromium.org/3673006 TBR=jstritar@chromium.org Review URL: http://codereview.chromium.org/3783007 git-svn-id: svn://svn.chromium.org/chrome/branches/552/src@62739 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser.cc33
-rw-r--r--chrome/browser/browser.h24
-rw-r--r--chrome/browser/browser_init.cc4
-rw-r--r--chrome/browser/dom_ui/app_launcher_handler.cc8
-rw-r--r--chrome/browser/extensions/extension_management_api.cc2
5 files changed, 48 insertions, 23 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 0c45dab..6bf9895 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -479,7 +479,8 @@ void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) {
// this function return an error reason as well so that callers can show
// reasonable errors?
TabContents* Browser::OpenApplication(Profile* profile,
- const std::string& app_id) {
+ const std::string& app_id,
+ TabContents* existing_tab) {
ExtensionsService* extensions_service = profile->GetExtensionsService();
if (!extensions_service->is_ready())
return NULL;
@@ -490,14 +491,16 @@ TabContents* Browser::OpenApplication(Profile* profile,
if (!extension)
return NULL;
- return OpenApplication(profile, extension, extension->launch_container());
+ return OpenApplication(profile, extension, extension->launch_container(),
+ existing_tab);
}
// static
TabContents* Browser::OpenApplication(
Profile* profile,
Extension* extension,
- extension_misc::LaunchContainer container) {
+ extension_misc::LaunchContainer container,
+ TabContents* existing_tab) {
TabContents* tab = NULL;
UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100);
@@ -510,7 +513,7 @@ TabContents* Browser::OpenApplication(
GURL());
break;
case extension_misc::LAUNCH_TAB: {
- tab = Browser::OpenApplicationTab(profile, extension);
+ tab = Browser::OpenApplicationTab(profile, extension, existing_tab);
break;
}
default:
@@ -574,7 +577,8 @@ TabContents* Browser::OpenApplicationWindow(Profile* profile, GURL& url) {
// static
TabContents* Browser::OpenApplicationTab(Profile* profile,
- Extension* extension) {
+ Extension* extension,
+ TabContents* existing_tab) {
Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
TabContents* contents = NULL;
if (!browser || browser->type() != Browser::TYPE_NORMAL)
@@ -596,7 +600,24 @@ TabContents* Browser::OpenApplicationTab(Profile* profile,
AddTabWithURLParams params(extension->GetFullLaunchURL(),
PageTransition::START_PAGE);
params.add_types = add_type;
- contents = browser->AddTabWithURL(&params);
+
+ // Launch the application in the existing TabContents, if it was supplied.
+ if (existing_tab) {
+ TabStripModel* model = browser->tabstrip_model();
+ int tab_index = model->GetIndexOfTabContents(existing_tab);
+
+ existing_tab->OpenURL(extension->GetFullLaunchURL(), existing_tab->GetURL(),
+ CURRENT_TAB, PageTransition::LINK);
+ if (params.add_types & TabStripModel::ADD_PINNED)
+ model->SetTabPinned(tab_index, true);
+ if (params.add_types & TabStripModel::ADD_SELECTED)
+ model->SelectTabContentsAt(tab_index, true);
+
+ contents = existing_tab;
+ } else {
+ contents = browser->AddTabWithURL(&params);
+ }
+
if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN)
browser->window()->SetFullscreen(true);
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 85a3ea40..36fff9e 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -223,17 +223,21 @@ class Browser : public TabHandlerDelegate,
static void OpenURLOffTheRecord(Profile* profile, const GURL& url);
// Open an application specified by |app_id| in the appropriate launch
- // container. Returns NULL if the app_id is invalid or if ExtensionsService
- // isn't ready/available.
+ // container. |existing_tab| is reused if it is not NULL and the launch
+ // container is a tab. Returns NULL if the app_id is invalid or if
+ // ExtensionsService isn't ready/available.
static TabContents* OpenApplication(Profile* profile,
- const std::string& app_id);
+ const std::string& app_id,
+ TabContents* existing_tab);
- // Open |extension| in |container|. Returns the TabContents* that was created
- // or NULL.
+ // Open |extension| in |container|, using |existing_tab| if not NULL and if
+ // the correct container type. Returns the TabContents* that was created or
+ // NULL.
static TabContents* OpenApplication(
Profile* profile,
Extension* extension,
- extension_misc::LaunchContainer container);
+ extension_misc::LaunchContainer container,
+ TabContents* existing_tab);
// Opens a new application window for the specified url. If |as_panel|
// is true, the application will be opened as a Browser::Type::APP_PANEL in
@@ -249,10 +253,12 @@ class Browser : public TabHandlerDelegate,
// Open an application for |extension| in a new application window or panel.
static TabContents* OpenApplicationWindow(Profile* profile, GURL& url);
- // Open an application for |extension| in a new application tab. Returns
- // NULL if there are no appropriate existing browser windows for |profile|.
+ // Open an application for |extension| in a new application tab, or
+ // |existing_tab| if not NULL. Returns NULL if there are no appropriate
+ // existing browser windows for |profile|.
static TabContents* OpenApplicationTab(Profile* profile,
- Extension* extension);
+ Extension* extension,
+ TabContents* existing_tab);
// Opens a new window and opens the bookmark manager.
static void OpenBookmarkManagerWindow(Profile* profile);
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 6e5cd9a..c503ab9 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -529,7 +529,7 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
if (IsAppLaunch(NULL, &app_id) && !app_id.empty()) {
// TODO(erikkay): This could fail if |app_id| is invalid (the app was
// uninstalled). We may want to show some reasonable error here.
- Browser::OpenApplication(profile, app_id);
+ Browser::OpenApplication(profile, app_id, NULL);
}
if (process_startup) {
@@ -610,7 +610,7 @@ bool BrowserInit::LaunchWithProfile::OpenApplicationWindow(Profile* profile) {
// TODO(rafaelw): Do something reasonable here. Pop up a warning panel?
// Open an URL to the gallery page of the extension id?
if (!app_id.empty())
- return Browser::OpenApplication(profile, app_id) != NULL;
+ return Browser::OpenApplication(profile, app_id, NULL) != NULL;
if (url_string.empty())
return false;
diff --git a/chrome/browser/dom_ui/app_launcher_handler.cc b/chrome/browser/dom_ui/app_launcher_handler.cc
index 674d951..3f3d04a 100644
--- a/chrome/browser/dom_ui/app_launcher_handler.cc
+++ b/chrome/browser/dom_ui/app_launcher_handler.cc
@@ -211,13 +211,11 @@ void AppLauncherHandler::HandleLaunchApp(const ListValue* args) {
old_contents = browser->GetSelectedTabContents();
AnimateAppIcon(extension, rect);
- Browser::OpenApplication(profile, extension, extension->launch_container());
+ TabContents* new_contents = Browser::OpenApplication(
+ profile, extension, extension->launch_container(), old_contents);
- if (old_contents &&
- old_contents->GetURL().GetOrigin() ==
- GURL(chrome::kChromeUINewTabURL).GetOrigin()) {
+ if (new_contents != old_contents)
browser->CloseTabContents(old_contents);
- }
}
void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) {
diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc
index e42764d..9c900de 100644
--- a/chrome/browser/extensions/extension_management_api.cc
+++ b/chrome/browser/extensions/extension_management_api.cc
@@ -120,7 +120,7 @@ bool LaunchAppFunction::RunImpl() {
}
extension_misc::LaunchContainer container = extension->launch_container();
- Browser::OpenApplication(profile(), extension, container);
+ Browser::OpenApplication(profile(), extension, container, NULL);
return true;
}