OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 info->app_mode_short_name = SysNSStringToUTF16( | 95 info->app_mode_short_name = SysNSStringToUTF16( |
95 [info_plist objectForKey:@"CrAppModeShortcutShortName"]); | 96 [info_plist objectForKey:@"CrAppModeShortcutShortName"]); |
96 | 97 |
97 info->app_mode_name = SysNSStringToUTF16( | 98 info->app_mode_name = SysNSStringToUTF16( |
98 [info_plist objectForKey:@"CrAppModeShortcutName"]); | 99 [info_plist objectForKey:@"CrAppModeShortcutName"]); |
99 | 100 |
100 info->app_mode_url = SysNSStringToUTF8( | 101 info->app_mode_url = SysNSStringToUTF8( |
101 [info_plist objectForKey:@"CrAppModeShortcutURL"]); | 102 [info_plist objectForKey:@"CrAppModeShortcutURL"]); |
102 //CHECK(info->app_mode_url.size()) << "couldn't get app shortcut URL"; | 103 //CHECK(info->app_mode_url.size()) << "couldn't get app shortcut URL"; |
103 | 104 |
| 105 info->user_data_dir = base::mac::NSStringToFilePath( |
| 106 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); |
| 107 |
104 // Open the framework. | 108 // Open the framework. |
105 *cr_dylib = dlopen(framework_shlib_path.value().c_str(), | 109 *cr_dylib = dlopen(framework_shlib_path.value().c_str(), |
106 RTLD_LAZY); | 110 RTLD_LAZY); |
107 CHECK(cr_dylib) << "couldn't load framework"; | 111 CHECK(cr_dylib) << "couldn't load framework"; |
108 } | 112 } |
109 | 113 |
110 } // namespace | 114 } // namespace |
111 | 115 |
112 __attribute__((visibility("default"))) | 116 __attribute__((visibility("default"))) |
113 int main(int argc, char** argv) { | 117 int main(int argc, char** argv) { |
(...skipping 12 matching lines...) Expand all Loading... |
126 | 130 |
127 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); | 131 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); |
128 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); | 132 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); |
129 CHECK(ChromeAppModeStart) << "couldn't get entry point"; | 133 CHECK(ChromeAppModeStart) << "couldn't get entry point"; |
130 | 134 |
131 // Exit instead of returning to avoid the the removal of |main()| from stack | 135 // Exit instead of returning to avoid the the removal of |main()| from stack |
132 // backtraces under tail call optimization. | 136 // backtraces under tail call optimization. |
133 int rv = ChromeAppModeStart(&info); | 137 int rv = ChromeAppModeStart(&info); |
134 exit(rv); | 138 exit(rv); |
135 } | 139 } |
OLD | NEW |