Chromium Code Reviews| Index: Source/modules/crypto/NormalizeAlgorithm.cpp |
| diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp |
| index c53c7c66b99d8e9c4a4e05200467323e32ae0a26..2a32e531c475baa85555b9a3fabdb097c258d688 100644 |
| --- a/Source/modules/crypto/NormalizeAlgorithm.cpp |
| +++ b/Source/modules/crypto/NormalizeAlgorithm.cpp |
| @@ -124,7 +124,10 @@ struct AlgorithmInfo { |
| // but in a more convenient runtime form. |
| class AlgorithmRegistry { |
| public: |
| - static const AlgorithmInfo* lookupAlgorithmByName(const String& algorithmName); |
| + static const AlgorithmRegistry* get(); |
| + |
| + const AlgorithmInfo* lookupAlgorithmByName(const String&) const; |
| + const AlgorithmInfo* lookupAlgorithmById(WebKit::WebCryptoAlgorithmId) const; |
| private: |
| AlgorithmRegistry(); |
| @@ -137,14 +140,24 @@ private: |
| AlgorithmInfo m_algorithms[WebKit::NumberOfWebCryptoAlgorithmId]; |
| }; |
| -const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algorithmName) |
| +const AlgorithmRegistry* AlgorithmRegistry::get() |
|
abarth-chromium
2013/08/30 07:14:09
We'll often call these functions instance() and re
eroman
2013/08/30 17:50:14
Done.
|
| { |
| DEFINE_STATIC_LOCAL(AlgorithmRegistry, registry, ()); |
| + return ®istry; |
| +} |
| - AlgorithmNameToIdMap::const_iterator it = registry.m_algorithmNameToId.find(algorithmName); |
| - if (it == registry.m_algorithmNameToId.end()) |
| +const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algorithmName) const |
| +{ |
| + AlgorithmNameToIdMap::const_iterator it = m_algorithmNameToId.find(algorithmName); |
| + if (it == m_algorithmNameToId.end()) |
| return 0; |
| - return ®istry.m_algorithms[it->value]; |
| + return lookupAlgorithmById(it->value); |
| +} |
| + |
| +const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmById(WebKit::WebCryptoAlgorithmId algorithmId) const |
| +{ |
| + ASSERT(algorithmId >= 0 && algorithmId < WTF_ARRAY_LENGTH(m_algorithms)); |
| + return &m_algorithms[algorithmId]; |
| } |
| AlgorithmRegistry::AlgorithmRegistry() |
| @@ -431,7 +444,7 @@ const AlgorithmInfo* algorithmInfo(const Dictionary& raw, const ExceptionContext |
| return 0; |
| } |
| - const AlgorithmInfo* info = AlgorithmRegistry::lookupAlgorithmByName(algorithmName); |
| + const AlgorithmInfo* info = AlgorithmRegistry::get()->lookupAlgorithmByName(algorithmName); |
| if (!info) { |
| es.throwDOMException(NotSupportedError, context.toString("Unrecognized algorithm name")); |
| return 0; |
| @@ -462,7 +475,7 @@ bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We |
| if (!parseAlgorithmParams(raw, paramsType, params, context, es)) |
| return false; |
| - algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, info->algorithmName, params.release()); |
| + algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, params.release()); |
| return true; |
| } |
| @@ -473,4 +486,9 @@ bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We |
| return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); |
| } |
| +const char* algorithmIdToName(WebKit::WebCryptoAlgorithmId id) |
| +{ |
| + return AlgorithmRegistry::get()->lookupAlgorithmById(id)->algorithmName; |
| +} |
| + |
| } // namespace WebCore |