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

Side by Side Diff: content/browser/download/quarantine_mac.mm

Issue 2389123002: [Mac Fix-It] Use FSPathMakeRef instead of base::mac::FSRefFromPath. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/download/quarantine.h" 5 #include "content/browser/download/quarantine.h"
6 6
7 #import <ApplicationServices/ApplicationServices.h> 7 #import <ApplicationServices/ApplicationServices.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 13 matching lines...) Expand all
24 // necessary. Note that LSCopyItemAttribute was deprecated in macOS 10.8, but 24 // necessary. Note that LSCopyItemAttribute was deprecated in macOS 10.8, but
25 // the replacement to kLSItemQuarantineProperties did not exist until macOS 25 // the replacement to kLSItemQuarantineProperties did not exist until macOS
26 // 10.10. 26 // 10.10.
27 #if !defined(MAC_OS_X_VERSION_10_10) || \ 27 #if !defined(MAC_OS_X_VERSION_10_10) || \
28 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 28 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
29 #pragma clang diagnostic push 29 #pragma clang diagnostic push
30 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 30 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
31 bool GetQuarantinePropertiesDeprecated( 31 bool GetQuarantinePropertiesDeprecated(
32 const base::FilePath& file, 32 const base::FilePath& file,
33 base::scoped_nsobject<NSMutableDictionary>* properties) { 33 base::scoped_nsobject<NSMutableDictionary>* properties) {
34 const UInt8* path = reinterpret_cast<const UInt8*>(file.value().c_str());
34 FSRef file_ref; 35 FSRef file_ref;
35 if (!base::mac::FSRefFromPath(file.value(), &file_ref)) 36 if (FSPathMakeRef(path, &file_ref, nullptr) != noErr)
36 return false; 37 return false;
37 38
38 base::ScopedCFTypeRef<CFTypeRef> quarantine_properties; 39 base::ScopedCFTypeRef<CFTypeRef> quarantine_properties;
39 OSStatus status = LSCopyItemAttribute(&file_ref, kLSRolesAll, 40 OSStatus status = LSCopyItemAttribute(&file_ref, kLSRolesAll,
40 kLSItemQuarantineProperties, quarantine_properties.InitializeInto()); 41 kLSItemQuarantineProperties, quarantine_properties.InitializeInto());
41 if (status != noErr) 42 if (status != noErr)
42 return true; 43 return true;
43 44
44 CFDictionaryRef quarantine_properties_dict = 45 CFDictionaryRef quarantine_properties_dict =
45 base::mac::CFCast<CFDictionaryRef>(quarantine_properties.get()); 46 base::mac::CFCast<CFDictionaryRef>(quarantine_properties.get());
46 if (!quarantine_properties_dict) { 47 if (!quarantine_properties_dict) {
47 LOG(WARNING) << "kLSItemQuarantineProperties is not a dictionary on file " 48 LOG(WARNING) << "kLSItemQuarantineProperties is not a dictionary on file "
48 << file.value(); 49 << file.value();
49 return false; 50 return false;
50 } 51 }
51 52
52 properties->reset( 53 properties->reset(
53 [base::mac::CFToNSCast(quarantine_properties_dict) mutableCopy]); 54 [base::mac::CFToNSCast(quarantine_properties_dict) mutableCopy]);
54 return true; 55 return true;
55 } 56 }
56 57
57 bool SetQuarantinePropertiesDeprecated(const base::FilePath& file, 58 bool SetQuarantinePropertiesDeprecated(const base::FilePath& file,
58 NSDictionary* properties) { 59 NSDictionary* properties) {
60 const UInt8* path = reinterpret_cast<const UInt8*>(file.value().c_str());
59 FSRef file_ref; 61 FSRef file_ref;
60 if (!base::mac::FSRefFromPath(file.value(), &file_ref)) 62 if (FSPathMakeRef(path, &file_ref, nullptr) != noErr)
61 return false; 63 return false;
62 OSStatus os_error = LSSetItemAttribute( 64 OSStatus os_error = LSSetItemAttribute(
63 &file_ref, kLSRolesAll, kLSItemQuarantineProperties, properties); 65 &file_ref, kLSRolesAll, kLSItemQuarantineProperties, properties);
64 if (os_error != noErr) { 66 if (os_error != noErr) {
65 OSSTATUS_LOG(WARNING, os_error) 67 OSSTATUS_LOG(WARNING, os_error)
66 << "Unable to set quarantine attributes on file " << file.value(); 68 << "Unable to set quarantine attributes on file " << file.value();
67 return false; 69 return false;
68 } 70 }
69 return true; 71 return true;
70 } 72 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 bool quarantine_succeeded = 295 bool quarantine_succeeded =
294 AddQuarantineMetadataToFile(file, source_url, referrer_url); 296 AddQuarantineMetadataToFile(file, source_url, referrer_url);
295 bool origin_succeeded = 297 bool origin_succeeded =
296 AddOriginMetadataToFile(file, source_url, referrer_url); 298 AddOriginMetadataToFile(file, source_url, referrer_url);
297 return quarantine_succeeded && origin_succeeded 299 return quarantine_succeeded && origin_succeeded
298 ? QuarantineFileResult::OK 300 ? QuarantineFileResult::OK
299 : QuarantineFileResult::ANNOTATION_FAILED; 301 : QuarantineFileResult::ANNOTATION_FAILED;
300 } 302 }
301 303
302 } // namespace content 304 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698