Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8728)

Unified Diff: chrome/browser/ui/extensions/application_launch.cc

Issue 10700130: Introduce LaunchParams struct for opening chrome apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/extensions/application_launch.cc
diff --git a/chrome/browser/ui/extensions/application_launch.cc b/chrome/browser/ui/extensions/application_launch.cc
index 3609e6fd07b3897b0f634697b4fac55d8b4b2815..35aadb993f8f2f4aeab8d904939318756c1763f5 100644
--- a/chrome/browser/ui/extensions/application_launch.cc
+++ b/chrome/browser/ui/extensions/application_launch.cc
@@ -79,89 +79,6 @@ bool AllowPanels(const std::string& app_name) {
web_app::GetExtensionIdFromApplicationName(app_name));
}
-} // namespace
-
-namespace application_launch {
-
-WebContents* OpenApplication(Profile* profile,
- const Extension* extension,
- extension_misc::LaunchContainer container,
- const GURL& override_url,
- WindowOpenDisposition disposition,
- const CommandLine* command_line) {
- WebContents* tab = NULL;
- ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs();
- prefs->SetActiveBit(extension->id(), true);
-
- UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100);
-#if defined(OS_CHROMEOS)
- if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled())
- chromeos::KioskModeMetrics::Get()->UserOpenedApp();
-#endif
-
- if (extension->is_platform_app()) {
- extensions::LaunchPlatformApp(profile, extension, command_line);
- return NULL;
- }
-
- switch (container) {
- case extension_misc::LAUNCH_NONE: {
- NOTREACHED();
- break;
- }
- case extension_misc::LAUNCH_PANEL: {
- bool open_panel = false;
-#if defined(USE_ASH)
- open_panel = CommandLine::ForCurrentProcess()->HasSwitch(
- ash::switches::kAuraPanelManager);
-#else
- open_panel = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kBrowserlessPanels);
-#endif
- if (open_panel) {
- tab = OpenApplicationPanel(profile, extension, override_url);
- break;
- }
- // else fall through to LAUNCH_WINDOW
- }
- case extension_misc::LAUNCH_WINDOW:
- tab = OpenApplicationWindow(profile, extension, container,
- override_url, NULL);
- break;
- case extension_misc::LAUNCH_TAB: {
- tab = OpenApplicationTab(profile, extension, override_url,
- disposition);
- break;
- }
- default:
- NOTREACHED();
- break;
- }
- return tab;
-}
-
-WebContents* OpenApplicationPanel(
- Profile* profile,
- const Extension* extension,
- const GURL& url_input) {
- GURL url = UrlForExtension(extension, url_input);
- std::string app_name =
- web_app::GenerateApplicationNameFromExtensionId(extension->id());
- gfx::Rect panel_bounds;
- panel_bounds.set_width(extension->launch_width());
- panel_bounds.set_height(extension->launch_height());
-#if defined(USE_ASH)
- PanelViewAura* panel_view = new PanelViewAura(app_name);
- panel_view->Init(profile, url, panel_bounds);
- return panel_view->WebContents();
-#else
- Panel* panel = PanelManager::GetInstance()->CreatePanel(
- app_name, profile, url, panel_bounds.size());
- panel->Show();
- return panel->GetWebContents();
-#endif
-}
-
WebContents* OpenApplicationWindow(
Profile* profile,
const Extension* extension,
@@ -233,34 +150,6 @@ WebContents* OpenApplicationWindow(
return contents;
}
-WebContents* OpenAppShortcutWindow(Profile* profile,
- const GURL& url,
- bool update_shortcut) {
- Browser* app_browser;
- WebContents* tab = OpenApplicationWindow(
- profile,
- NULL, // this is a URL app. No extension.
- extension_misc::LAUNCH_WINDOW,
- url,
- &app_browser);
-
- if (!tab)
- return NULL;
-
- if (update_shortcut) {
- TabContents* tab_contents = TabContents::FromWebContents(tab);
- // Set UPDATE_SHORTCUT as the pending web app action. This action is picked
- // up in LoadingStateChanged to schedule a GetApplicationInfo. And when
- // the web app info is available, ExtensionTabHelper notifies Browser via
- // OnDidGetApplicationInfo, which calls
- // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as
- // pending web app action.
- tab_contents->extension_tab_helper()->set_pending_web_app_action(
- ExtensionTabHelper::UPDATE_SHORTCUT);
- }
- return tab;
-}
-
WebContents* OpenApplicationTab(Profile* profile,
const Extension* extension,
const GURL& override_url,
@@ -352,4 +241,126 @@ WebContents* OpenApplicationTab(Profile* profile,
return contents;
}
+} // namespace
+
+namespace application_launch {
+
+LaunchParams::LaunchParams(Profile* profile,
+ const extensions::Extension* extension,
+ extension_misc::LaunchContainer container,
+ WindowOpenDisposition disposition)
+ : profile(profile),
+ extension(extension),
+ container(container),
+ disposition(disposition),
+ override_url(),
+ command_line(NULL) {}
+
+WebContents* OpenApplication(const LaunchParams& params) {
+ Profile* profile = params.profile;
+ const extensions::Extension* extension = params.extension;
+ extension_misc::LaunchContainer container = params.container;
+ const GURL& override_url = params.override_url;
+
+ WebContents* tab = NULL;
+ ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs();
+ prefs->SetActiveBit(extension->id(), true);
+
+ UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100);
+#if defined(OS_CHROMEOS)
+ if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled())
+ chromeos::KioskModeMetrics::Get()->UserOpenedApp();
+#endif
+
+ if (extension->is_platform_app()) {
+ extensions::LaunchPlatformApp(profile, extension, params.command_line);
+ return NULL;
+ }
+
+ switch (container) {
+ case extension_misc::LAUNCH_NONE: {
+ NOTREACHED();
+ break;
+ }
+ case extension_misc::LAUNCH_PANEL: {
+ bool open_panel = false;
+#if defined(USE_ASH)
+ open_panel = CommandLine::ForCurrentProcess()->HasSwitch(
+ ash::switches::kAuraPanelManager);
+#else
+ open_panel = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kBrowserlessPanels);
+#endif
+ if (open_panel) {
+ tab = OpenApplicationPanel(profile, extension, override_url);
+ break;
+ }
+ // else fall through to LAUNCH_WINDOW
+ }
+ case extension_misc::LAUNCH_WINDOW:
+ tab = OpenApplicationWindow(profile, extension, container,
+ override_url, NULL);
+ break;
+ case extension_misc::LAUNCH_TAB: {
+ tab = OpenApplicationTab(profile, extension, override_url,
+ params.disposition);
+ break;
+ }
+ default:
+ NOTREACHED();
+ break;
+ }
+ return tab;
+}
+
+WebContents* OpenApplicationPanel(
+ Profile* profile,
+ const Extension* extension,
+ const GURL& url_input) {
+ GURL url = UrlForExtension(extension, url_input);
+ std::string app_name =
+ web_app::GenerateApplicationNameFromExtensionId(extension->id());
+ gfx::Rect panel_bounds;
+ panel_bounds.set_width(extension->launch_width());
+ panel_bounds.set_height(extension->launch_height());
+#if defined(USE_ASH)
+ PanelViewAura* panel_view = new PanelViewAura(app_name);
+ panel_view->Init(profile, url, panel_bounds);
+ return panel_view->WebContents();
+#else
+ Panel* panel = PanelManager::GetInstance()->CreatePanel(
+ app_name, profile, url, panel_bounds.size());
+ panel->Show();
+ return panel->GetWebContents();
+#endif
+}
+
+WebContents* OpenAppShortcutWindow(Profile* profile,
+ const GURL& url,
+ bool update_shortcut) {
+ Browser* app_browser;
+ WebContents* tab = OpenApplicationWindow(
+ profile,
+ NULL, // this is a URL app. No extension.
+ extension_misc::LAUNCH_WINDOW,
+ url,
+ &app_browser);
+
+ if (!tab)
+ return NULL;
+
+ if (update_shortcut) {
+ TabContents* tab_contents = TabContents::FromWebContents(tab);
+ // Set UPDATE_SHORTCUT as the pending web app action. This action is picked
+ // up in LoadingStateChanged to schedule a GetApplicationInfo. And when
+ // the web app info is available, ExtensionTabHelper notifies Browser via
+ // OnDidGetApplicationInfo, which calls
+ // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as
+ // pending web app action.
+ tab_contents->extension_tab_helper()->set_pending_web_app_action(
+ ExtensionTabHelper::UPDATE_SHORTCUT);
+ }
+ return tab;
+}
+
} // namespace application_launch

Powered by Google App Engine
This is Rietveld 408576698