parsed_params.cc 2.1 KB

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