Chromium Code Reviews| 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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 setSearchingForNode(errorString, NotSearching, | 511 setSearchingForNode(errorString, NotSearching, |
| 512 Maybe<protocol::DOM::HighlightConfig>()); | 512 Maybe<protocol::DOM::HighlightConfig>()); |
| 513 m_instrumentingAgents->removeInspectorDOMAgent(this); | 513 m_instrumentingAgents->removeInspectorDOMAgent(this); |
| 514 m_history.clear(); | 514 m_history.clear(); |
| 515 m_domEditor.clear(); | 515 m_domEditor.clear(); |
| 516 setDocument(nullptr); | 516 setDocument(nullptr); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void InspectorDOMAgent::getDocument( | 519 void InspectorDOMAgent::getDocument( |
| 520 ErrorString* errorString, | 520 ErrorString* errorString, |
| 521 const Maybe<int>& depth, | |
| 522 const Maybe<bool>& traverseFrames, | |
| 521 std::unique_ptr<protocol::DOM::Node>* root) { | 523 std::unique_ptr<protocol::DOM::Node>* root) { |
| 522 // Backward compatibility. Mark agent as enabled when it requests document. | 524 // Backward compatibility. Mark agent as enabled when it requests document. |
| 523 if (!enabled()) | 525 if (!enabled()) |
| 524 innerEnable(); | 526 innerEnable(); |
| 525 | 527 |
| 526 if (!m_document) { | 528 if (!m_document) { |
| 527 *errorString = "Document is not available"; | 529 *errorString = "Document is not available"; |
| 528 return; | 530 return; |
| 529 } | 531 } |
| 530 | 532 |
| 531 discardFrontendBindings(); | 533 discardFrontendBindings(); |
| 532 | 534 |
| 533 *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get()); | 535 int sanitizedDepth = depth.fromMaybe(2); |
| 536 if (sanitizedDepth == -1) | |
| 537 sanitizedDepth = INT_MAX; | |
| 538 | |
| 539 *root = buildObjectForNode(m_document.get(), sanitizedDepth, | |
| 540 traverseFrames.fromMaybe(false), | |
| 541 m_documentNodeToIdMap.get()); | |
| 534 } | 542 } |
| 535 | 543 |
| 536 void InspectorDOMAgent::getLayoutTreeNodes( | 544 void InspectorDOMAgent::getLayoutTreeNodes( |
| 537 ErrorString* errorString, | 545 ErrorString* errorString, |
| 538 std::unique_ptr<protocol::Array<protocol::DOM::LayoutTreeNode>>* | 546 std::unique_ptr<protocol::Array<protocol::DOM::LayoutTreeNode>>* |
| 539 layoutTreeNodes) { | 547 layoutTreeNodes) { |
| 540 layoutTreeNodes->reset(new protocol::Array<protocol::DOM::LayoutTreeNode>); | 548 layoutTreeNodes->reset(new protocol::Array<protocol::DOM::LayoutTreeNode>); |
| 541 visitLayoutTreeNodes(m_document.get(), *layoutTreeNodes->get()); | 549 visitLayoutTreeNodes(m_document.get(), *layoutTreeNodes->get()); |
| 542 } | 550 } |
| 543 | 551 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 .build()); | 605 .build()); |
| 598 } | 606 } |
| 599 layoutTreeNode->setInlineTextNodes(std::move(inlineTextNodes)); | 607 layoutTreeNode->setInlineTextNodes(std::move(inlineTextNodes)); |
| 600 } | 608 } |
| 601 } | 609 } |
| 602 | 610 |
| 603 layoutTreeNodes.addItem(std::move(layoutTreeNode)); | 611 layoutTreeNodes.addItem(std::move(layoutTreeNode)); |
| 604 } | 612 } |
| 605 } | 613 } |
| 606 | 614 |
| 607 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) { | 615 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, |
| 616 int depth, | |
| 617 bool traverseFrames) { | |
| 608 Node* node = nodeForId(nodeId); | 618 Node* node = nodeForId(nodeId); |
| 609 if (!node || (!node->isElementNode() && !node->isDocumentNode() && | 619 if (!node || (!node->isElementNode() && !node->isDocumentNode() && |
| 610 !node->isDocumentFragment())) | 620 !node->isDocumentFragment())) |
| 611 return; | 621 return; |
| 612 | 622 |
| 613 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); | 623 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); |
| 614 | 624 |
| 615 if (m_childrenRequested.contains(nodeId)) { | 625 if (m_childrenRequested.contains(nodeId)) { |
| 616 if (depth <= 1) | 626 if (depth <= 1) |
| 617 return; | 627 return; |
| 618 | 628 |
| 619 depth--; | 629 depth--; |
| 620 | 630 |
| 621 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) { | 631 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) { |
| 622 int childNodeId = nodeMap->get(node); | 632 int childNodeId = nodeMap->get(node); |
| 623 ASSERT(childNodeId); | 633 ASSERT(childNodeId); |
| 624 pushChildNodesToFrontend(childNodeId, depth); | 634 pushChildNodesToFrontend(childNodeId, depth, traverseFrames); |
| 625 } | 635 } |
| 626 | 636 |
| 627 return; | 637 return; |
| 628 } | 638 } |
| 629 | 639 |
| 630 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 640 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 631 buildArrayForContainerChildren(node, depth, nodeMap); | 641 buildArrayForContainerChildren(node, depth, traverseFrames, nodeMap); |
| 632 frontend()->setChildNodes(nodeId, std::move(children)); | 642 frontend()->setChildNodes(nodeId, std::move(children)); |
| 633 } | 643 } |
| 634 | 644 |
| 635 void InspectorDOMAgent::discardFrontendBindings() { | 645 void InspectorDOMAgent::discardFrontendBindings() { |
| 636 if (m_history) | 646 if (m_history) |
| 637 m_history->reset(); | 647 m_history->reset(); |
| 638 m_searchResults.clear(); | 648 m_searchResults.clear(); |
| 639 m_documentNodeToIdMap->clear(); | 649 m_documentNodeToIdMap->clear(); |
| 640 m_idToNode.clear(); | 650 m_idToNode.clear(); |
| 641 m_idToNodesMap.clear(); | 651 m_idToNodesMap.clear(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 continue; | 688 continue; |
| 679 const SpaceSplitString& classNameList = element.classNames(); | 689 const SpaceSplitString& classNameList = element.classNames(); |
| 680 for (unsigned i = 0; i < classNameList.size(); ++i) | 690 for (unsigned i = 0; i < classNameList.size(); ++i) |
| 681 uniqueNames.add(classNameList[i]); | 691 uniqueNames.add(classNameList[i]); |
| 682 } | 692 } |
| 683 } | 693 } |
| 684 for (const String& className : uniqueNames) | 694 for (const String& className : uniqueNames) |
| 685 (*classNames)->addItem(className); | 695 (*classNames)->addItem(className); |
| 686 } | 696 } |
| 687 | 697 |
| 688 void InspectorDOMAgent::requestChildNodes(ErrorString* errorString, | 698 void InspectorDOMAgent::requestChildNodes( |
| 689 int nodeId, | 699 ErrorString* errorString, |
| 690 const Maybe<int>& depth) { | 700 int nodeId, |
| 701 const Maybe<int>& depth, | |
| 702 const Maybe<bool>& maybeTaverseFrames) { | |
| 691 int sanitizedDepth = depth.fromMaybe(1); | 703 int sanitizedDepth = depth.fromMaybe(1); |
| 692 if (sanitizedDepth == 0 || sanitizedDepth < -1) { | 704 if (sanitizedDepth == 0 || sanitizedDepth < -1) { |
| 693 *errorString = | 705 *errorString = |
| 694 "Please provide a positive integer as a depth or -1 for entire subtree"; | 706 "Please provide a positive integer as a depth or -1 for entire subtree"; |
| 695 return; | 707 return; |
| 696 } | 708 } |
| 697 if (sanitizedDepth == -1) | 709 if (sanitizedDepth == -1) |
| 698 sanitizedDepth = INT_MAX; | 710 sanitizedDepth = INT_MAX; |
| 699 | 711 |
| 700 pushChildNodesToFrontend(nodeId, sanitizedDepth); | 712 bool traverseFrames = maybeTaverseFrames.fromMaybe(false); |
| 713 // Cached results may not be valid if |traverseFrames| is true. | |
|
pfeldman
2016/10/12 18:45:26
childrenRequested is about children only, frames h
alex clarke (OOO till 29th)
2016/10/13 15:31:05
OK we can remove this. You need to be careful whe
| |
| 714 if (traverseFrames) | |
| 715 m_childrenRequested.clear(); | |
| 716 | |
| 717 pushChildNodesToFrontend(nodeId, sanitizedDepth, traverseFrames); | |
| 701 } | 718 } |
| 702 | 719 |
| 703 void InspectorDOMAgent::querySelector(ErrorString* errorString, | 720 void InspectorDOMAgent::querySelector(ErrorString* errorString, |
| 704 int nodeId, | 721 int nodeId, |
| 705 const String& selectors, | 722 const String& selectors, |
| 706 int* elementId) { | 723 int* elementId) { |
| 707 *elementId = 0; | 724 *elementId = 0; |
| 708 Node* node = assertNode(errorString, nodeId); | 725 Node* node = assertNode(errorString, nodeId); |
| 709 if (!node || !node->isContainerNode()) | 726 if (!node || !node->isContainerNode()) |
| 710 return; | 727 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 Node* node = nodeToPush; | 807 Node* node = nodeToPush; |
| 791 while (Node* parent = innerParentNode(node)) | 808 while (Node* parent = innerParentNode(node)) |
| 792 node = parent; | 809 node = parent; |
| 793 | 810 |
| 794 // Node being pushed is detached -> push subtree root. | 811 // Node being pushed is detached -> push subtree root. |
| 795 NodeToIdMap* newMap = new NodeToIdMap; | 812 NodeToIdMap* newMap = new NodeToIdMap; |
| 796 NodeToIdMap* danglingMap = newMap; | 813 NodeToIdMap* danglingMap = newMap; |
| 797 m_danglingNodeToIdMaps.append(newMap); | 814 m_danglingNodeToIdMaps.append(newMap); |
| 798 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 815 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 799 protocol::Array<protocol::DOM::Node>::create(); | 816 protocol::Array<protocol::DOM::Node>::create(); |
| 800 children->addItem(buildObjectForNode(node, 0, danglingMap)); | 817 children->addItem(buildObjectForNode(node, 0, false, danglingMap)); |
| 801 frontend()->setChildNodes(0, std::move(children)); | 818 frontend()->setChildNodes(0, std::move(children)); |
| 802 | 819 |
| 803 return pushNodePathToFrontend(nodeToPush, danglingMap); | 820 return pushNodePathToFrontend(nodeToPush, danglingMap); |
| 804 } | 821 } |
| 805 | 822 |
| 806 int InspectorDOMAgent::boundNodeId(Node* node) { | 823 int InspectorDOMAgent::boundNodeId(Node* node) { |
| 807 return m_documentNodeToIdMap->get(node); | 824 return m_documentNodeToIdMap->get(node); |
| 808 } | 825 } |
| 809 | 826 |
| 810 void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, | 827 void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1639 case ShadowRootType::Closed: | 1656 case ShadowRootType::Closed: |
| 1640 return protocol::DOM::ShadowRootTypeEnum::Closed; | 1657 return protocol::DOM::ShadowRootTypeEnum::Closed; |
| 1641 } | 1658 } |
| 1642 ASSERT_NOT_REACHED(); | 1659 ASSERT_NOT_REACHED(); |
| 1643 return protocol::DOM::ShadowRootTypeEnum::UserAgent; | 1660 return protocol::DOM::ShadowRootTypeEnum::UserAgent; |
| 1644 } | 1661 } |
| 1645 | 1662 |
| 1646 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( | 1663 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( |
| 1647 Node* node, | 1664 Node* node, |
| 1648 int depth, | 1665 int depth, |
| 1666 bool traverseFrames, | |
| 1649 NodeToIdMap* nodesMap) { | 1667 NodeToIdMap* nodesMap) { |
| 1650 int id = bind(node, nodesMap); | 1668 int id = bind(node, nodesMap); |
| 1651 String localName; | 1669 String localName; |
| 1652 String nodeValue; | 1670 String nodeValue; |
| 1653 | 1671 |
| 1654 switch (node->getNodeType()) { | 1672 switch (node->getNodeType()) { |
| 1655 case Node::kTextNode: | 1673 case Node::kTextNode: |
| 1656 case Node::kCommentNode: | 1674 case Node::kCommentNode: |
| 1657 case Node::kCdataSectionNode: | 1675 case Node::kCdataSectionNode: |
| 1658 nodeValue = node->nodeValue(); | 1676 nodeValue = node->nodeValue(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1683 Element* element = toElement(node); | 1701 Element* element = toElement(node); |
| 1684 value->setAttributes(buildArrayForElementAttributes(element)); | 1702 value->setAttributes(buildArrayForElementAttributes(element)); |
| 1685 | 1703 |
| 1686 if (node->isFrameOwnerElement()) { | 1704 if (node->isFrameOwnerElement()) { |
| 1687 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); | 1705 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); |
| 1688 if (LocalFrame* frame = frameOwner->contentFrame() && | 1706 if (LocalFrame* frame = frameOwner->contentFrame() && |
| 1689 frameOwner->contentFrame()->isLocalFrame() | 1707 frameOwner->contentFrame()->isLocalFrame() |
| 1690 ? toLocalFrame(frameOwner->contentFrame()) | 1708 ? toLocalFrame(frameOwner->contentFrame()) |
| 1691 : nullptr) | 1709 : nullptr) |
| 1692 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1710 value->setFrameId(IdentifiersFactory::frameId(frame)); |
| 1693 if (Document* doc = frameOwner->contentDocument()) | 1711 if (Document* doc = frameOwner->contentDocument()) { |
| 1694 value->setContentDocument(buildObjectForNode(doc, 0, nodesMap)); | 1712 value->setContentDocument(buildObjectForNode( |
| 1713 doc, traverseFrames ? depth : 0, traverseFrames, nodesMap)); | |
| 1714 } | |
| 1695 } | 1715 } |
| 1696 | 1716 |
| 1697 if (node->parentNode() && node->parentNode()->isDocumentNode()) { | 1717 if (node->parentNode() && node->parentNode()->isDocumentNode()) { |
| 1698 LocalFrame* frame = node->document().frame(); | 1718 LocalFrame* frame = node->document().frame(); |
| 1699 if (frame) | 1719 if (frame) |
| 1700 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1720 value->setFrameId(IdentifiersFactory::frameId(frame)); |
| 1701 } | 1721 } |
| 1702 | 1722 |
| 1703 ElementShadow* shadow = element->shadow(); | 1723 ElementShadow* shadow = element->shadow(); |
| 1704 if (shadow) { | 1724 if (shadow) { |
| 1705 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = | 1725 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = |
| 1706 protocol::Array<protocol::DOM::Node>::create(); | 1726 protocol::Array<protocol::DOM::Node>::create(); |
| 1707 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; | 1727 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; |
| 1708 root = root->olderShadowRoot()) | 1728 root = root->olderShadowRoot()) { |
| 1709 shadowRoots->addItem(buildObjectForNode(root, 0, nodesMap)); | 1729 shadowRoots->addItem( |
| 1730 buildObjectForNode(root, 0, traverseFrames, nodesMap)); | |
| 1731 } | |
| 1710 value->setShadowRoots(std::move(shadowRoots)); | 1732 value->setShadowRoots(std::move(shadowRoots)); |
| 1711 forcePushChildren = true; | 1733 forcePushChildren = true; |
| 1712 } | 1734 } |
| 1713 | 1735 |
| 1714 if (isHTMLLinkElement(*element)) { | 1736 if (isHTMLLinkElement(*element)) { |
| 1715 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); | 1737 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); |
| 1716 if (linkElement.isImport() && linkElement.import() && | 1738 if (linkElement.isImport() && linkElement.import() && |
| 1717 innerParentNode(linkElement.import()) == linkElement) | 1739 innerParentNode(linkElement.import()) == linkElement) { |
| 1718 value->setImportedDocument( | 1740 value->setImportedDocument(buildObjectForNode( |
| 1719 buildObjectForNode(linkElement.import(), 0, nodesMap)); | 1741 linkElement.import(), 0, traverseFrames, nodesMap)); |
| 1742 } | |
| 1720 forcePushChildren = true; | 1743 forcePushChildren = true; |
| 1721 } | 1744 } |
| 1722 | 1745 |
| 1723 if (isHTMLTemplateElement(*element)) { | 1746 if (isHTMLTemplateElement(*element)) { |
| 1724 value->setTemplateContent(buildObjectForNode( | 1747 value->setTemplateContent( |
| 1725 toHTMLTemplateElement(*element).content(), 0, nodesMap)); | 1748 buildObjectForNode(toHTMLTemplateElement(*element).content(), 0, |
| 1749 traverseFrames, nodesMap)); | |
| 1726 forcePushChildren = true; | 1750 forcePushChildren = true; |
| 1727 } | 1751 } |
| 1728 | 1752 |
| 1729 if (element->getPseudoId()) { | 1753 if (element->getPseudoId()) { |
| 1730 protocol::DOM::PseudoType pseudoType; | 1754 protocol::DOM::PseudoType pseudoType; |
| 1731 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), | 1755 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), |
| 1732 &pseudoType)) | 1756 &pseudoType)) |
| 1733 value->setPseudoType(pseudoType); | 1757 value->setPseudoType(pseudoType); |
| 1734 } else { | 1758 } else { |
| 1735 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = | 1759 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1770 } | 1794 } |
| 1771 | 1795 |
| 1772 if (node->isContainerNode()) { | 1796 if (node->isContainerNode()) { |
| 1773 int nodeCount = innerChildNodeCount(node); | 1797 int nodeCount = innerChildNodeCount(node); |
| 1774 value->setChildNodeCount(nodeCount); | 1798 value->setChildNodeCount(nodeCount); |
| 1775 if (nodesMap == m_documentNodeToIdMap) | 1799 if (nodesMap == m_documentNodeToIdMap) |
| 1776 m_cachedChildCount.set(id, nodeCount); | 1800 m_cachedChildCount.set(id, nodeCount); |
| 1777 if (forcePushChildren && !depth) | 1801 if (forcePushChildren && !depth) |
| 1778 depth = 1; | 1802 depth = 1; |
| 1779 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1803 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 1780 buildArrayForContainerChildren(node, depth, nodesMap); | 1804 buildArrayForContainerChildren(node, depth, traverseFrames, nodesMap); |
| 1781 if (children->length() > 0 || | 1805 if (children->length() > 0 || |
| 1782 depth) // Push children along with shadow in any case. | 1806 depth) // Push children along with shadow in any case. |
| 1783 value->setChildren(std::move(children)); | 1807 value->setChildren(std::move(children)); |
| 1784 } | 1808 } |
| 1785 | 1809 |
| 1786 return value; | 1810 return value; |
| 1787 } | 1811 } |
| 1788 | 1812 |
| 1789 std::unique_ptr<protocol::Array<String>> | 1813 std::unique_ptr<protocol::Array<String>> |
| 1790 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { | 1814 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { |
| 1791 std::unique_ptr<protocol::Array<String>> attributesValue = | 1815 std::unique_ptr<protocol::Array<String>> attributesValue = |
| 1792 protocol::Array<String>::create(); | 1816 protocol::Array<String>::create(); |
| 1793 // Go through all attributes and serialize them. | 1817 // Go through all attributes and serialize them. |
| 1794 AttributeCollection attributes = element->attributes(); | 1818 AttributeCollection attributes = element->attributes(); |
| 1795 for (auto& attribute : attributes) { | 1819 for (auto& attribute : attributes) { |
| 1796 // Add attribute pair | 1820 // Add attribute pair |
| 1797 attributesValue->addItem(attribute.name().toString()); | 1821 attributesValue->addItem(attribute.name().toString()); |
| 1798 attributesValue->addItem(attribute.value()); | 1822 attributesValue->addItem(attribute.value()); |
| 1799 } | 1823 } |
| 1800 return attributesValue; | 1824 return attributesValue; |
| 1801 } | 1825 } |
| 1802 | 1826 |
| 1803 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1827 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
| 1804 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, | 1828 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, |
| 1805 int depth, | 1829 int depth, |
| 1830 bool traverseFrames, | |
| 1806 NodeToIdMap* nodesMap) { | 1831 NodeToIdMap* nodesMap) { |
| 1807 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1832 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 1808 protocol::Array<protocol::DOM::Node>::create(); | 1833 protocol::Array<protocol::DOM::Node>::create(); |
| 1809 if (depth == 0) { | 1834 if (depth == 0) { |
| 1810 // Special-case the only text child - pretend that container's children have | 1835 // Special-case the only text child - pretend that container's children have |
| 1811 // been requested. | 1836 // been requested. |
| 1812 Node* firstChild = container->firstChild(); | 1837 Node* firstChild = container->firstChild(); |
| 1813 if (firstChild && firstChild->getNodeType() == Node::kTextNode && | 1838 if (firstChild && firstChild->getNodeType() == Node::kTextNode && |
| 1814 !firstChild->nextSibling()) { | 1839 !firstChild->nextSibling()) { |
| 1815 children->addItem(buildObjectForNode(firstChild, 0, nodesMap)); | 1840 children->addItem( |
| 1841 buildObjectForNode(firstChild, 0, traverseFrames, nodesMap)); | |
| 1816 m_childrenRequested.add(bind(container, nodesMap)); | 1842 m_childrenRequested.add(bind(container, nodesMap)); |
| 1817 } | 1843 } |
| 1818 return children; | 1844 return children; |
| 1819 } | 1845 } |
| 1820 | 1846 |
| 1821 Node* child = innerFirstChild(container); | 1847 Node* child = innerFirstChild(container); |
| 1822 depth--; | 1848 depth--; |
| 1823 m_childrenRequested.add(bind(container, nodesMap)); | 1849 m_childrenRequested.add(bind(container, nodesMap)); |
| 1824 | 1850 |
| 1825 while (child) { | 1851 while (child) { |
| 1826 children->addItem(buildObjectForNode(child, depth, nodesMap)); | 1852 children->addItem( |
| 1853 buildObjectForNode(child, depth, traverseFrames, nodesMap)); | |
| 1827 child = innerNextSibling(child); | 1854 child = innerNextSibling(child); |
| 1828 } | 1855 } |
| 1829 return children; | 1856 return children; |
| 1830 } | 1857 } |
| 1831 | 1858 |
| 1832 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1859 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
| 1833 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, | 1860 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, |
| 1834 NodeToIdMap* nodesMap) { | 1861 NodeToIdMap* nodesMap) { |
| 1835 if (!element->pseudoElement(PseudoIdBefore) && | 1862 if (!element->pseudoElement(PseudoIdBefore) && |
| 1836 !element->pseudoElement(PseudoIdAfter)) | 1863 !element->pseudoElement(PseudoIdAfter)) |
| 1837 return nullptr; | 1864 return nullptr; |
| 1838 | 1865 |
| 1839 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = | 1866 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = |
| 1840 protocol::Array<protocol::DOM::Node>::create(); | 1867 protocol::Array<protocol::DOM::Node>::create(); |
| 1841 if (element->pseudoElement(PseudoIdBefore)) | 1868 if (element->pseudoElement(PseudoIdBefore)) { |
| 1842 pseudoElements->addItem(buildObjectForNode( | 1869 pseudoElements->addItem(buildObjectForNode( |
| 1843 element->pseudoElement(PseudoIdBefore), 0, nodesMap)); | 1870 element->pseudoElement(PseudoIdBefore), 0, false, nodesMap)); |
| 1844 if (element->pseudoElement(PseudoIdAfter)) | 1871 } |
| 1845 pseudoElements->addItem( | 1872 if (element->pseudoElement(PseudoIdAfter)) { |
| 1846 buildObjectForNode(element->pseudoElement(PseudoIdAfter), 0, nodesMap)); | 1873 pseudoElements->addItem(buildObjectForNode( |
| 1874 element->pseudoElement(PseudoIdAfter), 0, false, nodesMap)); | |
| 1875 } | |
| 1847 return pseudoElements; | 1876 return pseudoElements; |
| 1848 } | 1877 } |
| 1849 | 1878 |
| 1850 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 1879 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 1851 InspectorDOMAgent::buildArrayForDistributedNodes( | 1880 InspectorDOMAgent::buildArrayForDistributedNodes( |
| 1852 InsertionPoint* insertionPoint) { | 1881 InsertionPoint* insertionPoint) { |
| 1853 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 1882 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 1854 distributedNodes = protocol::Array<protocol::DOM::BackendNode>::create(); | 1883 distributedNodes = protocol::Array<protocol::DOM::BackendNode>::create(); |
| 1855 for (size_t i = 0; i < insertionPoint->distributedNodesSize(); ++i) { | 1884 for (size_t i = 0; i < insertionPoint->distributedNodesSize(); ++i) { |
| 1856 Node* distributedNode = insertionPoint->distributedNodeAt(i); | 1885 Node* distributedNode = insertionPoint->distributedNodeAt(i); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1953 int frameOwnerId = m_documentNodeToIdMap->get(frameOwner); | 1982 int frameOwnerId = m_documentNodeToIdMap->get(frameOwner); |
| 1954 if (!frameOwnerId) | 1983 if (!frameOwnerId) |
| 1955 return; | 1984 return; |
| 1956 | 1985 |
| 1957 // Re-add frame owner element together with its new children. | 1986 // Re-add frame owner element together with its new children. |
| 1958 int parentId = m_documentNodeToIdMap->get(innerParentNode(frameOwner)); | 1987 int parentId = m_documentNodeToIdMap->get(innerParentNode(frameOwner)); |
| 1959 frontend()->childNodeRemoved(parentId, frameOwnerId); | 1988 frontend()->childNodeRemoved(parentId, frameOwnerId); |
| 1960 unbind(frameOwner, m_documentNodeToIdMap.get()); | 1989 unbind(frameOwner, m_documentNodeToIdMap.get()); |
| 1961 | 1990 |
| 1962 std::unique_ptr<protocol::DOM::Node> value = | 1991 std::unique_ptr<protocol::DOM::Node> value = |
| 1963 buildObjectForNode(frameOwner, 0, m_documentNodeToIdMap.get()); | 1992 buildObjectForNode(frameOwner, 0, false, m_documentNodeToIdMap.get()); |
| 1964 Node* previousSibling = innerPreviousSibling(frameOwner); | 1993 Node* previousSibling = innerPreviousSibling(frameOwner); |
| 1965 int prevId = | 1994 int prevId = |
| 1966 previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; | 1995 previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; |
| 1967 frontend()->childNodeInserted(parentId, prevId, std::move(value)); | 1996 frontend()->childNodeInserted(parentId, prevId, std::move(value)); |
| 1968 } | 1997 } |
| 1969 | 1998 |
| 1970 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) { | 1999 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) { |
| 1971 LocalFrame* inspectedFrame = m_inspectedFrames->root(); | 2000 LocalFrame* inspectedFrame = m_inspectedFrames->root(); |
| 1972 if (loader->frame() != inspectedFrame) { | 2001 if (loader->frame() != inspectedFrame) { |
| 1973 invalidateFrameOwnerElement(loader->frame()); | 2002 invalidateFrameOwnerElement(loader->frame()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1995 if (!m_childrenRequested.contains(parentId)) { | 2024 if (!m_childrenRequested.contains(parentId)) { |
| 1996 // No children are mapped yet -> only notify on changes of child count. | 2025 // No children are mapped yet -> only notify on changes of child count. |
| 1997 int count = m_cachedChildCount.get(parentId) + 1; | 2026 int count = m_cachedChildCount.get(parentId) + 1; |
| 1998 m_cachedChildCount.set(parentId, count); | 2027 m_cachedChildCount.set(parentId, count); |
| 1999 frontend()->childNodeCountUpdated(parentId, count); | 2028 frontend()->childNodeCountUpdated(parentId, count); |
| 2000 } else { | 2029 } else { |
| 2001 // Children have been requested -> return value of a new child. | 2030 // Children have been requested -> return value of a new child. |
| 2002 Node* prevSibling = innerPreviousSibling(node); | 2031 Node* prevSibling = innerPreviousSibling(node); |
| 2003 int prevId = prevSibling ? m_documentNodeToIdMap->get(prevSibling) : 0; | 2032 int prevId = prevSibling ? m_documentNodeToIdMap->get(prevSibling) : 0; |
| 2004 std::unique_ptr<protocol::DOM::Node> value = | 2033 std::unique_ptr<protocol::DOM::Node> value = |
| 2005 buildObjectForNode(node, 0, m_documentNodeToIdMap.get()); | 2034 buildObjectForNode(node, 0, false, m_documentNodeToIdMap.get()); |
| 2006 frontend()->childNodeInserted(parentId, prevId, std::move(value)); | 2035 frontend()->childNodeInserted(parentId, prevId, std::move(value)); |
| 2007 } | 2036 } |
| 2008 } | 2037 } |
| 2009 | 2038 |
| 2010 void InspectorDOMAgent::willRemoveDOMNode(Node* node) { | 2039 void InspectorDOMAgent::willRemoveDOMNode(Node* node) { |
| 2011 if (isWhitespace(node)) | 2040 if (isWhitespace(node)) |
| 2012 return; | 2041 return; |
| 2013 | 2042 |
| 2014 ContainerNode* parent = node->parentNode(); | 2043 ContainerNode* parent = node->parentNode(); |
| 2015 | 2044 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2114 void InspectorDOMAgent::didPushShadowRoot(Element* host, ShadowRoot* root) { | 2143 void InspectorDOMAgent::didPushShadowRoot(Element* host, ShadowRoot* root) { |
| 2115 if (!host->ownerDocument()) | 2144 if (!host->ownerDocument()) |
| 2116 return; | 2145 return; |
| 2117 | 2146 |
| 2118 int hostId = m_documentNodeToIdMap->get(host); | 2147 int hostId = m_documentNodeToIdMap->get(host); |
| 2119 if (!hostId) | 2148 if (!hostId) |
| 2120 return; | 2149 return; |
| 2121 | 2150 |
| 2122 pushChildNodesToFrontend(hostId, 1); | 2151 pushChildNodesToFrontend(hostId, 1); |
| 2123 frontend()->shadowRootPushed( | 2152 frontend()->shadowRootPushed( |
| 2124 hostId, buildObjectForNode(root, 0, m_documentNodeToIdMap.get())); | 2153 hostId, buildObjectForNode(root, 0, false, m_documentNodeToIdMap.get())); |
| 2125 } | 2154 } |
| 2126 | 2155 |
| 2127 void InspectorDOMAgent::willPopShadowRoot(Element* host, ShadowRoot* root) { | 2156 void InspectorDOMAgent::willPopShadowRoot(Element* host, ShadowRoot* root) { |
| 2128 if (!host->ownerDocument()) | 2157 if (!host->ownerDocument()) |
| 2129 return; | 2158 return; |
| 2130 | 2159 |
| 2131 int hostId = m_documentNodeToIdMap->get(host); | 2160 int hostId = m_documentNodeToIdMap->get(host); |
| 2132 int rootId = m_documentNodeToIdMap->get(root); | 2161 int rootId = m_documentNodeToIdMap->get(root); |
| 2133 if (hostId && rootId) | 2162 if (hostId && rootId) |
| 2134 frontend()->shadowRootPopped(hostId, rootId); | 2163 frontend()->shadowRootPopped(hostId, rootId); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2179 Element* parent = pseudoElement->parentOrShadowHostElement(); | 2208 Element* parent = pseudoElement->parentOrShadowHostElement(); |
| 2180 if (!parent) | 2209 if (!parent) |
| 2181 return; | 2210 return; |
| 2182 int parentId = m_documentNodeToIdMap->get(parent); | 2211 int parentId = m_documentNodeToIdMap->get(parent); |
| 2183 if (!parentId) | 2212 if (!parentId) |
| 2184 return; | 2213 return; |
| 2185 | 2214 |
| 2186 pushChildNodesToFrontend(parentId, 1); | 2215 pushChildNodesToFrontend(parentId, 1); |
| 2187 frontend()->pseudoElementAdded( | 2216 frontend()->pseudoElementAdded( |
| 2188 parentId, | 2217 parentId, |
| 2189 buildObjectForNode(pseudoElement, 0, m_documentNodeToIdMap.get())); | 2218 buildObjectForNode(pseudoElement, 0, false, m_documentNodeToIdMap.get())); |
| 2190 } | 2219 } |
| 2191 | 2220 |
| 2192 void InspectorDOMAgent::pseudoElementDestroyed(PseudoElement* pseudoElement) { | 2221 void InspectorDOMAgent::pseudoElementDestroyed(PseudoElement* pseudoElement) { |
| 2193 int pseudoElementId = m_documentNodeToIdMap->get(pseudoElement); | 2222 int pseudoElementId = m_documentNodeToIdMap->get(pseudoElement); |
| 2194 if (!pseudoElementId) | 2223 if (!pseudoElementId) |
| 2195 return; | 2224 return; |
| 2196 | 2225 |
| 2197 // If a PseudoElement is bound, its parent element must be bound, too. | 2226 // If a PseudoElement is bound, its parent element must be bound, too. |
| 2198 Element* parent = pseudoElement->parentOrShadowHostElement(); | 2227 Element* parent = pseudoElement->parentOrShadowHostElement(); |
| 2199 ASSERT(parent); | 2228 ASSERT(parent); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2344 ScriptState::Scope scope(scriptState); | 2373 ScriptState::Scope scope(scriptState); |
| 2345 return m_v8Session->wrapObject(scriptState->context(), | 2374 return m_v8Session->wrapObject(scriptState->context(), |
| 2346 nodeV8Value(scriptState->context(), node), | 2375 nodeV8Value(scriptState->context(), node), |
| 2347 toV8InspectorStringView(objectGroup)); | 2376 toV8InspectorStringView(objectGroup)); |
| 2348 } | 2377 } |
| 2349 | 2378 |
| 2350 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( | 2379 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( |
| 2351 ErrorString* errorString) { | 2380 ErrorString* errorString) { |
| 2352 if (!m_documentNodeToIdMap->contains(m_document)) { | 2381 if (!m_documentNodeToIdMap->contains(m_document)) { |
| 2353 std::unique_ptr<protocol::DOM::Node> root; | 2382 std::unique_ptr<protocol::DOM::Node> root; |
| 2354 getDocument(errorString, &root); | 2383 getDocument(errorString, Maybe<int>(), Maybe<bool>(), &root); |
| 2355 return errorString->isEmpty(); | 2384 return errorString->isEmpty(); |
| 2356 } | 2385 } |
| 2357 return true; | 2386 return true; |
| 2358 } | 2387 } |
| 2359 | 2388 |
| 2360 DEFINE_TRACE(InspectorDOMAgent) { | 2389 DEFINE_TRACE(InspectorDOMAgent) { |
| 2361 visitor->trace(m_domListener); | 2390 visitor->trace(m_domListener); |
| 2362 visitor->trace(m_inspectedFrames); | 2391 visitor->trace(m_inspectedFrames); |
| 2363 visitor->trace(m_documentNodeToIdMap); | 2392 visitor->trace(m_documentNodeToIdMap); |
| 2364 visitor->trace(m_danglingNodeToIdMaps); | 2393 visitor->trace(m_danglingNodeToIdMaps); |
| 2365 visitor->trace(m_idToNode); | 2394 visitor->trace(m_idToNode); |
| 2366 visitor->trace(m_idToNodesMap); | 2395 visitor->trace(m_idToNodesMap); |
| 2367 visitor->trace(m_document); | 2396 visitor->trace(m_document); |
| 2368 visitor->trace(m_revalidateTask); | 2397 visitor->trace(m_revalidateTask); |
| 2369 visitor->trace(m_searchResults); | 2398 visitor->trace(m_searchResults); |
| 2370 visitor->trace(m_history); | 2399 visitor->trace(m_history); |
| 2371 visitor->trace(m_domEditor); | 2400 visitor->trace(m_domEditor); |
| 2372 InspectorBaseAgent::trace(visitor); | 2401 InspectorBaseAgent::trace(visitor); |
| 2373 } | 2402 } |
| 2374 | 2403 |
| 2375 } // namespace blink | 2404 } // namespace blink |
| OLD | NEW |