Fix FullScreen crash in Webapp
[platform/framework/web/chromium-efl.git] / pdf / parsed_params.cc
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.
4
5 #include "pdf/parsed_params.h"
6
7 #include <string>
8
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"
14
15 namespace chrome_pdf {
16
17 ParsedParams::ParsedParams() = default;
18
19 ParsedParams::ParsedParams(const ParsedParams& other) = default;
20 ParsedParams& ParsedParams::operator=(const ParsedParams& other) = default;
21
22 ParsedParams::ParsedParams(ParsedParams&& other) = default;
23 ParsedParams& ParsedParams::operator=(ParsedParams&& other) = default;
24
25 ParsedParams::~ParsedParams() = default;
26
27 absl::optional<ParsedParams> ParseWebPluginParams(
28     const blink::WebPluginParams& params) {
29   ParsedParams result;
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)) {
42         return absl::nullopt;
43       }
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;
51     }
52   }
53
54   if (result.src_url.empty())
55     return absl::nullopt;
56
57   if (result.original_url.empty())
58     result.original_url = result.src_url;
59
60   return result;
61 }
62
63 }  // namespace chrome_pdf