diff options
-rw-r--r-- | webkit/glue/devtools/devtools_rpc.cc | 13 | ||||
-rw-r--r-- | webkit/glue/devtools/devtools_rpc.h | 14 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent.h | 15 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_impl.cc | 35 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_impl.h | 10 | ||||
-rw-r--r-- | webkit/glue/devtools/dom_agent_unittest.cc | 107 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent.h | 7 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/devtools/net_agent_impl.h | 3 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsclient_impl.cc | 55 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsclient_impl.h | 21 |
11 files changed, 184 insertions, 100 deletions
diff --git a/webkit/glue/devtools/devtools_rpc.cc b/webkit/glue/devtools/devtools_rpc.cc index e392ef9..c19e373 100644 --- a/webkit/glue/devtools/devtools_rpc.cc +++ b/webkit/glue/devtools/devtools_rpc.cc @@ -61,6 +61,14 @@ void DevToolsRpc::GetListValue( void DevToolsRpc::GetListValue( const ListValue& message, int index, + std::string* value) { + message.GetString(index, value); +} + +// static +void DevToolsRpc::GetListValue( + const ListValue& message, + int index, Value** value) { message.Get(index, value); } @@ -72,6 +80,11 @@ Value* DevToolsRpc::CreateValue(const String* value) { } // static +Value* DevToolsRpc::CreateValue(const std::string* value) { + return Value::CreateStringValue(*value); +} + +// static Value* DevToolsRpc::CreateValue(int* value) { return Value::CreateIntegerValue(*value); } diff --git a/webkit/glue/devtools/devtools_rpc.h b/webkit/glue/devtools/devtools_rpc.h index c85b32a..56d5266 100644 --- a/webkit/glue/devtools/devtools_rpc.h +++ b/webkit/glue/devtools/devtools_rpc.h @@ -95,6 +95,15 @@ struct RpcTypeTrait<String> { } }; +template<> +struct RpcTypeTrait<std::string> { + typedef const std::string& ApiType; + typedef std::string DispatchType; + static const DispatchType& Pass(const DispatchType& t) { + return t; + } +}; + /////////////////////////////////////////////////////// // RPC Api method declarations @@ -343,6 +352,10 @@ class DevToolsRpc { const ListValue& message, int index, String* value); + static void GetListValue( + const ListValue& message, + int index, + std::string* value); static void GetListValue(const ListValue& message, int index, Value** value); protected: @@ -352,6 +365,7 @@ class DevToolsRpc { private: // Value adapters for supported Rpc types. static Value* CreateValue(const String* value); + static Value* CreateValue(const std::string* value); static Value* CreateValue(int* value); static Value* CreateValue(bool* value); static Value* CreateValue(const Value* value); diff --git a/webkit/glue/devtools/dom_agent.h b/webkit/glue/devtools/dom_agent.h index a2d8818..491adb8 100644 --- a/webkit/glue/devtools/dom_agent.h +++ b/webkit/glue/devtools/dom_agent.h @@ -13,10 +13,10 @@ // DomAgent's environment is represented with the DomAgentDelegate interface. #define DOM_AGENT_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \ /* Requests that the document root element is sent to the delegate. */ \ - METHOD0(GetDocumentElement) \ + METHOD1(GetDocumentElement, int /* call_id */) \ \ /* Requests that the element's children are sent to the client. */ \ - METHOD1(GetChildNodes, int /* id */) \ + METHOD2(GetChildNodes, int /* call_id */, int /* id */) \ \ /* Sets attribute value in the element with given id. */ \ METHOD3(SetAttribute, int /* id */, String /* name */, String /* value */) \ @@ -35,14 +35,17 @@ DEFINE_RPC_CLASS(DomAgent, DOM_AGENT_STRUCT) #define DOM_AGENT_DELEGATE_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \ - /* Notifies the delegate that document element is available. */ \ - METHOD1(DocumentElementUpdated, Value /* node */) \ + /* Response to GetDocumentElement. */ \ + METHOD2(GetDocumentElementResult, int /* call_id */, std::string /* json */) \ + \ + /* Response to GetChildNodes. */ \ + METHOD2(GetChildNodesResult, int /* call_id */, std::string /* json */) \ \ /* Notifies the delegate that element's attributes are updated. */ \ METHOD2(AttributesUpdated, int /* id */, Value /* attributes */) \ \ /* Notifies the delegate that element's child nodes have been updated. */ \ - METHOD2(ChildNodesUpdated, int /* id */, Value /* node */) \ + METHOD2(ChildNodesUpdated, int /* parent_id */, Value /* nodes */) \ \ /* Notifies the delegate that element's 'has children' state has been updated */ \ @@ -53,7 +56,7 @@ DEFINE_RPC_CLASS(DomAgent, DOM_AGENT_STRUCT) Value /* node */) \ \ /* Notifies the delegate that child node has been deleted. */ \ - METHOD2(ChildNodeRemoved, int /* parent_id */, int /* id */) + METHOD2(ChildNodeRemoved, int /* parent_id */, int /* id */) \ DEFINE_RPC_CLASS(DomAgentDelegate, DOM_AGENT_DELEGATE_STRUCT) 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); +} diff --git a/webkit/glue/devtools/dom_agent_impl.h b/webkit/glue/devtools/dom_agent_impl.h index 5a58433..51e5ffa 100644 --- a/webkit/glue/devtools/dom_agent_impl.h +++ b/webkit/glue/devtools/dom_agent_impl.h @@ -32,8 +32,8 @@ class DomAgentImpl : public DomAgent { virtual ~DomAgentImpl(); // DomAgent implementation. - void GetDocumentElement(); - void GetChildNodes(int element_id); + void GetDocumentElement(int call_id); + void GetChildNodes(int call_id, int element_id); void SetAttribute( int element_id, const WebCore::String& name, @@ -103,6 +103,8 @@ class DomAgentImpl : public DomAgent { int InnerChildNodeCount(WebCore::Node* node); WebCore::Element* InnerParentElement(WebCore::Node* node); + void ToJson(const Value* value, std::string* json); + DomAgentDelegate* delegate_; HashMap<WebCore::Node*, int> node_to_id_; HashMap<int, WebCore::Node*> id_to_node_; @@ -110,7 +112,9 @@ class DomAgentImpl : public DomAgent { int last_node_id_; ListHashSet<RefPtr<WebCore::Document> > documents_; RefPtr<WebCore::EventListener> event_listener_; - bool document_element_requested_; + // Captures pending document element request's call id. + // Defaults to 0 meaning no pending request. + int document_element_call_id_; DISALLOW_COPY_AND_ASSIGN(DomAgentImpl); }; diff --git a/webkit/glue/devtools/dom_agent_unittest.cc b/webkit/glue/devtools/dom_agent_unittest.cc index ef92f8a..ce2f544 100644 --- a/webkit/glue/devtools/dom_agent_unittest.cc +++ b/webkit/glue/devtools/dom_agent_unittest.cc @@ -78,6 +78,13 @@ class DomAgentTests : public TestShellTest { static const int kHtmlElemId = 1; static const int kBodyElemId = 2; + enum { + kCallIdAny = 0, + kCallId1, + kCallId2, + kCallId3, + kCallId4 + }; RefPtr<Document> document_; RefPtr<Element> body_; @@ -88,32 +95,30 @@ class DomAgentTests : public TestShellTest { // Requests document node and tests that the callback with the serialized // version is called. -TEST_F(DomAgentTests, DocumentElementUpdated) { - OwnPtr<Value> v(DevToolsRpc::ParseMessage("[1,1,\"HTML\",\"\",[],1]")); - mock_delegate_->DocumentElementUpdated(*v.get()); +TEST_F(DomAgentTests, GetDocumentElement) { + mock_delegate_->GetDocumentElementResult(kCallId1, "[1,1,\"HTML\",\"\",[],1]"); mock_delegate_->Replay(); - dom_agent_->GetDocumentElement(); + dom_agent_->GetDocumentElement(kCallId1); mock_delegate_->Verify(); } // Requests element's children and tests that the callback with the serialized // version is called. -TEST_F(DomAgentTests, ChildNodesUpdated) { - dom_agent_->GetDocumentElement(); +TEST_F(DomAgentTests, GetChildNodes) { + dom_agent_->GetDocumentElement(kCallId1); mock_delegate_->Reset(); - OwnPtr<Value> v(DevToolsRpc::ParseMessage("[[2,1,\"BODY\",\"\",[],0]]")); - mock_delegate_->ChildNodesUpdated(1, *v.get()); + mock_delegate_->GetChildNodesResult(kCallId2, "[[2,1,\"BODY\",\"\",[],0]]"); mock_delegate_->Replay(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Verify(); } // Tests that "child node inserted" event is being fired. TEST_F(DomAgentTests, ChildNodeInsertedUnknownParent) { - dom_agent_->GetDocumentElement(); + dom_agent_->GetDocumentElement(1); mock_delegate_->Reset(); // There should be no events fired until parent node is known to client. @@ -125,8 +130,8 @@ TEST_F(DomAgentTests, ChildNodeInsertedUnknownParent) { // Tests that "child node inserted" event is being fired. TEST_F(DomAgentTests, ChildNodeInsertedKnownParent) { - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -141,9 +146,9 @@ TEST_F(DomAgentTests, ChildNodeInsertedKnownParent) { // Tests that "child node inserted" event is being fired. TEST_F(DomAgentTests, ChildNodeInsertedKnownChildren) { - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -163,9 +168,9 @@ TEST_F(DomAgentTests, ChildNodePrepend) { RefPtr<Element> div = document_->createElement("DIV", ec_); body_->appendChild(div, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -185,9 +190,9 @@ TEST_F(DomAgentTests, ChildNodeAppend) { RefPtr<Element> div = document_->createElement("DIV", ec_); body_->appendChild(div, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -209,9 +214,9 @@ TEST_F(DomAgentTests, ChildNodeInsert) { RefPtr<Element> div2 = document_->createElement("DIV", ec_); body_->appendChild(div2, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -231,7 +236,7 @@ TEST_F(DomAgentTests, ChildNodeRemovedUnknownParent) { RefPtr<Element> div = document_->createElement("DIV", ec_); body_->appendChild(div, ec_); - dom_agent_->GetDocumentElement(); + dom_agent_->GetDocumentElement(kCallId1); mock_delegate_->Reset(); // There should be no events fired until parent node is known to client. @@ -245,8 +250,8 @@ TEST_F(DomAgentTests, ChildNodeRemovedKnownParent) { RefPtr<Element> div = document_->createElement("DIV", ec_); body_->appendChild(div, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -263,9 +268,9 @@ TEST_F(DomAgentTests, ChildNodeRemovedKnownChildren) { RefPtr<Element> div = document_->createElement("DIV", ec_); body_->appendChild(div, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, @@ -282,9 +287,9 @@ TEST_F(DomAgentTests, GetPathToKnownNode) { RefPtr<Element> div1 = document_->createElement("DIV", ec_); body_->appendChild(div1, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // We expect no messages - node is already known. @@ -300,8 +305,8 @@ TEST_F(DomAgentTests, GetPathToKnownParent) { RefPtr<Element> div1 = document_->createElement("DIV", ec_); body_->appendChild(div1, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Reset(); OwnPtr<Value> v1(DevToolsRpc::ParseMessage("[[3,1,\"DIV\",\"\",[],0]]")); @@ -324,8 +329,8 @@ TEST_F(DomAgentTests, GetPathToUnknownNode) { div2->appendChild(div3, ec_); div3->appendChild(div4, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Reset(); OwnPtr<Value> v1(DevToolsRpc::ParseMessage("[[3,1,\"DIV\",\"\",[],1]]")); @@ -348,17 +353,16 @@ TEST_F(DomAgentTests, GetChildNodesOfFrameOwner) { RefPtr<Element> iframe = document_->createElement("IFRAME", ec_); body_->appendChild(iframe, ec_); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); + dom_agent_->GetChildNodes(kCallId3, kBodyElemId); mock_delegate_->Reset(); // Expecting HTML child with single (body) child. - OwnPtr<Value> v(DevToolsRpc::ParseMessage("[[4,1,\"HTML\",\"\",[],1]]")); - mock_delegate_->ChildNodesUpdated(3, *v.get()); + mock_delegate_->GetChildNodesResult(kCallId4, "[[4,1,\"HTML\",\"\",[],1]]"); mock_delegate_->Replay(); - dom_agent_->GetChildNodes(3); + dom_agent_->GetChildNodes(kCallId4, 3); mock_delegate_->Verify(); } @@ -371,8 +375,8 @@ TEST_F(DomAgentTests, GetPathToNodeOverFrameOwner) { Node* inner_body = frame_owner->contentDocument()->firstChild()-> firstChild(); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); + dom_agent_->GetDocumentElement(kCallId1); + dom_agent_->GetChildNodes(kCallId2, kHtmlElemId); mock_delegate_->Reset(); OwnPtr<Value> v1(DevToolsRpc::ParseMessage("[[3,1,\"IFRAME\",\"\",[],1]]")); @@ -381,7 +385,6 @@ TEST_F(DomAgentTests, GetPathToNodeOverFrameOwner) { mock_delegate_->ChildNodesUpdated(2, *v1.get()); mock_delegate_->ChildNodesUpdated(3, *v2.get()); mock_delegate_->ChildNodesUpdated(4, *v3.get()); - mock_delegate_->Replay(); dom_agent_->GetPathToNode(inner_body); @@ -397,12 +400,12 @@ TEST_F(DomAgentTests, ChildNodeInsertUnderFrameOwner) { Node* inner_body = frame_owner->contentDocument()->firstChild()-> firstChild(); - dom_agent_->GetDocumentElement(); - dom_agent_->GetChildNodes(kHtmlElemId); - dom_agent_->GetChildNodes(kBodyElemId); - dom_agent_->GetChildNodes(3); // IFrame children - dom_agent_->GetChildNodes(4); // IFrame html's children - dom_agent_->GetChildNodes(5); // IFrame body's children + dom_agent_->GetDocumentElement(kCallIdAny); + dom_agent_->GetChildNodes(kCallIdAny, kHtmlElemId); + dom_agent_->GetChildNodes(kCallIdAny, kBodyElemId); + dom_agent_->GetChildNodes(kCallIdAny, 3); // IFrame children + dom_agent_->GetChildNodes(kCallIdAny, 4); // IFrame html's children + dom_agent_->GetChildNodes(kCallIdAny, 5); // IFrame body's children mock_delegate_->Reset(); // There should be an event fired in case parent node is known to client, diff --git a/webkit/glue/devtools/net_agent.h b/webkit/glue/devtools/net_agent.h index 00db4af0..0921c26 100644 --- a/webkit/glue/devtools/net_agent.h +++ b/webkit/glue/devtools/net_agent.h @@ -14,7 +14,8 @@ #define NET_AGENT_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3) \ /* Requests that the agent sends content of the resource with given id to the delegate. */ \ - METHOD2(GetResourceContent, int /* identifier */, String /* url */) + METHOD3(GetResourceContent, int /* call_id */, int /* identifier */, \ + String /* url */) DEFINE_RPC_CLASS(NetAgent, NET_AGENT_STRUCT) @@ -32,8 +33,8 @@ DEFINE_RPC_CLASS(NetAgent, NET_AGENT_STRUCT) /* Notifies the delegate that resource loading has failed. */ \ METHOD2(DidFailLoading, int /* identifier */, Value /* response */) \ \ - /* Calls delegate back with requested resource content. */ \ - METHOD2(SetResourceContent, int /* identifier */, String /* content */) + /* Response to the async call. */ \ + METHOD2(GetResourceContentResult, int /* call_id */, std::string /* content */) DEFINE_RPC_CLASS(NetAgentDelegate, NET_AGENT_DELEGATE_STRUCT) diff --git a/webkit/glue/devtools/net_agent_impl.cc b/webkit/glue/devtools/net_agent_impl.cc index 08a64fb..2202bd0 100644 --- a/webkit/glue/devtools/net_agent_impl.cc +++ b/webkit/glue/devtools/net_agent_impl.cc @@ -131,6 +131,7 @@ void NetAgentImpl::DidLoadResourceFromMemoryCache( } void NetAgentImpl::GetResourceContent( + int call_id, int identifier, const String& url) { if (!document_) { @@ -189,7 +190,8 @@ void NetAgentImpl::GetResourceContent( break; } } - delegate_->SetResourceContent(identifier, source); + delegate_->GetResourceContentResult(call_id, + webkit_glue::StringToStdString(source)); } Value* NetAgentImpl::BuildValueForHeaders(const HTTPHeaderMap& headers) { diff --git a/webkit/glue/devtools/net_agent_impl.h b/webkit/glue/devtools/net_agent_impl.h index b9d56fc..661ecb5 100644 --- a/webkit/glue/devtools/net_agent_impl.h +++ b/webkit/glue/devtools/net_agent_impl.h @@ -36,7 +36,8 @@ class NetAgentImpl : public NetAgent { void SetDocument(WebCore::Document* document); // NetAgent implementation. - void GetResourceContent(int identifier, const WebCore::String& request_url); + void GetResourceContent(int call_id, int identifier, + const WebCore::String& request_url); void AssignIdentifierToRequest( WebCore::DocumentLoader* loader, int identifier, diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc index 49ba41f..b13e6c3 100644 --- a/webkit/glue/webdevtoolsclient_impl.cc +++ b/webkit/glue/webdevtoolsclient_impl.cc @@ -43,10 +43,11 @@ WebDevToolsClientImpl::WebDevToolsClientImpl( WebViewImpl* web_view_impl, WebDevToolsClientDelegate* delegate) : web_view_impl_(web_view_impl), - delegate_(delegate) { - dom_agent_stub_.reset(new DomAgentStub(this)); - net_agent_stub_.reset(new NetAgentStub(this)); - tools_agent_stub_.reset(new ToolsAgentStub(this)); + delegate_(delegate), + last_call_id_(1) { + dom_agent_stub_.set(new DomAgentStub(this)); + net_agent_stub_.set(new NetAgentStub(this)); + tools_agent_stub_.set(new ToolsAgentStub(this)); BindToJavascript(web_view_impl_->GetMainFrame(), L"DevToolsHost"); BindMethod("getDocumentElement", @@ -64,8 +65,16 @@ WebDevToolsClientImpl::~WebDevToolsClientImpl() { } // DomAgent::DomAgentDelegate implementation. -void WebDevToolsClientImpl::DocumentElementUpdated(const Value& value) { - MakeJsCall("dom.setDocumentElement", &value); +void WebDevToolsClientImpl::GetDocumentElementResult( + int call_id, + const std::string& root) { + ProcessCallback(call_id, root); +} + +void WebDevToolsClientImpl::GetChildNodesResult( + int call_id, + const std::string& list) { + ProcessCallback(call_id, list); } void WebDevToolsClientImpl::AttributesUpdated(int id, const Value& attributes) { @@ -114,21 +123,37 @@ void WebDevToolsClientImpl::DidFailLoading(int identifier, MakeJsCall("net.didFailLoading", identifier, &response); } -void WebDevToolsClientImpl::SetResourceContent( - int identifier, - const String& content) { - MakeJsCall("net.setResourceContent", identifier, content); +void WebDevToolsClientImpl::GetResourceContentResult( + int call_id, + const std::string& content) { + ProcessCallback(call_id, content); } void WebDevToolsClientImpl::UpdateFocusedNode(int node_id) { MakeJsCall("tools.updateFocusedNode", node_id); } +void WebDevToolsClientImpl::ProcessCallback( + int call_id, + const std::string& data) { + HashMap<int, CppVariant>::iterator it = callbacks_.find(call_id); + if (it != callbacks_.end()) { + CppVariant result; + CppVariant args[2]; + args[0].Set(*GetAsCppVariant()); + args[1].Set(data); + it->second.Invoke("call", args, 2, result); + callbacks_.remove(call_id); + } +} + void WebDevToolsClientImpl::JsGetResourceSource( const CppArgumentList& args, CppVariant* result) { - net_agent_stub_->GetResourceContent(args[0].ToInt32(), + int call_id = last_call_id_++; + net_agent_stub_->GetResourceContent(call_id, args[0].ToInt32(), webkit_glue::StdStringToString(args[1].ToString())); + callbacks_.set(call_id, args[1]); } void WebDevToolsClientImpl::JsGetDocumentElement( @@ -136,14 +161,18 @@ void WebDevToolsClientImpl::JsGetDocumentElement( CppVariant* result) { tools_agent_stub_->SetDomAgentEnabled(true); tools_agent_stub_->SetNetAgentEnabled(true); - dom_agent_stub_->GetDocumentElement(); + int call_id = last_call_id_++; + dom_agent_stub_->GetDocumentElement(call_id); + callbacks_.set(call_id, args[0]); result->SetNull(); } void WebDevToolsClientImpl::JsGetChildNodes( const CppArgumentList& args, CppVariant* result) { - dom_agent_stub_->GetChildNodes(args[0].ToInt32()); + int call_id = last_call_id_++; + dom_agent_stub_->GetChildNodes(call_id, args[0].ToInt32()); + callbacks_.set(call_id, args[1]); result->SetNull(); } diff --git a/webkit/glue/webdevtoolsclient_impl.h b/webkit/glue/webdevtoolsclient_impl.h index 9714d28..91ea321 100644 --- a/webkit/glue/webdevtoolsclient_impl.h +++ b/webkit/glue/webdevtoolsclient_impl.h @@ -7,6 +7,9 @@ #include <string> +#include <wtf/HashMap.h> +#include <wtf/OwnPtr.h> + #include "base/string_util.h" #include "webkit/glue/cpp_bound_class.h" #include "webkit/glue/devtools/devtools_rpc.h" @@ -38,7 +41,8 @@ class WebDevToolsClientImpl : public WebDevToolsClient, virtual ~WebDevToolsClientImpl(); // DomAgentDelegate implementation. - virtual void DocumentElementUpdated(const Value& value); + virtual void GetDocumentElementResult(int call_id, const std::string& value); + virtual void GetChildNodesResult(int call_id, const std::string& value); virtual void AttributesUpdated(int id, const Value& attributes); virtual void ChildNodesUpdated(int id, const Value& value); virtual void ChildNodeInserted( @@ -57,9 +61,9 @@ class WebDevToolsClientImpl : public WebDevToolsClient, const Value& response); virtual void DidFinishLoading(int identifier, const Value& response); virtual void DidFailLoading(int identifier, const Value& response); - virtual void SetResourceContent( - int identifier, - const WebCore::String& content); + virtual void GetResourceContentResult( + int call_id, + const std::string& content); // ToolsAgentDelegate implementation. virtual void UpdateFocusedNode(int node_id); @@ -71,6 +75,7 @@ class WebDevToolsClientImpl : public WebDevToolsClient, virtual void DispatchMessageFromAgent(const std::string& raw_msg); private: + void ProcessCallback(int call_id, const std::string& data); // MakeJsCall templates. void MakeJsCall(const std::string& func) { EvaluateJs(StringPrintf("%s()", func.c_str())); @@ -130,9 +135,11 @@ class WebDevToolsClientImpl : public WebDevToolsClient, WebViewImpl* web_view_impl_; WebDevToolsClientDelegate* delegate_; - scoped_ptr<DomAgentStub> dom_agent_stub_; - scoped_ptr<NetAgentStub> net_agent_stub_; - scoped_ptr<ToolsAgentStub> tools_agent_stub_; + OwnPtr<DomAgentStub> dom_agent_stub_; + OwnPtr<NetAgentStub> net_agent_stub_; + OwnPtr<ToolsAgentStub> tools_agent_stub_; + int last_call_id_; + HashMap<int, CppVariant> callbacks_; DISALLOW_COPY_AND_ASSIGN(WebDevToolsClientImpl); }; |