2009-02-18 Dimitri Glazkov <dglazkov@chromium.org>
authordglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2009 20:36:21 +0000 (20:36 +0000)
committerdglazkov@chromium.org <dglazkov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2009 20:36:21 +0000 (20:36 +0000)
        Reviewed by Antti Koivisto.

        https://bugs.webkit.org/show_bug.cgi?id=23999
        Split off MIME type parsing into its own class.

        * GNUmakefile.am: Added ContentType sources.
        * WebCore.pro: Ditto.
        * WebCore.scons: Ditto.
        * WebCore.vcproj/WebCore.vcproj: Ditto.
        * WebCore.xcodeproj/project.pbxproj: Ditto.
        * WebCoreSources.bkl: Ditto.
        * html/HTMLMediaElement.cpp: Changed to use ContentType.
        (WebCore::HTMLMediaElement::selectMediaURL):
        * platform/ContentType.cpp: Added.
        (WebCore::ContentType::ContentType):
        (WebCore::ContentType::parameter):
        (WebCore::ContentType::type):
        * platform/ContentType.h: Added.
        (WebCore::ContentType::raw):
        * platform/MIMETypeRegistry.cpp:
        * platform/MIMETypeRegistry.h:
        * platform/graphics/MediaPlayer.cpp:
        (WebCore::MediaPlayer::load):
        * rendering/style/ContentData.h: Renamed ContentType to StyleContentType.
        * rendering/style/RenderStyleConstants.h: Ditto.
        (WebCore::):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@41113 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
WebCore/ChangeLog
WebCore/GNUmakefile.am
WebCore/WebCore.pro
WebCore/WebCore.scons
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/WebCoreSources.bkl
WebCore/html/HTMLMediaElement.cpp
WebCore/platform/ContentType.cpp [new file with mode: 0644]
WebCore/platform/ContentType.h [new file with mode: 0644]
WebCore/platform/MIMETypeRegistry.cpp
WebCore/platform/MIMETypeRegistry.h
WebCore/platform/graphics/MediaPlayer.cpp
WebCore/rendering/style/ContentData.h
WebCore/rendering/style/RenderStyleConstants.h

index 42ee599..a0c23e7 100644 (file)
@@ -1,3 +1,32 @@
+2009-02-18  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Antti Koivisto.
+
+        https://bugs.webkit.org/show_bug.cgi?id=23999
+        Split off MIME type parsing into its own class.
+
+        * GNUmakefile.am: Added ContentType sources.
+        * WebCore.pro: Ditto.
+        * WebCore.scons: Ditto. 
+        * WebCore.vcproj/WebCore.vcproj: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * WebCoreSources.bkl: Ditto.
+        * html/HTMLMediaElement.cpp: Changed to use ContentType.
+        (WebCore::HTMLMediaElement::selectMediaURL):
+        * platform/ContentType.cpp: Added.
+        (WebCore::ContentType::ContentType):
+        (WebCore::ContentType::parameter):
+        (WebCore::ContentType::type):
+        * platform/ContentType.h: Added.
+        (WebCore::ContentType::raw):
+        * platform/MIMETypeRegistry.cpp:
+        * platform/MIMETypeRegistry.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::load):
+        * rendering/style/ContentData.h: Renamed ContentType to StyleContentType.
+        * rendering/style/RenderStyleConstants.h: Ditto.
+        (WebCore::):
+
 2009-02-20  Holger Hans Peter Freyther  <zecke@selfish.org>
 
         Unreviewed build fix.
index b84b8aa..e6f502d 100644 (file)
@@ -1212,6 +1212,8 @@ webcore_sources += \
        WebCore/platform/Arena.cpp \
        WebCore/platform/Arena.h \
        WebCore/platform/AutodrainedPool.h \
+       WebCore/platform/ContentType.cpp \
+       WebCore/platform/ContentType.h \
        WebCore/platform/ContextMenu.cpp \
        WebCore/platform/ContextMenu.h \
        WebCore/platform/ContextMenuItem.h \
index 5083a32..497754e 100644 (file)
@@ -870,6 +870,7 @@ SOURCES += \
     platform/text/AtomicString.cpp \
     platform/text/Base64.cpp \
     platform/text/BidiContext.cpp \
+    platform/ContentType.cpp \
     platform/ContextMenu.cpp \
     platform/text/CString.cpp \
     platform/DeprecatedPtrListImpl.cpp \
index 04f8700..a65100f 100644 (file)
@@ -718,6 +718,7 @@ sources['bridge/c'] = [
 # These may eventually move to a separate sources file
 sources['platform'] = [
     'platform/Arena.cpp',
+    'platform/ContentType.cpp',
     'platform/ContextMenu.cpp',
     'platform/DeprecatedPtrListImpl.cpp',
     'platform/DragData.cpp',
index 094bacc..1cd3127 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\platform\ContentType.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\platform\ContentType.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\platform\ContextMenu.cpp"\r
                                >\r
                        </File>\r
index 6d0c160..f408a4b 100644 (file)
                416E75CC0EDF90C700360E1D /* ScriptCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 416E75CA0EDF90C700360E1D /* ScriptCallFrame.cpp */; };
                416F45F00ED7B311008215B6 /* ScriptString.h in Headers */ = {isa = PBXBuildFile; fileRef = 416F45EF0ED7B311008215B6 /* ScriptString.h */; };
                41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; };
