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& attribute : m_styleAttrInvalidatedElements) |
226 for (it = m_styleAttrInvalidatedElements.begin(); it != m_styleAttrInvalidat
edElements.end(); ++it) | 226 elements.append(attribute.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& attribute : 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 = attribute.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, attribute.value()
, errorString)) |
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 (Document* document : docs) { |
1115 Document* document = *it; | |
1116 Node* documentElement = document->documentElement(); | 1113 Node* documentElement = document->documentElement(); |
1117 Node* node = documentElement; | 1114 Node* node = documentElement; |
1118 if (!node) | 1115 if (!node) |
1119 continue; | 1116 continue; |
1120 | 1117 |
1121 // Manual plain text search. | 1118 // Manual plain text search. |
1122 for (; node; node = nextNodeWithShadowDOMInMind(*node, documentElement,
includeUserAgentShadowDOM)) { | 1119 for (; node; node = nextNodeWithShadowDOMInMind(*node, documentElement,
includeUserAgentShadowDOM)) { |
1123 switch (node->nodeType()) { | 1120 switch (node->nodeType()) { |
1124 case Node::TEXT_NODE: | 1121 case Node::TEXT_NODE: |
1125 case Node::COMMENT_NODE: | 1122 case Node::COMMENT_NODE: |
1126 case Node::CDATA_SECTION_NODE: { | 1123 case Node::CDATA_SECTION_NODE: { |
1127 String text = node->nodeValue(); | 1124 String text = node->nodeValue(); |
1128 if (text.findIgnoringCase(whitespaceTrimmedQuery) != kNotFound) | 1125 if (text.findIgnoringCase(whitespaceTrimmedQuery) != kNotFound) |
1129 resultCollector.add(node); | 1126 resultCollector.add(node); |
1130 break; | 1127 break; |
1131 } | 1128 } |
1132 case Node::ELEMENT_NODE: { | 1129 case Node::ELEMENT_NODE: { |
1133 if ((!startTagFound && !endTagFound && (node->nodeName().findIgn
oringCase(tagNameQuery) != kNotFound)) | 1130 if ((!startTagFound && !endTagFound && (node->nodeName().findIgn
oringCase(tagNameQuery) != kNotFound)) |
1134 || (startTagFound && endTagFound && equalIgnoringCase(node->
nodeName(), tagNameQuery)) | 1131 || (startTagFound && endTagFound && equalIgnoringCase(node->
nodeName(), tagNameQuery)) |
1135 || (startTagFound && !endTagFound && node->nodeName().starts
With(tagNameQuery, false)) | 1132 || (startTagFound && !endTagFound && node->nodeName().starts
With(tagNameQuery, false)) |
1136 || (!startTagFound && endTagFound && node->nodeName().endsWi
th(tagNameQuery, false))) { | 1133 || (!startTagFound && endTagFound && node->nodeName().endsWi
th(tagNameQuery, false))) { |
1137 resultCollector.add(node); | 1134 resultCollector.add(node); |
1138 break; | 1135 break; |
1139 } | 1136 } |
1140 // Go through all attributes and serialize them. | 1137 // Go through all attributes and serialize them. |
1141 const Element* element = toElement(node); | 1138 const Element* element = toElement(node); |
1142 AttributeCollection attributes = element->attributes(); | 1139 AttributeCollection attributes = element->attributes(); |
1143 AttributeCollection::iterator end = attributes.end(); | 1140 for (auto& attribute : attributes) { |
1144 for (AttributeCollection::iterator it = attributes.begin(); it !
= end; ++it) { | |
1145 // Add attribute pair | 1141 // Add attribute pair |
1146 if (it->localName().find(whitespaceTrimmedQuery, 0, false) !
= kNotFound) { | 1142 if (attribute.localName().find(whitespaceTrimmedQuery, 0, fa
lse) != kNotFound) { |
1147 resultCollector.add(node); | 1143 resultCollector.add(node); |
1148 break; | 1144 break; |
1149 } | 1145 } |
1150 size_t foundPosition = it->value().find(attributeQuery, 0, f
alse); | 1146 size_t foundPosition = attribute.value().find(attributeQuery
, 0, false); |
1151 if (foundPosition != kNotFound) { | 1147 if (foundPosition != kNotFound) { |
1152 if (!exactAttributeMatch || (!foundPosition && it->value
().length() == attributeQuery.length())) { | 1148 if (!exactAttributeMatch || (!foundPosition && attribute
.value().length() == attributeQuery.length())) { |
1153 resultCollector.add(node); | 1149 resultCollector.add(node); |
1154 break; | 1150 break; |
1155 } | 1151 } |
1156 } | 1152 } |
1157 } | 1153 } |
1158 break; | 1154 break; |
1159 } | 1155 } |
1160 default: | 1156 default: |
1161 break; | 1157 break; |
1162 } | 1158 } |
1163 } | 1159 } |
1164 | 1160 |
1165 // XPath evaluation | 1161 // XPath evaluation |
1166 for (WillBeHeapVector<RawPtrWillBeMember<Document> >::iterator it = docs
.begin(); it != docs.end(); ++it) { | 1162 for (Document* document : docs) { |
1167 Document* document = *it; | |
1168 ASSERT(document); | 1163 ASSERT(document); |
1169 TrackExceptionState exceptionState; | 1164 TrackExceptionState exceptionState; |
1170 RefPtrWillBeRawPtr<XPathResult> result = DocumentXPathEvaluator::eva
luate(*document, whitespaceTrimmedQuery, document, nullptr, XPathResult::ORDERED
_NODE_SNAPSHOT_TYPE, 0, exceptionState); | 1165 RefPtrWillBeRawPtr<XPathResult> result = DocumentXPathEvaluator::eva
luate(*document, whitespaceTrimmedQuery, document, nullptr, XPathResult::ORDERED
_NODE_SNAPSHOT_TYPE, 0, exceptionState); |
1171 if (exceptionState.hadException() || !result) | 1166 if (exceptionState.hadException() || !result) |
1172 continue; | 1167 continue; |
1173 | 1168 |
1174 unsigned long size = result->snapshotLength(exceptionState); | 1169 unsigned long size = result->snapshotLength(exceptionState); |
1175 for (unsigned long i = 0; !exceptionState.hadException() && i < size
; ++i) { | 1170 for (unsigned long i = 0; !exceptionState.hadException() && i < size
; ++i) { |
1176 Node* node = result->snapshotItem(i, exceptionState); | 1171 Node* node = result->snapshotItem(i, exceptionState); |
1177 if (exceptionState.hadException()) | 1172 if (exceptionState.hadException()) |
1178 break; | 1173 break; |
1179 | 1174 |
1180 if (node->nodeType() == Node::ATTRIBUTE_NODE) | 1175 if (node->nodeType() == Node::ATTRIBUTE_NODE) |
1181 node = toAttr(node)->ownerElement(); | 1176 node = toAttr(node)->ownerElement(); |
1182 resultCollector.add(node); | 1177 resultCollector.add(node); |
1183 } | 1178 } |
1184 } | 1179 } |
1185 | 1180 |
1186 // Selector evaluation | 1181 // Selector evaluation |
1187 for (WillBeHeapVector<RawPtrWillBeMember<Document> >::iterator it = docs
.begin(); it != docs.end(); ++it) { | 1182 for (Document* document : docs) { |
1188 Document* document = *it; | |
1189 TrackExceptionState exceptionState; | 1183 TrackExceptionState exceptionState; |
1190 RefPtrWillBeRawPtr<StaticElementList> elementList = document->queryS
electorAll(AtomicString(whitespaceTrimmedQuery), exceptionState); | 1184 RefPtrWillBeRawPtr<StaticElementList> elementList = document->queryS
electorAll(AtomicString(whitespaceTrimmedQuery), exceptionState); |
1191 if (exceptionState.hadException() || !elementList) | 1185 if (exceptionState.hadException() || !elementList) |
1192 continue; | 1186 continue; |
1193 | 1187 |
1194 unsigned size = elementList->length(); | 1188 unsigned size = elementList->length(); |
1195 for (unsigned i = 0; i < size; ++i) | 1189 for (unsigned i = 0; i < size; ++i) |
1196 resultCollector.add(elementList->item(i)); | 1190 resultCollector.add(elementList->item(i)); |
1197 } | 1191 } |
1198 } | 1192 } |
1199 | 1193 |
1200 *searchId = IdentifiersFactory::createIdentifier(); | 1194 *searchId = IdentifiersFactory::createIdentifier(); |
1201 WillBeHeapVector<RefPtrWillBeMember<Node> >* resultsIt = &m_searchResults.ad
d(*searchId, WillBeHeapVector<RefPtrWillBeMember<Node> >()).storedValue->value; | 1195 WillBeHeapVector<RefPtrWillBeMember<Node> >* resultsIt = &m_searchResults.ad
d(*searchId, WillBeHeapVector<RefPtrWillBeMember<Node> >()).storedValue->value; |
1202 | 1196 |
1203 for (WillBeHeapListHashSet<RawPtrWillBeMember<Node> >::iterator it = resultC
ollector.begin(); it != resultCollector.end(); ++it) | 1197 for (auto& result : resultCollector) |
1204 resultsIt->append(*it); | 1198 resultsIt->append(result); |
1205 | 1199 |
1206 *resultCount = resultsIt->size(); | 1200 *resultCount = resultsIt->size(); |
1207 } | 1201 } |
1208 | 1202 |
1209 void InspectorDOMAgent::getSearchResults(ErrorString* errorString, const String&
searchId, int fromIndex, int toIndex, RefPtr<TypeBuilder::Array<int> >& nodeIds
) | 1203 void InspectorDOMAgent::getSearchResults(ErrorString* errorString, const String&
searchId, int fromIndex, int toIndex, RefPtr<TypeBuilder::Array<int> >& nodeIds
) |
1210 { | 1204 { |
1211 SearchResults::iterator it = m_searchResults.find(searchId); | 1205 SearchResults::iterator it = m_searchResults.find(searchId); |
1212 if (it == m_searchResults.end()) { | 1206 if (it == m_searchResults.end()) { |
1213 *errorString = "No search session with given id found"; | 1207 *errorString = "No search session with given id found"; |
1214 return; | 1208 return; |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 { | 1530 { |
1537 Node* node = assertNode(errorString, nodeId); | 1531 Node* node = assertNode(errorString, nodeId); |
1538 if (!node) | 1532 if (!node) |
1539 return; | 1533 return; |
1540 if (!isHTMLInputElement(*node) || toHTMLInputElement(*node).type() != InputT
ypeNames::file) { | 1534 if (!isHTMLInputElement(*node) || toHTMLInputElement(*node).type() != InputT
ypeNames::file) { |
1541 *errorString = "Node is not a file input element"; | 1535 *errorString = "Node is not a file input element"; |
1542 return; | 1536 return; |
1543 } | 1537 } |
1544 | 1538 |
1545 FileList* fileList = FileList::create(); | 1539 FileList* fileList = FileList::create(); |
1546 for (JSONArray::const_iterator iter = files->begin(); iter != files->end();
++iter) { | 1540 for (const auto& file : *files) { |
1547 String path; | 1541 String path; |
1548 if (!(*iter)->asString(&path)) { | 1542 if (!(file)->asString(&path)) { |
1549 *errorString = "Files must be strings"; | 1543 *errorString = "Files must be strings"; |
1550 return; | 1544 return; |
1551 } | 1545 } |
1552 fileList->append(File::create(path)); | 1546 fileList->append(File::create(path)); |
1553 } | 1547 } |
1554 toHTMLInputElement(node)->setFiles(fileList); | 1548 toHTMLInputElement(node)->setFiles(fileList); |
1555 } | 1549 } |
1556 | 1550 |
1557 void InspectorDOMAgent::getBoxModel(ErrorString* errorString, int nodeId, RefPtr
<TypeBuilder::DOM::BoxModel>& model) | 1551 void InspectorDOMAgent::getBoxModel(ErrorString* errorString, int nodeId, RefPtr
<TypeBuilder::DOM::BoxModel>& model) |
1558 { | 1552 { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 } | 1748 } |
1755 | 1749 |
1756 return value.release(); | 1750 return value.release(); |
1757 } | 1751 } |
1758 | 1752 |
1759 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA
ttributes(Element* element) | 1753 PassRefPtr<TypeBuilder::Array<String> > InspectorDOMAgent::buildArrayForElementA
ttributes(Element* element) |
1760 { | 1754 { |
1761 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str
ing>::create(); | 1755 RefPtr<TypeBuilder::Array<String> > attributesValue = TypeBuilder::Array<Str
ing>::create(); |
1762 // Go through all attributes and serialize them. | 1756 // Go through all attributes and serialize them. |
1763 AttributeCollection attributes = element->attributes(); | 1757 AttributeCollection attributes = element->attributes(); |
1764 AttributeCollection::iterator end = attributes.end(); | 1758 for (auto& attribute : attributes) { |
1765 for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it)
{ | |
1766 // Add attribute pair | 1759 // Add attribute pair |
1767 attributesValue->addItem(it->name().toString()); | 1760 attributesValue->addItem(attribute.name().toString()); |
1768 attributesValue->addItem(it->value()); | 1761 attributesValue->addItem(attribute.value()); |
1769 } | 1762 } |
1770 return attributesValue.release(); | 1763 return attributesValue.release(); |
1771 } | 1764 } |
1772 | 1765 |
1773 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build
ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap) | 1766 PassRefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > InspectorDOMAgent::build
ArrayForContainerChildren(Node* container, int depth, NodeToIdMap* nodesMap) |
1774 { | 1767 { |
1775 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder::
Array<TypeBuilder::DOM::Node>::create(); | 1768 RefPtr<TypeBuilder::Array<TypeBuilder::DOM::Node> > children = TypeBuilder::
Array<TypeBuilder::DOM::Node>::create(); |
1776 if (depth == 0) { | 1769 if (depth == 0) { |
1777 // Special-case the only text child - pretend that container's children
have been requested. | 1770 // Special-case the only text child - pretend that container's children
have been requested. |
1778 Node* firstChild = container->firstChild(); | 1771 Node* firstChild = container->firstChild(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2227 { | 2220 { |
2228 if (Node* node = nodeForPath(path)) | 2221 if (Node* node = nodeForPath(path)) |
2229 *nodeId = pushNodePathToFrontend(node); | 2222 *nodeId = pushNodePathToFrontend(node); |
2230 else | 2223 else |
2231 *errorString = "No node with given path found"; | 2224 *errorString = "No node with given path found"; |
2232 } | 2225 } |
2233 | 2226 |
2234 void InspectorDOMAgent::pushNodesByBackendIdsToFrontend(ErrorString* errorString
, const RefPtr<JSONArray>& backendNodeIds, RefPtr<TypeBuilder::Array<int> >& res
ult) | 2227 void InspectorDOMAgent::pushNodesByBackendIdsToFrontend(ErrorString* errorString
, const RefPtr<JSONArray>& backendNodeIds, RefPtr<TypeBuilder::Array<int> >& res
ult) |
2235 { | 2228 { |
2236 result = TypeBuilder::Array<int>::create(); | 2229 result = TypeBuilder::Array<int>::create(); |
2237 for (JSONArray::const_iterator it = backendNodeIds->begin(); it != backendNo
deIds->end(); ++it) { | 2230 for (const auto& backendNode : *backendNodeIds) { |
2238 int backendNodeId; | 2231 int backendNodeId; |
2239 | 2232 |
2240 if (!(*it)->asNumber(&backendNodeId)) { | 2233 if (!(backendNode)->asNumber(&backendNodeId)) { |
2241 *errorString = "Invalid argument type"; | 2234 *errorString = "Invalid argument type"; |
2242 return; | 2235 return; |
2243 } | 2236 } |
2244 | 2237 |
2245 Node* node = InspectorNodeIds::nodeForId(backendNodeId); | 2238 Node* node = InspectorNodeIds::nodeForId(backendNodeId); |
2246 if (node && node->document().page() == m_pageAgent->page()) | 2239 if (node && node->document().page() == m_pageAgent->page()) |
2247 result->addItem(pushNodePathToFrontend(node)); | 2240 result->addItem(pushNodePathToFrontend(node)); |
2248 else | 2241 else |
2249 result->addItem(0); | 2242 result->addItem(0); |
2250 } | 2243 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2304 visitor->trace(m_revalidateTask); | 2297 visitor->trace(m_revalidateTask); |
2305 visitor->trace(m_searchResults); | 2298 visitor->trace(m_searchResults); |
2306 #endif | 2299 #endif |
2307 visitor->trace(m_history); | 2300 visitor->trace(m_history); |
2308 visitor->trace(m_domEditor); | 2301 visitor->trace(m_domEditor); |
2309 visitor->trace(m_listener); | 2302 visitor->trace(m_listener); |
2310 InspectorBaseAgent::trace(visitor); | 2303 InspectorBaseAgent::trace(visitor); |
2311 } | 2304 } |
2312 | 2305 |
2313 } // namespace blink | 2306 } // namespace blink |
OLD | NEW |