OLD | NEW |
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 #include "chrome/common/mac/cfbundle_blocker.h" | 5 #include "chrome/common/mac/cfbundle_blocker.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 _CFBundleLoadExecutableAndReturnError_Type | 149 _CFBundleLoadExecutableAndReturnError_Type |
150 g_original_underscore_cfbundle_load_executable_and_return_error; | 150 g_original_underscore_cfbundle_load_executable_and_return_error; |
151 | 151 |
152 Boolean ChromeCFBundleLoadExecutableAndReturnError(CFBundleRef bundle, | 152 Boolean ChromeCFBundleLoadExecutableAndReturnError(CFBundleRef bundle, |
153 Boolean force_global, | 153 Boolean force_global, |
154 CFErrorRef* error) { | 154 CFErrorRef* error) { |
155 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 155 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
156 | 156 |
157 DCHECK(g_original_underscore_cfbundle_load_executable_and_return_error); | 157 DCHECK(g_original_underscore_cfbundle_load_executable_and_return_error); |
158 | 158 |
159 base::mac::ScopedCFTypeRef<CFURLRef> url_cf(CFBundleCopyBundleURL(bundle)); | 159 base::ScopedCFTypeRef<CFURLRef> url_cf(CFBundleCopyBundleURL(bundle)); |
160 scoped_nsobject<NSString> path(base::mac::CFToNSCast( | 160 scoped_nsobject<NSString> path(base::mac::CFToNSCast( |
161 CFURLCopyFileSystemPath(url_cf, kCFURLPOSIXPathStyle))); | 161 CFURLCopyFileSystemPath(url_cf, kCFURLPOSIXPathStyle))); |
162 | 162 |
163 NSString* bundle_id = base::mac::CFToNSCast(CFBundleGetIdentifier(bundle)); | 163 NSString* bundle_id = base::mac::CFToNSCast(CFBundleGetIdentifier(bundle)); |
164 | 164 |
165 NSDictionary* bundle_dictionary = | 165 NSDictionary* bundle_dictionary = |
166 base::mac::CFToNSCast(CFBundleGetInfoDictionary(bundle)); | 166 base::mac::CFToNSCast(CFBundleGetInfoDictionary(bundle)); |
167 NSString* version = [bundle_dictionary objectForKey: | 167 NSString* version = [bundle_dictionary objectForKey: |
168 base::mac::CFToNSCast(kCFBundleVersionKey)]; | 168 base::mac::CFToNSCast(kCFBundleVersionKey)]; |
169 if (![version isKindOfClass:[NSString class]]) { | 169 if (![version isKindOfClass:[NSString class]]) { |
170 // Deal with pranksters. | 170 // Deal with pranksters. |
171 version = nil; | 171 version = nil; |
172 } | 172 } |
173 | 173 |
174 if (IsBundlePathBlocked(path) && !IsBundleAllowed(bundle_id, version)) { | 174 if (IsBundlePathBlocked(path) && !IsBundleAllowed(bundle_id, version)) { |
175 NSString* bundle_id_print = bundle_id ? bundle_id : @"(nil)"; | 175 NSString* bundle_id_print = bundle_id ? bundle_id : @"(nil)"; |
176 NSString* version_print = version ? version : @"(nil)"; | 176 NSString* version_print = version ? version : @"(nil)"; |
177 | 177 |
178 // Provide a hint for the user (or module developer) to figure out | 178 // Provide a hint for the user (or module developer) to figure out |
179 // that the bundle was blocked. | 179 // that the bundle was blocked. |
180 LOG(INFO) << "Blocking attempt to load bundle " | 180 LOG(INFO) << "Blocking attempt to load bundle " |
181 << [bundle_id_print UTF8String] | 181 << [bundle_id_print UTF8String] |
182 << " version " | 182 << " version " |
183 << [version_print UTF8String] | 183 << [version_print UTF8String] |
184 << " at " | 184 << " at " |
185 << [path fileSystemRepresentation]; | 185 << [path fileSystemRepresentation]; |
186 | 186 |
187 if (error) { | 187 if (error) { |
188 base::mac::ScopedCFTypeRef<CFStringRef> app_bundle_id( | 188 base::ScopedCFTypeRef<CFStringRef> app_bundle_id( |
189 base::SysUTF8ToCFStringRef(base::mac::BaseBundleID())); | 189 base::SysUTF8ToCFStringRef(base::mac::BaseBundleID())); |
190 | 190 |
191 // 0xb10c10ad = "block load" | 191 // 0xb10c10ad = "block load" |
192 const CFIndex kBundleLoadBlocked = 0xb10c10ad; | 192 const CFIndex kBundleLoadBlocked = 0xb10c10ad; |
193 | 193 |
194 NSMutableDictionary* error_dict = | 194 NSMutableDictionary* error_dict = |
195 [NSMutableDictionary dictionaryWithCapacity:4]; | 195 [NSMutableDictionary dictionaryWithCapacity:4]; |
196 if (bundle_id) { | 196 if (bundle_id) { |
197 [error_dict setObject:bundle_id forKey:@"bundle_id"]; | 197 [error_dict setObject:bundle_id forKey:@"bundle_id"]; |
198 } | 198 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 // Nothing matched. | 326 // Nothing matched. |
327 return false; | 327 return false; |
328 } | 328 } |
329 | 329 |
330 } // namespace mac | 330 } // namespace mac |
331 } // namespace common | 331 } // namespace common |
332 } // namespace chrome | 332 } // namespace chrome |
OLD | NEW |