Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: chrome/app/app_mode_loader_mac.mm

Issue 9346013: Publish app shortcuts on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // The Cocoa APIs are a bit more convenient; for this an autorelease pool is 59 // The Cocoa APIs are a bit more convenient; for this an autorelease pool is
60 // needed. 60 // needed.
61 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 61 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
62 62
63 // Get the current main bundle, i.e., that of the app loader that's running. 63 // Get the current main bundle, i.e., that of the app loader that's running.
64 NSBundle* app_bundle = [NSBundle mainBundle]; 64 NSBundle* app_bundle = [NSBundle mainBundle];
65 CHECK_MSG(app_bundle, "couldn't get loader bundle"); 65 CHECK_MSG(app_bundle, "couldn't get loader bundle");
66 66
67 // Get the bundle ID of the browser that created this app bundle. 67 // Get the bundle ID of the browser that created this app bundle.
68 NSString* cr_bundle_id = [app_bundle 68 NSString* cr_bundle_id = [app_bundle
69 objectForInfoDictionaryKey:(NSString*)app_mode::kBrowserBundleIDKey]; 69 objectForInfoDictionaryKey:app_mode::kBrowserBundleIDKey];
70 CHECK_MSG(cr_bundle_id, "couldn't get browser bundle ID"); 70 CHECK_MSG(cr_bundle_id, "couldn't get browser bundle ID");
71 71
72 // Get the browser bundle path. 72 // Get the browser bundle path.
73 // TODO(viettrungluu): more fun 73 // TODO(viettrungluu): more fun
74 NSString* cr_bundle_path = 74 NSString* cr_bundle_path = [(NSString*)CFPreferencesCopyAppValue(
---DO-NOT-USE---rsesek1 2012/02/08 12:24:33 You could fix these up to use the NSToCFCast and C
sail 2012/02/08 19:09:15 Currently this code doesn't use base/*. This is fi
75 [(NSString*)CFPreferencesCopyAppValue( 75 (CFStringRef)app_mode::kLastRunAppBundlePathPrefsKey,
76 app_mode::kLastRunAppBundlePathPrefsKey, 76 (CFStringRef)cr_bundle_id) autorelease];
77 (CFStringRef)cr_bundle_id) autorelease];
78 CHECK_MSG(cr_bundle_path, "couldn't get browser bundle path"); 77 CHECK_MSG(cr_bundle_path, "couldn't get browser bundle path");
79 78
80 // Get the browser bundle. 79 // Get the browser bundle.
81 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path]; 80 NSBundle* cr_bundle = [NSBundle bundleWithPath:cr_bundle_path];
82 CHECK_MSG(cr_bundle, "couldn't get browser bundle"); 81 CHECK_MSG(cr_bundle, "couldn't get browser bundle");
83 82
84 // Get the current browser version. 83 // Get the current browser version.
85 NSString* cr_version = 84 NSString* cr_version =
86 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 85 [cr_bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
87 CHECK_MSG(cr_version, "couldn't get browser version"); 86 CHECK_MSG(cr_version, "couldn't get browser version");
(...skipping 14 matching lines...) Expand all
102 101
103 // Optional, so okay if it's NULL. 102 // Optional, so okay if it's NULL.
104 info.app_mode_bundle_path = NSStringToFSCString([app_bundle bundlePath]); 103 info.app_mode_bundle_path = NSStringToFSCString([app_bundle bundlePath]);
105 104
106 // Read information about the this app shortcut from the Info.plist. 105 // Read information about the this app shortcut from the Info.plist.
107 // Don't check for null-ness on optional items. 106 // Don't check for null-ness on optional items.
108 NSDictionary* info_plist = [app_bundle infoDictionary]; 107 NSDictionary* info_plist = [app_bundle infoDictionary];
109 CHECK_MSG(info_plist, "couldn't get loader Info.plist"); 108 CHECK_MSG(info_plist, "couldn't get loader Info.plist");
110 109
111 info.app_mode_id = NSStringToUTF8CString( 110 info.app_mode_id = NSStringToUTF8CString(
112 [info_plist objectForKey:@"CrAppModeShortcutID"]); 111 [info_plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
113 CHECK_MSG(info.app_mode_id, "couldn't get app shortcut ID"); 112 CHECK_MSG(info.app_mode_id, "couldn't get app shortcut ID");
114 113
115 info.app_mode_short_name = NSStringToUTF8CString( 114 info.app_mode_short_name = NSStringToUTF8CString(
116 [info_plist objectForKey:@"CrAppModeShortcutShortName"]); 115 [info_plist objectForKey:app_mode::kCrAppModeShortcutShortNameKey]);
117 116
118 info.app_mode_name = NSStringToUTF8CString( 117 info.app_mode_name = NSStringToUTF8CString(
119 [info_plist objectForKey:@"CrAppModeShortcutName"]); 118 [info_plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
120 119
121 info.app_mode_url = NSStringToUTF8CString( 120 info.app_mode_url = NSStringToUTF8CString(
122 [info_plist objectForKey:@"CrAppModeShortcutURL"]); 121 [info_plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
123 CHECK_MSG(info.app_mode_url, "couldn't get app shortcut URL"); 122 CHECK_MSG(info.app_mode_url, "couldn't get app shortcut URL");
124 123
125 // Get the framework path. 124 // Get the framework path.
126 NSString* cr_bundle_exe = 125 NSString* cr_bundle_exe =
127 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"]; 126 [cr_bundle objectForInfoDictionaryKey:@"CFBundleExecutable"];
128 NSString* cr_framework_path = 127 NSString* cr_framework_path =
129 [cr_versioned_path stringByAppendingPathComponent: 128 [cr_versioned_path stringByAppendingPathComponent:
130 [cr_bundle_exe stringByAppendingString:@" Framework.framework"]]; 129 [cr_bundle_exe stringByAppendingString:@" Framework.framework"]];
131 cr_framework_path = 130 cr_framework_path =
132 [cr_framework_path stringByAppendingPathComponent: 131 [cr_framework_path stringByAppendingPathComponent:
133 [cr_bundle_exe stringByAppendingString:@" Framework"]]; 132 [cr_bundle_exe stringByAppendingString:@" Framework"]];
134 133
135 // Open the framework. 134 // Open the framework.
136 void* cr_dylib = dlopen([cr_framework_path fileSystemRepresentation], 135 void* cr_dylib = dlopen([cr_framework_path fileSystemRepresentation],
137 RTLD_LAZY); 136 RTLD_LAZY);
138 CHECK_MSG(cr_dylib, "couldn't load framework"); 137 CHECK_MSG(cr_dylib, "couldn't load framework");
139 138
140 // Drain the pool as late as possible. 139 // Drain the pool as late as possible.
141 [pool drain]; 140 [pool drain];
142 141
143 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*); 142 typedef int (*StartFun)(const app_mode::ChromeAppModeInfo*);
144 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart"); 143 StartFun ChromeAppModeStart = (StartFun)dlsym(cr_dylib, "ChromeAppModeStart");
145 CHECK_MSG(ChromeAppModeStart, "couldn't get entry point"); 144 CHECK_MSG(ChromeAppModeStart, "couldn't get entry point");
146 145
147 // Exit instead of returning to avoid the the removal of |main()| from stack 146 // Exit instead of returning to avoid the the removal of |main()| from stack
148 // backtraces under tail call optimization. 147 // backtraces under tail call optimization.
149 int rv = ChromeAppModeStart(&info); 148 int rv = ChromeAppModeStart(&info);
150 exit(rv); 149 exit(rv);
151 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698