Chromium Code Reviews| 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/Crypto.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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 continue; | 396 continue; |
| 396 if (isHTMLBodyElement(*node) || isHTMLHeadElement(*node)) | 397 if (isHTMLBodyElement(*node) || isHTMLHeadElement(*node)) |
| 397 continue; // Never move head or body, move the rest of the nodes aro und them. | 398 continue; // Never move head or body, move the rest of the nodes aro und them. |
| 398 | 399 |
| 399 if (!m_domEditor->insertBefore(parentNode, node.release(), anchorNode, e xceptionState)) | 400 if (!m_domEditor->insertBefore(parentNode, node.release(), anchorNode, e xceptionState)) |
| 400 return false; | 401 return false; |
| 401 } | 402 } |
| 402 return true; | 403 return true; |
| 403 } | 404 } |
| 404 | 405 |
| 405 static void addStringToSHA1(SHA1& sha1, const String& string) | 406 static void addStringToDigestor(blink::WebCryptoDigestor* digestor, const String & string) |
| 406 { | 407 { |
| 407 CString cString = string.utf8(); | 408 digestor->consume(reinterpret_cast<const unsigned char*>(string.utf8().data( )), string.length()); |
| 408 sha1.addBytes(reinterpret_cast<const uint8_t*>(cString.data()), cString.leng th()); | |
| 409 } | 409 } |
| 410 | 410 |
| 411 PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un usedNodesMap* unusedNodesMap) | 411 PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un usedNodesMap* unusedNodesMap) |
| 412 { | 412 { |
| 413 Digest* digest = new Digest(node); | 413 Digest* digest = new Digest(node); |
| 414 | 414 |
| 415 SHA1 sha1; | 415 OwnPtr<blink::WebCryptoDigestor> digestor = adoptPtr(createDigestor(HashAlgo rithmSha1)); |
|
abarth-chromium
2014/04/01 23:46:48
Why doesn't createDigestor return a PassOwnPtr?
jww
2014/04/02 01:11:50
Fixed.
| |
| 416 DigestValue digestResult; | |
| 416 | 417 |
| 417 Node::NodeType nodeType = node->nodeType(); | 418 Node::NodeType nodeType = node->nodeType(); |
| 418 sha1.addBytes(reinterpret_cast<const uint8_t*>(&nodeType), sizeof(nodeType)) ; | 419 digestor->consume(reinterpret_cast<const unsigned char*>(&nodeType), sizeof( nodeType)); |
| 419 addStringToSHA1(sha1, node->nodeName()); | 420 addStringToDigestor(digestor.get(), node->nodeName()); |
| 420 addStringToSHA1(sha1, node->nodeValue()); | 421 addStringToDigestor(digestor.get(), node->nodeValue()); |
| 421 | 422 |
| 422 if (node->nodeType() == Node::ELEMENT_NODE) { | 423 if (node->nodeType() == Node::ELEMENT_NODE) { |
| 423 Node* child = node->firstChild(); | 424 Node* child = node->firstChild(); |
| 424 while (child) { | 425 while (child) { |
| 425 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); | 426 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); |
| 426 addStringToSHA1(sha1, childInfo->m_sha1); | 427 addStringToDigestor(digestor.get(), childInfo->m_sha1); |
| 427 child = child->nextSibling(); | 428 child = child->nextSibling(); |
| 428 digest->m_children.append(childInfo.release()); | 429 digest->m_children.append(childInfo.release()); |
| 429 } | 430 } |
| 430 Element* element = toElement(node); | 431 Element* element = toElement(node); |
| 431 | 432 |
| 432 if (element->hasAttributesWithoutUpdate()) { | 433 if (element->hasAttributesWithoutUpdate()) { |
| 433 size_t numAttrs = element->attributeCount(); | 434 size_t numAttrs = element->attributeCount(); |
| 434 SHA1 attrsSHA1; | 435 OwnPtr<blink::WebCryptoDigestor> attrsDigestor = adoptPtr(createDige stor(HashAlgorithmSha1)); |
| 435 for (size_t i = 0; i < numAttrs; ++i) { | 436 for (size_t i = 0; i < numAttrs; ++i) { |
| 436 const Attribute& attribute = element->attributeItem(i); | 437 const Attribute& attribute = element->attributeItem(i); |
| 437 addStringToSHA1(attrsSHA1, attribute.name().toString()); | 438 addStringToDigestor(attrsDigestor.get(), attribute.name().toStri ng()); |
| 438 addStringToSHA1(attrsSHA1, attribute.value()); | 439 addStringToDigestor(attrsDigestor.get(), attribute.value().strin g()); |
| 439 } | 440 } |
| 440 Vector<uint8_t, 20> attrsHash; | 441 finishDigestor(attrsDigestor.get(), digestResult); |
| 441 attrsSHA1.computeHash(attrsHash); | 442 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig estResult.data()), 10); |
| 442 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(att rsHash.data()), 10); | 443 addStringToDigestor(digestor.get(), digest->m_attrsSHA1); |
| 443 addStringToSHA1(sha1, digest->m_attrsSHA1); | 444 digestResult.clear(); |
| 444 } | 445 } |
| 445 } | 446 } |
| 447 finishDigestor(digestor.get(), digestResult); | |
| 448 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(digestResult.dat a()), 10); | |
| 446 | 449 |
| 447 Vector<uint8_t, 20> hash; | |
| 448 sha1.computeHash(hash); | |
| 449 digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(hash.data()), 10 ); | |
| 450 if (unusedNodesMap) | 450 if (unusedNodesMap) |
| 451 unusedNodesMap->add(digest->m_sha1, digest); | 451 unusedNodesMap->add(digest->m_sha1, digest); |
| 452 return adoptPtr(digest); | 452 return adoptPtr(digest); |
| 453 } | 453 } |
| 454 | 454 |
| 455 bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Diges t* digest, Node* anchor, ExceptionState& exceptionState) | 455 bool DOMPatchSupport::insertBeforeAndMarkAsUsed(ContainerNode* parentNode, Diges t* digest, Node* anchor, ExceptionState& exceptionState) |
| 456 { | 456 { |
| 457 bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, exceptionState); | 457 bool result = m_domEditor->insertBefore(parentNode, digest->m_node, anchor, exceptionState); |
| 458 markNodeAsUsed(digest); | 458 markNodeAsUsed(digest); |
| 459 return result; | 459 return result; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) | 511 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) |
| 512 { | 512 { |
| 513 fprintf(stderr, "\n\n"); | 513 fprintf(stderr, "\n\n"); |
| 514 for (size_t i = 0; i < map.size(); ++i) | 514 for (size_t i = 0; i < map.size(); ++i) |
| 515 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); | 515 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); |
| 516 } | 516 } |
| 517 #endif | 517 #endif |
| 518 | 518 |
| 519 } // namespace WebCore | 519 } // namespace WebCore |
| 520 | 520 |
| OLD | NEW |