[M120 Migration] Support Comma Delimiter for isTypeSupported 55/307055/2
authoryanqing.lu <yanqing.lu@samsung.com>
Mon, 4 Mar 2024 08:17:26 +0000 (16:17 +0800)
committerBot Blink <blinkbot@samsung.com>
Wed, 6 Mar 2024 10:43:02 +0000 (10:43 +0000)
most app use semi-colone to query format support.
eg: isTypeSupported("video/mp4; codecs=\"avc1.4d4015\"; width=426; height=240; framerate=30; bitrate=246887")

but some app use comma format.
eg: isTypeSupported("audio/mp4; codecs=\"ec-3\", channels=7.1, features=\"JOC\"")

it revert this patch to support comma format
https://chromium.googlesource.com/chromium/src.git/+/15e2e8f54574ace251541c3b4589513e22131b85

Original Patch Title: change mode to get parameter of idTypeSupported
Migration from:
https://review.tizen.org/gerrit/290761

Change-Id: I0eed0ebb5e491cf67461e85bd5202f366272fc86
Signed-off-by: yanqing.lu <yanqing.lu@samsung.com>
third_party/blink/renderer/platform/network/mime/content_type.cc
third_party/blink/renderer/platform/network/mime/content_type.h

index 5a3c8b0..a4dbcf5 100644 (file)
@@ -32,29 +32,34 @@ namespace blink {
 
 ContentType::ContentType(const String& content_type) : type_(content_type) {}
 
-static bool IsASCIIQuote(UChar c) {
-  return c == '"';
-}
-
 String ContentType::Parameter(const String& parameter_name) const {
-  Vector<String> parameters;
-  ParseParameters(parameters);
+  String parameter_value;
+  String stripped_type = type_.StripWhiteSpace();
 
-  for (auto& parameter : parameters) {
-    String stripped_parameter = parameter.StripWhiteSpace();
-    wtf_size_t separator_pos = stripped_parameter.find('=');
-    if (separator_pos != kNotFound) {
-      String attribute =
-          stripped_parameter.Left(separator_pos).StripWhiteSpace();
-      if (EqualIgnoringASCIICase(attribute, parameter_name)) {
-        return stripped_parameter.Substring(separator_pos + 1)
-            .StripWhiteSpace()
-            .RemoveCharacters(IsASCIIQuote);
+  // a MIME type can have one or more "param=value" after a semi-colon, and
+  // separated from each other by semi-colons
+  wtf_size_t semi = stripped_type.find(';');
+  if (semi != kNotFound) {
+    wtf_size_t start =
+        stripped_type.FindIgnoringASCIICase(parameter_name, semi + 1);
+    if (start != kNotFound) {
+      start = stripped_type.find('=', start + parameter_name.length());
+      if (start != kNotFound) {
+        wtf_size_t quote = stripped_type.find('\"', start + 1);
+        wtf_size_t end = stripped_type.find('\"', start + 2);
+        if (quote != kNotFound && end != kNotFound) {
+          start = quote;
+        } else {
+          end = stripped_type.find(';', start + 1);
+          if (end == kNotFound)
+            end = stripped_type.length();
+        }
+        parameter_value = stripped_type.Substring(start + 1, end - (start + 1))
+                              .StripWhiteSpace();
       }
     }
   }
-
-  return String();
+  return parameter_value;
 }
 
 String ContentType::GetType() const {
@@ -68,29 +73,4 @@ String ContentType::GetType() const {
   return stripped_type;
 }
 
-void ContentType::ParseParameters(Vector<String>& result) const {
-  String stripped_type = type_.StripWhiteSpace();
-
-  unsigned cur_pos = 0;
-  unsigned end_pos = stripped_type.length();
-  unsigned start_pos = 0;
-  bool is_quote = false;
-
-  while (cur_pos < end_pos) {
-    if (!is_quote && stripped_type[cur_pos] == ';') {
-      if (cur_pos != start_pos) {
-        result.push_back(
-            stripped_type.Substring(start_pos, cur_pos - start_pos));
-      }
-      start_pos = cur_pos + 1;
-    } else if (stripped_type[cur_pos] == '"') {
-      is_quote = !is_quote;
-    }
-    cur_pos++;
-  }
-
-  if (start_pos != end_pos)
-    result.push_back(stripped_type.Substring(start_pos));
-}
-
 }  // namespace blink
index e02b098..e1d5bbc 100644 (file)
@@ -44,8 +44,6 @@ class PLATFORM_EXPORT ContentType {
   const String& Raw() const { return type_; }
 
  private:
-  void ParseParameters(Vector<String>& result) const;
-
   String type_;
 };