OLD | NEW |
---|---|
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/public/common/quarantine.h" | 5 #include "content/public/common/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/files/scoped_temp_dir.h" | |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
15 #include "content/common/quarantine/quarantine_constants_linux.h" | 16 #include "content/common/quarantine/quarantine_constants_linux.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 const char kSourceURLExtendedAttrName[] = "user.xdg.origin.url"; | 21 const char kSourceURLExtendedAttrName[] = "user.xdg.origin.url"; |
21 const char kReferrerURLExtendedAttrName[] = "user.xdg.referrer.url"; | 22 const char kReferrerURLExtendedAttrName[] = "user.xdg.referrer.url"; |
22 | 23 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 90 |
90 if (source_url != GURL(url_value)) | 91 if (source_url != GURL(url_value)) |
91 return false; | 92 return false; |
92 | 93 |
93 return !referrer_url.is_valid() || | 94 return !referrer_url.is_valid() || |
94 GURL(GetExtendedFileAttribute(file.value().c_str(), | 95 GURL(GetExtendedFileAttribute(file.value().c_str(), |
95 kReferrerURLExtendedAttrName)) == | 96 kReferrerURLExtendedAttrName)) == |
96 referrer_url; | 97 referrer_url; |
97 } | 98 } |
98 | 99 |
100 // Only to be used in tests. | |
101 bool IsQuarantineSupportedForTesting() { | |
bcf
2017/01/06 20:43:00
We should update quarantine_linux_unittest.cc to u
| |
102 base::ScopedTempDir temp_dir; | |
103 if (!temp_dir.CreateUniqueTempDir()) | |
104 return false; | |
105 | |
106 base::FilePath xattr_test_file; | |
107 if (!base::CreateTemporaryFileInDir(temp_dir.GetPath(), &xattr_test_file)) | |
108 return false; | |
109 | |
110 int result = | |
111 setxattr(xattr_test_file.value().c_str(), "user.test", "test", 4, 0); | |
112 bool is_xattr_supported = (!result) || (errno != ENOTSUP); | |
113 | |
114 return is_xattr_supported; | |
115 } | |
116 | |
99 } // namespace content | 117 } // namespace content |
OLD | NEW |