1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "pdf/parsed_params.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "pdf/pdfium/pdfium_form_filler.h"
11 #include "third_party/blink/public/platform/web_string.h"
12 #include "third_party/blink/public/platform/web_vector.h"
13 #include "third_party/blink/public/web/web_plugin_params.h"
15 namespace chrome_pdf {
17 ParsedParams::ParsedParams() = default;
19 ParsedParams::ParsedParams(const ParsedParams& other) = default;
20 ParsedParams& ParsedParams::operator=(const ParsedParams& other) = default;
22 ParsedParams::ParsedParams(ParsedParams&& other) = default;
23 ParsedParams& ParsedParams::operator=(ParsedParams&& other) = default;
25 ParsedParams::~ParsedParams() = default;
27 absl::optional<ParsedParams> ParseWebPluginParams(
28 const blink::WebPluginParams& params) {
30 for (size_t i = 0; i < params.attribute_names.size(); ++i) {
31 if (params.attribute_names[i] == "src") {
32 result.src_url = params.attribute_values[i].Utf8();
33 } else if (params.attribute_names[i] == "original-url") {
34 result.original_url = params.attribute_values[i].Utf8();
35 } else if (params.attribute_names[i] == "top-level-url") {
36 result.top_level_url = params.attribute_values[i].Utf8();
37 } else if (params.attribute_names[i] == "full-frame") {
38 result.full_frame = true;
39 } else if (params.attribute_names[i] == "background-color") {
40 if (!base::StringToUint(params.attribute_values[i].Utf8(),
41 &result.background_color)) {
44 } else if (params.attribute_names[i] == "javascript") {
45 if (params.attribute_values[i] != "allow")
46 result.script_option = PDFiumFormFiller::ScriptOption::kNoJavaScript;
47 } else if (params.attribute_names[i] == "has-edits") {
48 result.has_edits = true;
49 } else if (params.attribute_names[i] == "use-skia") {
50 result.use_skia = true;
54 if (result.src_url.empty())
57 if (result.original_url.empty())
58 result.original_url = result.src_url;
63 } // namespace chrome_pdf