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

Side by Side Diff: Source/core/inspector/DOMPatchSupport.cpp

Issue 23453033: Have DOMPatchSupport and DocumentFragment deal with Document references (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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/core/inspector/DOMPatchSupport.h ('k') | Source/core/inspector/InspectorDOMAgent.cpp » ('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) 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 struct DOMPatchSupport::Digest { 62 struct DOMPatchSupport::Digest {
63 explicit Digest(Node* node) : m_node(node) { } 63 explicit Digest(Node* node) : m_node(node) { }
64 64
65 String m_sha1; 65 String m_sha1;
66 String m_attrsSHA1; 66 String m_attrsSHA1;
67 Node* m_node; 67 Node* m_node;
68 Vector<OwnPtr<Digest> > m_children; 68 Vector<OwnPtr<Digest> > m_children;
69 }; 69 };
70 70
71 void DOMPatchSupport::patchDocument(Document* document, const String& markup) 71 void DOMPatchSupport::patchDocument(Document& document, const String& markup)
72 { 72 {
73 InspectorHistory history; 73 InspectorHistory history;
74 DOMEditor domEditor(&history); 74 DOMEditor domEditor(&history);
75 DOMPatchSupport patchSupport(&domEditor, document); 75 DOMPatchSupport patchSupport(&domEditor, document);
76 patchSupport.patchDocument(markup); 76 patchSupport.patchDocument(markup);
77 } 77 }
78 78
79 DOMPatchSupport::DOMPatchSupport(DOMEditor* domEditor, Document* document) 79 DOMPatchSupport::DOMPatchSupport(DOMEditor* domEditor, Document& document)
80 : m_domEditor(domEditor) 80 : m_domEditor(domEditor)
81 , m_document(document) 81 , m_document(document)
82 { 82 {
83 } 83 }
84 84
85 DOMPatchSupport::~DOMPatchSupport() { } 85 DOMPatchSupport::~DOMPatchSupport() { }
86 86
87 void DOMPatchSupport::patchDocument(const String& markup) 87 void DOMPatchSupport::patchDocument(const String& markup)
88 { 88 {
89 RefPtr<Document> newDocument; 89 RefPtr<Document> newDocument;
90 if (m_document->isHTMLDocument()) 90 if (m_document.isHTMLDocument())
91 newDocument = HTMLDocument::create(); 91 newDocument = HTMLDocument::create();
92 else if (m_document->isXHTMLDocument()) 92 else if (m_document.isXHTMLDocument())
93 newDocument = HTMLDocument::createXHTML(); 93 newDocument = HTMLDocument::createXHTML();
94 else if (m_document->isSVGDocument()) 94 else if (m_document.isSVGDocument())
95 newDocument = Document::create(); 95 newDocument = Document::create();
96 96
97 ASSERT(newDocument); 97 ASSERT(newDocument);
98 newDocument->setContextFeatures(m_document->contextFeatures()); 98 newDocument->setContextFeatures(m_document.contextFeatures());
99 RefPtr<DocumentParser> parser; 99 RefPtr<DocumentParser> parser;
100 if (m_document->isHTMLDocument()) 100 if (m_document.isHTMLDocument())
101 parser = HTMLDocumentParser::create(toHTMLDocument(newDocument.get()), f alse); 101 parser = HTMLDocumentParser::create(toHTMLDocument(newDocument.get()), f alse);
102 else 102 else
103 parser = XMLDocumentParser::create(newDocument.get(), 0); 103 parser = XMLDocumentParser::create(newDocument.get(), 0);
104 parser->insert(markup); // Use insert() so that the parser will not yield. 104 parser->insert(markup); // Use insert() so that the parser will not yield.
105 parser->finish(); 105 parser->finish();
106 parser->detach(); 106 parser->detach();
107 107
108 OwnPtr<Digest> oldInfo = createDigest(m_document->documentElement(), 0); 108 OwnPtr<Digest> oldInfo = createDigest(m_document.documentElement(), 0);
109 OwnPtr<Digest> newInfo = createDigest(newDocument->documentElement(), &m_unu sedNodesMap); 109 OwnPtr<Digest> newInfo = createDigest(newDocument->documentElement(), &m_unu sedNodesMap);
110 110
111 if (!innerPatchNode(oldInfo.get(), newInfo.get(), IGNORE_EXCEPTION)) { 111 if (!innerPatchNode(oldInfo.get(), newInfo.get(), IGNORE_EXCEPTION)) {
112 // Fall back to rewrite. 112 // Fall back to rewrite.
113 m_document->write(markup); 113 m_document.write(markup);
114 m_document->close(); 114 m_document.close();
115 } 115 }
116 } 116 }
117 117
118 Node* DOMPatchSupport::patchNode(Node* node, const String& markup, ExceptionStat e& es) 118 Node* DOMPatchSupport::patchNode(Node* node, const String& markup, ExceptionStat e& es)
119 { 119 {
120 // Don't parse <html> as a fragment. 120 // Don't parse <html> as a fragment.
121 if (node->isDocumentNode() || (node->parentNode() && node->parentNode()->isD ocumentNode())) { 121 if (node->isDocumentNode() || (node->parentNode() && node->parentNode()->isD ocumentNode())) {
122 patchDocument(markup); 122 patchDocument(markup);
123 return 0; 123 return 0;
124 } 124 }
125 125
126 Node* previousSibling = node->previousSibling(); 126 Node* previousSibling = node->previousSibling();
127 // FIXME: This code should use one of createFragment* in markup.h 127 // FIXME: This code should use one of createFragment* in markup.h
128 RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document); 128 RefPtr<DocumentFragment> fragment = DocumentFragment::create(m_document);
129 if (m_document->isHTMLDocument()) 129 if (m_document.isHTMLDocument())
130 fragment->parseHTML(markup, node->parentElement() ? node->parentElement( ) : m_document->documentElement()); 130 fragment->parseHTML(markup, node->parentElement() ? node->parentElement( ) : m_document.documentElement());
131 else 131 else
132 fragment->parseXML(markup, node->parentElement() ? node->parentElement() : m_document->documentElement()); 132 fragment->parseXML(markup, node->parentElement() ? node->parentElement() : m_document.documentElement());
133 133
134 // Compose the old list. 134 // Compose the old list.
135 ContainerNode* parentNode = node->parentNode(); 135 ContainerNode* parentNode = node->parentNode();
136 Vector<OwnPtr<Digest> > oldList; 136 Vector<OwnPtr<Digest> > oldList;
137 for (Node* child = parentNode->firstChild(); child; child = child->nextSibli ng()) 137 for (Node* child = parentNode->firstChild(); child; child = child->nextSibli ng())
138 oldList.append(createDigest(child, 0)); 138 oldList.append(createDigest(child, 0));
139 139
140 // Compose the new list. 140 // Compose the new list.
141 String markupCopy = markup; 141 String markupCopy = markup;
142 markupCopy.makeLower(); 142 markupCopy.makeLower();
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name) 510 void DOMPatchSupport::dumpMap(const ResultMap& map, const String& name)
511 { 511 {
512 fprintf(stderr, "\n\n"); 512 fprintf(stderr, "\n\n");
513 for (size_t i = 0; i < map.size(); ++i) 513 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); 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);
515 } 515 }
516 #endif 516 #endif
517 517
518 } // namespace WebCore 518 } // namespace WebCore
519 519
OLDNEW
« no previous file with comments | « Source/core/inspector/DOMPatchSupport.h ('k') | Source/core/inspector/InspectorDOMAgent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698