| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/browser/ui/cocoa/file_metadata.h" | 5 #include "chrome/browser/ui/cocoa/file_metadata.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Foundation/Foundation.h> | 8 #include <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 | 15 |
| 16 namespace file_metadata { | 16 namespace file_metadata { |
| 17 | 17 |
| 18 // As of Mac OS X 10.4 ("Tiger"), files can be tagged with metadata describing | 18 // As of Mac OS X 10.4 ("Tiger"), files can be tagged with metadata describing |
| 19 // various attributes. Metadata is integrated with the system's Spotlight | 19 // various attributes. Metadata is integrated with the system's Spotlight |
| 20 // feature and is searchable. Ordinarily, metadata can only be set by | 20 // feature and is searchable. Ordinarily, metadata can only be set by |
| 21 // Spotlight importers, which requires that the importer own the target file. | 21 // Spotlight importers, which requires that the importer own the target file. |
| 22 // However, there's an attribute intended to describe the origin of a | 22 // However, there's an attribute intended to describe the origin of a |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 reinterpret_cast<CFArrayRef>(list)); | 91 reinterpret_cast<CFArrayRef>(list)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // The OS will automatically quarantine files due to the | 94 // The OS will automatically quarantine files due to the |
| 95 // LSFileQuarantineEnabled entry in our Info.plist, but it knows relatively | 95 // LSFileQuarantineEnabled entry in our Info.plist, but it knows relatively |
| 96 // little about the files. We add more information about the download to | 96 // little about the files. We add more information about the download to |
| 97 // improve the UI shown by the OS when the users tries to open the file. | 97 // improve the UI shown by the OS when the users tries to open the file. |
| 98 void AddQuarantineMetadataToFile(const FilePath& file, const GURL& source, | 98 void AddQuarantineMetadataToFile(const FilePath& file, const GURL& source, |
| 99 const GURL& referrer) { | 99 const GURL& referrer) { |
| 100 FSRef file_ref; | 100 FSRef file_ref; |
| 101 if (!mac_util::FSRefFromPath(file.value(), &file_ref)) | 101 if (!base::mac::FSRefFromPath(file.value(), &file_ref)) |
| 102 return; | 102 return; |
| 103 | 103 |
| 104 NSMutableDictionary* quarantine_properties = nil; | 104 NSMutableDictionary* quarantine_properties = nil; |
| 105 CFTypeRef quarantine_properties_base = NULL; | 105 CFTypeRef quarantine_properties_base = NULL; |
| 106 if (LSCopyItemAttribute(&file_ref, kLSRolesAll, kLSItemQuarantineProperties, | 106 if (LSCopyItemAttribute(&file_ref, kLSRolesAll, kLSItemQuarantineProperties, |
| 107 &quarantine_properties_base) == noErr) { | 107 &quarantine_properties_base) == noErr) { |
| 108 if (CFGetTypeID(quarantine_properties_base) == | 108 if (CFGetTypeID(quarantine_properties_base) == |
| 109 CFDictionaryGetTypeID()) { | 109 CFDictionaryGetTypeID()) { |
| 110 // Quarantine properties will already exist if LSFileQuarantineEnabled | 110 // Quarantine properties will already exist if LSFileQuarantineEnabled |
| 111 // is on and the file doesn't match an exclusion. | 111 // is on and the file doesn't match an exclusion. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 OSStatus os_error = LSSetItemAttribute(&file_ref, kLSRolesAll, | 158 OSStatus os_error = LSSetItemAttribute(&file_ref, kLSRolesAll, |
| 159 kLSItemQuarantineProperties, | 159 kLSItemQuarantineProperties, |
| 160 quarantine_properties); | 160 quarantine_properties); |
| 161 if (os_error != noErr) { | 161 if (os_error != noErr) { |
| 162 LOG(WARNING) << "Unable to set quarantine attributes on file " | 162 LOG(WARNING) << "Unable to set quarantine attributes on file " |
| 163 << file.value(); | 163 << file.value(); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace file_metadata | 167 } // namespace file_metadata |
| OLD | NEW |