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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 continue; | 420 continue; |
421 } | 421 } |
422 | 422 |
423 if (!dom_editor_->InsertBefore(parent_node, node, anchor_node, | 423 if (!dom_editor_->InsertBefore(parent_node, node, anchor_node, |
424 exception_state)) | 424 exception_state)) |
425 return false; | 425 return false; |
426 } | 426 } |
427 return true; | 427 return true; |
428 } | 428 } |
429 | 429 |
430 static void AddStringToDigestor(WebCryptoDigestor* digestor, | 430 static void AddUtf8StringToDigestor(WebCryptoDigestor* digestor, |
431 const String& string) { | 431 const String& string) { |
432 digestor->Consume( | 432 digestor->Consume( |
433 reinterpret_cast<const unsigned char*>(string.Utf8().data()), | 433 reinterpret_cast<const unsigned char*>(string.Utf8().data()), |
434 string.length()); | 434 string.length()); |
alph
2017/07/10 21:26:06
The length still doesn't match the data though. Co
| |
435 } | 435 } |
436 | 436 |
437 DOMPatchSupport::Digest* DOMPatchSupport::CreateDigest( | 437 DOMPatchSupport::Digest* DOMPatchSupport::CreateDigest( |
438 Node* node, | 438 Node* node, |
439 UnusedNodesMap* unused_nodes_map) { | 439 UnusedNodesMap* unused_nodes_map) { |
440 Digest* digest = new Digest(node); | 440 Digest* digest = new Digest(node); |
441 | 441 |
442 std::unique_ptr<WebCryptoDigestor> digestor = | 442 std::unique_ptr<WebCryptoDigestor> digestor = |
443 CreateDigestor(kHashAlgorithmSha1); | 443 CreateDigestor(kHashAlgorithmSha1); |
444 DigestValue digest_result; | 444 DigestValue digest_result; |
445 | 445 |
446 Node::NodeType node_type = node->getNodeType(); | 446 Node::NodeType node_type = node->getNodeType(); |
447 digestor->Consume(reinterpret_cast<const unsigned char*>(&node_type), | 447 digestor->Consume(reinterpret_cast<const unsigned char*>(&node_type), |
448 sizeof(node_type)); | 448 sizeof(node_type)); |
449 AddStringToDigestor(digestor.get(), node->nodeName()); | 449 AddUtf8StringToDigestor(digestor.get(), node->nodeName()); |
450 AddStringToDigestor(digestor.get(), node->nodeValue()); | 450 AddUtf8StringToDigestor(digestor.get(), node->nodeValue()); |
451 | 451 |
452 if (node->IsElementNode()) { | 452 if (node->IsElementNode()) { |
453 Element& element = ToElement(*node); | 453 Element& element = ToElement(*node); |
454 Node* child = element.firstChild(); | 454 Node* child = element.firstChild(); |
455 while (child) { | 455 while (child) { |
456 Digest* child_info = CreateDigest(child, unused_nodes_map); | 456 Digest* child_info = CreateDigest(child, unused_nodes_map); |
457 AddStringToDigestor(digestor.get(), child_info->sha1_); | 457 AddUtf8StringToDigestor(digestor.get(), child_info->sha1_); |
458 child = child->nextSibling(); | 458 child = child->nextSibling(); |
459 digest->children_.push_back(child_info); | 459 digest->children_.push_back(child_info); |
460 } | 460 } |
461 | 461 |
462 AttributeCollection attributes = element.AttributesWithoutUpdate(); | 462 AttributeCollection attributes = element.AttributesWithoutUpdate(); |
463 if (!attributes.IsEmpty()) { | 463 if (!attributes.IsEmpty()) { |
464 std::unique_ptr<WebCryptoDigestor> attrs_digestor = | 464 std::unique_ptr<WebCryptoDigestor> attrs_digestor = |
465 CreateDigestor(kHashAlgorithmSha1); | 465 CreateDigestor(kHashAlgorithmSha1); |
466 for (auto& attribute : attributes) { | 466 for (auto& attribute : attributes) { |
467 AddStringToDigestor(attrs_digestor.get(), | 467 AddUtf8StringToDigestor(attrs_digestor.get(), |
468 attribute.GetName().ToString()); | 468 attribute.GetName().ToString()); |
469 AddStringToDigestor(attrs_digestor.get(), | 469 AddUtf8StringToDigestor(attrs_digestor.get(), |
470 attribute.Value().GetString()); | 470 attribute.Value().GetString()); |
471 } | 471 } |
472 FinishDigestor(attrs_digestor.get(), digest_result); | 472 FinishDigestor(attrs_digestor.get(), digest_result); |
473 digest->attrs_sha1_ = | 473 digest->attrs_sha1_ = |
474 Base64Encode(reinterpret_cast<const char*>(digest_result.data()), 10); | 474 Base64Encode(reinterpret_cast<const char*>(digest_result.data()), 10); |
475 AddStringToDigestor(digestor.get(), digest->attrs_sha1_); | 475 AddUtf8StringToDigestor(digestor.get(), digest->attrs_sha1_); |
476 digest_result.clear(); | 476 digest_result.clear(); |
477 } | 477 } |
478 } | 478 } |
479 FinishDigestor(digestor.get(), digest_result); | 479 FinishDigestor(digestor.get(), digest_result); |
480 digest->sha1_ = | 480 digest->sha1_ = |
481 Base64Encode(reinterpret_cast<const char*>(digest_result.data()), 10); | 481 Base64Encode(reinterpret_cast<const char*>(digest_result.data()), 10); |
482 | 482 |
483 if (unused_nodes_map) | 483 if (unused_nodes_map) |
484 unused_nodes_map->insert(digest->sha1_, digest); | 484 unused_nodes_map->insert(digest->sha1_, digest); |
485 return digest; | 485 return digest; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 queue.push_back(first->children_[i].Get()); | 539 queue.push_back(first->children_[i].Get()); |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
543 DEFINE_TRACE(DOMPatchSupport::Digest) { | 543 DEFINE_TRACE(DOMPatchSupport::Digest) { |
544 visitor->Trace(node_); | 544 visitor->Trace(node_); |
545 visitor->Trace(children_); | 545 visitor->Trace(children_); |
546 } | 546 } |
547 | 547 |
548 } // namespace blink | 548 } // namespace blink |
OLD | NEW |