diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-12 17:28:56 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-12 17:28:56 +0000 |
commit | c28071ad39fdf60db886e6d6844da7c3331825a6 (patch) | |
tree | 89edfcbf7bd70f18191496fbefafe843316e6139 /chrome/browser/browser_init.cc | |
parent | a883f8fc702c2cb37130361b7ddc6fc86a8f2edf (diff) | |
download | chromium_src-c28071ad39fdf60db886e6d6844da7c3331825a6.zip chromium_src-c28071ad39fdf60db886e6d6844da7c3331825a6.tar.gz chromium_src-c28071ad39fdf60db886e6d6844da7c3331825a6.tar.bz2 |
Support app tabs as a launch point for apps. Also, move the logic for launching into Browser for easier access by the launcher.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/668245
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_init.cc')
-rw-r--r-- | chrome/browser/browser_init.cc | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 8481acf..a983a76 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -460,8 +460,8 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, } // Open the required browser windows and tabs. - // First, see if we're being run as a web application (thin frame window). - if (!OpenApplicationURL(profile)) { + // First, see if we're being run as an application window. + if (!OpenApplicationWindow(profile)) { std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); RecordLaunchModeHistogram(urls_to_open.empty()? LM_TO_BE_DECIDED : LM_WITH_URLS); @@ -477,6 +477,16 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, OpenURLsInBrowser(browser, process_startup, urls_to_open); } + + // If this is an app launch, but we didn't open an app window, it may + // be an app tab. + std::string app_id; + 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); + } + if (process_startup) { if (browser_defaults::kOSSupportsOtherBrowsers && !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { @@ -525,43 +535,41 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, return true; } -bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { - if (!command_line_.HasSwitch(switches::kApp) && - !command_line_.HasSwitch(switches::kAppId)) - return false; - - std::string url_string(command_line_.GetSwitchValueASCII(switches::kApp)); - bool launch_as_panel = false; - - if (command_line_.HasSwitch(switches::kEnableExtensionApps)) { - if (command_line_.HasSwitch(switches::kAppId)) { - // http://crbug.com/37548 - // TODO(rafaelw): There are two legitimate cases where the extensions - // service could not be ready at this point which need to be handled: - // 1) The locale has changed and the manifests stored in the preferences - // need to be relocalized. - // 2) An externally installed extension will be found and installed. - ExtensionsService* extensions_service = profile->GetExtensionsService(); - if (!extensions_service->is_ready()) - return false; +bool BrowserInit::LaunchWithProfile::IsAppLaunch(std::string* app_url, + std::string* app_id) { + if (command_line_.HasSwitch(switches::kApp)) { + if (app_url) + *app_url = command_line_.GetSwitchValueASCII(switches::kApp); + return true; + } + if (command_line_.HasSwitch(switches::kEnableExtensionApps) && + command_line_.HasSwitch(switches::kAppId)) { + if (app_id) + *app_id = command_line_.GetSwitchValueASCII(switches::kAppId); + return true; + } + return false; +} - std::string app_id(command_line_.GetSwitchValueASCII(switches::kAppId)); - Extension* extension_app = - extensions_service->GetExtensionById(app_id, false); +bool BrowserInit::LaunchWithProfile::OpenApplicationWindow(Profile* profile) { + std::string url_string, app_id; + if (!IsAppLaunch(&url_string, &app_id)) + return false; - // The extension with |app_id| could't be found, most likely because it - // was uninstalled. - // TODO(rafaelw): Do something reasonable here. Pop up a warning panel? - // Open a URL to the gallery page of the extension id? - if (!extension_app) - return false; - url_string = extension_app->app_launch_url().spec(); - launch_as_panel = - extension_app->app_launch_window_type() == Extension::PANEL; - } else { - launch_as_panel = command_line_.HasSwitch(switches::kAppLaunchAsPanel); - } - } + // http://crbug.com/37548 + // TODO(rafaelw): There are two legitimate cases where the extensions + // service could not be ready at this point which need to be handled: + // 1) The locale has changed and the manifests stored in the preferences + // need to be relocalized. + // 2) An externally installed extension will be found and installed. + // Note that this can also fail if the app_id is simply invalid. + // 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); + + if (url_string.empty()) + return false; #if defined(OS_WIN) // Fix up Windows shortcuts. ReplaceSubstringsAfterOffset(&url_string, 0, "\\x", "%"); @@ -574,7 +582,7 @@ bool BrowserInit::LaunchWithProfile::OpenApplicationURL(Profile* profile) { ChildProcessSecurityPolicy::GetInstance(); if (policy->IsWebSafeScheme(url.scheme()) || url.SchemeIs(chrome::kFileScheme)) { - Browser::OpenApplicationWindow(profile, url, launch_as_panel); + Browser::OpenApplicationWindow(profile, url, false); return true; } } |