Platform apps shortcuts use their own browser process

Shortcuts for platform apps, created via the right click menu
on the NTP, or when installing applications from the web store,
will now add the --user-data-dir flag to run with their own
profile, and the --load-extension flag to locate the extension.

Also included in this change, loading unpacked extensions will
no longer create shortcuts.

BUG=None
TEST=Tested manually


Review URL: http://codereview.chromium.org/9493001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124370 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/shell_integration.cc b/chrome/browser/shell_integration.cc
index fe900e4..c7362d6 100644
--- a/chrome/browser/shell_integration.cc
+++ b/chrome/browser/shell_integration.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -25,7 +25,8 @@
 }
 
 ShellIntegration::ShortcutInfo::ShortcutInfo()
-    : create_on_desktop(false),
+    : is_platform_app(false),
+      create_on_desktop(false),
       create_in_applications_menu(false),
       create_in_quick_launch_bar(false) {
 }
@@ -69,6 +70,45 @@
   return new_cmd_line;
 }
 
+
+// static
+CommandLine ShellIntegration::CommandLineArgsForPlatformApp(
+    const std::string& extension_app_id,
+    const FilePath& user_data_dir,
+    const FilePath& extension_path) {
+  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+  CommandLine new_cmd_line(CommandLine::NO_PROGRAM);
+
+  DCHECK(!extension_app_id.empty());
+  DCHECK(!user_data_dir.empty());
+  DCHECK(!extension_path.empty());
+
+  // Convert path to absolute and ensure it exists.
+  FilePath absolute_user_data_dir(user_data_dir);
+  DCHECK(file_util::AbsolutePath(&absolute_user_data_dir) &&
+      file_util::PathExists(absolute_user_data_dir));
+  new_cmd_line.AppendSwitchPath(switches::kUserDataDir, absolute_user_data_dir);
+
+#if defined(OS_CHROMEOS)
+  const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
+  FilePath profile = cmd_line.GetSwitchValuePath(switches::kLoginProfile);
+  if (!profile.empty())
+    new_cmd_line.AppendSwitchPath(switches::kLoginProfile, profile);
+#endif
+
+  new_cmd_line.AppendSwitchASCII(switches::kAppId, extension_app_id);
+
+  // Convert path to absolute and ensure it exists.
+  FilePath absolute_extension_path(extension_path);
+  DCHECK(file_util::AbsolutePath(&absolute_extension_path) &&
+      file_util::PathExists(absolute_extension_path));
+  // TODO(sail): Use a different flag that doesn't imply Location::LOAD for the
+  // extension.
+  new_cmd_line.AppendSwitchPath(switches::kLoadExtension,
+      absolute_extension_path);
+
+  return new_cmd_line;
+}
 ///////////////////////////////////////////////////////////////////////////////
 // ShellIntegration::DefaultWebClientWorker
 //