+               41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D015C90F4B5C71004A662F /* ContentType.cpp */; };
                41F1D21F0EF35C2A00DA8753 /* ScriptCachedFrameData.h in Headers */ = {isa = PBXBuildFile; fileRef = 41F1D21D0EF35C2A00DA8753 /* ScriptCachedFrameData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41F1D2200EF35C2A00DA8753 /* ScriptCachedFrameData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */; };
                4415292E0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */; };
                416E75CA0EDF90C700360E1D /* ScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptCallFrame.cpp; sourceTree = "<group>"; };
                416F45EF0ED7B311008215B6 /* ScriptString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptString.h; sourceTree = "<group>"; };
                41C760B00EDE03D300C1655F /* ScriptState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptState.h; sourceTree = "<group>"; };
+               41D015C80F4B5C71004A662F /* ContentType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentType.h; sourceTree = "<group>"; };
+               41D015C90F4B5C71004A662F /* ContentType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ContentType.cpp; sourceTree = "<group>"; };
                41F1D21D0EF35C2A00DA8753 /* ScriptCachedFrameData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptCachedFrameData.h; sourceTree = "<group>"; };
                41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptCachedFrameData.cpp; sourceTree = "<group>"; };
                4415292C0E1AE8A000C4A2D0 /* HTMLPlugInImageElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLPlugInImageElement.h; sourceTree = "<group>"; };
                                935207BD09BD410A00F2038D /* LocalizedStrings.h */,
                                A8239DFE09B3CF8A00B60641 /* Logging.cpp */,
                                A8239DFF09B3CF8A00B60641 /* Logging.h */,
+                               41D015C80F4B5C71004A662F /* ContentType.h */,
+                               41D015C90F4B5C71004A662F /* ContentType.cpp */,
                                BC772C4C0C4EB3040083285F /* MIMETypeRegistry.cpp */,
                                BC772C4D0C4EB3040083285F /* MIMETypeRegistry.h */,
                                4B2708C50AF19EE40065127F /* Pasteboard.h */,
                                1A569D250D7E2B82007C3983 /* runtime_root.h in Headers */,
                                93309E1E099E64920056E581 /* visible_units.h in Headers */,
                                A17C81230F2A5CF7005DAAEB /* HTMLElementFactory.h in Headers */,
+                               41D015CA0F4B5C71004A662F /* ContentType.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                1A569D240D7E2B82007C3983 /* runtime_root.cpp in Sources */,
                                93309E1D099E64920056E581 /* visible_units.cpp in Sources */,
                                A17C81220F2A5CF7005DAAEB /* HTMLElementFactory.cpp in Sources */,
+                               41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 33d4925..8c7daf5 100644 (file)
@@ -724,6 +724,7 @@ This file contains the list of files needed to build WebCore.
         platform/text/Base64.cpp
         platform/text/BidiContext.cpp
         platform/text/CString.cpp
+        platform/ContentType.cpp
         platform/ContextMenu.cpp
         platform/DeprecatedPtrListImpl.cpp
         platform/DragImage.cpp
index 26065f1..e319ca2 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(VIDEO)
 #include "HTMLMediaElement.h"
 
+#include "ContentType.h"
 #include "CSSHelper.h"
 #include "CSSPropertyNames.h"
 #include "CSSValueKeywords.h"
@@ -934,15 +935,12 @@ String HTMLMediaElement::selectMediaURL(String& mediaMIMEType)
                         continue;
                 }
                 if (source->hasAttribute(typeAttr)) {
-                    String type = source->type().stripWhiteSpace();
-                    String codecs = MIMETypeRegistry::getParameterFromMIMEType(type, "codecs");
-                    String simpleType = MIMETypeRegistry::stripParametersFromMIMEType(type);
-
-                    if (!MediaPlayer::supportsType(simpleType, codecs))
+                    ContentType contentType(source->type());
+                    if (!MediaPlayer::supportsType(contentType.type(), contentType.parameter("codecs")))
                         continue;
 
                     // return type with all parameters in place so the media engine can use them
-                    mediaMIMEType = type;
+                    mediaMIMEType = contentType.raw();
                 }
                 mediaSrc = source->src().string();
                 break;
