| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we | 5 // On Mac, one can't make shortcuts with command-line arguments. Instead, we |
| 6 // produce small app bundles which locate the Chromium framework and load it, | 6 // produce small app bundles which locate the Chromium framework and load it, |
| 7 // passing the appropriate data. This is the entry point into the framework for | 7 // passing the appropriate data. This is the entry point into the framework for |
| 8 // those app bundles. | 8 // those app bundles. |
| 9 | 9 |
| 10 #include <string> // TODO(viettrungluu): only needed for temporary hack | 10 #include <string> // TODO(viettrungluu): only needed for temporary hack |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "chrome/common/chrome_paths_internal.h" | 16 #include "chrome/common/chrome_paths_internal.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/mac/app_mode_common.h" | 18 #include "chrome/common/mac/app_mode_common.h" |
| 17 | 19 |
| 18 extern "C" { | 20 extern "C" { |
| 19 | 21 |
| 20 // |ChromeAppModeStart()| is the point of entry into the framework from the app | 22 // |ChromeAppModeStart()| is the point of entry into the framework from the app |
| 21 // mode loader. | 23 // mode loader. |
| 22 __attribute__((visibility("default"))) | 24 __attribute__((visibility("default"))) |
| 23 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); | 25 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info); |
| 24 | 26 |
| 25 // TODO(viettrungluu): put this in a header file somewhere. | 27 // TODO(viettrungluu): put this in a header file somewhere. |
| 26 int ChromeMain(int argc, char** argv); | 28 int ChromeMain(int argc, char** argv); |
| 27 | 29 |
| 28 } // extern "C" | 30 } // extern "C" |
| 29 | 31 |
| 30 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { | 32 int ChromeAppModeStart(const app_mode::ChromeAppModeInfo* info) { |
| 31 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 33 if (info->major_version < app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
| 32 RAW_LOG(ERROR, "App Mode Loader too old."); | 34 RAW_LOG(ERROR, "App Mode Loader too old."); |
| 33 return 1; | 35 return 1; |
| 34 } | 36 } |
| 35 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { | 37 if (info->major_version > app_mode::kCurrentChromeAppModeInfoMajorVersion) { |
| 36 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); | 38 RAW_LOG(ERROR, "Browser Framework too old to load App Shortcut."); |
| 37 return 1; | 39 return 1; |
| 38 } | 40 } |
| 39 | 41 |
| 40 RAW_CHECK(!info->chrome_versioned_path.empty()); | 42 RAW_CHECK(!info->chrome_versioned_path.empty()); |
| 41 FilePath* chrome_versioned_path = new FilePath(info->chrome_versioned_path); | 43 FilePath* chrome_versioned_path = new FilePath(info->chrome_versioned_path); |
| 42 RAW_CHECK(!chrome_versioned_path->empty()); | 44 RAW_CHECK(!chrome_versioned_path->empty()); |
| 43 chrome::SetOverrideVersionedDirectory(chrome_versioned_path); | 45 chrome::SetOverrideVersionedDirectory(chrome_versioned_path); |
| 44 | 46 |
| 45 // TODO(viettrungluu): do something intelligent with data | 47 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 46 // return ChromeMain(info->argc, info->argv); | 48 command_line.AppendSwitch(info->argv[0]); |
| 47 // For now, a cheesy hack instead. | |
| 48 RAW_CHECK(info->app_mode_id.size()); | 49 RAW_CHECK(info->app_mode_id.size()); |
| 49 std::string argv1(std::string("--app-id=") + info->app_mode_id); | 50 command_line.AppendSwitchASCII(switches::kAppId, info->app_mode_id); |
| 50 std::string argv2( | 51 command_line.AppendSwitchPath(switches::kUserDataDir, info->user_data_dir); |
| 51 std::string("--user-data-dir=") + info->user_data_dir.value()); | 52 // TODO(sail): Use a different flag that doesn't imply Location::LOAD for the |
| 52 char* argv[] = { info->argv[0], | 53 // extension. |
| 53 const_cast<char*>(argv1.c_str()), | 54 command_line.AppendSwitchPath(switches::kLoadExtension, info->extension_path); |
| 54 const_cast<char*>(argv2.c_str()) }; | 55 |
| 55 return ChromeMain(static_cast<int>(arraysize(argv)), argv); | 56 int argc = command_line.argv().size(); |
| 57 char* argv[argc]; |
| 58 for (int i = 0; i < argc; ++i) |
| 59 argv[i] = const_cast<char*>(command_line.argv()[i].c_str()); |
| 60 |
| 61 return ChromeMain(argc, argv); |
| 56 } | 62 } |
| OLD | NEW |