Skip to content

Commit

Permalink
Move file quarantine implementation to components
Browse files Browse the repository at this point in the history
The implementation is currently in content/ and used by download and pepper.
Download code is being moved to components/.
This CL moves the quarantine implemetation to components/ so it
can be shared between content/ and components/

BUG=803135

Change-Id: Id68afca113891abb8475b6b64f5854be28b0ca3e
Reviewed-on: https://chromium-review.googlesource.com/933287
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539817}
  • Loading branch information
Min Qin authored and Commit Bot committed Feb 28, 2018
1 parent ab7770e commit d103f11
Show file tree
Hide file tree
Showing 25 changed files with 146 additions and 93 deletions.
8 changes: 4 additions & 4 deletions chrome/browser/download/download_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_interrupt_reasons.h"
#include "components/download/public/common/download_item.h"
#include "components/download/quarantine/quarantine.h"
#include "components/history/content/browser/download_conversions.h"
#include "components/history/core/browser/download_constants.h"
#include "components/history/core/browser/download_row.h"
Expand All @@ -99,7 +100,6 @@
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/context_menu_params.h"
#include "content/public/common/quarantine.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/download_test_observer.h"
#include "content/public/test/slow_download_http_response.h"
Expand Down Expand Up @@ -1250,7 +1250,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, Quarantine_DependsOnLocalConfig) {
base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
base::FilePath downloaded_file(DestinationFile(browser(), file));
base::ScopedAllowBlockingForTesting allow_blocking;
EXPECT_TRUE(content::IsFileQuarantined(downloaded_file, url, GURL()));
EXPECT_TRUE(download::IsFileQuarantined(downloaded_file, url, GURL()));
CheckDownload(browser(), file, file);
}
#endif
Expand All @@ -1275,7 +1275,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalhostZone_DependsOnLocalConfig) {
DownloadAndWait(browser(), url);
base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip"));
base::FilePath downloaded_file(DestinationFile(browser(), file));
EXPECT_FALSE(content::IsFileQuarantined(downloaded_file, GURL(), GURL()));
EXPECT_FALSE(download::IsFileQuarantined(downloaded_file, GURL(), GURL()));
}

// Same as the test above, but uses a file:// URL to a local file.
Expand All @@ -1288,7 +1288,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalFileZone_DependsOnLocalConfig) {
DownloadAndWait(browser(), url);
base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip"));
base::FilePath downloaded_file(DestinationFile(browser(), file));
EXPECT_FALSE(content::IsFileQuarantined(downloaded_file, GURL(), GURL()));
EXPECT_FALSE(download::IsFileQuarantined(downloaded_file, GURL(), GURL()));
}
#endif

Expand Down
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ test("browser_tests") {
"//components/dom_distiller/content/browser",
"//components/dom_distiller/content/renderer",
"//components/dom_distiller/core:test_support",
"//components/download/quarantine",
"//components/feature_engagement/test:test_support",
"//components/optimization_guide:test_support",
"//components/policy:chrome_settings_proto_generated_compile",
Expand Down
4 changes: 2 additions & 2 deletions chrome/test/ppapi/ppapi_filechooser_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/ppapi/ppapi_test.h"
#include "content/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"
#include "ppapi/shared_impl/test_utils.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_dialog_factory.h"
Expand Down Expand Up @@ -389,7 +389,7 @@ IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Quarantine) {
temp_dir.GetPath().AppendASCII("dangerous.exe");

ASSERT_TRUE(base::PathExists(actual_filename));
EXPECT_TRUE(content::IsFileQuarantined(actual_filename, GURL(), GURL()));
EXPECT_TRUE(download::IsFileQuarantined(actual_filename, GURL(), GURL()));
}
#endif // defined(OS_WIN) || defined(OS_LINUX)

Expand Down
1 change: 1 addition & 0 deletions components/download/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ group("unit_tests") {
"//components/download/downloader/in_progress:unit_tests",
"//components/download/internal/background_service:unit_tests",
"//components/download/internal/common:unit_tests",
"//components/download/quarantine:unit_tests",
]
}

Expand Down
59 changes: 59 additions & 0 deletions components/download/quarantine/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromecast_build.gni")

if (is_android) {
import("//build/config/android/rules.gni")
}

static_library("quarantine") {
sources = [
"quarantine.cc",
"quarantine.h",
"quarantine_constants_linux.h",
"quarantine_linux.cc",
"quarantine_mac.mm",
"quarantine_win.cc",
]

deps = [
"//base",
"//net",
"//url",
]

if (is_mac) {
libs = [
"Carbon.framework",
"Foundation.framework",
]
}
}

source_set("unit_tests") {
testonly = true
sources = [
"quarantine_linux_unittest.cc",
"quarantine_mac_unittest.mm",
"quarantine_win_unittest.cc",
]

# Chromecasts do not have extended attributes enabled; even if it were
# enabled, the devices use tmpfs which restricts the extended attributes that
# can be set such that quarantining still would not work. (The platform
# specific tests include a runtime guard to skip tests that need xattr.)
if (!is_chromecast) {
sources += [ "quarantine_unittest.cc" ]
}

deps = [
":quarantine",
"//base",
"//base/test:test_support",
"//net",
"//testing/gtest",
"//url",
]
}
3 changes: 3 additions & 0 deletions components/download/quarantine/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+net/base/filename_util.h",
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"

#include "build/build_config.h"

#if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_LINUX)