diff --git a/WebCore/platform/ContentType.cpp b/WebCore/platform/ContentType.cpp
new file mode 100644 (file)
index 0000000..4a29364
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2009 Apple Inc.  All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or othematerials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ContentType.h"
+
+namespace WebCore {
+
+ContentType::ContentType(const String& contentType)
+    : m_type(contentType)
+{
+}
+
+String ContentType::parameter(const String& parameterName) const
+{
+    String parameterValue;
+    String strippedType = m_type.stripWhiteSpace();
+
+    // a MIME type can have one or more "param=value" after a semi-colon, and separated from each other by semi-colons
+    int semi = strippedType.find(';');
+    if (semi != -1) {
+        int start = strippedType.find(parameterName, semi + 1, false);
+        if (start != -1) {
+            start = strippedType.find('=', start + 6);
+            if (start != -1) {
+                int end = strippedType.find(';', start + 6);
+                if (end == -1)
+                    end = strippedType.length();
+                parameterValue = strippedType.substring(start + 1, end - (start + 1)).stripWhiteSpace();
+            }
+        }
+    }
+
+    return parameterValue;
+}
+
+String ContentType::type() const
+{
+    String strippedType = m_type.stripWhiteSpace();
+
+    // "type" can have parameters after a semi-colon, strip them
+    int semi = strippedType.find(';');
+    if (semi != -1)
+        strippedType = strippedType.left(semi).stripWhiteSpace();
+
+    return strippedType;
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/ContentType.h b/WebCore/platform/ContentType.h
new file mode 100644 (file)
index 0000000..dc11749
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 Apple Inc.  All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or othematerials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ContentType_h
+#define ContentType_h
+
+#include "PlatformString.h"
+
+namespace WebCore {
+
+    class ContentType {
+    public:
+        ContentType(const String& type);
+
+        String parameter (const String& parameterName) const;
+        String type() const;
+        const String& raw() const { return m_type; }
+    private:
+        String m_type;
+    };
+
+} // namespace WebCore
+
+#endif // ContentType_h
index 45bf417..8f98735 100644 (file)
@@ -239,42 +239,6 @@ String MIMETypeRegistry::getMIMETypeForPath(const String& path)
     return "application/octet-stream";
 }
 
-String MIMETypeRegistry::getParameterFromMIMEType(const String& type, const String& parameterName)
-{
-    String parameterValue;
-
-    // a MIME type can have one or more "param=value" after a semi-colon, and separated from each other by semi-colons
-    int semi = type.find(';');
-    if (semi != -1) {
-        int start = type.find(parameterName, semi + 1, false);
-        if (start != -1) {
-            start = type.find('=', start + 6);
-            if (start != -1) {
-                int end = type.find(';', start + 6);
-                if (end == -1)
-                    end = type.length();
-                parameterValue = type.substring(start + 1, end - (start + 1)).stripWhiteSpace();
-            }
-        }
-    }
-
-    return parameterValue;
-}
-
-String MIMETypeRegistry::stripParametersFromMIMEType(const String& mimeType)
-{
-    String strippedType = mimeType.stripWhiteSpace();
-
-    // "type" can have parameters after a semi-colon, strip them
-    int semi = strippedType.find(';');
-    if (semi != -1)
-        strippedType = strippedType.left(semi).stripWhiteSpace();
-
-    return strippedType;
-}
-
-
-
 bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
index e9ec811..fca467f 100644 (file)
@@ -39,9 +39,6 @@ public:
     static Vector<String> getExtensionsForMIMEType(const String& type);
     static String getPreferredExtensionForMIMEType(const String& type);
 
-    static String getParameterFromMIMEType(const String& type, const String& parameterName);
-    static String stripParametersFromMIMEType(const String& type);
-
     static String getMIMETypeForPath(const String& path);
 
     // Check to see if a mime type is suitable for being loaded inline as an
index eb93269..729f362 100644 (file)
@@ -29,6 +29,7 @@
 #include "MediaPlayer.h"
 #include "MediaPlayerPrivate.h"
 
+#include "ContentType.h"
 #include "IntRect.h"
 #include "MIMETypeRegistry.h"
 #include "FrameView.h"
@@ -187,7 +188,7 @@ void MediaPlayer::load(const String& url, const String& mimeType)
 {
     // if we don't know the MIME type, see if the path can help
     String type = mimeType.isEmpty() ? MIMETypeRegistry::getMIMETypeForPath(url) : mimeType;
-    String codecs = MIMETypeRegistry::getParameterFromMIMEType(type, "codecs");
+    String codecs = ContentType(type).parameter("codecs");
 
     MediaPlayerFactory* engine = chooseBestEngineForTypeAndCodecs(type, codecs);
 
index d924d1a..44785ef 100644 (file)
@@ -48,7 +48,7 @@ struct ContentData : Noncopyable {
 
     void clear();
 
-    ContentType m_type;
+    StyleContentType m_type;
     union {
         StyleImage* m_image;
         StringImpl* m_text;
index cb68035..405cf7c 100644 (file)
@@ -201,7 +201,7 @@ enum EListStyleType {
      HIRAGANA, KATAKANA, HIRAGANA_IROHA, KATAKANA_IROHA, LNONE
 };
 
-enum ContentType {
+enum StyleContentType {
     CONTENT_NONE, CONTENT_OBJECT, CONTENT_TEXT, CONTENT_COUNTER
 };