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

Side by Side Diff: chrome/browser/ui/cocoa/file_metadata.mm

Issue 6594096: Clean up CF To NS Casts and make them slightly safer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix space Created 9 years, 9 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
« no previous file with comments | « chrome/browser/importer/safari_importer.mm ('k') | ui/gfx/canvas_skia_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 if (!md_item_set_attribute_func) 64 if (!md_item_set_attribute_func)
65 return; 65 return;
66 66
67 NSString* file_path = 67 NSString* file_path =
68 [NSString stringWithUTF8String:file.value().c_str()]; 68 [NSString stringWithUTF8String:file.value().c_str()];
69 if (!file_path) 69 if (!file_path)
70 return; 70 return;
71 71
72 base::mac::ScopedCFTypeRef<MDItemRef> md_item( 72 base::mac::ScopedCFTypeRef<MDItemRef> md_item(
73 MDItemCreate(NULL, reinterpret_cast<CFStringRef>(file_path))); 73 MDItemCreate(NULL, base::mac::NSToCFCast(file_path)));
74 if (!md_item) 74 if (!md_item)
75 return; 75 return;
76 76
77 // We won't put any more than 2 items into the attribute. 77 // We won't put any more than 2 items into the attribute.
78 NSMutableArray* list = [NSMutableArray arrayWithCapacity:2]; 78 NSMutableArray* list = [NSMutableArray arrayWithCapacity:2];
79 79
80 // Follow Safari's lead: the first item in the list is the source URL of 80 // Follow Safari's lead: the first item in the list is the source URL of
81 // the downloaded file. If the referrer is known, store that, too. 81 // the downloaded file. If the referrer is known, store that, too.
82 NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()]; 82 NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()];
83 if (origin_url) 83 if (origin_url)
84 [list addObject:origin_url]; 84 [list addObject:origin_url];
85 NSString* referrer_url = 85 NSString* referrer_url =
86 [NSString stringWithUTF8String:referrer.spec().c_str()]; 86 [NSString stringWithUTF8String:referrer.spec().c_str()];
87 if (referrer_url) 87 if (referrer_url)
88 [list addObject:referrer_url]; 88 [list addObject:referrer_url];
89 89
90 md_item_set_attribute_func(md_item, kMDItemWhereFroms, 90 md_item_set_attribute_func(md_item, kMDItemWhereFroms,
91 reinterpret_cast<CFArrayRef>(list)); 91 base::mac::NSToCFCast(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 (!base::mac::FSRefFromPath(file.value(), &file_ref)) 101 if (!base::mac::FSRefFromPath(file.value(), &file_ref))
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « chrome/browser/importer/safari_importer.mm ('k') | ui/gfx/canvas_skia_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698