Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 23503016: Cleanup: Remove the WebCryptoAlgorithm::name() attribute. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename get() --> instance() Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.h ('k') | public/platform/WebCryptoAlgorithm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 WebKit::WebCryptoAlgorithmId algorithmId; 117 WebKit::WebCryptoAlgorithmId algorithmId;
118 const char* algorithmName; 118 const char* algorithmName;
119 AlgorithmParamsForOperation paramsForOperation[NumberOfAlgorithmOperations]; 119 AlgorithmParamsForOperation paramsForOperation[NumberOfAlgorithmOperations];
120 }; 120 };
121 121
122 // AlgorithmRegistry enumerates each of the different algorithms and its 122 // AlgorithmRegistry enumerates each of the different algorithms and its
123 // parameters. This describes the same information as the static tables above, 123 // parameters. This describes the same information as the static tables above,
124 // but in a more convenient runtime form. 124 // but in a more convenient runtime form.
125 class AlgorithmRegistry { 125 class AlgorithmRegistry {
126 public: 126 public:
127 static const AlgorithmInfo* lookupAlgorithmByName(const String& algorithmNam e); 127 static AlgorithmRegistry& instance();
128
129 const AlgorithmInfo* lookupAlgorithmByName(const String&) const;
130 const AlgorithmInfo* lookupAlgorithmById(WebKit::WebCryptoAlgorithmId) const ;
128 131
129 private: 132 private:
130 AlgorithmRegistry(); 133 AlgorithmRegistry();
131 134
132 // Algorithm name to ID. 135 // Algorithm name to ID.
133 typedef HashMap<String, WebKit::WebCryptoAlgorithmId, CaseFoldingHash> Algor ithmNameToIdMap; 136 typedef HashMap<String, WebKit::WebCryptoAlgorithmId, CaseFoldingHash> Algor ithmNameToIdMap;
134 AlgorithmNameToIdMap m_algorithmNameToId; 137 AlgorithmNameToIdMap m_algorithmNameToId;
135 138
136 // Algorithm ID to information. 139 // Algorithm ID to information.
137 AlgorithmInfo m_algorithms[WebKit::NumberOfWebCryptoAlgorithmId]; 140 AlgorithmInfo m_algorithms[WebKit::NumberOfWebCryptoAlgorithmId];
138 }; 141 };
139 142
140 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algo rithmName) 143 AlgorithmRegistry& AlgorithmRegistry::instance()
141 { 144 {
142 DEFINE_STATIC_LOCAL(AlgorithmRegistry, registry, ()); 145 DEFINE_STATIC_LOCAL(AlgorithmRegistry, registry, ());
146 return registry;
147 }
143 148
144 AlgorithmNameToIdMap::const_iterator it = registry.m_algorithmNameToId.find( algorithmName); 149 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algo rithmName) const
145 if (it == registry.m_algorithmNameToId.end()) 150 {
151 AlgorithmNameToIdMap::const_iterator it = m_algorithmNameToId.find(algorithm Name);
152 if (it == m_algorithmNameToId.end())
146 return 0; 153 return 0;
147 return &registry.m_algorithms[it->value]; 154 return lookupAlgorithmById(it->value);
155 }
156
157 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmById(WebKit::WebCryptoAlg orithmId algorithmId) const
158 {
159 ASSERT(algorithmId >= 0 && algorithmId < WTF_ARRAY_LENGTH(m_algorithms));
160 return &m_algorithms[algorithmId];
148 } 161 }
149 162
150 AlgorithmRegistry::AlgorithmRegistry() 163 AlgorithmRegistry::AlgorithmRegistry()
151 { 164 {
152 for (size_t i = 0; i < WTF_ARRAY_LENGTH(algorithmNameMappings); ++i) { 165 for (size_t i = 0; i < WTF_ARRAY_LENGTH(algorithmNameMappings); ++i) {
153 const AlgorithmNameMapping& mapping = algorithmNameMappings[i]; 166 const AlgorithmNameMapping& mapping = algorithmNameMappings[i];
154 m_algorithmNameToId.add(mapping.algorithmName, mapping.algorithmId); 167 m_algorithmNameToId.add(mapping.algorithmName, mapping.algorithmId);
155 m_algorithms[mapping.algorithmId].algorithmName = mapping.algorithmName; 168 m_algorithms[mapping.algorithmId].algorithmName = mapping.algorithmName;
156 m_algorithms[mapping.algorithmId].algorithmId = mapping.algorithmId; 169 m_algorithms[mapping.algorithmId].algorithmId = mapping.algorithmId;
157 } 170 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 es.throwTypeError(context.toString("Not an object")); 437 es.throwTypeError(context.toString("Not an object"));
425 return 0; 438 return 0;
426 } 439 }
427 440
428 String algorithmName; 441 String algorithmName;
429 if (!raw.get("name", algorithmName)) { 442 if (!raw.get("name", algorithmName)) {
430 es.throwTypeError(context.toString("name", "Missing or not a string")); 443 es.throwTypeError(context.toString("name", "Missing or not a string"));
431 return 0; 444 return 0;
432 } 445 }
433 446
434 const AlgorithmInfo* info = AlgorithmRegistry::lookupAlgorithmByName(algorit hmName); 447 const AlgorithmInfo* info = AlgorithmRegistry::instance().lookupAlgorithmByN ame(algorithmName);
435 if (!info) { 448 if (!info) {
436 es.throwDOMException(NotSupportedError, context.toString("Unrecognized a lgorithm name")); 449 es.throwDOMException(NotSupportedError, context.toString("Unrecognized a lgorithm name"));
437 return 0; 450 return 0;
438 } 451 }
439 452
440 return info; 453 return info;
441 } 454 }
442 455
443 // This implementation corresponds with: 456 // This implementation corresponds with:
444 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules 457 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules
(...skipping 10 matching lines...) Expand all
455 if (info->paramsForOperation[op] == UnsupportedOp) { 468 if (info->paramsForOperation[op] == UnsupportedOp) {
456 es.throwDOMException(NotSupportedError, context.toString("Unsupported op eration")); 469 es.throwDOMException(NotSupportedError, context.toString("Unsupported op eration"));
457 return false; 470 return false;
458 } 471 }
459 472
460 WebKit::WebCryptoAlgorithmParamsType paramsType = static_cast<WebKit::WebCry ptoAlgorithmParamsType>(info->paramsForOperation[op]); 473 WebKit::WebCryptoAlgorithmParamsType paramsType = static_cast<WebKit::WebCry ptoAlgorithmParamsType>(info->paramsForOperation[op]);
461 OwnPtr<WebKit::WebCryptoAlgorithmParams> params; 474 OwnPtr<WebKit::WebCryptoAlgorithmParams> params;
462 if (!parseAlgorithmParams(raw, paramsType, params, context, es)) 475 if (!parseAlgorithmParams(raw, paramsType, params, context, es))
463 return false; 476 return false;
464 477
465 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, info->algorithmNam e, params.release()); 478 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, params.release());
466 return true; 479 return true;
467 } 480 }
468 481
469 } // namespace 482 } // namespace
470 483
471 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We bCryptoAlgorithm& algorithm, ExceptionState& es) 484 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We bCryptoAlgorithm& algorithm, ExceptionState& es)
472 { 485 {
473 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); 486 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es);
474 } 487 }
475 488
489 const char* algorithmIdToName(WebKit::WebCryptoAlgorithmId id)
490 {
491 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName;
492 }
493
476 } // namespace WebCore 494 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/crypto/NormalizeAlgorithm.h ('k') | public/platform/WebCryptoAlgorithm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698