OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 28 matching lines...) Expand all Loading... | |
39 #include "core/dom/DocumentFragment.h" | 39 #include "core/dom/DocumentFragment.h" |
40 #include "core/dom/Node.h" | 40 #include "core/dom/Node.h" |
41 #include "core/dom/XMLDocument.h" | 41 #include "core/dom/XMLDocument.h" |
42 #include "core/html/HTMLBodyElement.h" | 42 #include "core/html/HTMLBodyElement.h" |
43 #include "core/html/HTMLDocument.h" | 43 #include "core/html/HTMLDocument.h" |
44 #include "core/html/HTMLHeadElement.h" | 44 #include "core/html/HTMLHeadElement.h" |
45 #include "core/html/parser/HTMLDocumentParser.h" | 45 #include "core/html/parser/HTMLDocumentParser.h" |
46 #include "core/inspector/DOMEditor.h" | 46 #include "core/inspector/DOMEditor.h" |
47 #include "core/inspector/InspectorHistory.h" | 47 #include "core/inspector/InspectorHistory.h" |
48 #include "core/xml/parser/XMLDocumentParser.h" | 48 #include "core/xml/parser/XMLDocumentParser.h" |
49 #include "platform/CryptoUtilities.h" | |
50 #include "public/platform/Platform.h" | |
49 #include "wtf/Deque.h" | 51 #include "wtf/Deque.h" |
50 #include "wtf/HashTraits.h" | 52 #include "wtf/HashTraits.h" |
51 #include "wtf/RefPtr.h" | 53 #include "wtf/RefPtr.h" |
52 #include "wtf/SHA1.h" | |
53 #include "wtf/text/Base64.h" | 54 #include "wtf/text/Base64.h" |
54 #include "wtf/text/CString.h" | 55 #include "wtf/text/CString.h" |
55 | 56 |
56 using namespace std; | 57 using namespace std; |
57 | 58 |
58 namespace WebCore { | 59 namespace WebCore { |
59 | 60 |
60 struct DOMPatchSupport::Digest { | 61 struct DOMPatchSupport::Digest { |
61 explicit Digest(Node* node) : m_node(node) { } | 62 explicit Digest(Node* node) : m_node(node) { } |
62 | 63 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 continue; | 388 continue; |
388 if (isHTMLBodyElement(*node) || isHTMLHeadElement(*node)) | 389 if (isHTMLBodyElement(*node) || isHTMLHeadElement(*node)) |
389 continue; // Never move head or body, move the rest of the nodes aro und them. | 390 continue; // Never move head or body, move the rest of the nodes aro und them. |
390 | 391 |
391 if (!m_domEditor->insertBefore(parentNode, node.release(), anchorNode, e xceptionState)) | 392 if (!m_domEditor->insertBefore(parentNode, node.release(), anchorNode, e xceptionState)) |
392 return false; | 393 return false; |
393 } | 394 } |
394 return true; | 395 return true; |
395 } | 396 } |
396 | 397 |
397 static void addStringToSHA1(SHA1& sha1, const String& string) | |
398 { | |
399 CString cString = string.utf8(); | |
400 sha1.addBytes(reinterpret_cast<const uint8_t*>(cString.data()), cString.leng th()); | |
401 } | |
402 | |
403 PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un usedNodesMap* unusedNodesMap) | 398 PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un usedNodesMap* unusedNodesMap) |
404 { | 399 { |
405 Digest* digest = new Digest(node); | 400 Digest* digest = new Digest(node); |
406 | 401 |
407 SHA1 sha1; | 402 CryptoUtil::DigestValue digestResult; |
403 StringBuilder digestable; | |
408 | 404 |
409 Node::NodeType nodeType = node->nodeType(); | 405 Node::NodeType nodeType = node->nodeType(); |
410 sha1.addBytes(reinterpret_cast<const uint8_t*>(&nodeType), sizeof(nodeType)) ; | 406 digestable.append(reinterpret_cast<const char*>(&nodeType), sizeof(nodeType) ); |
411 addStringToSHA1(sha1, node->nodeName()); | 407 digestable.append(node->nodeName()); |
eseidel
2014/03/12 06:50:29
You could have just used Vector<uint8_t> here, Str
abarth-chromium
2014/03/12 18:59:02
Yeah, you've got an UTF-8 conversion at the end, w
jww
2014/04/01 23:29:09
I think this is irrelevant now because I've modifi
| |
412 addStringToSHA1(sha1, node->nodeValue()); | 408 digestable.append(node->nodeValue()); |
413 | 409 |
414 if (node->nodeType() == Node::ELEMENT_NODE) { | 410 if (node->nodeType() == Node::ELEMENT_NODE) { |
415 Node* child = node->firstChild(); | 411 Node* child = node->firstChild(); |
416 while (child) { | 412 while (child) { |
417 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); | 413 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); |
418 addStringToSHA1(sha1, childInfo->m_sha1); | 414 digestable.append(childInfo->m_sha1); |
419 child = child->nextSibling(); | 415 child = child->nextSibling(); |
420 digest->m_children.append(childInfo.release()); | 416 digest->m_children.append(childInfo.release()); |
421 } | 417 } |
422 Element* element = toElement(node); | 418 Element* element = toElement(node); |
423 | 419 |
424 if (element->hasAttributesWithoutUpdate()) { | 420 if (element->hasAttributesWithoutUpdate()) { |
425 size_t numAttrs = element->attributeCount(); | 421 size_t numAttrs = element->attributeCount(); |
426 SHA1 attrsSHA1; | 422 StringBuilder attrsDigestable; |
427 for (size_t i = 0; i < numAttrs; ++i) { | 423 for (size_t i = 0; i < numAttrs; ++i) { |
428 const Attribute& attribute = element->attributeItem(i); | 424 const Attribute& attribute = element->attributeItem(i); |
429 addStringToSHA1(attrsSHA1, attribute.name().toString()); | 425 attrsDigestable.append(attribute.name().toString()); |
430 addStringToSHA1(attrsSHA1, attribute.value()); | 426 attrsDigestable.append(attribute.value()); |
431 } | 427 } |
432 Vector<uint8_t, 20> attrsHash; | 428 CString attrsDigestableCString = attrsDigestable.toString().utf8(); |
433 attrsSHA1.computeHash(attrsHash); | 429 CryptoUtil::computeDigest(CryptoUtil::HashAlgorithmSha1, attrsDigest ableCString.data(), attrsDigestableCString.length(), digestResult); |
434 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(att rsHash.data()), 10); | 430 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig estResult.data()), 10); |
eseidel
2014/03/12 06:50:29
I take it we only want the first 10 bytes of the d
jww
2014/04/01 23:29:09
I don't ask questions; I just make compatible with
| |
435 addStringToSHA1(sha1, digest->m_attrsSHA1); | 431 digestable.append(digest->m_attrsSHA1); |
432 digestResult.clear(); | |
436 } | 433 } |
437 } | 434 } |
438 | 435 |
439 Vector<uint8_t, 20> hash; | 436 CString digestableCString = digestable.toString().utf8(); |
440 sha1.computeHash(hash); | 437 CryptoUtil::computeDigest(CryptoUtil::HashAlgorithmSha1, digestableCString.d ata(), digestableCString.length(), digestResult); |
441 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(hash.data()), 10 ); | 438 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(digestResult.dat a()), 10); |
442 if (unusedNodesMap) | 439 if (unusedNodesMap) |
443 unusedNodesMap->add(digest->m_sha1, digest); | 440 unusedNodesMap->add(digest->m_sha1, digest); |
444 return adoptPtr(digest); | 441 return adoptPtr(digest); |
445 } | 442 } |
446 | 443 |
447 bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Diges t* digest, Node* anchor, ExceptionState& exceptionState) | 444 bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Diges t* digest, Node* anchor, ExceptionState& exceptionState) |
448 { | 445 { |
449 bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, exceptionState); | 446 bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, exceptionState); |
450 markNodeAsUsed(digest); | 447 markNodeAsUsed(digest); |
451 return result; | 448 return result; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) | 500 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) |
504 { | 501 { |
505 fprintf(stderr, "\n\n"); | 502 fprintf(stderr, "\n\n"); |
506 for (size_t i = 0; i < map.size(); ++i) | 503 for (size_t i = 0; i < map.size(); ++i) |
507 fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map [i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map [i].second); | 504 fprintf(stderr, "%s[%lu]: %s (%p) - [%lu]\n", name.utf8().data(), i, map [i].first ? nodeName(map[i].first->m_node).utf8().data() : "", map[i].first, map [i].second); |
508 } | 505 } |
509 #endif | 506 #endif |
510 | 507 |
511 } // namespace WebCore | 508 } // namespace WebCore |
512 | 509 |
OLD | NEW |