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

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp

Issue 2373023002: Make DOM.getChildNodes & DOM.getDocument optionally pierce iframe boundaries (Closed)
Patch Set: Per IM conversation, let DOM.getDocument optionally return the sub tree as well. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp
index 57c3c68cf8e576bd11a7bb2bafce430175c4a91e..efcfddfcd967a8305b42cb09e00f3e2f1955cd81 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorDOMAgent.cpp
@@ -254,6 +254,7 @@ InspectorDOMAgent::InspectorDOMAgent(
m_documentNodeToIdMap(new NodeToIdMap()),
m_lastNodeId(1),
m_suppressAttributeModifiedEvent(false),
+ m_traverseFrames(false),
m_backendNodeIdToInspect(0) {}
InspectorDOMAgent::~InspectorDOMAgent() {}
@@ -506,6 +507,8 @@ void InspectorDOMAgent::disable(ErrorString* errorString) {
void InspectorDOMAgent::getDocument(
ErrorString* errorString,
+ const Maybe<int>& depth,
+ const Maybe<bool>& traverseFrames,
std::unique_ptr<protocol::DOM::Node>* root) {
// Backward compatibility. Mark agent as enabled when it requests document.
if (!enabled())
@@ -518,7 +521,10 @@ void InspectorDOMAgent::getDocument(
discardFrontendBindings();
- *root = buildObjectForNode(m_document.get(), 2, m_documentNodeToIdMap.get());
+ m_traverseFrames = traverseFrames.fromMaybe(false);
pfeldman 2016/10/07 19:35:12 You should plumb it, it is sessional, not a proper
alex clarke (OOO till 29th) 2016/10/11 12:05:12 Done.
+
+ *root = buildObjectForNode(m_document.get(), depth.fromMaybe(2),
+ m_documentNodeToIdMap.get());
}
void InspectorDOMAgent::pushChildNodesToFrontend(int nodeId, int depth) {
@@ -604,7 +610,8 @@ void InspectorDOMAgent::collectClassNamesFromSubtree(
void InspectorDOMAgent::requestChildNodes(ErrorString* errorString,
int nodeId,
- const Maybe<int>& depth) {
+ const Maybe<int>& depth,
+ const Maybe<bool>& traverseFrames) {
int sanitizedDepth = depth.fromMaybe(1);
if (sanitizedDepth == 0 || sanitizedDepth < -1) {
*errorString =
@@ -614,6 +621,12 @@ void InspectorDOMAgent::requestChildNodes(ErrorString* errorString,
if (sanitizedDepth == -1)
sanitizedDepth = INT_MAX;
+ // Cached results may not be valid if |m_traverseFrames| changes.
+ if (m_traverseFrames != traverseFrames.fromMaybe(false)) {
+ m_traverseFrames = traverseFrames.fromMaybe(false);
+ m_childrenRequested.clear();
+ }
+
pushChildNodesToFrontend(nodeId, sanitizedDepth);
}
@@ -1607,8 +1620,10 @@ std::unique_ptr<protocol::DOM::Node> InspectorDOMAgent::buildObjectForNode(
? toLocalFrame(frameOwner->contentFrame())
: nullptr)
value->setFrameId(IdentifiersFactory::frameId(frame));
- if (Document* doc = frameOwner->contentDocument())
- value->setContentDocument(buildObjectForNode(doc, 0, nodesMap));
+ if (Document* doc = frameOwner->contentDocument()) {
+ value->setContentDocument(
+ buildObjectForNode(doc, m_traverseFrames ? -1 : 0, nodesMap));
pfeldman 2016/10/07 19:35:12 You should still respect the depth here.
alex clarke (OOO till 29th) 2016/10/11 12:05:12 Done.
+ }
}
if (node->parentNode() && node->parentNode()->isDocumentNode()) {
@@ -2268,7 +2283,7 @@ bool InspectorDOMAgent::pushDocumentUponHandlelessOperation(
ErrorString* errorString) {
if (!m_documentNodeToIdMap->contains(m_document)) {
std::unique_ptr<protocol::DOM::Node> root;
- getDocument(errorString, &root);
+ getDocument(errorString, Maybe<int>(), Maybe<bool>(), &root);
return errorString->isEmpty();
}
return true;

Powered by Google App Engine
This is Rietveld 408576698