summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/dom_agent_impl.cc
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 13:54:28 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-24 13:54:28 +0000
commitd0ef30f4636680ba1ca213d72bb13540fb5ce7f2 (patch)
tree5c76b111a2e8a54e7d6343cdf56d6eec4b3cd75b /webkit/glue/devtools/dom_agent_impl.cc
parent8ee332ca459d463eecb7807ecd966eda13be0456 (diff)
downloadchromium_src-d0ef30f4636680ba1ca213d72bb13540fb5ce7f2.zip
chromium_src-d0ef30f4636680ba1ca213d72bb13540fb5ce7f2.tar.gz
chromium_src-d0ef30f4636680ba1ca213d72bb13540fb5ce7f2.tar.bz2
Wire 'Inspect Element' action to the new DevTools (depending on the devtools flag):
- Add new devtools IPC message - Expose WebView's hit target - Refactor dom_agent interaction not to send information known to client - Collect incoming messages on the client until frontend is loaded - Add Inspect Element scenario into the devtools_host_stub Review URL: http://codereview.chromium.org/45022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools/dom_agent_impl.cc')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.cc55
1 files changed, 36 insertions, 19 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc
index 0170db9..34e1be5 100644
--- a/webkit/glue/devtools/dom_agent_impl.cc
+++ b/webkit/glue/devtools/dom_agent_impl.cc
@@ -46,7 +46,7 @@ void DomAgentImpl::EventListenerWrapper::handleEvent(
DomAgentImpl::DomAgentImpl(DomAgentDelegate* delegate)
: delegate_(delegate),
last_node_id_(1),
- document_element_call_id_(0) {
+ document_element_requested_(false) {
event_listener_ = EventListenerWrapper::Create(this);
}
@@ -66,9 +66,9 @@ void DomAgentImpl::SetDocument(Document* doc) {
if (doc) {
StartListening(doc);
- if (document_element_call_id_) {
- GetDocumentElement(document_element_call_id_);
- document_element_call_id_ = 0;
+ if (document_element_requested_) {
+ GetDocumentElement();
+ document_element_requested_ = false;
}
}
}
@@ -128,6 +128,27 @@ void DomAgentImpl::Unbind(Node* node) {
}
}
+void DomAgentImpl::PushDocumentElementToClient() {
+ Element* doc_elem = (*documents_.begin())->documentElement();
+ if (!node_to_id_.contains(doc_elem)) {
+ OwnPtr<Value> value(BuildValueForNode(doc_elem, 0));
+ delegate_->SetDocumentElement(*value.get());
+ }
+}
+
+void DomAgentImpl::PushChildNodesToClient(int element_id) {
+ Node* node = GetNodeForId(element_id);
+ if (!node || (node->nodeType() != Node::ELEMENT_NODE))
+ return;
+ if (children_requested_.contains(element_id))
+ return;
+
+ Element* element = static_cast<Element*>(node);
+ OwnPtr<Value> children(BuildValueForElementChildren(element, 1));
+ children_requested_.add(element_id);
+ delegate_->SetChildNodes(element_id, *children.get());
+}
+
void DomAgentImpl::DiscardBindings() {
node_to_id_.clear();
id_to_node_.clear();
@@ -208,28 +229,20 @@ void DomAgentImpl::handleEvent(Event* event, bool isWindowEvent) {
}
}
-void DomAgentImpl::GetDocumentElement(int call_id) {
+void DomAgentImpl::GetDocumentElement() {
if (documents_.size() > 0) {
- OwnPtr<Value> value(
- BuildValueForNode((*documents_.begin())->documentElement(), 0));
- delegate_->GetDocumentElementResult(call_id, *value.get());
+ PushDocumentElementToClient();
} else {
- document_element_call_id_ = call_id;
+ document_element_requested_ = true;
}
}
void DomAgentImpl::GetChildNodes(int call_id, int element_id) {
- Node* node = GetNodeForId(element_id);
- if (!node || (node->nodeType() != Node::ELEMENT_NODE))
- return;
-
- Element* element = static_cast<Element*>(node);
- OwnPtr<Value> children(BuildValueForElementChildren(element, 1));
- children_requested_.add(element_id);
- delegate_->GetChildNodesResult(call_id, *children.get());
+ PushChildNodesToClient(element_id);
+ delegate_->DidGetChildNodes(call_id);
}
-int DomAgentImpl::GetPathToNode(Node* node_to_select) {
+int DomAgentImpl::PushNodePathToClient(Node* node_to_select) {
ASSERT(node_to_select); // Invalid input
// Return id in case the node is known.
@@ -240,6 +253,10 @@ int DomAgentImpl::GetPathToNode(Node* node_to_select) {
Element* element = InnerParentElement(node_to_select);
ASSERT(element); // Node is detached or is a document itself
+ // If we are sending information to the client that is currently being
+ // created. Send root node first.
+ PushDocumentElementToClient();
+
Vector<Element*> path;
while (element && !GetIdForNode(element)) {
path.append(element);
@@ -252,7 +269,7 @@ int DomAgentImpl::GetPathToNode(Node* node_to_select) {
for (int i = path.size() - 1; i >= 0; --i) {
element = path.at(i);
OwnPtr<Value> children(BuildValueForElementChildren(element, 1));
- delegate_->ChildNodesUpdated(GetIdForNode(element), *children.get());
+ delegate_->SetChildNodes(GetIdForNode(element), *children.get());
}
return GetIdForNode(node_to_select);
}