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

Side by Side Diff: content/browser/download/quarantine_linux.cc

Issue 2123023002: [Downloads] Consolidate MOTW annotation APIs into a single API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-safe-util-to-downloads
Patch Set: [win] Verify that the Zone.Identifier stream has the correct contents. 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
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 "content/browser/download/file_metadata_linux.h" 5 #include "content/browser/download/quarantine.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 10
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/threading/thread_restrictions.h"
15 #include "content/browser/download/quarantine_constants_linux.h"
14 #include "url/gurl.h" 16 #include "url/gurl.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 const char kSourceURLAttrName[] = "user.xdg.origin.url"; 20 const char kSourceURLExtendedAttrName[] = "user.xdg.origin.url";
19 const char kReferrerURLAttrName[] = "user.xdg.referrer.url"; 21 const char kReferrerURLExtendedAttrName[] = "user.xdg.referrer.url";
20 22
21 static void SetExtendedFileAttribute(const char* path, const char* name, 23 namespace {
22 const char* value, size_t value_size, 24
23 int flags) { 25 bool SetExtendedFileAttribute(const char* path,
26 const char* name,
27 const char* value,
28 size_t value_size,
29 int flags) {
30 base::ThreadRestrictions::AssertIOAllowed();
24 int result = setxattr(path, name, value, value_size, flags); 31 int result = setxattr(path, name, value, value_size, flags);
25 if (result) { 32 if (result) {
26 DPLOG(ERROR) 33 DPLOG(ERROR) << "Could not set extended attribute " << name << " on file "
27 << "Could not set extended attribute " << name << " on file " << path; 34 << path;
35 return false;
28 } 36 }
37 return true;
29 } 38 }
30 39
31 void AddOriginMetadataToFile(const base::FilePath& file, const GURL& source, 40 } // namespace
32 const GURL& referrer) { 41
42 QuarantineFileResult QuarantineFile(const base::FilePath& file,
43 const GURL& source_url,
44 const GURL& referrer_url,
45 const std::string& client_guid) {
33 DCHECK(base::PathIsWritable(file)); 46 DCHECK(base::PathIsWritable(file));
34 if (source.is_valid()) { 47
35 SetExtendedFileAttribute(file.value().c_str(), kSourceURLAttrName, 48 bool source_succeeded =
36 source.spec().c_str(), source.spec().length(), 0); 49 source_url.is_valid() &&
37 } 50 SetExtendedFileAttribute(file.value().c_str(), kSourceURLExtendedAttrName,
38 if (referrer.is_valid()) { 51 source_url.spec().c_str(),
39 SetExtendedFileAttribute(file.value().c_str(), kReferrerURLAttrName, 52 source_url.spec().length(), 0);
40 referrer.spec().c_str(), referrer.spec().length(), 0); 53
41 } 54 // Referrer being empty is not considered an error. This could happen if the
55 // referrer policy resulted in an empty referrer for the download request.
56 bool referrer_succeeded =
57 !referrer_url.is_valid() ||
58 SetExtendedFileAttribute(
59 file.value().c_str(), kReferrerURLExtendedAttrName,
60 referrer_url.spec().c_str(), referrer_url.spec().length(), 0);
61 return source_succeeded && referrer_succeeded
62 ? QuarantineFileResult::OK
63 : QuarantineFileResult::ANNOTATION_FAILED;
42 } 64 }
43 65
44 } // namespace content 66 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698