| 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 21 matching lines...) Expand all  Loading... | 
|   32   using base::mac::NSToCFCast; |   32   using base::mac::NSToCFCast; | 
|   33  |   33  | 
|   34   base::mac::ScopedNSAutoreleasePool scoped_pool; |   34   base::mac::ScopedNSAutoreleasePool scoped_pool; | 
|   35  |   35  | 
|   36   // Get the current main bundle, i.e., that of the app loader that's running. |   36   // Get the current main bundle, i.e., that of the app loader that's running. | 
|   37   NSBundle* app_bundle = [NSBundle mainBundle]; |   37   NSBundle* app_bundle = [NSBundle mainBundle]; | 
|   38   CHECK(app_bundle) << "couldn't get loader bundle"; |   38   CHECK(app_bundle) << "couldn't get loader bundle"; | 
|   39  |   39  | 
|   40   // ** 1: Get path to outer Chrome bundle. |   40   // ** 1: Get path to outer Chrome bundle. | 
|   41   // Get the bundle ID of the browser that created this app bundle. |   41   // Get the bundle ID of the browser that created this app bundle. | 
|   42   NSString* cr_bundle_id = [app_bundle |   42   NSString* cr_bundle_id = base::mac::ObjCCast<NSString>( | 
|   43       objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]; |   43       [app_bundle objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey]); | 
|   44   CHECK(cr_bundle_id) << "couldn't get browser bundle ID"; |   44   CHECK(cr_bundle_id) << "couldn't get browser bundle ID"; | 
|   45  |   45  | 
|   46   // First check if Chrome exists at the last known location. |   46   // First check if Chrome exists at the last known location. | 
|   47   FilePath cr_bundle_path; |   47   FilePath cr_bundle_path; | 
|   48   NSString* cr_bundle_path_ns = |   48   NSString* cr_bundle_path_ns = | 
|   49       [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( |   49       [CFToNSCast(CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue( | 
|   50           NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), |   50           NSToCFCast(app_mode::kLastRunAppBundlePathPrefsKey), | 
|   51           NSToCFCast(cr_bundle_id)))) autorelease]; |   51           NSToCFCast(cr_bundle_id)))) autorelease]; | 
|   52   cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); |   52   cr_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns); | 
|   53   bool found_bundle = |   53   bool found_bundle = | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|   65   // ** 2: Read information from the Chrome bundle. |   65   // ** 2: Read information from the Chrome bundle. | 
|   66   string16 raw_version_str; |   66   string16 raw_version_str; | 
|   67   FilePath version_path; |   67   FilePath version_path; | 
|   68   FilePath framework_shlib_path; |   68   FilePath framework_shlib_path; | 
|   69   if (!app_mode::GetChromeBundleInfo(cr_bundle_path, &raw_version_str, |   69   if (!app_mode::GetChromeBundleInfo(cr_bundle_path, &raw_version_str, | 
|   70           &version_path, &framework_shlib_path)) { |   70           &version_path, &framework_shlib_path)) { | 
|   71     LOG(FATAL) << "Couldn't ready Chrome bundle info"; |   71     LOG(FATAL) << "Couldn't ready Chrome bundle info"; | 
|   72   } |   72   } | 
|   73  |   73  | 
|   74   // ** 3: Fill in ChromeAppModeInfo. |   74   // ** 3: Fill in ChromeAppModeInfo. | 
 |   75   info->chrome_outer_bundle_path = cr_bundle_path; | 
|   75   info->chrome_versioned_path = version_path; |   76   info->chrome_versioned_path = version_path; | 
|   76   info->app_mode_bundle_path = |   77   info->app_mode_bundle_path = | 
|   77       base::mac::NSStringToFilePath([app_bundle bundlePath]); |   78       base::mac::NSStringToFilePath([app_bundle bundlePath]); | 
|   78  |   79  | 
|   79   // Read information about the this app shortcut from the Info.plist. |   80   // Read information about the this app shortcut from the Info.plist. | 
|   80   // Don't check for null-ness on optional items. |   81   // Don't check for null-ness on optional items. | 
|   81   NSDictionary* info_plist = [app_bundle infoDictionary]; |   82   NSDictionary* info_plist = [app_bundle infoDictionary]; | 
|   82   CHECK(info_plist) << "couldn't get loader Info.plist"; |   83   CHECK(info_plist) << "couldn't get loader Info.plist"; | 
|   83  |   84  | 
|   84   info->app_mode_id = SysNSStringToUTF8( |   85   info->app_mode_id = SysNSStringToUTF8( | 
|   85       [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |   86       [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 
|   86   CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; |   87   CHECK(info->app_mode_id.size()) << "couldn't get app shortcut ID"; | 
|   87  |   88  | 
|   88   info->app_mode_short_name = SysNSStringToUTF16( |   89   info->app_mode_short_name = SysNSStringToUTF16( | 
|   89       [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]); |   90       [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]); | 
|   90  |   91  | 
|   91   info->app_mode_name = SysNSStringToUTF16( |   92   info->app_mode_name = SysNSStringToUTF16( | 
|   92       [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |   93       [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 
|   93  |   94  | 
|   94   info->app_mode_url = SysNSStringToUTF8( |   95   info->app_mode_url = SysNSStringToUTF8( | 
|   95       [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |   96       [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 
|   96   CHECK(info->app_mode_url.size()) << "couldn't get app shortcut URL"; |  | 
|   97  |   97  | 
|   98   // Open the framework. |   98   // Open the framework. | 
|   99   *cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); |   99   *cr_dylib = dlopen(framework_shlib_path.value().c_str(), RTLD_LAZY); | 
|  100   CHECK(cr_dylib) << "couldn't load framework: " << dlerror(); |  100   CHECK(cr_dylib) << "couldn't load framework: " << dlerror(); | 
|  101 } |  101 } | 
|  102  |  102  | 
|  103 } // namespace |  103 } // namespace | 
|  104  |  104  | 
|  105 __attribute__((visibility("default"))) |  105 __attribute__((visibility("default"))) | 
|  106 int main(int argc, char** argv) { |  106 int main(int argc, char** argv) { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|  118  |  118  | 
|  119   typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); |  119   typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); | 
|  120   StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); |  120   StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); | 
|  121   CHECK(ChromeAppModeStart) << "couldn't get entry point"; |  121   CHECK(ChromeAppModeStart) << "couldn't get entry point"; | 
|  122  |  122  | 
|  123   // Exit instead of returning to avoid the the removal of |main()| from stack |  123   // Exit instead of returning to avoid the the removal of |main()| from stack | 
|  124   // backtraces under tail call optimization. |  124   // backtraces under tail call optimization. | 
|  125   int rv = ChromeAppModeStart(&info); |  125   int rv = ChromeAppModeStart(&info); | 
|  126   exit(rv); |  126   exit(rv); | 
|  127 } |  127 } | 
| OLD | NEW |