| Index: content/common/quarantine/quarantine_linux.cc
|
| diff --git a/content/browser/download/quarantine_linux.cc b/content/common/quarantine/quarantine_linux.cc
|
| similarity index 64%
|
| rename from content/browser/download/quarantine_linux.cc
|
| rename to content/common/quarantine/quarantine_linux.cc
|
| index 293dd46f107e4579b45b91af4b36a1c822c1d573..af207836d758758c495114eae6674f5bdad655e8 100644
|
| --- a/content/browser/download/quarantine_linux.cc
|
| +++ b/content/common/quarantine/quarantine_linux.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/download/quarantine.h"
|
| +#include "content/public/common/quarantine.h"
|
|
|
| #include <stddef.h>
|
| #include <sys/types.h>
|
| @@ -12,7 +12,7 @@
|
| #include "base/files/file_util.h"
|
| #include "base/logging.h"
|
| #include "base/threading/thread_restrictions.h"
|
| -#include "content/browser/download/quarantine_constants_linux.h"
|
| +#include "content/common/quarantine/quarantine_constants_linux.h"
|
| #include "url/gurl.h"
|
|
|
| namespace content {
|
| @@ -37,6 +37,19 @@ bool SetExtendedFileAttribute(const char* path,
|
| return true;
|
| }
|
|
|
| +std::string GetExtendedFileAttribute(const char* path, const char* name) {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + ssize_t len = getxattr(path, name, nullptr, 0);
|
| + if (len <= 0)
|
| + return std::string();
|
| +
|
| + std::vector<char> buffer(len);
|
| + len = getxattr(path, name, buffer.data(), buffer.size());
|
| + if (len < static_cast<ssize_t>(buffer.size()))
|
| + return std::string();
|
| + return std::string(buffer.begin(), buffer.end());
|
| +}
|
| +
|
| } // namespace
|
|
|
| QuarantineFileResult QuarantineFile(const base::FilePath& file,
|
| @@ -63,4 +76,24 @@ QuarantineFileResult QuarantineFile(const base::FilePath& file,
|
| : QuarantineFileResult::ANNOTATION_FAILED;
|
| }
|
|
|
| +bool IsFileQuarantined(const base::FilePath& file,
|
| + const GURL& source_url,
|
| + const GURL& referrer_url) {
|
| + if (!base::PathExists(file))
|
| + return false;
|
| +
|
| + std::string url_value = GetExtendedFileAttribute(file.value().c_str(),
|
| + kSourceURLExtendedAttrName);
|
| + if (source_url.is_empty())
|
| + return !url_value.empty();
|
| +
|
| + if (source_url != GURL(url_value))
|
| + return false;
|
| +
|
| + return !referrer_url.is_valid() ||
|
| + GURL(GetExtendedFileAttribute(file.value().c_str(),
|
| + kReferrerURLExtendedAttrName)) ==
|
| + referrer_url;
|
| +}
|
| +
|
| } // namespace content
|
|
|