OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 { | 215 { |
216 m_contentDistributionInvalidatedElements.add(element); | 216 m_contentDistributionInvalidatedElements.add(element); |
217 if (!m_timer.isActive()) | 217 if (!m_timer.isActive()) |
218 m_timer.startOneShot(0, FROM_HERE); | 218 m_timer.startOneShot(0, FROM_HERE); |
219 } | 219 } |
220 | 220 |
221 void InspectorRevalidateDOMTask::onTimer(Timer<InspectorRevalidateDOMTask>*) | 221 void InspectorRevalidateDOMTask::onTimer(Timer<InspectorRevalidateDOMTask>*) |
222 { | 222 { |
223 // The timer is stopped on m_domAgent destruction, so this method will never
be called after m_domAgent has been destroyed. | 223 // The timer is stopped on m_domAgent destruction, so this method will never
be called after m_domAgent has been destroyed. |
224 WillBeHeapVector<RawPtrWillBeMember<Element> > elements; | 224 WillBeHeapVector<RawPtrWillBeMember<Element> > elements; |
225 WillBePersistentHeapHashSet<RefPtrWillBeMember<Element> >::iterator it; | 225 for (auto it : m_styleAttrInvalidatedElements) |
226 for (it = m_styleAttrInvalidatedElements.begin(); it != m_styleAttrInvalidat
edElements.end(); ++it) | 226 elements.append(it.get()); |
227 elements.append(it->get()); | |
228 m_domAgent->styleAttributeInvalidated(elements); | 227 m_domAgent->styleAttributeInvalidated(elements); |
229 | 228 |
230 m_styleAttrInvalidatedElements.clear(); | 229 m_styleAttrInvalidatedElements.clear(); |
231 | 230 |
232 elements.clear(); | 231 elements.clear(); |
233 for (const RefPtrWillBeMember<Element>& it : m_contentDistributionInvalidate
dElements) | 232 for (const RefPtrWillBeMember<Element>& it : m_contentDistributionInvalidate
dElements) |
234 elements.append(it.get()); | 233 elements.append(it.get()); |
235 m_domAgent->contentDistributionInvalidated(elements); | 234 m_domAgent->contentDistributionInvalidated(elements); |
236 | 235 |
237 m_contentDistributionInvalidatedElements.clear(); | 236 m_contentDistributionInvalidatedElements.clear(); |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 835 |
837 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name)
: String(); | 836 String caseAdjustedName = name ? (shouldIgnoreCase ? name->lower() : *name)
: String(); |
838 | 837 |
839 AttributeCollection attributes = parsedElement->attributes(); | 838 AttributeCollection attributes = parsedElement->attributes(); |
840 if (attributes.isEmpty() && name) { | 839 if (attributes.isEmpty() && name) { |
841 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); | 840 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); |
842 return; | 841 return; |
843 } | 842 } |
844 | 843 |
845 bool foundOriginalAttribute = false; | 844 bool foundOriginalAttribute = false; |
846 AttributeCollection::iterator end = attributes.end(); | 845 for (auto it : attributes) { |
847 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it)
{ | |
848 // Add attribute pair | 846 // Add attribute pair |
849 String attributeName = it->name().toString(); | 847 String attributeName = it.name().toString(); |
850 if (shouldIgnoreCase) | 848 if (shouldIgnoreCase) |
851 attributeName = attributeName.lower(); | 849 attributeName = attributeName.lower(); |
852 foundOriginalAttribute |= name && attributeName == caseAdjustedName; | 850 foundOriginalAttribute |= name && attributeName == caseAdjustedName; |
853 if (!m_domEditor->setAttribute(element, attributeName, it->value(), erro
rString)) | 851 if (!m_domEditor->setAttribute(element, attributeName, it.value(), error
String)) |
854 return; | 852 return; |
855 } | 853 } |
856 | 854 |
857 if (!foundOriginalAttribute && name && !name->stripWhiteSpace().isEmpty()) | 855 if (!foundOriginalAttribute && name && !name->stripWhiteSpace().isEmpty()) |
858 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); | 856 m_domEditor->removeAttribute(element, caseAdjustedName, errorString); |
859 } | 857 } |
860 | 858 |
861 void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId,
const String& name) | 859 void InspectorDOMAgent::removeAttribute(ErrorString* errorString, int elementId,
const String& name) |
862 { | 860 { |
863 Element* element = assertEditableElement(errorString, elementId); | 861 Element* element = assertEditableElement(errorString, elementId); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 if (endTagFound) | 1102 if (endTagFound) |
1105 tagNameQuery = tagNameQuery.left(tagNameQuery.length() - 1); | 1103 tagNameQuery = tagNameQuery.left(tagNameQuery.length() - 1); |
1106 if (startQuoteFound) | 1104 if (startQuoteFound) |
1107 attributeQuery = attributeQuery.right(attributeQuery.length() - 1); | 1105 attributeQuery = attributeQuery.right(attributeQuery.length() - 1); |
1108 if (endQuoteFound) | 1106 if (endQuoteFound) |
1109 attributeQuery = attributeQuery.left(attributeQuery.length() - 1); | 1107 attributeQuery = attributeQuery.left(attributeQuery.length() - 1); |
1110 | 1108 |
1111 WillBeHeapVector<RawPtrWillBeMember<Document> > docs = documents(); | 1109 WillBeHeapVector<RawPtrWillBeMember<Document> > docs = documents(); |
1112 WillBeHeapListHashSet<RawPtrWillBeMember<Node> > resultCollector; | 1110 WillBeHeapListHashSet<RawPtrWillBeMember<Node> > resultCollector; |
1113 | 1111 |
1114 for (WillBeHeapVector<RawPtrWillBeMember<Document> >::iterator it = docs.beg
in(); it != docs.end(); ++it) { | 1112 for (auto it : docs) { |
1115 Document* document = *it; | 1113 Document* document = it; |
1116 Node* documentElement = document->documentElement(); | 1114 Node* documentElement = document->documentElement(); |
1117 Node* node = documentElement; | 1115 Node* node = documentElement; |
1118 if (!node) | 1116 if (!node) |
1119 continue; | 1117 continue; |
1120 | 1118 |
1121 // Manual plain text search. | 1119 // Manual plain text search. |
1122 for (; node; node = nextNodeWithShadowDOMInMind(*node, documentElement,
includeUserAgentShadowDOM)) { | 1120 for (; node; node = nextNodeWithShadowDOMInMind(*node, documentElement,
includeUserAgentShadowDOM)) { |
1123 switch (node->nodeType()) { | 1121 switch (node->nodeType()) { |
1124 case Node::TEXT_NODE: | 1122 case Node::TEXT_NODE: |
1125 case Node::COMMENT_NODE: | 1123 case Node::COMMENT_NODE: |
1126 case Node::CDATA_SECTION_NODE: { | 1124 case Node::CDATA_SECTION_NODE: { |
1127 String text = node->nodeValue(); | 1125 String text = node->nodeValue(); |
1128 if (text.findIgnoringCase(whitespaceTrimmedQuery) != kNotFound) | 1126 if (text.findIgnoringCase(whitespaceTrimmedQuery) != kNotFound) |
1129 resultCollector.add(node); | 1127 resultCollector.add(node); |
1130 break; | 1128 break; |
1131 } | 1129 } |
1132 case Node::ELEMENT_NODE: { | 1130 case Node::ELEMENT_NODE: { |
1133 if ((!startTagFound && !endTagFound && (node->nodeName().findIgn
oringCase(tagNameQuery) != kNotFound)) | 1131 if ((!startTagFound && !endTagFound && (node->nodeName().findIgn
oringCase(tagNameQuery) != kNotFound)) |
1134 || (startTagFound && endTagFound && equalIgnoringCase(node->
nodeName(), tagNameQuery)) | 1132 || (startTagFound && endTagFound && equalIgnoringCase(node->
nodeName(), tagNameQuery)) |
1135 || (startTagFound && !endTagFound && node->nodeName().starts
With(tagNameQuery, false)) | 1133 || (startTagFound && !endTagFound && node->nodeName().starts
With(tagNameQuery, false)) |
1136 || (!startTagFound && endTagFound && node->nodeName().endsWi
th(tagNameQuery, false))) { | 1134 || (!startTagFound && endTagFound && node->nodeName().endsWi
th(tagNameQuery, false))) { |
1137 resultCollector.add(node); | 1135 resultCollector.add(node); |
1138 break; | 1136 break; |
1139 } | 1137 } |
1140 // Go through all attributes and serialize them. | 1138 // Go through all attributes and serialize them. |
1141 const Element* element = toElement(node); | 1139 const Element* element = toElement(node); |
1142 AttributeCollection attributes = element->attributes(); | 1140 AttributeCollection attributes = element->attributes(); |
1143 AttributeCollection::iterator end = attributes.end(); | 1141 for (auto it : attributes) { |
1144 for (AttributeCollection::iterator it = attributes.begin(); it !
= end; ++it) { | |
1145 // Add attribute pair | 1142 // Add attribute pair |
1146 if (it->localName().find(whitespaceTrimmedQuery, 0, false) !
= kNotFound) { | 1143 if (it.localName().find(whitespaceTrimmedQuery, 0, false) !=
kNotFound) { |
1147 resultCollector.add(node); | 1144 resultCollector.add(node); |
1148 break; | 1145 break; |
1149 } | 1146 } |
1150 size_t foundPosition = it->value().find(attributeQuery, 0, f
alse); | 1147 size_t foundPosition = it.value().find(attributeQuery, 0, fa
lse); |
1151 if (foundPosition != kNotFound) { | 1148 if (foundPosition != kNotFound) { |
1152 if (!exactAttributeMatch || (!foundPosition && it->value
().length() == attributeQuery.length())) { | 1149 if (!exactAttributeMatch || (!foundPosition && it.value(
).length() == attributeQuery.length())) { |
1153 resultCollector.add(node); | 1150 resultCollector.add(node); |
1154 break; | 1151 break; |
1155 } | 1152 } |
1156 } | 1153 } |
1157 } | 1154 } |
1158 break; | 1155 break; |
1159 } | 1156 } |
1160 default: | 1157 default: |
1161 break; | 1158 break; |
1162 } | 1159 } |
1163 } | 1160 } |
1164 | 1161 |
1165 // XPath evaluation | 1162 // XPath evaluation |
1166 for (WillBeHeapVector<RawPtrWillBeMember<Document> >::iterator it = docs
.begin(); it != docs.end(); ++it) { | 1163 for (auto it : docs) { |
1167 Document* document = *it; | 1164 Document* document = it; |
1168 ASSERT(document); | 1165 ASSERT(document); |
1169 TrackExceptionState exceptionState; | 1166 TrackExceptionState exceptionState; |
1170 RefPtrWillBeRawPtr<XPathResult> result = DocumentXPathEvaluator::eva
luate(*document, whitespaceTrimmedQuery, document, nullptr, XPathResult::ORDERED
_NODE_SNAPSHOT_TYPE, 0, exceptionState); | 1167 RefPtrWillBeRawPtr<XPathResult> result = DocumentXPathEvaluator::eva
luate(*document, whitespaceTrimmedQuery, document, nullptr, XPathResult::ORDERED
_NODE_SNAPSHOT_TYPE, 0, exceptionState); |
1171 if (exceptionState.hadException() || !result) | 1168 if (exceptionState.hadException() || !result) |
1172 continue; | 1169 continue; |
1173 | 1170 |
1174 unsigned long size = result->snapshotLength(exceptionState); | 1171 unsigned long size = result->snapshotLength(exceptionState); |
1175 for (unsigned long i = 0; !exceptionState.hadException() && i < size
; ++i) { | 1172 for (unsigned long i = 0; !exceptionState.hadException() && i < size
; ++i) { |
1176 Node* node = result->snapshotItem(i, exceptionState); | 1173 Node* node = result->snapshotItem(i, exceptionState); |
1177 if (exceptionState.hadException()) | 1174 if (exceptionState.hadException()) |
1178 break; | 1175 break; |
1179 | 1176 |
1180 if (node->nodeType() == Node::ATTRIBUTE_NODE) | 1177 if (node->nodeType() == Node::ATTRIBUTE_NODE) |
1181 node = toAttr(node)->ownerElement(); | 1178 node = toAttr(node)->ownerElement(); |
1182 resultCollector.add(node); | 1179 resultCollector.add(node); |
1183 } | 1180 } |
1184 } | 1181 } |
1185 | 1182 |
1186 // Selector evaluation | 1183 // Selector evaluation |
1187 for (WillBeHeapVector<RawPtrWillBeMember<Document> >::iterator it = docs
.begin(); it != docs.end(); ++it) { | 1184 for (auto it : docs) { |
1188 Document* document = *it; | 1185 Document* document = it; |
1189 TrackExceptionState exceptionState; | 1186 TrackExceptionState exceptionState; |
1190 RefPtrWillBeRawPtr<StaticElementList> elementList = document->queryS
electorAll(AtomicString(whitespaceTrimmedQuery), exceptionState); | 1187 RefPtrWillBeRawPtr<StaticElementList> elementList = document->queryS
electorAll(AtomicString(whitespaceTrimmedQuery), exceptionState); |
1191 if (exceptionState.hadException() || !elementList) | 1188 if (exceptionState.hadException() || !elementList) |
1192 continue; | 1189 continue; |
1193 | 1190 |
1194 unsigned size = elementList->length(); | 1191 unsigned size = elementList->length(); |
1195 for (unsigned i = 0; i < size; ++i) | 1192 for (unsigned i = 0; i < size; ++i) |
1196 resultCollector.add(elementList->item(i)); | 1193 resultCollector.add(elementList->item(i)); |
1197 } | 1194 } |
1198 } | 1195 } |
1199 | 1196 |
1200 *searchId = IdentifiersFactory::createIdentifier(); | 1197 *searchId = IdentifiersFactory::createIdentifier(); |
1201 WillBeHeapVector<RefPtrWillBeMember<Node> >* resultsIt = &m_searchResults.ad
d(*searchId, WillBeHeapVector<RefPtrWillBeMember<Node> >()).storedValue->value; | 1198 WillBeHeapVector<RefPtrWillBeMember<Node> >* resultsIt = &m_searchResults.ad
d(*searchId, WillBeHeapVector<RefPtrWillBeMember<Node> >()).storedValue->value; |
1202 | 1199 |
1203 for (WillBeHeapListHashSet<RawPtrWillBeMember<Node> >::iterator it = resultC
ollector.begin(); it != resultCollector.end(); ++it) | 1200 for (auto it : resultCollector) |
1204 resultsIt->append(*it); | 1201 resultsIt->append(it); |
1205 | 1202 |
1206 *resultCount = resultsIt->size(); | 1203 *resultCount = resultsIt->size(); |
1207 } | 1204 } |
1208 | 1205 |
1209 void InspectorDOMAgent::getSearchResults(ErrorString* errorString, const String&
searchId, int fromIndex, int toIndex, RefPtr<TypeBuilder::Array<int> >& nodeIds
) | 1206 void InspectorDOMAgent::getSearchResults(ErrorString* errorString, const String&
searchId, int fromIndex, int toIndex, RefPtr<TypeBuilder::Array<int> >& nodeIds
) |
1210 { | 1207 { |
1211 SearchResults::iterator it = m_searchResults.find(searchId); | 1208 SearchResults::iterator it = m_searchResults.find(searchId); |
1212 if (it == m_searchResults.end()) { | 1209 if (it == m_searchResults.end()) { |
1213 *errorString = "No search session with given id found"; | 1210 *errorString = "No search session with given id found"; |
1214 return; | 1211 return; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 { | 1533 { |
1537 Node* node = assertNode(errorString, nodeId); | 1534 Node* node = assertNode(errorString, nodeId); |
1538 if (!node) | 1535 if (!node) |
1539 return; | 1536 return; |
1540 if (!isHTMLInputElement(*node) || toHTMLInputElement(*node).type() != InputT
ypeNames::file) { | 1537 if (!isHTMLInputElement(*node) || toHTMLInputElement(*node).type() != InputT
ypeNames::file) { |
1541 *errorString = "Node is not a file input element"; | 1538 *errorString = "Node is not a file input element"; |
1542 return; | 1539 return; |
1543 } | 1540 } |
1544 | 1541 |
1545 FileList* fileList = FileList::create(); | 1542 FileList* fileList = FileList::create(); |
1546 for (JSONArray::const_iterator iter = files->begin(); iter != files->end();
++iter) { | 1543 for (const auto& iter : *files) { |
1547 String path; | 1544 String path; |
1548 if (!(*iter)->asString(&path)) { | 1545 if (!(iter)->asString(&path)) { |
1549 *errorString = "Files must be strings"; | 1546 *errorString = "Files must be strings"; |
1550 return; | 1547 return; |
1551 } | 1548 } |
1552 fileList->append(File::create(path)); | 1549 fileList->append(File::create(path)); |
1553 } | 1550 } |
1554 toHTMLInputElement(node)->setFiles(fileList); | 1551 toHTMLInputElement(node)->setFiles(fileList); |
1555 } | 1552 } |
1556 | 1553 |
1557 void InspectorDOMAgent::getBoxModel(ErrorString* errorString, int nodeId, RefPtr
<TypeBuilder::DOM::BoxModel>& model) | 1554 void InspectorDOMAgent::getBoxModel(ErrorString* errorString, int nodeId, RefPtr
<TypeBuilder::DOM::BoxModel>& model) |
1558 { | 1555 { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 } | 1751 } |
1755 | 1752 |
1756 return value.release(); | 1753 return value.release(); |
1757 } | 1754 } |
1758 | 1755 |
1759 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA
ttributes(Element* element) | 1756 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA
ttributes(Element* element) |
1760 { | 1757 { |
1761 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str
ing>::create(); | 1758 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str
ing>::create(); |
1762 // Go through all attributes and serialize them. | 1759 // Go through all attributes and serialize them. |
1763 AttributeCollection attributes = element->attributes(); | 1760 AttributeCollection attributes = element->attributes(); |
1764 AttributeCollection::iterator end = attributes.end(); | 1761 for (auto it : attributes) { |
1765 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it)
{ | |
1766 // Add attribute pair | 1762 // Add attribute pair |
1767 attributesValue->addItem(it->name().toString()); | 1763 attributesValue->addItem(it.name().toString()); |
1768 attributesValue->addItem(it->value()); | 1764 attributesValue->addItem(it.value()); |
1769 } | 1765 } |
1770 return attributesValue.release(); | 1766 return attributesValue.release(); |
1771 } | 1767 } |
1772 | 1768 |
1773 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build
ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap) | 1769 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build
ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap) |
1774 { | 1770 { |
1775 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder::
Array<TypeBuilder::DOM::Node>::create(); | 1771 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder::
Array<TypeBuilder::DOM::Node>::create(); |
1776 if (depth == 0) { | 1772 if (depth == 0) { |
1777 // Special-case the only text child - pretend that container's children
have been requested. | 1773 // Special-case the only text child - pretend that container's children
have been requested. |
1778 Node* firstChild = container->firstChild(); | 1774 Node* firstChild = container->firstChild(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 { | 2223 { |
2228 if (Node* node = nodeForPath(path)) | 2224 if (Node* node = nodeForPath(path)) |
2229 *nodeId = pushNodePathToFrontend(node); | 2225 *nodeId = pushNodePathToFrontend(node); |
2230 else | 2226 else |
2231 *errorString = "No node with given path found"; | 2227 *errorString = "No node with given path found"; |
2232 } | 2228 } |
2233 | 2229 |
2234 void InspectorDOMAgent::pushNodesByBackendIdsToFrontend(ErrorString* errorString
, const RefPtr<JSONArray>& backendNodeIds, RefPtr<TypeBuilder::Array<int> >& res
ult) | 2230 void InspectorDOMAgent::pushNodesByBackendIdsToFrontend(ErrorString* errorString
, const RefPtr<JSONArray>& backendNodeIds, RefPtr<TypeBuilder::Array<int> >& res
ult) |
2235 { | 2231 { |
2236 result = TypeBuilder::Array<int>::create(); | 2232 result = TypeBuilder::Array<int>::create(); |
2237 for (JSONArray::const_iterator it = backendNodeIds->begin(); it != backendNo
deIds->end(); ++it) { | 2233 for (const auto& it : *backendNodeIds) { |
2238 int backendNodeId; | 2234 int backendNodeId; |
2239 | 2235 |
2240 if (!(*it)->asNumber(&backendNodeId)) { | 2236 if (!(it)->asNumber(&backendNodeId)) { |
2241 *errorString = "Invalid argument type"; | 2237 *errorString = "Invalid argument type"; |
2242 return; | 2238 return; |
2243 } | 2239 } |
2244 | 2240 |
2245 Node* node = InspectorNodeIds::nodeForId(backendNodeId); | 2241 Node* node = InspectorNodeIds::nodeForId(backendNodeId); |
2246 if (node && node->document().page() == m_pageAgent->page()) | 2242 if (node && node->document().page() == m_pageAgent->page()) |
2247 result->addItem(pushNodePathToFrontend(node)); | 2243 result->addItem(pushNodePathToFrontend(node)); |
2248 else | 2244 else |
2249 result->addItem(0); | 2245 result->addItem(0); |
2250 } | 2246 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2304 visitor->trace(m_revalidateTask); | 2300 visitor->trace(m_revalidateTask); |
2305 visitor->trace(m_searchResults); | 2301 visitor->trace(m_searchResults); |
2306 #endif | 2302 #endif |
2307 visitor->trace(m_history); | 2303 visitor->trace(m_history); |
2308 visitor->trace(m_domEditor); | 2304 visitor->trace(m_domEditor); |
2309 visitor->trace(m_listener); | 2305 visitor->trace(m_listener); |
2310 InspectorBaseAgent::trace(visitor); | 2306 InspectorBaseAgent::trace(visitor); |
2311 } | 2307 } |
2312 | 2308 |
2313 } // namespace blink | 2309 } // namespace blink |
OLD | NEW |