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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 v8_inspector::V8InspectorSession* v8Session, | 247 v8_inspector::V8InspectorSession* v8Session, |
248 Client* client) | 248 Client* client) |
249 : m_isolate(isolate), | 249 : m_isolate(isolate), |
250 m_inspectedFrames(inspectedFrames), | 250 m_inspectedFrames(inspectedFrames), |
251 m_v8Session(v8Session), | 251 m_v8Session(v8Session), |
252 m_client(client), | 252 m_client(client), |
253 m_domListener(nullptr), | 253 m_domListener(nullptr), |
254 m_documentNodeToIdMap(new NodeToIdMap()), | 254 m_documentNodeToIdMap(new NodeToIdMap()), |
255 m_lastNodeId(1), | 255 m_lastNodeId(1), |
256 m_suppressAttributeModifiedEvent(false), | 256 m_suppressAttributeModifiedEvent(false), |
257 m_traverseFrames(false), | |
257 m_backendNodeIdToInspect(0) {} | 258 m_backendNodeIdToInspect(0) {} |
258 | 259 |
259 InspectorDOMAgent::~InspectorDOMAgent() {} | 260 InspectorDOMAgent::~InspectorDOMAgent() {} |
260 | 261 |
261 void InspectorDOMAgent::restore() { | 262 void InspectorDOMAgent::restore() { |
262 if (!enabled()) | 263 if (!enabled()) |
263 return; | 264 return; |
264 innerEnable(); | 265 innerEnable(); |
265 } | 266 } |
266 | 267 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 setSearchingForNode(errorString, NotSearching, | 500 setSearchingForNode(errorString, NotSearching, |
500 Maybe<protocol::DOM::HighlightConfig>()); | 501 Maybe<protocol::DOM::HighlightConfig>()); |
501 m_instrumentingAgents->removeInspectorDOMAgent(this); | 502 m_instrumentingAgents->removeInspectorDOMAgent(this); |
502 m_history.clear(); | 503 m_history.clear(); |
503 m_domEditor.clear(); | 504 m_domEditor.clear(); |
504 setDocument(nullptr); | 505 setDocument(nullptr); |
505 } | 506 } |
506 | 507 |
507 void InspectorDOMAgent::getDocument( | 508 void InspectorDOMAgent::getDocument( |
508 ErrorString* errorString, | 509 ErrorString* errorString, |
510 const Maybe<int>& depth, | |
511 const Maybe<bool>& traverseFrames, | |
509 std::unique_ptr<protocol::DOM::Node>* root) { | 512 std::unique_ptr<protocol::DOM::Node>* root) { |
510 // Backward compatibility. Mark agent as enabled when it requests document. | 513 // Backward compatibility. Mark agent as enabled when it requests document. |
511 if (!enabled()) | 514 if (!enabled()) |
512 innerEnable(); | 515 innerEnable(); |
513 | 516 |
514 if (!m_document) { | 517 if (!m_document) { |
515 *errorString = "Document is not available"; | 518 *errorString = "Document is not available"; |
516 return; | 519 return; |
517 } | 520 } |
518 | 521 |
519 discardFrontendBindings(); | 522 discardFrontendBindings(); |
520 | 523 |
521 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()); | 524 m_traverseFrames = traverseFrames.fromMaybe(false); |
pfeldman
2016/10/07 19:35:12
You should plumb it, it is sessional, not a proper
alex clarke (OOO till 29th)
2016/10/11 12:05:12
Done.
| |
525 | |
526 *root = buildObjectForNode(m_document.get(), depth.fromMaybe(2), | |
527 m_documentNodeToIdMap.get()); | |
522 } | 528 } |
523 | 529 |
524 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) { | 530 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) { |
525 Node* node = nodeForId(nodeId); | 531 Node* node = nodeForId(nodeId); |
526 if (!node || (!node->isElementNode() && !node->isDocumentNode() && | 532 if (!node || (!node->isElementNode() && !node->isDocumentNode() && |
527 !node->isDocumentFragment())) | 533 !node->isDocumentFragment())) |
528 return; | 534 return; |
529 | 535 |
530 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); | 536 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); |
531 | 537 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 for (unsigned i = 0; i < classNameList.size(); ++i) | 603 for (unsigned i = 0; i < classNameList.size(); ++i) |
598 uniqueNames.add(classNameList[i]); | 604 uniqueNames.add(classNameList[i]); |
599 } | 605 } |
600 } | 606 } |
601 for (const String& className : uniqueNames) | 607 for (const String& className : uniqueNames) |
602 (*classNames)->addItem(className); | 608 (*classNames)->addItem(className); |
603 } | 609 } |
604 | 610 |
605 void InspectorDOMAgent::requestChildNodes(ErrorString* errorString, | 611 void InspectorDOMAgent::requestChildNodes(ErrorString* errorString, |
606 int nodeId, | 612 int nodeId, |
607 const Maybe<int>& depth) { | 613 const Maybe<int>& depth, |
614 const Maybe<bool>& traverseFrames) { | |
608 int sanitizedDepth = depth.fromMaybe(1); | 615 int sanitizedDepth = depth.fromMaybe(1); |
609 if (sanitizedDepth == 0 || sanitizedDepth < -1) { | 616 if (sanitizedDepth == 0 || sanitizedDepth < -1) { |
610 *errorString = | 617 *errorString = |
611 "Please provide a positive integer as a depth or -1 for entire subtree"; | 618 "Please provide a positive integer as a depth or -1 for entire subtree"; |
612 return; | 619 return; |
613 } | 620 } |
614 if (sanitizedDepth == -1) | 621 if (sanitizedDepth == -1) |
615 sanitizedDepth = INT_MAX; | 622 sanitizedDepth = INT_MAX; |
616 | 623 |
624 // Cached results may not be valid if |m_traverseFrames| changes. | |
625 if (m_traverseFrames != traverseFrames.fromMaybe(false)) { | |
626 m_traverseFrames = traverseFrames.fromMaybe(false); | |
627 m_childrenRequested.clear(); | |
628 } | |
629 | |
617 pushChildNodesToFrontend(nodeId, sanitizedDepth); | 630 pushChildNodesToFrontend(nodeId, sanitizedDepth); |
618 } | 631 } |
619 | 632 |
620 void InspectorDOMAgent::querySelector(ErrorString* errorString, | 633 void InspectorDOMAgent::querySelector(ErrorString* errorString, |
621 int nodeId, | 634 int nodeId, |
622 const String& selectors, | 635 const String& selectors, |
623 int* elementId) { | 636 int* elementId) { |
624 *elementId = 0; | 637 *elementId = 0; |
625 Node* node = assertNode(errorString, nodeId); | 638 Node* node = assertNode(errorString, nodeId); |
626 if (!node || !node->isContainerNode()) | 639 if (!node || !node->isContainerNode()) |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1600 Element* element = toElement(node); | 1613 Element* element = toElement(node); |
1601 value->setAttributes(buildArrayForElementAttributes(element)); | 1614 value->setAttributes(buildArrayForElementAttributes(element)); |
1602 | 1615 |
1603 if (node->isFrameOwnerElement()) { | 1616 if (node->isFrameOwnerElement()) { |
1604 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); | 1617 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); |
1605 if (LocalFrame* frame = frameOwner->contentFrame() && | 1618 if (LocalFrame* frame = frameOwner->contentFrame() && |
1606 frameOwner->contentFrame()->isLocalFrame() | 1619 frameOwner->contentFrame()->isLocalFrame() |
1607 ? toLocalFrame(frameOwner->contentFrame()) | 1620 ? toLocalFrame(frameOwner->contentFrame()) |
1608 : nullptr) | 1621 : nullptr) |
1609 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1622 value->setFrameId(IdentifiersFactory::frameId(frame)); |
1610 if (Document* doc = frameOwner->contentDocument()) | 1623 if (Document* doc = frameOwner->contentDocument()) { |
1611 value->setContentDocument(buildObjectForNode(doc, 0, nodesMap)); | 1624 value->setContentDocument( |
1625 buildObjectForNode(doc, m_traverseFrames ? -1 : 0, nodesMap)); | |
pfeldman
2016/10/07 19:35:12
You should still respect the depth here.
alex clarke (OOO till 29th)
2016/10/11 12:05:12
Done.
| |
1626 } | |
1612 } | 1627 } |
1613 | 1628 |
1614 if (node->parentNode() && node->parentNode()->isDocumentNode()) { | 1629 if (node->parentNode() && node->parentNode()->isDocumentNode()) { |
1615 LocalFrame* frame = node->document().frame(); | 1630 LocalFrame* frame = node->document().frame(); |
1616 if (frame) | 1631 if (frame) |
1617 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1632 value->setFrameId(IdentifiersFactory::frameId(frame)); |
1618 } | 1633 } |
1619 | 1634 |
1620 ElementShadow* shadow = element->shadow(); | 1635 ElementShadow* shadow = element->shadow(); |
1621 if (shadow) { | 1636 if (shadow) { |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2261 ScriptState::Scope scope(scriptState); | 2276 ScriptState::Scope scope(scriptState); |
2262 return m_v8Session->wrapObject(scriptState->context(), | 2277 return m_v8Session->wrapObject(scriptState->context(), |
2263 nodeV8Value(scriptState->context(), node), | 2278 nodeV8Value(scriptState->context(), node), |
2264 toV8InspectorStringView(objectGroup)); | 2279 toV8InspectorStringView(objectGroup)); |
2265 } | 2280 } |
2266 | 2281 |
2267 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( | 2282 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( |
2268 ErrorString* errorString) { | 2283 ErrorString* errorString) { |
2269 if (!m_documentNodeToIdMap->contains(m_document)) { | 2284 if (!m_documentNodeToIdMap->contains(m_document)) { |
2270 std::unique_ptr<protocol::DOM::Node> root; | 2285 std::unique_ptr<protocol::DOM::Node> root; |
2271 getDocument(errorString, &root); | 2286 getDocument(errorString, Maybe<int>(), Maybe<bool>(), &root); |
2272 return errorString->isEmpty(); | 2287 return errorString->isEmpty(); |
2273 } | 2288 } |
2274 return true; | 2289 return true; |
2275 } | 2290 } |
2276 | 2291 |
2277 DEFINE_TRACE(InspectorDOMAgent) { | 2292 DEFINE_TRACE(InspectorDOMAgent) { |
2278 visitor->trace(m_domListener); | 2293 visitor->trace(m_domListener); |
2279 visitor->trace(m_inspectedFrames); | 2294 visitor->trace(m_inspectedFrames); |
2280 visitor->trace(m_documentNodeToIdMap); | 2295 visitor->trace(m_documentNodeToIdMap); |
2281 visitor->trace(m_danglingNodeToIdMaps); | 2296 visitor->trace(m_danglingNodeToIdMaps); |
2282 visitor->trace(m_idToNode); | 2297 visitor->trace(m_idToNode); |
2283 visitor->trace(m_idToNodesMap); | 2298 visitor->trace(m_idToNodesMap); |
2284 visitor->trace(m_document); | 2299 visitor->trace(m_document); |
2285 visitor->trace(m_revalidateTask); | 2300 visitor->trace(m_revalidateTask); |
2286 visitor->trace(m_searchResults); | 2301 visitor->trace(m_searchResults); |
2287 visitor->trace(m_history); | 2302 visitor->trace(m_history); |
2288 visitor->trace(m_domEditor); | 2303 visitor->trace(m_domEditor); |
2289 InspectorBaseAgent::trace(visitor); | 2304 InspectorBaseAgent::trace(visitor); |
2290 } | 2305 } |
2291 | 2306 |
2292 } // namespace blink | 2307 } // namespace blink |
OLD | NEW |