Chromium Code Reviews| 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 25 matching lines...) Expand all Loading... | |
| 36 using base::mac::CFToNSCast; | 36 using base::mac::CFToNSCast; |
| 37 using base::mac::CFCastStrict; | 37 using base::mac::CFCastStrict; |
| 38 using base::mac::NSToCFCast; | 38 using base::mac::NSToCFCast; |
| 39 | 39 |
| 40 base::mac::ScopedNSAutoreleasePool scoped_pool; | 40 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 41 | 41 |
| 42 // Get the current main bundle, i.e., that of the app loader that's running. | 42 // Get the current main bundle, i.e., that of the app loader that's running. |
| 43 NSBundle* app_bundle = [NSBundle mainBundle]; | 43 NSBundle* app_bundle = [NSBundle mainBundle]; |
| 44 CHECK(app_bundle) << "couldn't get loader bundle"; | 44 CHECK(app_bundle) << "couldn't get loader bundle"; |
| 45 | 45 |
| 46 // Read information about the this app shortcut from the Info.plist. | |
| 47 // Don't check for null-ness on optional items. | |
| 48 NSDictionary* info_plist = [app_bundle infoDictionary]; | |
| 49 CHECK(info_plist) << "couldn't get loader Info.plist"; | |
| 50 | |
| 51 info->app_mode_id = SysNSStringToUTF8( | |
| 52 [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | |
| 53 CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; | |
| 54 | |
| 55 info->app_mode_name = SysNSStringToUTF16( | |
| 56 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | |
| 57 | |
| 58 info->app_mode_url = SysNSStringToUTF8( | |
| 59 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | |
| 60 | |
| 61 info->user_data_dir = base::mac::NSStringToFilePath( | |
| 62 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); | |
| 63 | |
| 64 info->profile_dir = base::mac::NSStringToFilePath( | |
| 65 [info_plist objectForKey:app_mode::kCrAppModeProfileDirKey]); | |
| 66 | |
| 46 // ** 1: Get path to outer Chrome bundle. | 67 // ** 1: Get path to outer Chrome bundle. |
| 47 // Get the bundle ID of the browser that created this app bundle. | 68 // Get the bundle ID of the browser that created this app bundle. |
| 48 NSString* cr_bundle_id = base::mac::ObjCCast<NSString>( | 69 NSString* cr_bundle_id = base::mac::ObjCCast<NSString>( |
| 49 [app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]); | 70 [app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]); |
| 50 CHECK(cr_bundle_id) << "couldn't get browser bundle ID"; | 71 CHECK(cr_bundle_id) << "couldn't get browser bundle ID"; |
| 51 | 72 |
| 52 // First check if Chrome exists at the last known location. | 73 // First check if Chrome exists at the last known location. |
| 53 base::FilePath cr_bundle_path; | 74 base::FilePath cr_bundle_path; |
| 54 NSString* cr_bundle_path_ns = | 75 NSString* cr_bundle_path_ns = |
| 55 [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( | 76 [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( |
| 56 NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), | 77 NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), |
| 57 NSToCFCast(cr_bundle_id)))) autorelease]; | 78 NSToCFCast(cr_bundle_id)))) autorelease]; |
| 58 cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); | 79 cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); |
| 59 bool found_bundle = | 80 bool found_bundle = |
| 60 !cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path); | 81 !cr_bundle_path.empty() && base::DirectoryExists(cr_bundle_path); |
| 61 | 82 |
| 62 if (!found_bundle) { | 83 if (!found_bundle) { |
| 63 // If no such bundle path exists, try to search by bundle ID. | 84 // If no such bundle path exists, try to search by bundle ID. |
| 64 if (!app_mode::FindBundleById(cr_bundle_id, &cr_bundle_path)) { | 85 if (!app_mode::FindBundleById(cr_bundle_id, &cr_bundle_path)) { |
| 65 // TODO(jeremy): Display UI to allow user to manually locate the Chrome | 86 // TODO(jeremy): Display UI to allow user to manually locate the Chrome |
| 66 // bundle. | 87 // bundle. |
| 67 LOG(FATAL) << "Failed to locate bundle by identifier"; | 88 LOG(FATAL) << "Failed to locate bundle by identifier"; |
| 68 } | 89 } |
| 69 } | 90 } |
| 70 | 91 |
| 92 // The user_data_dir for shims actually contains the app_data_path. | |
|
tapted
2014/08/26 07:12:47
for consistency: // ** 2: Read the running Chrome
jackhou1
2014/08/26 08:15:14
Done.
| |
| 93 // I.e. <user_data_dir>/<profile_dir>/Web Applications/_crx_extensionid/ | |
| 94 base::FilePath user_data_dir = | |
|
tapted
2014/08/26 07:12:47
Can you keep the ChromeAppModeInfo populating toge
jackhou1
2014/08/26 08:15:14
Done.
| |
| 95 info->user_data_dir.DirName().DirName().DirName(); | |
| 96 CHECK(!user_data_dir.empty()); | |
| 97 | |
| 98 // Check if there is a version file written by Chrome. If so, use it to load | |
| 99 // the correct version of the framework. If not, app_mode::GetChromeBundleInfo | |
| 100 // will just load the latest version. | |
| 101 base::FilePath cr_version_str; | |
| 102 base::ReadSymbolicLink( | |
| 103 user_data_dir.Append(app_mode::kAppShimVersionSymlinkName), | |
| 104 &cr_version_str); | |
| 105 | |
| 71 // ** 2: Read information from the Chrome bundle. | 106 // ** 2: Read information from the Chrome bundle. |
| 72 base::FilePath executable_path; | 107 base::FilePath executable_path; |
| 73 base::string16 raw_version_str; | |
| 74 base::FilePath version_path; | 108 base::FilePath version_path; |
| 75 base::FilePath framework_shlib_path; | 109 base::FilePath framework_shlib_path; |
| 76 if (!app_mode::GetChromeBundleInfo(cr_bundle_path, | 110 if (!app_mode::GetChromeBundleInfo(cr_bundle_path, |
| 111 cr_version_str.value(), | |
|
tapted
2014/08/26 07:12:47
I think we can only pass this in when we know for
jackhou1
2014/08/26 08:15:14
Hmm... I think we can read the SingletonLock to co
tapted
2014/08/26 08:43:47
yeah I think that should be OK - it's only a remot
jackhou1
2014/08/27 03:04:52
Reading SingletonLock doesn't seem to work, maybe
| |
| 77 &executable_path, | 112 &executable_path, |
| 78 &raw_version_str, | |
| 79 &version_path, | 113 &version_path, |
| 80 &framework_shlib_path)) { | 114 &framework_shlib_path)) { |
| 81 LOG(FATAL) << "Couldn't ready Chrome bundle info"; | 115 LOG(FATAL) << "Couldn't ready Chrome bundle info"; |
| 82 } | 116 } |
| 83 base::FilePath app_mode_bundle_path = | 117 base::FilePath app_mode_bundle_path = |
| 84 base::mac::NSStringToFilePath([app_bundle bundlePath]); | 118 base::mac::NSStringToFilePath([app_bundle bundlePath]); |
| 85 | 119 |
| 86 // ** 3: Fill in ChromeAppModeInfo. | 120 // ** 3: Fill in ChromeAppModeInfo. |
| 87 info->chrome_outer_bundle_path = cr_bundle_path; | 121 info->chrome_outer_bundle_path = cr_bundle_path; |
| 88 info->chrome_versioned_path = version_path; | 122 info->chrome_versioned_path = version_path; |
| 89 info->app_mode_bundle_path = app_mode_bundle_path; | 123 info->app_mode_bundle_path = app_mode_bundle_path; |
| 90 | 124 |
| 91 // Read information about the this app shortcut from the Info.plist. | |
| 92 // Don't check for null-ness on optional items. | |
| 93 NSDictionary* info_plist = [app_bundle infoDictionary]; | |
| 94 CHECK(info_plist) << "couldn't get loader Info.plist"; | |
| 95 | |
| 96 info->app_mode_id = SysNSStringToUTF8( | |
| 97 [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | |
| 98 CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; | |
| 99 | |
| 100 info->app_mode_name = SysNSStringToUTF16( | |
| 101 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | |
| 102 | |
| 103 info->app_mode_url = SysNSStringToUTF8( | |
| 104 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | |
| 105 | |
| 106 info->user_data_dir = base::mac::NSStringToFilePath( | |
| 107 [info_plist objectForKey:app_mode::kCrAppModeUserDataDirKey]); | |
| 108 | |
| 109 info->profile_dir = base::mac::NSStringToFilePath( | |
| 110 [info_plist objectForKey:app_mode::kCrAppModeProfileDirKey]); | |
| 111 | |
| 112 // Open the framework. | 125 // Open the framework. |
| 113 StartFun ChromeAppModeStart = NULL; | 126 StartFun ChromeAppModeStart = NULL; |
| 114 void* cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); | 127 void* cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); |
| 115 if (cr_dylib) { | 128 if (cr_dylib) { |
| 116 // Find the entry point. | 129 // Find the entry point. |
| 117 ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); | 130 ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); |
| 118 if (!ChromeAppModeStart) | 131 if (!ChromeAppModeStart) |
| 119 LOG(ERROR) << "Couldn't get entry point: " << dlerror(); | 132 LOG(ERROR) << "Couldn't get entry point: " << dlerror(); |
| 120 } else { | 133 } else { |
| 121 LOG(ERROR) << "Couldn't load framework: " << dlerror(); | 134 LOG(ERROR) << "Couldn't load framework: " << dlerror(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 // Hard coded info parameters. | 186 // Hard coded info parameters. |
| 174 info.major_version = app_mode::kCurrentChromeAppModeInfoMajorVersion; | 187 info.major_version = app_mode::kCurrentChromeAppModeInfoMajorVersion; |
| 175 info.minor_version = app_mode::kCurrentChromeAppModeInfoMinorVersion; | 188 info.minor_version = app_mode::kCurrentChromeAppModeInfoMinorVersion; |
| 176 info.argc = argc; | 189 info.argc = argc; |
| 177 info.argv = argv; | 190 info.argv = argv; |
| 178 | 191 |
| 179 // Exit instead of returning to avoid the the removal of |main()| from stack | 192 // Exit instead of returning to avoid the the removal of |main()| from stack |
| 180 // backtraces under tail call optimization. | 193 // backtraces under tail call optimization. |
| 181 exit(LoadFrameworkAndStart(&info)); | 194 exit(LoadFrameworkAndStart(&info)); |
| 182 } | 195 } |
| OLD | NEW |