namespace content {
namespace download {

QuarantineFileResult QuarantineFile(const base::FilePath& file,
const GURL& source_url,
Expand All @@ -23,6 +23,6 @@ bool IsFileQuarantined(const base::FilePath& file,
return false;
}

} // namespace content
} // namespace download

#endif // !WIN && !MAC && !LINUX
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_COMMON_QUARANTINE_H_
#define CONTENT_PUBLIC_COMMON_QUARANTINE_H_
#ifndef COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_
#define COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_

#include <string>

#include "content/common/content_export.h"

class GURL;

namespace base {
class FilePath;
}

namespace content {
namespace download {

// Return value for QuarantineFile.
enum class QuarantineFileResult {
Expand Down Expand Up @@ -72,11 +70,10 @@ enum class QuarantineFileResult {
// |referrer_url|: Referring URL.
// |client_guid|: Only used on Windows. Identifies the client application
// that downloaded the file.
CONTENT_EXPORT QuarantineFileResult
QuarantineFile(const base::FilePath& file,
const GURL& source_url,
const GURL& referrer_url,
const std::string& client_guid);
QuarantineFileResult QuarantineFile(const base::FilePath& file,
const GURL& source_url,
const GURL& referrer_url,
const std::string& client_guid);

// Determine if a file has quarantine metadata attached to it.
//
Expand All @@ -97,10 +94,10 @@ QuarantineFile(const base::FilePath& file,
// **Note**: On Windows, this function only checks if the |ZoneIdentifier|
// metadata is present. |source_url| and |referrer_url| are ignored. Windows
// currently doesn't store individual URLs as part of the mark-of-the-web.
CONTENT_EXPORT bool IsFileQuarantined(const base::FilePath& file,
const GURL& source_url,
const GURL& referrer_url);
bool IsFileQuarantined(const base::FilePath& file,
const GURL& source_url,
const GURL& referrer_url);

} // namespace content
} // namespace download

#endif // CONTENT_PUBLIC_COMMON_QUARANTINE_H_
#endif // COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_
#define CONTENT_COMMON_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_
#ifndef COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_
#define COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_

#include "content/common/content_export.h"

namespace content {
namespace download {

// Attribute names to be used with setxattr and friends.
//
// The source URL attribute is part of the XDG standard.
// The referrer URL attribute is not part of the XDG standard,
// but it is used to keep the naming consistent.
// http://freedesktop.org/wiki/CommonExtendedAttributes
CONTENT_EXPORT extern const char kSourceURLExtendedAttrName[];
CONTENT_EXPORT extern const char kReferrerURLExtendedAttrName[];
extern const char kSourceURLExtendedAttrName[];
extern const char kReferrerURLExtendedAttrName[];

} // namespace content
} // namespace download

#endif // CONTENT_COMMON_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_
#endif // COMPONENTS_DOWNLOAD_QUARANTINE_QUARANTINE_CONSTANTS_LINUX_H_
Original file line number Diff line number Diff line change
Expand Up @@ -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/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"

#include <stddef.h>
#include <sys/types.h>
Expand All @@ -12,10 +12,11 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
#include "content/common/quarantine/quarantine_constants_linux.h"
#include "components/download/quarantine/quarantine.h"
#include "components/download/quarantine/quarantine_constants_linux.h"
#include "url/gurl.h"

namespace content {
namespace download {

const char kSourceURLExtendedAttrName[] = "user.xdg.origin.url";
const char kReferrerURLExtendedAttrName[] = "user.xdg.referrer.url";
Expand Down Expand Up @@ -96,4 +97,4 @@ bool IsFileQuarantined(const base::FilePath& file,
referrer_url;
}

} // namespace content
} // namespace download
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "content/common/quarantine/quarantine_constants_linux.h"
#include "content/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"
#include "components/download/quarantine/quarantine_constants_linux.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace content {
namespace download {
namespace {

using std::istringstream;
Expand Down Expand Up @@ -180,4 +180,4 @@ TEST_F(QuarantineLinuxTest, IsFileQuarantined) {
IsFileQuarantined(fully_annotated, referrer_url(), referrer_url()));
}

} // namespace content
} // namespace download
Original file line number Diff line number Diff line change
Expand Up @@ -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/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"

#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -137,7 +137,7 @@ bool SetQuarantineProperties(const base::FilePath& file,

} // namespace

namespace content {
namespace download {

namespace {

Expand Down Expand Up @@ -339,4 +339,4 @@ bool IsFileQuarantined(const base::FilePath& file,
isEqualToString:base::SysUTF8ToNSString(referrer_url.spec())];
}

} // namespace content
} // namespace download
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "content/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "url/gurl.h"

namespace content {
namespace download {
namespace {

class QuarantineMacTest : public testing::Test {
Expand Down Expand Up @@ -119,4 +119,4 @@ void SetUp() override {
}

} // namespace
} // namespace content
} // namespace downlod
Original file line number Diff line number Diff line change
Expand Up @@ -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/public/common/quarantine.h"
#include "components/download/quarantine/quarantine.h"

#include <iterator>
#include <string>
Expand All @@ -14,7 +14,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace content {
namespace download {

namespace {

Expand Down Expand Up @@ -55,4 +55,4 @@ TEST(QuarantineTest, FileCanBeAnnotatedWithNoGUID) {
GURL(kInternetReferrerURL), std::string()));
}

} // namespace content
} // namespace download
Loading

0 comments on commit d103f11

Please sign in to comment.