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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 setSearchingForNode(NotSearching, Maybe<protocol::DOM::HighlightConfig>()); | 469 setSearchingForNode(NotSearching, Maybe<protocol::DOM::HighlightConfig>()); |
470 m_instrumentingAgents->removeInspectorDOMAgent(this); | 470 m_instrumentingAgents->removeInspectorDOMAgent(this); |
471 m_history.clear(); | 471 m_history.clear(); |
472 m_domEditor.clear(); | 472 m_domEditor.clear(); |
473 setDocument(nullptr); | 473 setDocument(nullptr); |
474 return Response::OK(); | 474 return Response::OK(); |
475 } | 475 } |
476 | 476 |
477 Response InspectorDOMAgent::getDocument( | 477 Response InspectorDOMAgent::getDocument( |
478 Maybe<int> depth, | 478 Maybe<int> depth, |
479 Maybe<bool> traverseFrames, | 479 Maybe<bool> pierce, |
480 std::unique_ptr<protocol::DOM::Node>* root) { | 480 std::unique_ptr<protocol::DOM::Node>* root) { |
481 // Backward compatibility. Mark agent as enabled when it requests document. | 481 // Backward compatibility. Mark agent as enabled when it requests document. |
482 if (!enabled()) | 482 if (!enabled()) |
483 innerEnable(); | 483 innerEnable(); |
484 | 484 |
485 if (!m_document) | 485 if (!m_document) |
486 return Response::Error("Document is not available"); | 486 return Response::Error("Document is not available"); |
487 | 487 |
488 discardFrontendBindings(); | 488 discardFrontendBindings(); |
489 | 489 |
490 int sanitizedDepth = depth.fromMaybe(2); | 490 int sanitizedDepth = depth.fromMaybe(2); |
491 if (sanitizedDepth == -1) | 491 if (sanitizedDepth == -1) |
492 sanitizedDepth = INT_MAX; | 492 sanitizedDepth = INT_MAX; |
493 | 493 |
494 *root = buildObjectForNode(m_document.get(), sanitizedDepth, | 494 *root = |
495 traverseFrames.fromMaybe(false), | 495 buildObjectForNode(m_document.get(), sanitizedDepth, |
496 m_documentNodeToIdMap.get()); | 496 pierce.fromMaybe(false), m_documentNodeToIdMap.get()); |
497 return Response::OK(); | 497 return Response::OK(); |
498 } | 498 } |
499 | 499 |
500 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, | 500 void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, |
501 int depth, | 501 int depth, |
502 bool traverseFrames) { | 502 bool pierce) { |
503 Node* node = nodeForId(nodeId); | 503 Node* node = nodeForId(nodeId); |
504 if (!node || (!node->isElementNode() && !node->isDocumentNode() && | 504 if (!node || (!node->isElementNode() && !node->isDocumentNode() && |
505 !node->isDocumentFragment())) | 505 !node->isDocumentFragment())) |
506 return; | 506 return; |
507 | 507 |
508 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); | 508 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); |
509 | 509 |
510 if (m_childrenRequested.contains(nodeId)) { | 510 if (m_childrenRequested.contains(nodeId)) { |
511 if (depth <= 1) | 511 if (depth <= 1) |
512 return; | 512 return; |
513 | 513 |
514 depth--; | 514 depth--; |
515 | 515 |
516 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) { | 516 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) { |
517 int childNodeId = nodeMap->get(node); | 517 int childNodeId = nodeMap->get(node); |
518 ASSERT(childNodeId); | 518 ASSERT(childNodeId); |
519 pushChildNodesToFrontend(childNodeId, depth, traverseFrames); | 519 pushChildNodesToFrontend(childNodeId, depth, pierce); |
520 } | 520 } |
521 | 521 |
522 return; | 522 return; |
523 } | 523 } |
524 | 524 |
525 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 525 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
526 buildArrayForContainerChildren(node, depth, traverseFrames, nodeMap); | 526 buildArrayForContainerChildren(node, depth, pierce, nodeMap); |
527 frontend()->setChildNodes(nodeId, std::move(children)); | 527 frontend()->setChildNodes(nodeId, std::move(children)); |
528 } | 528 } |
529 | 529 |
530 void InspectorDOMAgent::discardFrontendBindings() { | 530 void InspectorDOMAgent::discardFrontendBindings() { |
531 if (m_history) | 531 if (m_history) |
532 m_history->reset(); | 532 m_history->reset(); |
533 m_searchResults.clear(); | 533 m_searchResults.clear(); |
534 m_documentNodeToIdMap->clear(); | 534 m_documentNodeToIdMap->clear(); |
535 m_idToNode.clear(); | 535 m_idToNode.clear(); |
536 m_idToNodesMap.clear(); | 536 m_idToNodesMap.clear(); |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 case ShadowRootType::Closed: | 1535 case ShadowRootType::Closed: |
1536 return protocol::DOM::ShadowRootTypeEnum::Closed; | 1536 return protocol::DOM::ShadowRootTypeEnum::Closed; |
1537 } | 1537 } |
1538 ASSERT_NOT_REACHED(); | 1538 ASSERT_NOT_REACHED(); |
1539 return protocol::DOM::ShadowRootTypeEnum::UserAgent; | 1539 return protocol::DOM::ShadowRootTypeEnum::UserAgent; |
1540 } | 1540 } |
1541 | 1541 |
1542 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( | 1542 std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode( |
1543 Node* node, | 1543 Node* node, |
1544 int depth, | 1544 int depth, |
1545 bool traverseFrames, | 1545 bool pierce, |
1546 NodeToIdMap* nodesMap) { | 1546 NodeToIdMap* nodesMap) { |
1547 int id = bind(node, nodesMap); | 1547 int id = bind(node, nodesMap); |
1548 String localName; | 1548 String localName; |
1549 String nodeValue; | 1549 String nodeValue; |
1550 | 1550 |
1551 switch (node->getNodeType()) { | 1551 switch (node->getNodeType()) { |
1552 case Node::kTextNode: | 1552 case Node::kTextNode: |
1553 case Node::kCommentNode: | 1553 case Node::kCommentNode: |
1554 case Node::kCdataSectionNode: | 1554 case Node::kCdataSectionNode: |
1555 nodeValue = node->nodeValue(); | 1555 nodeValue = node->nodeValue(); |
(...skipping 26 matching lines...) Expand all Loading... |
1582 value->setAttributes(buildArrayForElementAttributes(element)); | 1582 value->setAttributes(buildArrayForElementAttributes(element)); |
1583 | 1583 |
1584 if (node->isFrameOwnerElement()) { | 1584 if (node->isFrameOwnerElement()) { |
1585 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); | 1585 HTMLFrameOwnerElement* frameOwner = toHTMLFrameOwnerElement(node); |
1586 if (LocalFrame* frame = frameOwner->contentFrame() && | 1586 if (LocalFrame* frame = frameOwner->contentFrame() && |
1587 frameOwner->contentFrame()->isLocalFrame() | 1587 frameOwner->contentFrame()->isLocalFrame() |
1588 ? toLocalFrame(frameOwner->contentFrame()) | 1588 ? toLocalFrame(frameOwner->contentFrame()) |
1589 : nullptr) | 1589 : nullptr) |
1590 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1590 value->setFrameId(IdentifiersFactory::frameId(frame)); |
1591 if (Document* doc = frameOwner->contentDocument()) { | 1591 if (Document* doc = frameOwner->contentDocument()) { |
1592 value->setContentDocument(buildObjectForNode( | 1592 value->setContentDocument( |
1593 doc, traverseFrames ? depth : 0, traverseFrames, nodesMap)); | 1593 buildObjectForNode(doc, pierce ? depth : 0, pierce, nodesMap)); |
1594 } | 1594 } |
1595 } | 1595 } |
1596 | 1596 |
1597 if (node->parentNode() && node->parentNode()->isDocumentNode()) { | 1597 if (node->parentNode() && node->parentNode()->isDocumentNode()) { |
1598 LocalFrame* frame = node->document().frame(); | 1598 LocalFrame* frame = node->document().frame(); |
1599 if (frame) | 1599 if (frame) |
1600 value->setFrameId(IdentifiersFactory::frameId(frame)); | 1600 value->setFrameId(IdentifiersFactory::frameId(frame)); |
1601 } | 1601 } |
1602 | 1602 |
1603 ElementShadow* shadow = element->shadow(); | 1603 ElementShadow* shadow = element->shadow(); |
1604 if (shadow) { | 1604 if (shadow) { |
1605 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = | 1605 std::unique_ptr<protocol::Array<protocol::DOM::Node>> shadowRoots = |
1606 protocol::Array<protocol::DOM::Node>::create(); | 1606 protocol::Array<protocol::DOM::Node>::create(); |
1607 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; | 1607 for (ShadowRoot* root = &shadow->youngestShadowRoot(); root; |
1608 root = root->olderShadowRoot()) { | 1608 root = root->olderShadowRoot()) { |
1609 shadowRoots->addItem( | 1609 shadowRoots->addItem( |
1610 buildObjectForNode(root, 0, traverseFrames, nodesMap)); | 1610 buildObjectForNode(root, pierce ? depth : 0, pierce, nodesMap)); |
1611 } | 1611 } |
1612 value->setShadowRoots(std::move(shadowRoots)); | 1612 value->setShadowRoots(std::move(shadowRoots)); |
1613 forcePushChildren = true; | 1613 forcePushChildren = true; |
1614 } | 1614 } |
1615 | 1615 |
1616 if (isHTMLLinkElement(*element)) { | 1616 if (isHTMLLinkElement(*element)) { |
1617 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); | 1617 HTMLLinkElement& linkElement = toHTMLLinkElement(*element); |
1618 if (linkElement.isImport() && linkElement.import() && | 1618 if (linkElement.isImport() && linkElement.import() && |
1619 innerParentNode(linkElement.import()) == linkElement) { | 1619 innerParentNode(linkElement.import()) == linkElement) { |
1620 value->setImportedDocument(buildObjectForNode( | 1620 value->setImportedDocument( |
1621 linkElement.import(), 0, traverseFrames, nodesMap)); | 1621 buildObjectForNode(linkElement.import(), 0, pierce, nodesMap)); |
1622 } | 1622 } |
1623 forcePushChildren = true; | 1623 forcePushChildren = true; |
1624 } | 1624 } |
1625 | 1625 |
1626 if (isHTMLTemplateElement(*element)) { | 1626 if (isHTMLTemplateElement(*element)) { |
1627 value->setTemplateContent( | 1627 value->setTemplateContent(buildObjectForNode( |
1628 buildObjectForNode(toHTMLTemplateElement(*element).content(), 0, | 1628 toHTMLTemplateElement(*element).content(), 0, pierce, nodesMap)); |
1629 traverseFrames, nodesMap)); | |
1630 forcePushChildren = true; | 1629 forcePushChildren = true; |
1631 } | 1630 } |
1632 | 1631 |
1633 if (element->getPseudoId()) { | 1632 if (element->getPseudoId()) { |
1634 protocol::DOM::PseudoType pseudoType; | 1633 protocol::DOM::PseudoType pseudoType; |
1635 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), | 1634 if (InspectorDOMAgent::getPseudoElementType(element->getPseudoId(), |
1636 &pseudoType)) | 1635 &pseudoType)) |
1637 value->setPseudoType(pseudoType); | 1636 value->setPseudoType(pseudoType); |
1638 } else { | 1637 } else { |
1639 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = | 1638 std::unique_ptr<protocol::Array<protocol::DOM::Node>> pseudoElements = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 } | 1673 } |
1675 | 1674 |
1676 if (node->isContainerNode()) { | 1675 if (node->isContainerNode()) { |
1677 int nodeCount = innerChildNodeCount(node); | 1676 int nodeCount = innerChildNodeCount(node); |
1678 value->setChildNodeCount(nodeCount); | 1677 value->setChildNodeCount(nodeCount); |
1679 if (nodesMap == m_documentNodeToIdMap) | 1678 if (nodesMap == m_documentNodeToIdMap) |
1680 m_cachedChildCount.set(id, nodeCount); | 1679 m_cachedChildCount.set(id, nodeCount); |
1681 if (forcePushChildren && !depth) | 1680 if (forcePushChildren && !depth) |
1682 depth = 1; | 1681 depth = 1; |
1683 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1682 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
1684 buildArrayForContainerChildren(node, depth, traverseFrames, nodesMap); | 1683 buildArrayForContainerChildren(node, depth, pierce, nodesMap); |
1685 if (children->length() > 0 || | 1684 if (children->length() > 0 || |
1686 depth) // Push children along with shadow in any case. | 1685 depth) // Push children along with shadow in any case. |
1687 value->setChildren(std::move(children)); | 1686 value->setChildren(std::move(children)); |
1688 } | 1687 } |
1689 | 1688 |
1690 return value; | 1689 return value; |
1691 } | 1690 } |
1692 | 1691 |
1693 std::unique_ptr<protocol::Array<String>> | 1692 std::unique_ptr<protocol::Array<String>> |
1694 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { | 1693 InspectorDOMAgent::buildArrayForElementAttributes(Element* element) { |
1695 std::unique_ptr<protocol::Array<String>> attributesValue = | 1694 std::unique_ptr<protocol::Array<String>> attributesValue = |
1696 protocol::Array<String>::create(); | 1695 protocol::Array<String>::create(); |
1697 // Go through all attributes and serialize them. | 1696 // Go through all attributes and serialize them. |
1698 AttributeCollection attributes = element->attributes(); | 1697 AttributeCollection attributes = element->attributes(); |
1699 for (auto& attribute : attributes) { | 1698 for (auto& attribute : attributes) { |
1700 // Add attribute pair | 1699 // Add attribute pair |
1701 attributesValue->addItem(attribute.name().toString()); | 1700 attributesValue->addItem(attribute.name().toString()); |
1702 attributesValue->addItem(attribute.value()); | 1701 attributesValue->addItem(attribute.value()); |
1703 } | 1702 } |
1704 return attributesValue; | 1703 return attributesValue; |
1705 } | 1704 } |
1706 | 1705 |
1707 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1706 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
1708 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, | 1707 InspectorDOMAgent::buildArrayForContainerChildren(Node* container, |
1709 int depth, | 1708 int depth, |
1710 bool traverseFrames, | 1709 bool pierce, |
1711 NodeToIdMap* nodesMap) { | 1710 NodeToIdMap* nodesMap) { |
1712 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = | 1711 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = |
1713 protocol::Array<protocol::DOM::Node>::create(); | 1712 protocol::Array<protocol::DOM::Node>::create(); |
1714 if (depth == 0) { | 1713 if (depth == 0) { |
1715 // Special-case the only text child - pretend that container's children have | 1714 // Special-case the only text child - pretend that container's children have |
1716 // been requested. | 1715 // been requested. |
1717 Node* firstChild = container->firstChild(); | 1716 Node* firstChild = container->firstChild(); |
1718 if (firstChild && firstChild->getNodeType() == Node::kTextNode && | 1717 if (firstChild && firstChild->getNodeType() == Node::kTextNode && |
1719 !firstChild->nextSibling()) { | 1718 !firstChild->nextSibling()) { |
1720 children->addItem( | 1719 children->addItem(buildObjectForNode(firstChild, 0, pierce, nodesMap)); |
1721 buildObjectForNode(firstChild, 0, traverseFrames, nodesMap)); | |
1722 m_childrenRequested.add(bind(container, nodesMap)); | 1720 m_childrenRequested.add(bind(container, nodesMap)); |
1723 } | 1721 } |
1724 return children; | 1722 return children; |
1725 } | 1723 } |
1726 | 1724 |
1727 Node* child = innerFirstChild(container); | 1725 Node* child = innerFirstChild(container); |
1728 depth--; | 1726 depth--; |
1729 m_childrenRequested.add(bind(container, nodesMap)); | 1727 m_childrenRequested.add(bind(container, nodesMap)); |
1730 | 1728 |
1731 while (child) { | 1729 while (child) { |
1732 children->addItem( | 1730 children->addItem(buildObjectForNode(child, depth, pierce, nodesMap)); |
1733 buildObjectForNode(child, depth, traverseFrames, nodesMap)); | |
1734 child = innerNextSibling(child); | 1731 child = innerNextSibling(child); |
1735 } | 1732 } |
1736 return children; | 1733 return children; |
1737 } | 1734 } |
1738 | 1735 |
1739 std::unique_ptr<protocol::Array<protocol::DOM::Node>> | 1736 std::unique_ptr<protocol::Array<protocol::DOM::Node>> |
1740 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, | 1737 InspectorDOMAgent::buildArrayForPseudoElements(Element* element, |
1741 NodeToIdMap* nodesMap) { | 1738 NodeToIdMap* nodesMap) { |
1742 if (!element->pseudoElement(PseudoIdBefore) && | 1739 if (!element->pseudoElement(PseudoIdBefore) && |
1743 !element->pseudoElement(PseudoIdAfter)) | 1740 !element->pseudoElement(PseudoIdAfter)) |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 visitor->trace(m_idToNodesMap); | 2278 visitor->trace(m_idToNodesMap); |
2282 visitor->trace(m_document); | 2279 visitor->trace(m_document); |
2283 visitor->trace(m_revalidateTask); | 2280 visitor->trace(m_revalidateTask); |
2284 visitor->trace(m_searchResults); | 2281 visitor->trace(m_searchResults); |
2285 visitor->trace(m_history); | 2282 visitor->trace(m_history); |
2286 visitor->trace(m_domEditor); | 2283 visitor->trace(m_domEditor); |
2287 InspectorBaseAgent::trace(visitor); | 2284 InspectorBaseAgent::trace(visitor); |
2288 } | 2285 } |
2289 | 2286 |
2290 } // namespace blink | 2287 } // namespace blink |
OLD | NEW |