| 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 pushChildNodesToFrontend(nodeId, sanitizedDepth, |
| 713 maybeTaverseFrames.fromMaybe(false)); |
| 701 } | 714 } |
| 702 | 715 |
| 703 void InspectorDOMAgent::querySelector(ErrorString* errorString, | 716 void InspectorDOMAgent::querySelector(ErrorString* errorString, |
| 704 int nodeId, | 717 int nodeId, |
| 705 const String& selectors, | 718 const String& selectors, |
| 706 int* elementId) { | 719 int* elementId) { |
| 707 *elementId = 0; | 720 *elementId = 0; |
| 708 Node* node = assertNode(errorString, nodeId); | 721 Node* node = assertNode(errorString, nodeId); |
| 709 if (!node || !node->isContainerNode()) | 722 if (!node || !node->isContainerNode()) |
| 710 return; | 723 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 Node* node = nodeToPush; | 803 Node* node = nodeToPush; |
| 791 while (Node* parent = innerParentNode(node)) | 804 while (Node* parent = innerParentNode(node)) |
| 792 node = parent; | 805 node = parent; |
| 793 | 806 |
| 794 // Node being pushed is detached -> push subtree root. | 807 // Node being pushed is detached -> push subtree root. |
| 795 NodeToIdMap* newMap = new NodeToIdMap; | 808 NodeToIdMap* newMap = new NodeToIdMap; |
| 796 NodeToIdMap* danglingMap = newMap; | 809 NodeToIdMap* danglingMap = newMap; |
| 797 m_danglingNodeToIdMaps.append(newMap); | 810 m_danglingNodeToIdMaps.append(newMap); |
| 798 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 811 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 799 protocol::Array<protocol::DOM::Node>::create(); | 812 protocol::Array<protocol::DOM::Node>::create(); |
| 800 children->addItem(buildObjectForNode(node, 0, danglingMap)); | 813 children->addItem(buildObjectForNode(node, 0, false, danglingMap)); |
| 801 frontend()->setChildNodes(0, std::move(children)); | 814 frontend()->setChildNodes(0, std::move(children)); |
| 802 | 815 |
| 803 return pushNodePathToFrontend(nodeToPush, danglingMap); | 816 return pushNodePathToFrontend(nodeToPush, danglingMap); |
| 804 } | 817 } |
| 805 | 818 |
| 806 int InspectorDOMAgent::boundNodeId(Node* node) { | 819 int InspectorDOMAgent::boundNodeId(Node* node) { |
| 807 return m_documentNodeToIdMap->get(node); | 820 return m_documentNodeToIdMap->get(node); |
| 808 } | 821 } |
| 809 | 822 |
| 810 void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, | 823 void InspectorDOMAgent::setAttributeValue(ErrorString* errorString, |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 case ShadowRootType::Closed: | 1652 case ShadowRootType::Closed: |
| 1640 return protocol::DOM::ShadowRootTypeEnum::Closed; | 1653 return protocol::DOM::ShadowRootTypeEnum::Closed; |
| 1641 } | 1654 } |
| 1642 ASSERT_NOT_REACHED(); | 1655 ASSERT_NOT_REACHED(); |
| 1643 return protocol::DOM::ShadowRootTypeEnum::UserAgent; | 1656 return protocol::DOM::ShadowRootTypeEnum::UserAgent; |
| 1644 } | 1657 } |
| 1645 | 1658 |
| 1646 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( | 1659 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( |
| 1647 Node* node, | 1660 Node* node, |
| 1648 int depth, | 1661 int depth, |
| 1662 bool traverseFrames, |
| 1649 NodeToIdMap* nodesMap) { | 1663 NodeToIdMap* nodesMap) { |
| 1650 int id = bind(node, nodesMap); | 1664 int id = bind(node, nodesMap); |
| 1651 String localName; | 1665 String localName; |
| 1652 String nodeValue; | 1666 String nodeValue; |
| 1653 | 1667 |
| 1654 switch (node->getNodeType()) { | 1668 switch (node->getNodeType()) { |
| 1655 case Node::kTextNode: | 1669 case Node::kTextNode: |
| 1656 case Node::kCommentNode: | 1670 case Node::kCommentNode: |
| 1657 case Node::kCdataSectionNode: | 1671 case Node::kCdataSectionNode: |
| 1658 nodeValue = node->nodeValue(); | 1672 nodeValue = node->nodeValue(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1683 Element* element = toElement(node); | 1697 Element* element = toElement(node); |
| 1684 value->setAttributes(buildArrayForElementAttributes(element)); | 1698 value->setAttributes(buildArrayForElementAttributes(element)); |
| 1685 | 1699 |
| 1686 if (node->isFrameOwnerElement()) { | 1700 if (node->isFrameOwnerElement()) { |
| 1687 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); | 1701 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); |
| 1688 if (LocalFrame* frame = frameOwner->contentFrame() && | 1702 if (LocalFrame* frame = frameOwner->contentFrame() && |
| 1689 frameOwner->contentFrame()->isLocalFrame() | 1703 frameOwner->contentFrame()->isLocalFrame() |
| 1690 ? toLocalFrame(frameOwner->contentFrame()) | 1704 ? toLocalFrame(frameOwner->contentFrame()) |
| 1691 : nullptr) | 1705 : nullptr) |
| 1692 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1706 value->setFrameId(IdentifiersFactory::frameId(frame)); |
| 1693 if (Document* doc = frameOwner->contentDocument()) | 1707 if (Document* doc = frameOwner->contentDocument()) { |
| 1694 value->setContentDocument(buildObjectForNode(doc, 0, nodesMap)); | 1708 value->setContentDocument(buildObjectForNode( |
| 1709 doc, traverseFrames ? depth : 0, traverseFrames, nodesMap)); |
| 1710 } |
| 1695 } | 1711 } |
| 1696 | 1712 |
| 1697 if (node->parentNode() && node->parentNode()->isDocumentNode()) { | 1713 if (node->parentNode() && node->parentNode()->isDocumentNode()) { |
| 1698 LocalFrame* frame = node->document().frame(); | 1714 LocalFrame* frame = node->document().frame(); |
| 1699 if (frame) | 1715 if (frame) |
| 1700 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1716 value->setFrameId(IdentifiersFactory::frameId(frame)); |
| 1701 } | 1717 } |
| 1702 | 1718 |
| 1703 ElementShadow* shadow = element->shadow(); | 1719 ElementShadow* shadow = element->shadow(); |
| 1704 if (shadow) { | 1720 if (shadow) { |
| 1705 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = | 1721 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = |
| 1706 protocol::Array<protocol::DOM::Node>::create(); | 1722 protocol::Array<protocol::DOM::Node>::create(); |
| 1707 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; | 1723 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; |
| 1708 root = root->olderShadowRoot()) | 1724 root = root->olderShadowRoot()) { |
| 1709 shadowRoots->addItem(buildObjectForNode(root, 0, nodesMap)); | 1725 shadowRoots->addItem( |
| 1726 buildObjectForNode(root, 0, traverseFrames, nodesMap)); |
| 1727 } |
| 1710 value->setShadowRoots(std::move(shadowRoots)); | 1728 value->setShadowRoots(std::move(shadowRoots)); |
| 1711 forcePushChildren = true; | 1729 forcePushChildren = true; |
| 1712 } | 1730 } |
| 1713 | 1731 |
| 1714 if (isHTMLLinkElement(*element)) { | 1732 if (isHTMLLinkElement(*element)) { |
| 1715 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); | 1733 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); |
| 1716 if (linkElement.isImport() && linkElement.import() && | 1734 if (linkElement.isImport() && linkElement.import() && |
| 1717 innerParentNode(linkElement.import()) == linkElement) | 1735 innerParentNode(linkElement.import()) == linkElement) { |
| 1718 value->setImportedDocument( | 1736 value->setImportedDocument(buildObjectForNode( |
| 1719 buildObjectForNode(linkElement.import(), 0, nodesMap)); | 1737 linkElement.import(), 0, traverseFrames, nodesMap)); |
| 1738 } |
| 1720 forcePushChildren = true; | 1739 forcePushChildren = true; |
| 1721 } | 1740 } |
| 1722 | 1741 |
| 1723 if (isHTMLTemplateElement(*element)) { | 1742 if (isHTMLTemplateElement(*element)) { |
| 1724 value->setTemplateContent(buildObjectForNode( | 1743 value->setTemplateContent( |
| 1725 toHTMLTemplateElement(*element).content(), 0, nodesMap)); | 1744 buildObjectForNode(toHTMLTemplateElement(*element).content(), 0, |
| 1745 traverseFrames, nodesMap)); |
| 1726 forcePushChildren = true; | 1746 forcePushChildren = true; |
| 1727 } | 1747 } |
| 1728 | 1748 |
| 1729 if (element->getPseudoId()) { | 1749 if (element->getPseudoId()) { |
| 1730 protocol::DOM::PseudoType pseudoType; | 1750 protocol::DOM::PseudoType pseudoType; |
| 1731 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), | 1751 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), |
| 1732 &pseudoType)) | 1752 &pseudoType)) |
| 1733 value->setPseudoType(pseudoType); | 1753 value->setPseudoType(pseudoType); |
| 1734 } else { | 1754 } else { |
| 1735 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = | 1755 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 } | 1790 } |
| 1771 | 1791 |
| 1772 if (node->isContainerNode()) { | 1792 if (node->isContainerNode()) { |
| 1773 int nodeCount = innerChildNodeCount(node); | 1793 int nodeCount = innerChildNodeCount(node); |
| 1774 value->setChildNodeCount(nodeCount); | 1794 value->setChildNodeCount(nodeCount); |
| 1775 if (nodesMap == m_documentNodeToIdMap) | 1795 if (nodesMap == m_documentNodeToIdMap) |
| 1776 m_cachedChildCount.set(id, nodeCount); | 1796 m_cachedChildCount.set(id, nodeCount); |
| 1777 if (forcePushChildren && !depth) | 1797 if (forcePushChildren && !depth) |
| 1778 depth = 1; | 1798 depth = 1; |
| 1779 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1799 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 1780 buildArrayForContainerChildren(node, depth, nodesMap); | 1800 buildArrayForContainerChildren(node, depth, traverseFrames, nodesMap); |
| 1781 if (children->length() > 0 || | 1801 if (children->length() > 0 || |
| 1782 depth) // Push children along with shadow in any case. | 1802 depth) // Push children along with shadow in any case. |
| 1783 value->setChildren(std::move(children)); | 1803 value->setChildren(std::move(children)); |
| 1784 } | 1804 } |
| 1785 | 1805 |
| 1786 return value; | 1806 return value; |
| 1787 } | 1807 } |
| 1788 | 1808 |
| 1789 std::unique_ptr<protocol::Array<String>> | 1809 std::unique_ptr<protocol::Array<String>> |
| 1790 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { | 1810 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { |
| 1791 std::unique_ptr<protocol::Array<String>> attributesValue = | 1811 std::unique_ptr<protocol::Array<String>> attributesValue = |
| 1792 protocol::Array<String>::create(); | 1812 protocol::Array<String>::create(); |
| 1793 // Go through all attributes and serialize them. | 1813 // Go through all attributes and serialize them. |
| 1794 AttributeCollection attributes = element->attributes(); | 1814 AttributeCollection attributes = element->attributes(); |
| 1795 for (auto& attribute : attributes) { | 1815 for (auto& attribute : attributes) { |
| 1796 // Add attribute pair | 1816 // Add attribute pair |
| 1797 attributesValue->addItem(attribute.name().toString()); | 1817 attributesValue->addItem(attribute.name().toString()); |
| 1798 attributesValue->addItem(attribute.value()); | 1818 attributesValue->addItem(attribute.value()); |
| 1799 } | 1819 } |
| 1800 return attributesValue; | 1820 return attributesValue; |
| 1801 } | 1821 } |
| 1802 | 1822 |
| 1803 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1823 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
| 1804 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, | 1824 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, |
| 1805 int depth, | 1825 int depth, |
| 1826 bool traverseFrames, |
| 1806 NodeToIdMap* nodesMap) { | 1827 NodeToIdMap* nodesMap) { |
| 1807 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1828 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
| 1808 protocol::Array<protocol::DOM::Node>::create(); | 1829 protocol::Array<protocol::DOM::Node>::create(); |
| 1809 if (depth == 0) { | 1830 if (depth == 0) { |
| 1810 // Special-case the only text child - pretend that container's children have | 1831 // Special-case the only text child - pretend that container's children have |
| 1811 // been requested. | 1832 // been requested. |
| 1812 Node* firstChild = container->firstChild(); | 1833 Node* firstChild = container->firstChild(); |
| 1813 if (firstChild && firstChild->getNodeType() == Node::kTextNode && | 1834 if (firstChild && firstChild->getNodeType() == Node::kTextNode && |
| 1814 !firstChild->nextSibling()) { | 1835 !firstChild->nextSibling()) { |
| 1815 children->addItem(buildObjectForNode(firstChild, 0, nodesMap)); | 1836 children->addItem( |
| 1837 buildObjectForNode(firstChild, 0, traverseFrames, nodesMap)); |
| 1816 m_childrenRequested.add(bind(container, nodesMap)); | 1838 m_childrenRequested.add(bind(container, nodesMap)); |
| 1817 } | 1839 } |
| 1818 return children; | 1840 return children; |
| 1819 } | 1841 } |
| 1820 | 1842 |
| 1821 Node* child = innerFirstChild(container); | 1843 Node* child = innerFirstChild(container); |
| 1822 depth--; | 1844 depth--; |
| 1823 m_childrenRequested.add(bind(container, nodesMap)); | 1845 m_childrenRequested.add(bind(container, nodesMap)); |
| 1824 | 1846 |
| 1825 while (child) { | 1847 while (child) { |
| 1826 children->addItem(buildObjectForNode(child, depth, nodesMap)); | 1848 children->addItem( |
| 1849 buildObjectForNode(child, depth, traverseFrames, nodesMap)); |
| 1827 child = innerNextSibling(child); | 1850 child = innerNextSibling(child); |
| 1828 } | 1851 } |
| 1829 return children; | 1852 return children; |
| 1830 } | 1853 } |
| 1831 | 1854 |
| 1832 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1855 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
| 1833 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, | 1856 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, |
| 1834 NodeToIdMap* nodesMap) { | 1857 NodeToIdMap* nodesMap) { |
| 1835 if (!element->pseudoElement(PseudoIdBefore) && | 1858 if (!element->pseudoElement(PseudoIdBefore) && |
| 1836 !element->pseudoElement(PseudoIdAfter)) | 1859 !element->pseudoElement(PseudoIdAfter)) |
| 1837 return nullptr; | 1860 return nullptr; |
| 1838 | 1861 |
| 1839 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = | 1862 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = |
| 1840 protocol::Array<protocol::DOM::Node>::create(); | 1863 protocol::Array<protocol::DOM::Node>::create(); |
| 1841 if (element->pseudoElement(PseudoIdBefore)) | 1864 if (element->pseudoElement(PseudoIdBefore)) { |
| 1842 pseudoElements->addItem(buildObjectForNode( | 1865 pseudoElements->addItem(buildObjectForNode( |
| 1843 element->pseudoElement(PseudoIdBefore), 0, nodesMap)); | 1866 element->pseudoElement(PseudoIdBefore), 0, false, nodesMap)); |
| 1844 if (element->pseudoElement(PseudoIdAfter)) | 1867 } |
| 1845 pseudoElements->addItem( | 1868 if (element->pseudoElement(PseudoIdAfter)) { |
| 1846 buildObjectForNode(element->pseudoElement(PseudoIdAfter), 0, nodesMap)); | 1869 pseudoElements->addItem(buildObjectForNode( |
| 1870 element->pseudoElement(PseudoIdAfter), 0, false, nodesMap)); |
| 1871 } |
| 1847 return pseudoElements; | 1872 return pseudoElements; |
| 1848 } | 1873 } |
| 1849 | 1874 |
| 1850 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 1875 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 1851 InspectorDOMAgent::buildArrayForDistributedNodes( | 1876 InspectorDOMAgent::buildArrayForDistributedNodes( |
| 1852 InsertionPoint* insertionPoint) { | 1877 InsertionPoint* insertionPoint) { |
| 1853 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> | 1878 std::unique_ptr<protocol::Array<protocol::DOM::BackendNode>> |
| 1854 distributedNodes = protocol::Array<protocol::DOM::BackendNode>::create(); | 1879 distributedNodes = protocol::Array<protocol::DOM::BackendNode>::create(); |
| 1855 for (size_t i = 0; i < insertionPoint->distributedNodesSize(); ++i) { | 1880 for (size_t i = 0; i < insertionPoint->distributedNodesSize(); ++i) { |
| 1856 Node* distributedNode = insertionPoint->distributedNodeAt(i); | 1881 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); | 1978 int frameOwnerId = m_documentNodeToIdMap->get(frameOwner); |
| 1954 if (!frameOwnerId) | 1979 if (!frameOwnerId) |
| 1955 return; | 1980 return; |
| 1956 | 1981 |
| 1957 // Re-add frame owner element together with its new children. | 1982 // Re-add frame owner element together with its new children. |
| 1958 int parentId = m_documentNodeToIdMap->get(innerParentNode(frameOwner)); | 1983 int parentId = m_documentNodeToIdMap->get(innerParentNode(frameOwner)); |
| 1959 frontend()->childNodeRemoved(parentId, frameOwnerId); | 1984 frontend()->childNodeRemoved(parentId, frameOwnerId); |
| 1960 unbind(frameOwner, m_documentNodeToIdMap.get()); | 1985 unbind(frameOwner, m_documentNodeToIdMap.get()); |
| 1961 | 1986 |
| 1962 std::unique_ptr<protocol::DOM::Node> value = | 1987 std::unique_ptr<protocol::DOM::Node> value = |
| 1963 buildObjectForNode(frameOwner, 0, m_documentNodeToIdMap.get()); | 1988 buildObjectForNode(frameOwner, 0, false, m_documentNodeToIdMap.get()); |
| 1964 Node* previousSibling = innerPreviousSibling(frameOwner); | 1989 Node* previousSibling = innerPreviousSibling(frameOwner); |
| 1965 int prevId = | 1990 int prevId = |
| 1966 previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; | 1991 previousSibling ? m_documentNodeToIdMap->get(previousSibling) : 0; |
| 1967 frontend()->childNodeInserted(parentId, prevId, std::move(value)); | 1992 frontend()->childNodeInserted(parentId, prevId, std::move(value)); |
| 1968 } | 1993 } |
| 1969 | 1994 |
| 1970 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) { | 1995 void InspectorDOMAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) { |
| 1971 LocalFrame* inspectedFrame = m_inspectedFrames->root(); | 1996 LocalFrame* inspectedFrame = m_inspectedFrames->root(); |
| 1972 if (loader->frame() != inspectedFrame) { | 1997 if (loader->frame() != inspectedFrame) { |
| 1973 invalidateFrameOwnerElement(loader->frame()); | 1998 invalidateFrameOwnerElement(loader->frame()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1995 if (!m_childrenRequested.contains(parentId)) { | 2020 if (!m_childrenRequested.contains(parentId)) { |
| 1996 // No children are mapped yet -> only notify on changes of child count. | 2021 // No children are mapped yet -> only notify on changes of child count. |
| 1997 int count = m_cachedChildCount.get(parentId) + 1; | 2022 int count = m_cachedChildCount.get(parentId) + 1; |
| 1998 m_cachedChildCount.set(parentId, count); | 2023 m_cachedChildCount.set(parentId, count); |
| 1999 frontend()->childNodeCountUpdated(parentId, count); | 2024 frontend()->childNodeCountUpdated(parentId, count); |
| 2000 } else { | 2025 } else { |
| 2001 // Children have been requested -> return value of a new child. | 2026 // Children have been requested -> return value of a new child. |
| 2002 Node* prevSibling = innerPreviousSibling(node); | 2027 Node* prevSibling = innerPreviousSibling(node); |
| 2003 int prevId = prevSibling ? m_documentNodeToIdMap->get(prevSibling) : 0; | 2028 int prevId = prevSibling ? m_documentNodeToIdMap->get(prevSibling) : 0; |
| 2004 std::unique_ptr<protocol::DOM::Node> value = | 2029 std::unique_ptr<protocol::DOM::Node> value = |
| 2005 buildObjectForNode(node, 0, m_documentNodeToIdMap.get()); | 2030 buildObjectForNode(node, 0, false, m_documentNodeToIdMap.get()); |
| 2006 frontend()->childNodeInserted(parentId, prevId, std::move(value)); | 2031 frontend()->childNodeInserted(parentId, prevId, std::move(value)); |
| 2007 } | 2032 } |
| 2008 } | 2033 } |
| 2009 | 2034 |
| 2010 void InspectorDOMAgent::willRemoveDOMNode(Node* node) { | 2035 void InspectorDOMAgent::willRemoveDOMNode(Node* node) { |
| 2011 if (isWhitespace(node)) | 2036 if (isWhitespace(node)) |
| 2012 return; | 2037 return; |
| 2013 | 2038 |
| 2014 ContainerNode* parent = node->parentNode(); | 2039 ContainerNode* parent = node->parentNode(); |
| 2015 | 2040 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 void InspectorDOMAgent::didPushShadowRoot(Element* host, ShadowRoot* root) { | 2139 void InspectorDOMAgent::didPushShadowRoot(Element* host, ShadowRoot* root) { |
| 2115 if (!host->ownerDocument()) | 2140 if (!host->ownerDocument()) |
| 2116 return; | 2141 return; |
| 2117 | 2142 |
| 2118 int hostId = m_documentNodeToIdMap->get(host); | 2143 int hostId = m_documentNodeToIdMap->get(host); |
| 2119 if (!hostId) | 2144 if (!hostId) |
| 2120 return; | 2145 return; |
| 2121 | 2146 |
| 2122 pushChildNodesToFrontend(hostId, 1); | 2147 pushChildNodesToFrontend(hostId, 1); |
| 2123 frontend()->shadowRootPushed( | 2148 frontend()->shadowRootPushed( |
| 2124 hostId, buildObjectForNode(root, 0, m_documentNodeToIdMap.get())); | 2149 hostId, buildObjectForNode(root, 0, false, m_documentNodeToIdMap.get())); |
| 2125 } | 2150 } |
| 2126 | 2151 |
| 2127 void InspectorDOMAgent::willPopShadowRoot(Element* host, ShadowRoot* root) { | 2152 void InspectorDOMAgent::willPopShadowRoot(Element* host, ShadowRoot* root) { |
| 2128 if (!host->ownerDocument()) | 2153 if (!host->ownerDocument()) |
| 2129 return; | 2154 return; |
| 2130 | 2155 |
| 2131 int hostId = m_documentNodeToIdMap->get(host); | 2156 int hostId = m_documentNodeToIdMap->get(host); |
| 2132 int rootId = m_documentNodeToIdMap->get(root); | 2157 int rootId = m_documentNodeToIdMap->get(root); |
| 2133 if (hostId && rootId) | 2158 if (hostId && rootId) |
| 2134 frontend()->shadowRootPopped(hostId, rootId); | 2159 frontend()->shadowRootPopped(hostId, rootId); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2179 Element* parent = pseudoElement->parentOrShadowHostElement(); | 2204 Element* parent = pseudoElement->parentOrShadowHostElement(); |
| 2180 if (!parent) | 2205 if (!parent) |
| 2181 return; | 2206 return; |
| 2182 int parentId = m_documentNodeToIdMap->get(parent); | 2207 int parentId = m_documentNodeToIdMap->get(parent); |
| 2183 if (!parentId) | 2208 if (!parentId) |
| 2184 return; | 2209 return; |
| 2185 | 2210 |
| 2186 pushChildNodesToFrontend(parentId, 1); | 2211 pushChildNodesToFrontend(parentId, 1); |
| 2187 frontend()->pseudoElementAdded( | 2212 frontend()->pseudoElementAdded( |
| 2188 parentId, | 2213 parentId, |
| 2189 buildObjectForNode(pseudoElement, 0, m_documentNodeToIdMap.get())); | 2214 buildObjectForNode(pseudoElement, 0, false, m_documentNodeToIdMap.get())); |
| 2190 } | 2215 } |
| 2191 | 2216 |
| 2192 void InspectorDOMAgent::pseudoElementDestroyed(PseudoElement* pseudoElement) { | 2217 void InspectorDOMAgent::pseudoElementDestroyed(PseudoElement* pseudoElement) { |
| 2193 int pseudoElementId = m_documentNodeToIdMap->get(pseudoElement); | 2218 int pseudoElementId = m_documentNodeToIdMap->get(pseudoElement); |
| 2194 if (!pseudoElementId) | 2219 if (!pseudoElementId) |
| 2195 return; | 2220 return; |
| 2196 | 2221 |
| 2197 // If a PseudoElement is bound, its parent element must be bound, too. | 2222 // If a PseudoElement is bound, its parent element must be bound, too. |
| 2198 Element* parent = pseudoElement->parentOrShadowHostElement(); | 2223 Element* parent = pseudoElement->parentOrShadowHostElement(); |
| 2199 ASSERT(parent); | 2224 ASSERT(parent); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 ScriptState::Scope scope(scriptState); | 2369 ScriptState::Scope scope(scriptState); |
| 2345 return m_v8Session->wrapObject(scriptState->context(), | 2370 return m_v8Session->wrapObject(scriptState->context(), |
| 2346 nodeV8Value(scriptState->context(), node), | 2371 nodeV8Value(scriptState->context(), node), |
| 2347 toV8InspectorStringView(objectGroup)); | 2372 toV8InspectorStringView(objectGroup)); |
| 2348 } | 2373 } |
| 2349 | 2374 |
| 2350 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( | 2375 bool InspectorDOMAgent::pushDocumentUponHandlelessOperation( |
| 2351 ErrorString* errorString) { | 2376 ErrorString* errorString) { |
| 2352 if (!m_documentNodeToIdMap->contains(m_document)) { | 2377 if (!m_documentNodeToIdMap->contains(m_document)) { |
| 2353 std::unique_ptr<protocol::DOM::Node> root; | 2378 std::unique_ptr<protocol::DOM::Node> root; |
| 2354 getDocument(errorString, &root); | 2379 getDocument(errorString, Maybe<int>(), Maybe<bool>(), &root); |
| 2355 return errorString->isEmpty(); | 2380 return errorString->isEmpty(); |
| 2356 } | 2381 } |
| 2357 return true; | 2382 return true; |
| 2358 } | 2383 } |
| 2359 | 2384 |
| 2360 DEFINE_TRACE(InspectorDOMAgent) { | 2385 DEFINE_TRACE(InspectorDOMAgent) { |
| 2361 visitor->trace(m_domListener); | 2386 visitor->trace(m_domListener); |
| 2362 visitor->trace(m_inspectedFrames); | 2387 visitor->trace(m_inspectedFrames); |
| 2363 visitor->trace(m_documentNodeToIdMap); | 2388 visitor->trace(m_documentNodeToIdMap); |
| 2364 visitor->trace(m_danglingNodeToIdMaps); | 2389 visitor->trace(m_danglingNodeToIdMaps); |
| 2365 visitor->trace(m_idToNode); | 2390 visitor->trace(m_idToNode); |
| 2366 visitor->trace(m_idToNodesMap); | 2391 visitor->trace(m_idToNodesMap); |
| 2367 visitor->trace(m_document); | 2392 visitor->trace(m_document); |
| 2368 visitor->trace(m_revalidateTask); | 2393 visitor->trace(m_revalidateTask); |
| 2369 visitor->trace(m_searchResults); | 2394 visitor->trace(m_searchResults); |
| 2370 visitor->trace(m_history); | 2395 visitor->trace(m_history); |
| 2371 visitor->trace(m_domEditor); | 2396 visitor->trace(m_domEditor); |
| 2372 InspectorBaseAgent::trace(visitor); | 2397 InspectorBaseAgent::trace(visitor); |
| 2373 } | 2398 } |
| 2374 | 2399 |
| 2375 } // namespace blink | 2400 } // namespace blink |
| OLD | NEW |