| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 | 182 |
| 183 if (!oldNode->isElementNode()) | 183 if (!oldNode->isElementNode()) |
| 184 return true; | 184 return true; |
| 185 | 185 |
| 186 // Patch attributes | 186 // Patch attributes |
| 187 Element* oldElement = toElement(oldNode); | 187 Element* oldElement = toElement(oldNode); |
| 188 Element* newElement = toElement(newNode); | 188 Element* newElement = toElement(newNode); |
| 189 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) { | 189 if (oldDigest->m_attrsSHA1 != newDigest->m_attrsSHA1) { |
| 190 // FIXME: Create a function in Element for removing all properties. Take
in account whether did/willModifyAttribute are important. | 190 // FIXME: Create a function in Element for removing all properties. Take
in account whether did/willModifyAttribute are important. |
| 191 if (oldElement->hasAttributesWithoutUpdate()) { | 191 while (oldElement->attributesWithoutUpdate().size()) { |
| 192 while (oldElement->attributes().size()) { | 192 const Attribute& attribute = oldElement->attributesWithoutUpdate().a
t(0); |
| 193 const Attribute& attribute = oldElement->attributes().at(0); | 193 if (!m_domEditor->removeAttribute(oldElement, attribute.localName(),
exceptionState)) |
| 194 if (!m_domEditor->removeAttribute(oldElement, attribute.localNam
e(), exceptionState)) | 194 return false; |
| 195 return false; | |
| 196 } | |
| 197 } | 195 } |
| 198 | 196 |
| 199 // FIXME: Create a function in Element for copying properties. cloneData
FromElement() is close but not enough for this case. | 197 // FIXME: Create a function in Element for copying properties. cloneData
FromElement() is close but not enough for this case. |
| 200 if (newElement->hasAttributesWithoutUpdate()) { | 198 AttributeCollection attributes = newElement->attributesWithoutUpdate(); |
| 201 AttributeCollection attributes = newElement->attributes(); | 199 AttributeCollection::const_iterator end = attributes.end(); |
| 202 AttributeCollection::const_iterator end = attributes.end(); | 200 for (AttributeCollection::const_iterator it = attributes.begin(); it !=
end; ++it) { |
| 203 for (AttributeCollection::const_iterator it = attributes.begin(); it
!= end; ++it) { | 201 if (!m_domEditor->setAttribute(oldElement, it->name().localName(), i
t->value(), exceptionState)) |
| 204 if (!m_domEditor->setAttribute(oldElement, it->name().localName(
), it->value(), exceptionState)) | 202 return false; |
| 205 return false; | |
| 206 } | |
| 207 } | 203 } |
| 208 } | 204 } |
| 209 | 205 |
| 210 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges
t->m_children, exceptionState); | 206 bool result = innerPatchChildren(oldElement, oldDigest->m_children, newDiges
t->m_children, exceptionState); |
| 211 m_unusedNodesMap.remove(newDigest->m_sha1); | 207 m_unusedNodesMap.remove(newDigest->m_sha1); |
| 212 return result; | 208 return result; |
| 213 } | 209 } |
| 214 | 210 |
| 215 pair<DOMPatchSupport::ResultMap, DOMPatchSupport::ResultMap> | 211 pair<DOMPatchSupport::ResultMap, DOMPatchSupport::ResultMap> |
| 216 DOMPatchSupport::diff(const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPt
r<Digest> >& newList) | 212 DOMPatchSupport::diff(const Vector<OwnPtr<Digest> >& oldList, const Vector<OwnPt
r<Digest> >& newList) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 if (node->isElementNode()) { | 418 if (node->isElementNode()) { |
| 423 Element& element = toElement(*node); | 419 Element& element = toElement(*node); |
| 424 Node* child = element.firstChild(); | 420 Node* child = element.firstChild(); |
| 425 while (child) { | 421 while (child) { |
| 426 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); | 422 OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); |
| 427 addStringToDigestor(digestor.get(), childInfo->m_sha1); | 423 addStringToDigestor(digestor.get(), childInfo->m_sha1); |
| 428 child = child->nextSibling(); | 424 child = child->nextSibling(); |
| 429 digest->m_children.append(childInfo.release()); | 425 digest->m_children.append(childInfo.release()); |
| 430 } | 426 } |
| 431 | 427 |
| 432 if (element.hasAttributesWithoutUpdate()) { | 428 AttributeCollection attributes = element.attributesWithoutUpdate(); |
| 429 if (!attributes.isEmpty()) { |
| 433 OwnPtr<blink::WebCryptoDigestor> attrsDigestor = createDigestor(Hash
AlgorithmSha1); | 430 OwnPtr<blink::WebCryptoDigestor> attrsDigestor = createDigestor(Hash
AlgorithmSha1); |
| 434 AttributeCollection attributes = element.attributes(); | |
| 435 AttributeCollection::const_iterator end = attributes.end(); | 431 AttributeCollection::const_iterator end = attributes.end(); |
| 436 for (AttributeCollection::const_iterator it = attributes.begin(); it
!= end; ++it) { | 432 for (AttributeCollection::const_iterator it = attributes.begin(); it
!= end; ++it) { |
| 437 addStringToDigestor(attrsDigestor.get(), it->name().toString()); | 433 addStringToDigestor(attrsDigestor.get(), it->name().toString()); |
| 438 addStringToDigestor(attrsDigestor.get(), it->value().string()); | 434 addStringToDigestor(attrsDigestor.get(), it->value().string()); |
| 439 } | 435 } |
| 440 finishDigestor(attrsDigestor.get(), digestResult); | 436 finishDigestor(attrsDigestor.get(), digestResult); |
| 441 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig
estResult.data()), 10); | 437 digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(dig
estResult.data()), 10); |
| 442 addStringToDigestor(digestor.get(), digest->m_attrsSHA1); | 438 addStringToDigestor(digestor.get(), digest->m_attrsSHA1); |
| 443 digestResult.clear(); | 439 digestResult.clear(); |
| 444 } | 440 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) | 506 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) |
| 511 { | 507 { |
| 512 fprintf(stderr, "\n\n"); | 508 fprintf(stderr, "\n\n"); |
| 513 for (size_t i = 0; i < map.size(); ++i) | 509 for (size_t i = 0; i < map.size(); ++i) |
| 514 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); | 510 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 } | 511 } |
| 516 #endif | 512 #endif |
| 517 | 513 |
| 518 } // namespace blink | 514 } // namespace blink |
| 519 | 515 |
| OLD | NEW |