| 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, shortcuts can't have command-line arguments. Instead, produce small | 5 // On Mac, shortcuts can't have command-line arguments. Instead, produce small |
| 6 // app bundles which locate the Chromium framework and load it, passing the | 6 // app bundles which locate the Chromium framework and load it, passing the |
| 7 // appropriate data. This is the code for such an app bundle. It should be kept | 7 // appropriate data. This is the code for such an app bundle. It should be kept |
| 8 // minimal and do as little work as possible (with as much work done on | 8 // minimal and do as little work as possible (with as much work done on |
| 9 // framework side as possible). | 9 // framework side as possible). |
| 10 | 10 |
| 11 #include <dlfcn.h> | 11 #include <dlfcn.h> |
| 12 | 12 |
| 13 #include <CoreFoundation/CoreFoundation.h> | 13 #include <CoreFoundation/CoreFoundation.h> |
| 14 #import <Foundation/Foundation.h> | 14 #import <Foundation/Foundation.h> |
| 15 | 15 |
| 16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/mac/foundation_util.h" |
| 19 #include "base/mac/scoped_nsautorelease_pool.h" | 20 #include "base/mac/scoped_nsautorelease_pool.h" |
| 20 #include "base/sys_string_conversions.h" | 21 #include "base/sys_string_conversions.h" |
| 21 #import "chrome/common/mac/app_mode_chrome_locator.h" | 22 #import "chrome/common/mac/app_mode_chrome_locator.h" |
| 22 #include "chrome/common/mac/app_mode_common.h" | 23 #include "chrome/common/mac/app_mode_common.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 void LoadFramework(void** cr_dylib, app_mode::ChromeAppModeInfo* info) { | 27 void LoadFramework(void** cr_dylib, app_mode::ChromeAppModeInfo* info) { |
| 27 using base::SysNSStringToUTF8; | 28 using base::SysNSStringToUTF8; |
| 28 using base::SysNSStringToUTF16; | 29 using base::SysNSStringToUTF16; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 info->app_mode_short_name = SysNSStringToUTF16( | 86 info->app_mode_short_name = SysNSStringToUTF16( |
| 86 [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]); | 87 [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]); |
| 87 | 88 |
| 88 info->app_mode_name = SysNSStringToUTF16( | 89 info->app_mode_name = SysNSStringToUTF16( |
| 89 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 90 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 90 | 91 |
| 91 info->app_mode_url = SysNSStringToUTF8( | 92 info->app_mode_url = SysNSStringToUTF8( |
| 92 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 93 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
| 93 CHECK(info->app_mode_url.size()) << "couldn't get app shortcut URL"; | 94 CHECK(info->app_mode_url.size()) << "couldn't get app shortcut URL"; |
| 94 | 95 |
| 96 info->user_data_dir = base::mac::NSStringToFilePath( |
| 97 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); |
| 98 |
| 95 // Open the framework. | 99 // Open the framework. |
| 96 *cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); | 100 *cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); |
| 97 CHECK(cr_dylib) << "couldn't load framework: " << dlerror(); | 101 CHECK(cr_dylib) << "couldn't load framework: " << dlerror(); |
| 98 } | 102 } |
| 99 | 103 |
| 100 } // namespace | 104 } // namespace |
| 101 | 105 |
| 102 __attribute__((visibility("default"))) | 106 __attribute__((visibility("default"))) |
| 103 int main(int argc, char** argv) { | 107 int main(int argc, char** argv) { |
| 104 app_mode::ChromeAppModeInfo info; | 108 app_mode::ChromeAppModeInfo info; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 | 119 |
| 116 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); | 120 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); |
| 117 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); | 121 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); |
| 118 CHECK(ChromeAppModeStart) << "couldn't get entry point"; | 122 CHECK(ChromeAppModeStart) << "couldn't get entry point"; |
| 119 | 123 |
| 120 // Exit instead of returning to avoid the the removal of |main()| from stack | 124 // Exit instead of returning to avoid the the removal of |main()| from stack |
| 121 // backtraces under tail call optimization. | 125 // backtraces under tail call optimization. |
| 122 int rv = ChromeAppModeStart(&info); | 126 int rv = ChromeAppModeStart(&info); |
| 123 exit(rv); | 127 exit(rv); |
| 124 } | 128 } |
| OLD | NEW |