| 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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 using base::SysNSStringToUTF8; | 41 using base::SysNSStringToUTF8; |
| 42 using base::SysNSStringToUTF16; | 42 using base::SysNSStringToUTF16; |
| 43 using base::mac::CFToNSCast; | 43 using base::mac::CFToNSCast; |
| 44 using base::mac::CFCastStrict; | 44 using base::mac::CFCastStrict; |
| 45 using base::mac::NSToCFCast; | 45 using base::mac::NSToCFCast; |
| 46 | 46 |
| 47 base::mac::ScopedNSAutoreleasePool scoped_pool; | 47 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 48 | 48 |
| 49 // Get the current main bundle, i.e., that of the app loader that's running. | 49 // Get the current main bundle, i.e., that of the app loader that's running. |
| 50 NSBundle* app_bundle = [NSBundle mainBundle]; | 50 NSBundle* app_bundle = [NSBundle mainBundle]; |
| 51 CHECK(app_bundle) << "couldn't get loader bundle"; | 51 // couldn't get loader bundle |
| 52 CHECK(app_bundle); |
| 52 | 53 |
| 53 // ** 1: Get path to outer Chrome bundle. | 54 // ** 1: Get path to outer Chrome bundle. |
| 54 // Get the bundle ID of the browser that created this app bundle. | 55 // Get the bundle ID of the browser that created this app bundle. |
| 55 NSString* cr_bundle_id = base::mac::ObjCCast<NSString>( | 56 NSString* cr_bundle_id = base::mac::ObjCCast<NSString>( |
| 56 [app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]); | 57 [app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]); |
| 57 CHECK(cr_bundle_id) << "couldn't get browser bundle ID"; | 58 // couldn't get browser bundle ID |
| 59 CHECK(cr_bundle_id); |
| 58 | 60 |
| 59 // First check if Chrome exists at the last known location. | 61 // First check if Chrome exists at the last known location. |
| 60 base::FilePath cr_bundle_path; | 62 base::FilePath cr_bundle_path; |
| 61 NSString* cr_bundle_path_ns = | 63 NSString* cr_bundle_path_ns = |
| 62 [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( | 64 [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( |
| 63 NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), | 65 NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), |
| 64 NSToCFCast(cr_bundle_id)))) autorelease]; | 66 NSToCFCast(cr_bundle_id)))) autorelease]; |
| 65 cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); | 67 cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); |
| 66 bool found_bundle = | 68 bool found_bundle = |
| 67 !cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path); | 69 !cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 base::mac::NSStringToFilePath([app_bundle bundlePath]); | 116 base::mac::NSStringToFilePath([app_bundle bundlePath]); |
| 115 | 117 |
| 116 // ** 4: Fill in ChromeAppModeInfo. | 118 // ** 4: Fill in ChromeAppModeInfo. |
| 117 info->chrome_outer_bundle_path = cr_bundle_path; | 119 info->chrome_outer_bundle_path = cr_bundle_path; |
| 118 info->chrome_versioned_path = version_path; | 120 info->chrome_versioned_path = version_path; |
| 119 info->app_mode_bundle_path = app_mode_bundle_path; | 121 info->app_mode_bundle_path = app_mode_bundle_path; |
| 120 | 122 |
| 121 // Read information about the this app shortcut from the Info.plist. | 123 // Read information about the this app shortcut from the Info.plist. |
| 122 // Don't check for null-ness on optional items. | 124 // Don't check for null-ness on optional items. |
| 123 NSDictionary* info_plist = [app_bundle infoDictionary]; | 125 NSDictionary* info_plist = [app_bundle infoDictionary]; |
| 124 CHECK(info_plist) << "couldn't get loader Info.plist"; | 126 // couldn't get loader Info.plist |
| 127 CHECK(info_plist); |
| 125 | 128 |
| 126 info->app_mode_id = SysNSStringToUTF8( | 129 info->app_mode_id = SysNSStringToUTF8( |
| 127 [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 130 [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| 128 CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; | 131 // couldn't get app shortcut ID |
| 132 CHECK(info->app_mode_id.size()); |
| 129 | 133 |
| 130 info->app_mode_name = SysNSStringToUTF16( | 134 info->app_mode_name = SysNSStringToUTF16( |
| 131 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 135 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 132 | 136 |
| 133 info->app_mode_url = SysNSStringToUTF8( | 137 info->app_mode_url = SysNSStringToUTF8( |
| 134 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 138 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
| 135 | 139 |
| 136 info->user_data_dir = base::mac::NSStringToFilePath( | 140 info->user_data_dir = base::mac::NSStringToFilePath( |
| 137 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); | 141 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); |
| 138 | 142 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // Hard coded info parameters. | 206 // Hard coded info parameters. |
| 203 info.major_version = app_mode::kCurrentChromeAppModeInfoMajorVersion; | 207 info.major_version = app_mode::kCurrentChromeAppModeInfoMajorVersion; |
| 204 info.minor_version = app_mode::kCurrentChromeAppModeInfoMinorVersion; | 208 info.minor_version = app_mode::kCurrentChromeAppModeInfoMinorVersion; |
| 205 info.argc = argc; | 209 info.argc = argc; |
| 206 info.argv = argv; | 210 info.argv = argv; |
| 207 | 211 |
| 208 // Exit instead of returning to avoid the the removal of |main()| from stack | 212 // Exit instead of returning to avoid the the removal of |main()| from stack |
| 209 // backtraces under tail call optimization. | 213 // backtraces under tail call optimization. |
| 210 exit(LoadFrameworkAndStart(&info)); | 214 exit(LoadFrameworkAndStart(&info)); |
| 211 } | 215 } |
| OLD | NEW |