0

Determine whether to use Skia renderer from browser process

Currently PDFium SDK determines whether to use Skia renderer in the
renderer process, and it's determined by feature flag (it's a choice
made by either the user or the finch experiment).

An enterprise policy will be created to also control the decision on
whether to use Skia renderer. Therefore the decision point needs to
be moved into the browser process.

This CL moves the feature flag check to the browser process before
the PDF plugin is created, and sends a `use_skia` flag through the
mime handler together with other PDF plugin attributes, so that the
logic of checking enterprise policy can be added in the browser
process in the future.

Bug: 1440430
Change-Id: I8b74d493576f62be6231b872aec4018e7627a3b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4481627
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Nigi <nigi@chromium.org>
Reviewed-by: Matthew Denton <mpdenton@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1141525}
This commit is contained in:
Hui Yingst
2023-05-09 18:10:40 +00:00
committed by Chromium LUCI CQ
parent eb059009fe
commit 4e9dea8d3d
11 changed files with 66 additions and 12 deletions

@ -46,6 +46,8 @@ absl::optional<ParsedParams> ParseWebPluginParams(
result.script_option = PDFiumFormFiller::ScriptOption::kNoJavaScript;
} else if (params.attribute_names[i] == "has-edits") {
result.has_edits = true;
} else if (params.attribute_names[i] == "use-skia") {
result.use_skia = true;
}
}

@ -46,6 +46,10 @@ struct ParsedParams {
// Whether the PDF was edited previously in annotation mode.
bool has_edits = false;
// Whether the PDF viewer uses Skia renderer. When set to false, the PDF
// viewer uses AGG renderer.
bool use_skia = false;
};
// Creates an `ParsedParams` by parsing a `blink::WebPluginParams`. If

@ -46,6 +46,7 @@ TEST(ParsedParamsTest, ParseWebPluginParamsMinimal) {
EXPECT_EQ(SK_ColorTRANSPARENT, result->background_color);
EXPECT_EQ(PDFiumFormFiller::DefaultScriptOption(), result->script_option);
EXPECT_FALSE(result->has_edits);
EXPECT_FALSE(result->use_skia);
}
TEST(ParsedParamsTest, ParseWebPluginParamsWithoutSourceUrl) {
@ -181,4 +182,26 @@ TEST(ParsedParamsTest, ParseWebPluginParamsWithHasEditsNonEmpty) {
EXPECT_TRUE(result->has_edits);
}
TEST(ParsedParamsTest, ParseWebPluginParamsWithHasUseSkia) {
blink::WebPluginParams params = CreateMinimalWebPluginParams();
params.attribute_names.push_back(blink::WebString("use-skia"));
params.attribute_values.push_back(blink::WebString(""));
absl::optional<ParsedParams> result = ParseWebPluginParams(params);
ASSERT_TRUE(result.has_value());
EXPECT_TRUE(result->use_skia);
}
TEST(ParsedParamsTest, ParseWebPluginParamsWithHasUseSkiaNonEmpty) {
blink::WebPluginParams params = CreateMinimalWebPluginParams();
params.attribute_names.push_back(blink::WebString("use-skia"));
params.attribute_values.push_back(blink::WebString("false"));
absl::optional<ParsedParams> result = ParseWebPluginParams(params);
ASSERT_TRUE(result.has_value());
EXPECT_TRUE(result->use_skia);
}
} // namespace chrome_pdf

@ -24,6 +24,9 @@ class ScopedSdkInitializer {
public:
explicit ScopedSdkInitializer(bool enable_v8) {
if (!IsSDKInitializedViaPlugin()) {
// TODO(crbug.com/1440430): Modify ScopedSdkInitializer() so that the
// option to use Skia can be based on enterprise policy if such policy is
// set.
InitializeSDK(enable_v8,
base::FeatureList::IsEnabled(features::kPdfUseSkiaRenderer),
FontMappingMode::kNoMapping);

@ -179,7 +179,7 @@ class PerProcessInitializer final {
return *instance;
}
void Acquire() {
void Acquire(bool use_skia) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK_GE(init_count_, 0);
@ -187,9 +187,7 @@ class PerProcessInitializer final {
return;
DCHECK(!IsSDKInitializedViaPlugin());
InitializeSDK(/*enable_v8=*/true,
base::FeatureList::IsEnabled(features::kPdfUseSkiaRenderer),
FontMappingMode::kBlink);
InitializeSDK(/*enable_v8=*/true, use_skia, FontMappingMode::kBlink);
SetIsSDKInitializedViaPlugin(true);
}
@ -335,7 +333,7 @@ bool PdfViewWebPlugin::InitializeCommon() {
base::debug::CrashKeySize::Size256);
base::debug::SetCrashKeyString(subresource_url, params->original_url);
PerProcessInitializer::GetInstance().Acquire();
PerProcessInitializer::GetInstance().Acquire(params->use_skia);
initialized_ = true;
// Check if the PDF is being loaded in the PDF chrome extension. We only allow