Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp

Issue 2373023002: Make DOM.getChildNodes & DOM.getDocument optionally pierce iframe boundaries (Closed)
Patch Set: Added a requestFrames parameter to fix the broken test Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 InspectorDOMAgent::InspectorDOMAgent(v8::Isolate* isolate, InspectedFrames* insp ectedFrames, v8_inspector::V8InspectorSession* v8Session, Client* client) 244 InspectorDOMAgent::InspectorDOMAgent(v8::Isolate* isolate, InspectedFrames* insp ectedFrames, v8_inspector::V8InspectorSession* v8Session, Client* client)
245 : m_isolate(isolate) 245 : m_isolate(isolate)
246 , m_inspectedFrames(inspectedFrames) 246 , m_inspectedFrames(inspectedFrames)
247 , m_v8Session(v8Session) 247 , m_v8Session(v8Session)
248 , m_client(client) 248 , m_client(client)
249 , m_domListener(nullptr) 249 , m_domListener(nullptr)
250 , m_documentNodeToIdMap(new NodeToIdMap()) 250 , m_documentNodeToIdMap(new NodeToIdMap())
251 , m_lastNodeId(1) 251 , m_lastNodeId(1)
252 , m_suppressAttributeModifiedEvent(false) 252 , m_suppressAttributeModifiedEvent(false)
253 , m_traverseFrames(false)
253 , m_backendNodeIdToInspect(0) 254 , m_backendNodeIdToInspect(0)
254 { 255 {
255 } 256 }
256 257
257 InspectorDOMAgent::~InspectorDOMAgent() 258 InspectorDOMAgent::~InspectorDOMAgent()
258 { 259 {
259 } 260 }
260 261
261 void InspectorDOMAgent::restore() 262 void InspectorDOMAgent::restore()
262 { 263 {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return; 537 return;
537 538
538 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId); 539 NodeToIdMap* nodeMap = m_idToNodesMap.get(nodeId);
539 540
540 if (m_childrenRequested.contains(nodeId)) { 541 if (m_childrenRequested.contains(nodeId)) {
541 if (depth <= 1) 542 if (depth <= 1)
542 return; 543 return;
543 544
544 depth--; 545 depth--;
545 546
547 if (m_traverseFrames && node->isFrameOwnerElement()) {
548 int iframeDocumentId = nodeMap->get(toHTMLFrameOwnerElement(node)->c ontentDocument()->documentElement());
549 CHECK(iframeDocumentId);
550 pushChildNodesToFrontend(iframeDocumentId, depth);
551 }
546 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) { 552 for (node = innerFirstChild(node); node; node = innerNextSibling(node)) {
547 int childNodeId = nodeMap->get(node); 553 int childNodeId = nodeMap->get(node);
548 ASSERT(childNodeId); 554 CHECK(childNodeId);
549 pushChildNodesToFrontend(childNodeId, depth); 555 pushChildNodesToFrontend(childNodeId, depth);
550 } 556 }
551 557
552 return; 558 return;
553 } 559 }
554 560
555 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = buildArrayF orContainerChildren(node, depth, nodeMap); 561 std::unique_ptr<protocol::Array<protocol::DOM::Node>> children = buildArrayF orContainerChildren(node, depth, nodeMap);
556 frontend()->setChildNodes(nodeId, std::move(children)); 562 frontend()->setChildNodes(nodeId, std::move(children));
557 } 563 }
558 564
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 continue; 605 continue;
600 const SpaceSplitString& classNameList = element.classNames(); 606 const SpaceSplitString& classNameList = element.classNames();
601 for (unsigned i = 0; i < classNameList.size(); ++i) 607 for (unsigned i = 0; i < classNameList.size(); ++i)
602 uniqueNames.add(classNameList[i]); 608 uniqueNames.add(classNameList[i]);
603 } 609 }
604 } 610 }
605 for (const String& className : uniqueNames) 611 for (const String& className : uniqueNames)
606 (*classNames)->addItem(className); 612 (*classNames)->addItem(className);
607 } 613 }
608 614
609 void InspectorDOMAgent::requestChildNodes(ErrorString* errorString, int nodeId, const Maybe<int>& depth) 615 void InspectorDOMAgent::requestChildNodes(ErrorString* errorString, int nodeId, const Maybe<int>& depth, const Maybe<bool>& traverseFrames)
610 { 616 {
611 int sanitizedDepth = depth.fromMaybe(1); 617 int sanitizedDepth = depth.fromMaybe(1);
612 if (sanitizedDepth == 0 || sanitizedDepth < -1) { 618 if (sanitizedDepth == 0 || sanitizedDepth < -1) {
613 *errorString = "Please provide a positive integer as a depth or -1 for e ntire subtree"; 619 *errorString = "Please provide a positive integer as a depth or -1 for e ntire subtree";
614 return; 620 return;
615 } 621 }
622 bool prevMayCrossIframeBoundary = m_traverseFrames;
616 if (sanitizedDepth == -1) 623 if (sanitizedDepth == -1)
617 sanitizedDepth = INT_MAX; 624 sanitizedDepth = INT_MAX;
618 625
626 m_traverseFrames = traverseFrames.fromMaybe(false);
627
628 // Cached results may not be valid if |m_traverseFrames| changes.
629 if (prevMayCrossIframeBoundary != m_traverseFrames)
630 m_childrenRequested.clear();
631
619 pushChildNodesToFrontend(nodeId, sanitizedDepth); 632 pushChildNodesToFrontend(nodeId, sanitizedDepth);
620 } 633 }
621 634
622 void InspectorDOMAgent::querySelector(ErrorString* errorString, int nodeId, cons t String& selectors, int* elementId) 635 void InspectorDOMAgent::querySelector(ErrorString* errorString, int nodeId, cons t String& selectors, int* elementId)
623 { 636 {
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())
627 return; 640 return;
628 641
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 children->addItem(buildObjectForNode(firstChild, 0, nodesMap)); 1610 children->addItem(buildObjectForNode(firstChild, 0, nodesMap));
1598 m_childrenRequested.add(bind(container, nodesMap)); 1611 m_childrenRequested.add(bind(container, nodesMap));
1599 } 1612 }
1600 return children; 1613 return children;
1601 } 1614 }
1602 1615
1603 Node* child = innerFirstChild(container); 1616 Node* child = innerFirstChild(container);
1604 depth--; 1617 depth--;
1605 m_childrenRequested.add(bind(container, nodesMap)); 1618 m_childrenRequested.add(bind(container, nodesMap));
1606 1619
1620 if (m_traverseFrames && container->isFrameOwnerElement()) {
1621 Node* iframeDocument = toHTMLFrameOwnerElement(container)->contentDocume nt()->documentElement();
1622 children->addItem(buildObjectForNode(iframeDocument, depth, nodesMap));
pfeldman 2016/09/27 18:37:41 Those are not the children, you should report ifra
alex clarke (OOO till 29th) 2016/09/28 14:30:00 Done.
1623 }
1607 while (child) { 1624 while (child) {
1608 children->addItem(buildObjectForNode(child, depth, nodesMap)); 1625 children->addItem(buildObjectForNode(child, depth, nodesMap));
1609 child = innerNextSibling(child); 1626 child = innerNextSibling(child);
1610 } 1627 }
1611 return children; 1628 return children;
1612 } 1629 }
1613 1630
1614 std::unique_ptr<protocol::Array<protocol::DOM::Node>> InspectorDOMAgent::buildAr rayForPseudoElements(Element* element, NodeToIdMap* nodesMap) 1631 std::unique_ptr<protocol::Array<protocol::DOM::Node>> InspectorDOMAgent::buildAr rayForPseudoElements(Element* element, NodeToIdMap* nodesMap)
1615 { 1632 {
1616 if (!element->pseudoElement(PseudoIdBefore) && !element->pseudoElement(Pseud oIdAfter)) 1633 if (!element->pseudoElement(PseudoIdBefore) && !element->pseudoElement(Pseud oIdAfter))
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 visitor->trace(m_idToNodesMap); 2146 visitor->trace(m_idToNodesMap);
2130 visitor->trace(m_document); 2147 visitor->trace(m_document);
2131 visitor->trace(m_revalidateTask); 2148 visitor->trace(m_revalidateTask);
2132 visitor->trace(m_searchResults); 2149 visitor->trace(m_searchResults);
2133 visitor->trace(m_history); 2150 visitor->trace(m_history);
2134 visitor->trace(m_domEditor); 2151 visitor->trace(m_domEditor);
2135 InspectorBaseAgent::trace(visitor); 2152 InspectorBaseAgent::trace(visitor);
2136 } 2153 }
2137 2154
2138 } // namespace blink 2155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698