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-20 16:01:03 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-20 16:01:03 +0000
commita95972d843da1bfe3b0c5a3d850604dc660609d7 (patch)
tree955c8f5ba9a7a45601a68f1f2f744b63e8ee1f6d /webkit/glue/devtools/dom_agent_impl.cc
parentdaa071ea80b8498f497ed41b4892e5e02208e38d (diff)
downloadchromium_src-a95972d843da1bfe3b0c5a3d850604dc660609d7.zip
chromium_src-a95972d843da1bfe3b0c5a3d850604dc660609d7.tar.gz
chromium_src-a95972d843da1bfe3b0c5a3d850604dc660609d7.tar.bz2
Add support for Javascript function callbacks into the WebDevToolsClient.
Review URL: http://codereview.chromium.org/42443 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools/dom_agent_impl.cc')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.cc35
1 files changed, 21 insertions, 14 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc
index 4cdbf1e..28b11da 100644
--- a/webkit/glue/devtools/dom_agent_impl.cc
+++ b/webkit/glue/devtools/dom_agent_impl.cc
@@ -20,6 +20,7 @@
#include <wtf/Vector.h>
#undef LOG
+#include "base/json_writer.h"
#include "base/values.h"
#include "webkit/glue/devtools/dom_agent_impl.h"
#include "webkit/glue/glue_util.h"
@@ -46,7 +47,7 @@ void DomAgentImpl::EventListenerWrapper::handleEvent(
DomAgentImpl::DomAgentImpl(DomAgentDelegate* delegate)
: delegate_(delegate),
last_node_id_(1),
- document_element_requested_(false) {
+ document_element_call_id_(0) {
event_listener_ = EventListenerWrapper::Create(this);
}
@@ -66,15 +67,15 @@ void DomAgentImpl::SetDocument(Document* doc) {
if (doc) {
StartListening(doc);
- if (document_element_requested_) {
- GetDocumentElement();
- document_element_requested_ = false;
+ if (document_element_call_id_) {
+ GetDocumentElement(document_element_call_id_);
+ document_element_call_id_ = 0;
}
}
}
void DomAgentImpl::StartListening(Document* doc) {
- if (documents_.find(doc) != documents_.end())
+ if (documents_.contains(doc))
return;
doc->addEventListener(eventNames().DOMContentLoadedEvent, event_listener_,
false);
@@ -179,8 +180,7 @@ void DomAgentImpl::handleEvent(Event* event, bool isWindowEvent) {
// Parent is not mapped yet -> ignore the event.
return;
}
- HashSet<int>::iterator cit = children_requested_.find(parent_id);
- if (cit == children_requested_.end()) {
+ if (!children_requested_.contains(parent_id)) {
// No children are mapped yet -> only notify on changes of hasChildren.
delegate_->HasChildrenUpdated(parent_id, true);
} else {
@@ -196,8 +196,7 @@ void DomAgentImpl::handleEvent(Event* event, bool isWindowEvent) {
// Parent is not mapped yet -> ignore the event.
return;
}
- HashSet<int>::iterator cit = children_requested_.find(parent_id);
- if (cit == children_requested_.end()) {
+ if (!children_requested_.contains(parent_id)) {
// No children are mapped yet -> only notify on changes of hasChildren.
if (parent->childNodeCount() == 1)
delegate_->HasChildrenUpdated(parent_id, false);
@@ -210,17 +209,19 @@ void DomAgentImpl::handleEvent(Event* event, bool isWindowEvent) {
}
}
-void DomAgentImpl::GetDocumentElement() {
+void DomAgentImpl::GetDocumentElement(int call_id) {
if (documents_.size() > 0) {
OwnPtr<Value> value(
BuildValueForNode((*documents_.begin())->documentElement(), 0));
- delegate_->DocumentElementUpdated(*value.get());
+ std::string json;
+ ToJson(value.get(), &json);
+ delegate_->GetDocumentElementResult(call_id, json);
} else {
- document_element_requested_ = true;
+ document_element_call_id_ = call_id;
}
}
-void DomAgentImpl::GetChildNodes(int element_id) {
+void DomAgentImpl::GetChildNodes(int call_id, int element_id) {
Node* node = GetNodeForId(element_id);
if (!node || (node->nodeType() != Node::ELEMENT_NODE))
return;
@@ -228,7 +229,9 @@ void DomAgentImpl::GetChildNodes(int element_id) {
Element* element = static_cast<Element*>(node);
OwnPtr<Value> children(BuildValueForElementChildren(element, 1));
children_requested_.add(element_id);
- delegate_->ChildNodesUpdated(element_id, *children.get());
+ std::string json;
+ ToJson(children.get(), &json);
+ delegate_->GetChildNodesResult(call_id, json);
}
int DomAgentImpl::GetPathToNode(Node* node_to_select) {
@@ -404,3 +407,7 @@ Element* DomAgentImpl::InnerParentElement(Node* node) {
}
return element;
}
+
+void DomAgentImpl::ToJson(const Value* value, std::string* json) {
+ JSONWriter::Write(value, false, json);
+}