Chromium Code Reviews| Index: Source/core/html/MediaProvider.cpp |
| diff --git a/Source/core/html/MediaProvider.cpp b/Source/core/html/MediaProvider.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b35b7dd0633d268b443bc777b2bcd77089b582ec |
| --- /dev/null |
| +++ b/Source/core/html/MediaProvider.cpp |
| @@ -0,0 +1,86 @@ |
| +/* |
| + * Copyright (C) 2014 Google Inc. All rights reserved. |
|
sof
2014/09/18 07:33:17
New files are preferably adorned with a shorter ve
perkj_chrome
2014/09/18 14:47:08
Done.
|
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions |
| + * are met: |
| + * |
| + * 1. Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * 2. Redistributions in binary form must reproduce the above copyright |
| + * notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * 3. 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 "core/html/MediaProvider.h" |
| + |
| +#include "wtf/HashMap.h" |
| +#include "wtf/MainThread.h" |
| +#include "wtf/text/StringHash.h" |
| + |
| +namespace blink { |
| + |
| +class MediaProviderConverterContainer { |
| +public: |
| + static MediaProviderConverterContainer& container(); |
| + |
| + void registerMediaProviderConverter(const String& interfaceName, const MediaProvider::Converter&); |
| + virtual MediaProvider* convert(const ScriptValue&); |
| + |
| +private: |
| + HashMap<String, MediaProvider::Converter> m_converters; |
| +}; |
| + |
| +MediaProviderConverterContainer& MediaProviderConverterContainer::container() |
| +{ |
| + ASSERT(isMainThread()); |
| + DEFINE_STATIC_LOCAL(MediaProviderConverterContainer, instance, ()); |
| + return instance; |
| +} |
| + |
| +void MediaProviderConverterContainer::registerMediaProviderConverter(const String& interfaceName, const MediaProvider::Converter& converter) |
| +{ |
| + if (m_converters.get(interfaceName).isNull()) |
| + m_converters.set(interfaceName, converter); |
| +} |
| + |
| +MediaProvider* MediaProviderConverterContainer::convert(const ScriptValue& value) |
| +{ |
| + for (HashMap<String, MediaProvider::Converter>::iterator it = m_converters.begin(); it != m_converters.end(); ++it) { |
| + MediaProvider* provider = (it->value)(value); |
| + if (provider) |
| + return provider; |
| + } |
| + return nullptr; |
| +} |
| + |
| +MediaProvider::MediaProvider(const String& interfaceName, const Converter& converter) |
| +{ |
| + MediaProviderConverterContainer& container = MediaProviderConverterContainer::container(); |
| + container.registerMediaProviderConverter(interfaceName, converter); |
| +} |
| + |
| +MediaProvider* MediaProvider::convert(const ScriptValue& value) |
| +{ |
| + MediaProviderConverterContainer& container = MediaProviderConverterContainer::container(); |
| + return container.convert(value); |
| +} |
| + |
| +} // namespace blink |