Commit 635a85c6 authored by Tim Volodine's avatar Tim Volodine Committed by Commit Bot

Componentize renderer-side phishing classifier [1]

Initial componentization of chrome/renderer/safe_browsing
code.

In this patch:
 - move some initial files and tests to components/
   safe_browsing/content/renderer/phishing_classifier
   (in particular features* and test_utils code).
 - add new build config file,
 - update all relevant build files and includes.

BUG=1115700

Change-Id: I75e6ca754ad00135d8e6d9e466565885377b92f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437384
Commit-Queue: Tim Volodine <timvolodine@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812800}
parent fd4fe41b
......@@ -260,8 +260,6 @@ static_library("renderer") {
if (safe_browsing_mode != 0) {
sources += [
"safe_browsing/features.cc",
"safe_browsing/features.h",
"safe_browsing/murmurhash3_util.cc",
"safe_browsing/murmurhash3_util.h",
"safe_browsing/phishing_classifier.cc",
......@@ -280,6 +278,7 @@ static_library("renderer") {
deps += [
"//chrome/common/safe_browsing:proto",
"//components/safe_browsing/content/renderer",
"//components/safe_browsing/content/renderer/phishing_classifier",
"//components/safe_browsing/core:client_model_proto",
"//components/safe_browsing/core:csd_proto",
"//components/safe_browsing/core/common",
......@@ -431,13 +430,12 @@ static_library("test_support") {
sources = [
"chrome_mock_render_thread.cc",
"chrome_mock_render_thread.h",
"safe_browsing/test_utils.cc",
"safe_browsing/test_utils.h",
]
deps = [
":renderer",
"//chrome/common/search:mojo_bindings",
"//components/safe_browsing/content/renderer/phishing_classifier:unit_tests_support",
"//content/test:test_support",
"//extensions/buildflags",
"//testing/gmock",
......
......@@ -21,12 +21,12 @@
#include "base/threading/thread_task_runner_handle.h"
#include "cc/paint/skia_paint_canvas.h"
#include "chrome/common/url_constants.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h"
#include "chrome/renderer/safe_browsing/phishing_term_feature_extractor.h"
#include "chrome/renderer/safe_browsing/phishing_url_feature_extractor.h"
#include "chrome/renderer/safe_browsing/scorer.h"
#include "components/paint_preview/common/paint_preview_tracker.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
......
......@@ -14,10 +14,10 @@
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_discardable_memory_allocator.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/murmurhash3_util.h"
#include "chrome/renderer/safe_browsing/scorer.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/core/proto/client_model.pb.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "content/public/renderer/render_frame.h"
......
......@@ -8,12 +8,12 @@
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/phishing_classifier.h"
#include "chrome/renderer/safe_browsing/scorer.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "chrome/test/base/chrome_unit_test_suite.h"
#include "components/safe_browsing/content/common/safe_browsing.mojom-shared.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
......
......@@ -15,7 +15,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "content/public/renderer/render_view.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/blink/public/platform/web_string.h"
......
......@@ -12,9 +12,9 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/test_utils.h"
#include "content/public/common/content_switches.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/test/test_utils.h"
......
......@@ -21,8 +21,8 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_tick_clock.h"
#include "base/time/time.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/murmurhash3_util.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "crypto/sha2.h"
namespace safe_browsing {
......
......@@ -23,9 +23,9 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/murmurhash3_util.h"
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/test_utils.h"
#include "crypto/sha2.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -12,7 +12,7 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/timer/elapsed_timer.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "url/gurl.h"
......
......@@ -8,8 +8,8 @@
#include <vector>
#include "base/format_macros.h"
#include "base/strings/stringprintf.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......
......@@ -15,8 +15,8 @@
#include "base/strings/string_piece.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/password_protection/visual_utils.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/core/proto/client_model.pb.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "content/public/renderer/render_thread.h"
......
......@@ -16,7 +16,7 @@
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "components/safe_browsing/core/proto/client_model.pb.h"
#include "components/safe_browsing/core/proto/csd.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
......
......@@ -5460,7 +5460,6 @@ test("unit_tests") {
"../common/safe_browsing/ipc_protobuf_message_test_messages.h",
"../common/safe_browsing/ipc_protobuf_message_unittest.cc",
"../common/safe_browsing/mach_o_image_reader_mac_unittest.cc",
"../renderer/safe_browsing/features_unittest.cc",
"../renderer/safe_browsing/murmurhash3_util_unittest.cc",
"../renderer/safe_browsing/phishing_term_feature_extractor_unittest.cc",
"../renderer/safe_browsing/phishing_url_feature_extractor_unittest.cc",
......
......@@ -440,6 +440,10 @@ test("components_unittests") {
deps += [ "//components/safe_browsing/android:unit_tests_mobile" ]
}
if (safe_browsing_mode == 1) {
deps += [ "//components/safe_browsing/content/renderer/phishing_classifier:unit_tests" ]
}
if (!is_ios) {
deps += [
"//components/safe_browsing/core/realtime:unit_tests",
......
# Copyright 2020 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/features.gni")
import("//components/safe_browsing/buildflags.gni")
source_set("phishing_classifier") {
if (safe_browsing_mode != 0) {
sources = [
"features.cc",
"features.h",
]
deps = [
"//components/safe_browsing/content/renderer",
"//components/safe_browsing/core/common",
]
}
}
source_set("unit_tests") {
testonly = true
sources = [ "features_unittest.cc" ]
deps = [
":phishing_classifier",
"//base:base",
"//components/safe_browsing/content/renderer/phishing_classifier:unit_tests_support",
"//testing/gtest",
]
}
source_set("unit_tests_support") {
testonly = true
sources = [
"test_utils.cc",
"test_utils.h",
]
deps = [
":phishing_classifier",
"//testing/gmock",
]
}
......@@ -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 "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "base/metrics/histogram_macros.h"
......
......@@ -22,8 +22,8 @@
// just a thin wrapper around a map of feature name to value. The entire set
// of features for a URL is extracted before we do any scoring.
#ifndef CHROME_RENDERER_SAFE_BROWSING_FEATURES_H_
#define CHROME_RENDERER_SAFE_BROWSING_FEATURES_H_
#ifndef COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_FEATURES_H_
#define COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_FEATURES_H_
#include <stddef.h>
#include <string>
......@@ -178,4 +178,4 @@ extern const char kPageTerm[];
} // namespace features
} // namespace safe_browsing
#endif // CHROME_RENDERER_SAFE_BROWSING_FEATURES_H_
#endif // COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_FEATURES_H_
......@@ -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 "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include <stddef.h>
#include "base/format_macros.h"
#include "base/strings/stringprintf.h"
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace safe_browsing {
......@@ -16,15 +16,15 @@ namespace safe_browsing {
TEST(PhishingFeaturesTest, TooManyFeatures) {
FeatureMap features;
for (size_t i = 0; i < FeatureMap::kMaxFeatureMapSize; ++i) {
EXPECT_TRUE(features.AddBooleanFeature(
base::StringPrintf("Feature%" PRIuS, i)));
EXPECT_TRUE(
features.AddBooleanFeature(base::StringPrintf("Feature%" PRIuS, i)));
}
EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
// Attempting to add more features should fail.
for (size_t i = 0; i < 3; ++i) {
EXPECT_FALSE(features.AddBooleanFeature(
base::StringPrintf("Extra%" PRIuS, i)));
EXPECT_FALSE(
features.AddBooleanFeature(base::StringPrintf("Extra%" PRIuS, i)));
}
EXPECT_EQ(FeatureMap::kMaxFeatureMapSize, features.features().size());
}
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/test_utils.h"
#include <map>
#include <string>
#include "chrome/renderer/safe_browsing/features.h"
#include "components/safe_browsing/content/renderer/phishing_classifier/features.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace safe_browsing {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_SAFE_BROWSING_TEST_UTILS_H_
#define CHROME_RENDERER_SAFE_BROWSING_TEST_UTILS_H_
#ifndef COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_TEST_UTILS_H_
#define COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_TEST_UTILS_H_
namespace safe_browsing {
class FeatureMap;
......@@ -16,4 +16,4 @@ void ExpectFeatureMapsAreEqual(const FeatureMap& first,
} // namespace safe_browsing
#endif // CHROME_RENDERER_SAFE_BROWSING_TEST_UTILS_H_
#endif // COMPONENTS_SAFE_BROWSING_CONTENT_RENDERER_PHISHING_CLASSIFIER_TEST_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment