Commit 21735e20 authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Add FontIndexer tool to enumerate locally installed fonts

This will aid in constructing a catalog of known font digests for the
identifiability study.

Change-Id: Ic0d4b603513aed6c5f1fec7d3606a371119e2707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2399446Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Commit-Queue: Alex Turner <alexmt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824015}
parent 046f5c79
...@@ -154,6 +154,7 @@ group("gn_all") { ...@@ -154,6 +154,7 @@ group("gn_all") {
"//third_party/pdfium/samples:pdfium_test", "//third_party/pdfium/samples:pdfium_test",
"//tools/perf/clear_system_cache", "//tools/perf/clear_system_cache",
"//tools/polymer:polymer_tools_python_unittests", "//tools/polymer:polymer_tools_python_unittests",
"//tools/privacy_budget:privacy_budget_tools",
"//ui/accessibility:accessibility_perftests", "//ui/accessibility:accessibility_perftests",
"//ui/accessibility:accessibility_unittests", "//ui/accessibility:accessibility_unittests",
"//ui/accessibility/extensions:extension_tests", "//ui/accessibility/extensions:extension_tests",
......
...@@ -253,6 +253,7 @@ component("platform") { ...@@ -253,6 +253,7 @@ component("platform") {
"//services/device/public/mojom:mojom_blink", "//services/device/public/mojom:mojom_blink",
"//services/media_session/public/mojom:mojom_blink", "//services/media_session/public/mojom:mojom_blink",
"//third_party/blink/*", "//third_party/blink/*",
"//tools/privacy_budget/font_indexer:*",
"//url/mojom:url_mojom_gurl_blink", "//url/mojom:url_mojom_gurl_blink",
"//url/mojom:url_mojom_origin_blink", "//url/mojom:url_mojom_origin_blink",
] ]
...@@ -1773,7 +1774,10 @@ component("platform") { ...@@ -1773,7 +1774,10 @@ component("platform") {
} }
static_library("test_support") { static_library("test_support") {
visibility += [ "//third_party/blink/*" ] visibility += [
"//third_party/blink/*",
"//tools/privacy_budget/font_indexer:*",
]
testonly = true testonly = true
sources = [ sources = [
......
# 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.
group("privacy_budget_tools") {
testonly = true
deps = [ "font_indexer:font_indexer" ]
}
include_rules = [
"+base",
"+content/public",
"+mojo/core/embedder",
"+third_party/blink",
]
file://third_party/blink/public/common/privacy_budget/OWNERS
# TEAM: privacy-sandbox-dev@chromium.org
# COMPONENT: Privacy>Fingerprinting
# 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.
static_library("tools_lib") {
sources = [
"font_indexer.cc",
"font_indexer.h",
]
deps = [
"//base:base",
"//content/public/browser:browser",
"//third_party/blink/renderer/platform:platform",
]
}
executable("font_indexer") {
testonly = true
sources = [ "font_indexer_main.cc" ]
deps = [
":tools_lib",
"//base:base",
"//base/test:test_support",
"//content/public/browser:browser",
"//mojo/core/embedder",
"//third_party/blink/renderer/platform:test_support",
]
}
This diff is collapsed.
// 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.
#ifndef TOOLS_PRIVACY_BUDGET_FONT_INDEXER_FONT_INDEXER_H_
#define TOOLS_PRIVACY_BUDGET_FONT_INDEXER_FONT_INDEXER_H_
#include <string>
#include <utility>
#include "base/callback_forward.h"
#include "base/values.h"
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#include "third_party/blink/renderer/platform/fonts/font_description.h"
#include "third_party/blink/renderer/platform/fonts/font_selection_types.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace privacy_budget {
// Note that in the following constants, we prioritize the more common values as
// we later associate each unique digest with the first set of settings for
// which that digest is found.
extern const std::pair<blink::FontSelectionValue, std::string> kFontWeights[];
extern const std::pair<blink::FontSelectionValue, std::string> kFontWidths[];
// Not as thorough as above, given its rarity and to reduce the speed impact.
extern const std::pair<blink::FontSelectionValue, std::string> kFontSlopes[];
// Following only used if |more_slope_checks_|
extern const std::pair<blink::FontSelectionValue, std::string>
kAdditionalFontSlopes[];
extern const char kOutputHeader[];
extern const char kOutputSeparator[];
// FontIndexer allows for enumerating all locally installed fonts and computing
// identifiability digests of each typeface.
class FontIndexer {
public:
FontIndexer();
~FontIndexer();
// The main function that enumerates all fonts and prints a tab-separated file
// containing the fonts' details to stdout.
void PrintAllFonts();
// By default, this tool attempts to determine whether the fonts vary along
// each axis (i.e. width, weight and slope), skipping checks along the axes
// with no variation. This call disables this optimization, slowing the tool
// substantially, but possibly being more thorough (if the determinations are
// incorrect).
void SetNoSmartSkipping() { smart_skipping_ = false; }
// By default, the tool only checks a limited number of slope values as
// substantial slope variation is rare and slow to check for. This call adds
// more granularity when slopes are varied. This will slow down the tool, but
// will give more results if a font with many slope variations is available.
void SetMoreSlopeChecks() { more_slope_checks_ = true; }
private:
void FontListHasLoaded(std::unique_ptr<base::ListValue> list);
void WaitForFontListToLoad();
// Determines whether the fonts with |name| appear to vary along the specified
// axis, by comparing font digests at extreme values to |default_font_digest|.
bool DoFontsWithNameHaveVaryingWeights(WTF::AtomicString name,
int64_t default_font_digest);
bool DoFontsWithNameHaveVaryingWidths(WTF::AtomicString name,
int64_t default_font_digest);
bool DoFontsWithNameHaveVaryingSlopes(WTF::AtomicString name,
int64_t default_font_digest);
// Determines whether a font lookup for |name| with |font_description| results
// in a typeface with |digest|.
bool DoesFontHaveDigest(WTF::AtomicString name,
blink::FontDescription font_description,
int64_t digest);
// Enumerates fonts with |name| and prints tab-separated lines with each
// font's details.
void PrintAllFontsWithName(WTF::AtomicString name);
blink::FontCache* font_cache_;
bool has_font_list_loaded_ = false;
bool smart_skipping_ = true;
bool more_slope_checks_ = false;
base::OnceClosure quit_closure_;
};
} // namespace privacy_budget
#endif // TOOLS_PRIVACY_BUDGET_FONT_INDEXER_FONT_INDEXER_H_
// 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.
#include <iostream>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/task_runner_util.h"
#include "base/test/task_environment.h"
#include "base/test/test_io_thread.h"
#include "base/test/test_suite.h"
#include "base/test/test_timeouts.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/core/embedder/scoped_ipc_support.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "tools/privacy_budget/font_indexer/font_indexer.h"
namespace {
const char kHelpMsg[] = R"(
font_indexer [--no-smart-skipping] [--more-slope-checks]
--no-smart-skipping stops the tool from skipping checks along axes of
variation when it appears the font does not varying along those axes. This
will slow down the tool substantially, but may be more thorough if the checks
are incorrect.
--more-slope-checks gives more granular checking of different slopes. This
will slow down the tool, but will give more results if a font with many
slope variations is available.
)";
const char kNoSmartSkippingSwitch[] = "no-smart-skipping";
const char kMoreSlopeChecksSwitch[] = "more-slope-checks";
void PrintHelp() {
printf("%s\n\n", kHelpMsg);
}
bool ShouldPrintHelpAndQuit(const base::CommandLine::StringVector& args,
const base::CommandLine::SwitchMap& switches) {
if (args.size() != 0U || switches.size() > 2) {
return true;
}
for (const auto& switch_entry : switches) {
std::string switch_name = switch_entry.first;
if (switch_name != kNoSmartSkippingSwitch &&
switch_name != kMoreSlopeChecksSwitch) {
return true;
}
}
return false;
}
} // namespace
int main(int argc, char* argv[]) {
base::CommandLine::Init(argc, argv);
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
base::CommandLine::StringVector args = command_line.GetArgs();
if (ShouldPrintHelpAndQuit(command_line.GetArgs(),
command_line.GetSwitches())) {
PrintHelp();
return 1;
}
// Initialize a test environment to satisfy the expectations of
// content::GetFontListAsync().
blink::ScopedUnittestsEnvironmentSetup testEnvironmentSetup(argc, argv);
base::TestSuite testSuite(argc, argv);
mojo::core::Init();
base::TestIOThread testIoThread(base::TestIOThread::kAutoStart);
mojo::core::ScopedIPCSupport ipcSupport(
testIoThread.task_runner(),
mojo::core::ScopedIPCSupport::ShutdownPolicy::CLEAN);
TestTimeouts::Initialize();
base::test::TaskEnvironment env(
base::test::TaskEnvironment::TimeSource::MOCK_TIME);
// Set up and run tool.
privacy_budget::FontIndexer indexer;
if (command_line.HasSwitch(kNoSmartSkippingSwitch)) {
indexer.SetNoSmartSkipping();
}
if (command_line.HasSwitch(kMoreSlopeChecksSwitch)) {
indexer.SetMoreSlopeChecks();
}
indexer.PrintAllFonts();
return 0;
}
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