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

Side by Side Diff: base/mac/foundation_util.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) 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 #include "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // bundle dictionary. It needs to look at the actual running .app's 66 // bundle dictionary. It needs to look at the actual running .app's
67 // Info.plist to access its LSUIElement property. 67 // Info.plist to access its LSUIElement property.
68 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; 68 NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary];
69 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO; 69 return [[info_dictionary objectForKey:@"LSUIElement"] boolValue] != NO;
70 } 70 }
71 71
72 FilePath PathForFrameworkBundleResource(CFStringRef resourceName) { 72 FilePath PathForFrameworkBundleResource(CFStringRef resourceName) {
73 NSBundle* bundle = base::mac::FrameworkBundle(); 73 NSBundle* bundle = base::mac::FrameworkBundle();
74 NSString* resourcePath = [bundle pathForResource:(NSString*)resourceName 74 NSString* resourcePath = [bundle pathForResource:(NSString*)resourceName
75 ofType:nil]; 75 ofType:nil];
76 if (!resourcePath) 76 return NSStringToFilePath(resourcePath);
77 return FilePath();
78 return FilePath([resourcePath fileSystemRepresentation]);
79 } 77 }
80 78
81 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) { 79 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) {
82 OSType creator = kUnknownType; 80 OSType creator = kUnknownType;
83 CFBundleGetPackageInfo(bundle, NULL, &creator); 81 CFBundleGetPackageInfo(bundle, NULL, &creator);
84 return creator; 82 return creator;
85 } 83 }
86 84
87 OSType CreatorCodeForApplication() { 85 OSType CreatorCodeForApplication() {
88 CFBundleRef bundle = CFBundleGetMainBundle(); 86 CFBundleRef bundle = CFBundleGetMainBundle();
89 if (!bundle) 87 if (!bundle)
90 return kUnknownType; 88 return kUnknownType;
91 89
92 return CreatorCodeForCFBundleRef(bundle); 90 return CreatorCodeForCFBundleRef(bundle);
93 } 91 }
94 92
95 bool GetSearchPathDirectory(NSSearchPathDirectory directory, 93 bool GetSearchPathDirectory(NSSearchPathDirectory directory,
96 NSSearchPathDomainMask domain_mask, 94 NSSearchPathDomainMask domain_mask,
97 FilePath* result) { 95 FilePath* result) {
98 DCHECK(result); 96 DCHECK(result);
99 NSArray* dirs = 97 NSArray* dirs =
100 NSSearchPathForDirectoriesInDomains(directory, domain_mask, YES); 98 NSSearchPathForDirectoriesInDomains(directory, domain_mask, YES);
101 if ([dirs count] < 1) { 99 if ([dirs count] < 1) {
102 return false; 100 return false;
103 } 101 }
104 NSString* path = [dirs objectAtIndex:0]; 102 *result = NSStringToFilePath([dirs objectAtIndex:0]);
105 *result = FilePath([path fileSystemRepresentation]);
106 return true; 103 return true;
107 } 104 }
108 105
109 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) { 106 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) {
110 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); 107 return GetSearchPathDirectory(directory, NSLocalDomainMask, result);
111 } 108 }
112 109
113 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { 110 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) {
114 return GetSearchPathDirectory(directory, NSUserDomainMask, result); 111 return GetSearchPathDirectory(directory, NSUserDomainMask, result);
115 } 112 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 CFCopyTypeIDDescription(CFGetTypeID(value))); 320 CFCopyTypeIDDescription(CFGetTypeID(value)));
324 return "Expected value for key " + 321 return "Expected value for key " +
325 base::SysCFStringRefToUTF8(key) + 322 base::SysCFStringRefToUTF8(key) +
326 " to be " + 323 " to be " +
327 expected_type + 324 expected_type +
328 " but it was " + 325 " but it was " +
329 base::SysCFStringRefToUTF8(actual_type_ref) + 326 base::SysCFStringRefToUTF8(actual_type_ref) +
330 " instead"; 327 " instead";
331 } 328 }
332 329
330 NSString* FilePathToNSString(const FilePath& path) {
331 if (path.empty())
332 return nil;
333 return [[NSFileManager defaultManager]
334 stringWithFileSystemRepresentation:path.value().c_str()
Mark Mentovai 2012/02/08 04:29:04 This is overkill. +[NSString stringWithUTF8String:
sail 2012/02/08 05:21:38 Done.
335 length:path.value().size()];
336 }
337
338 FilePath NSStringToFilePath(NSString* str) {
339 if (!str || ![str length])
Mark Mentovai 2012/02/08 04:29:04 You can simplify this to (![str length]).
sail 2012/02/08 05:21:38 Done.
340 return FilePath();
341 return FilePath([str fileSystemRepresentation]);
342 }
343
333 } // namespace mac 344 } // namespace mac
334 } // namespace base 345 } // namespace base
335 346
336 std::ostream& operator<<(std::ostream& o, const CFStringRef string) { 347 std::ostream& operator<<(std::ostream& o, const CFStringRef string) {
337 return o << base::SysCFStringRefToUTF8(string); 348 return o << base::SysCFStringRefToUTF8(string);
338 } 349 }
339 350
340 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { 351 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) {
341 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); 352 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err));
342 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( 353 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info(
343 CFErrorCopyUserInfo(err)); 354 CFErrorCopyUserInfo(err));
344 CFStringRef errorDesc = NULL; 355 CFStringRef errorDesc = NULL;
345 if (user_info.get()) { 356 if (user_info.get()) {
346 errorDesc = reinterpret_cast<CFStringRef>( 357 errorDesc = reinterpret_cast<CFStringRef>(
347 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 358 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
348 } 359 }
349 o << "Code: " << CFErrorGetCode(err) 360 o << "Code: " << CFErrorGetCode(err)
350 << " Domain: " << CFErrorGetDomain(err) 361 << " Domain: " << CFErrorGetDomain(err)
351 << " Desc: " << desc.get(); 362 << " Desc: " << desc.get();
352 if(errorDesc) { 363 if(errorDesc) {
353 o << "(" << errorDesc << ")"; 364 o << "(" << errorDesc << ")";
354 } 365 }
355 return o; 366 return o;
356 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698