diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-12 13:03:51 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-12 13:03:51 +0000 |
commit | 097e38421957bcdf84a79fbed193570fbb2e647e (patch) | |
tree | 088062f435d940d67b06a1b7a35a5b0850cb9243 /webkit/glue/webdevtoolsclient_impl.cc | |
parent | 31d58b18c3ae0bc157eab12371f5777f3340cabc (diff) | |
download | chromium_src-097e38421957bcdf84a79fbed193570fbb2e647e.zip chromium_src-097e38421957bcdf84a79fbed193570fbb2e647e.tar.gz chromium_src-097e38421957bcdf84a79fbed193570fbb2e647e.tar.bz2 |
Initial WebDevToolsAgent implementation contains two agent objects: Dom agent
and Net agent.
Dom agent provides API for querying for DOM nodes and receiving notifications
on
Dom updates. It has some logic in and this logic is covered with the unit
tests.
Net agent pushes an initial set of request/response-related events to the
client. It is to be filled with more data later on. It currently caches loaders
for all the requests which is Ok for the case when this agent is turned ON (at
least for now).
Note that this code is not yet wired to the dev tools agent (this is by design).
The plan is to start enrolling the dev tools agent glue that connects these
sub-agents with the IPC transport once this CL is in.
Original CL: http://codereview.chromium.org/41008/show
Review URL: http://codereview.chromium.org/43128
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/webdevtoolsclient_impl.cc')
-rw-r--r-- | webkit/glue/webdevtoolsclient_impl.cc | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/webkit/glue/webdevtoolsclient_impl.cc b/webkit/glue/webdevtoolsclient_impl.cc new file mode 100644 index 0000000..07f0055 --- /dev/null +++ b/webkit/glue/webdevtoolsclient_impl.cc @@ -0,0 +1,225 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" +#include "webkit/glue/webdevtoolsclient_impl.h" + +#include <string> + +#include "CString.h" +#include "Document.h" +#include "InspectorController.h" +#include "Node.h" +#include "Page.h" +#include "PlatformString.h" + +#include "base/json_reader.h" +#include "base/json_writer.h" +#include "base/string_util.h" +#include "base/values.h" + +#include "webkit/glue/glue_util.h" +#include "webkit/glue/webdevtoolsclient_delegate.h" +#include "webkit/glue/webframe.h" +#include "webkit/glue/webview_impl.h" + +using WebCore::CString; +using WebCore::Document; +using WebCore::InspectorController; +using WebCore::Node; +using WebCore::Page; +using WebCore::String; + +/*static*/ +WebDevToolsClient* WebDevToolsClient::Create( + WebView* view, + WebDevToolsClientDelegate* delegate) { + return new WebDevToolsClientImpl(static_cast<WebViewImpl*>(view), delegate); +} + +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)); + + BindToJavascript(web_view_impl_->GetMainFrame(), L"DevToolsHost"); + BindMethod("getDocumentElement", + &WebDevToolsClientImpl::JsGetDocumentElement); + BindMethod("getChildNodes", &WebDevToolsClientImpl::JsGetChildNodes); + BindMethod("setAttribute", &WebDevToolsClientImpl::JsSetAttribute); + BindMethod("removeAttribute", &WebDevToolsClientImpl::JsRemoveAttribute); + BindMethod("setTextNodeValue", &WebDevToolsClientImpl::JsSetTextNodeValue); + BindMethod("highlightDOMNode", &WebDevToolsClientImpl::JsHighlightDOMNode); + BindMethod("hideDOMNodeHighlight", + &WebDevToolsClientImpl::JsHideDOMNodeHighlight); +} + +WebDevToolsClientImpl::~WebDevToolsClientImpl() { +} + +// DomAgent::DomAgentDelegate implementation. +void WebDevToolsClientImpl::DocumentElementUpdated(const Value& value) { + MakeJsCall("dom.setDocumentElement", &value); +} + +void WebDevToolsClientImpl::AttributesUpdated(int id, const Value& attributes) { + MakeJsCall("dom.setAttributes", id, &attributes); +} + +void WebDevToolsClientImpl::ChildNodesUpdated(int id, const Value& children) { + MakeJsCall("dom.setChildren", id, &children); +} + +void WebDevToolsClientImpl::ChildNodeInserted( + int parent_id, + int prev_id, + const Value& value) { + MakeJsCall("dom.nodeInserted", parent_id, prev_id, &value); +} + +void WebDevToolsClientImpl::ChildNodeRemoved(int parent_id, int id) { + MakeJsCall("dom.nodeRemoved", parent_id, id); +} + +void WebDevToolsClientImpl::HasChildrenUpdated(int id, bool new_value) { + MakeJsCall("dom.setHasChildren", id, true); +} + +// NetAgent::NetAgentDelegate implementation. +void WebDevToolsClientImpl::WillSendRequest( + int identifier, + const Value& request) { + MakeJsCall("net.willSendRequest", identifier, &request); +} + +void WebDevToolsClientImpl::DidReceiveResponse( + int identifier, + const Value& response) { + MakeJsCall("net.didReceiveResponse", identifier, &response); +} + +void WebDevToolsClientImpl::DidFinishLoading(int identifier, + const Value& response) { + MakeJsCall("net.didFinishLoading", identifier, &response); +} + +void WebDevToolsClientImpl::DidFailLoading(int identifier, + const Value& response) { + MakeJsCall("net.didFailLoading", identifier, &response); +} + +void WebDevToolsClientImpl::SetResourceContent( + int identifier, + const String& content) { + MakeJsCall("net.setResourceContent", identifier, content); +} + +void WebDevToolsClientImpl::UpdateFocusedNode(int node_id) { + MakeJsCall("tools.updateFocusedNode", node_id); +} + +void WebDevToolsClientImpl::JsGetResourceSource( + const CppArgumentList& args, + CppVariant* result) { + net_agent_stub_->GetResourceContent(args[0].ToInt32(), + webkit_glue::StdStringToString(args[1].ToString())); +} + +void WebDevToolsClientImpl::JsGetDocumentElement( + const CppArgumentList& args, + CppVariant* result) { + tools_agent_stub_->SetDomAgentEnabled(true); + tools_agent_stub_->SetNetAgentEnabled(true); + dom_agent_stub_->GetDocumentElement(); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsGetChildNodes( + const CppArgumentList& args, + CppVariant* result) { + dom_agent_stub_->GetChildNodes(args[0].ToInt32()); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsSetAttribute( + const CppArgumentList& args, + CppVariant* result) { + dom_agent_stub_->SetAttribute(args[0].ToInt32(), + webkit_glue::StdStringToString(args[1].ToString()), + webkit_glue::StdStringToString(args[2].ToString())); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsRemoveAttribute( + const CppArgumentList& args, + CppVariant* result) { + dom_agent_stub_->RemoveAttribute(args[0].ToInt32(), + webkit_glue::StdStringToString(args[1].ToString())); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsSetTextNodeValue( + const CppArgumentList& args, + CppVariant* result) { + dom_agent_stub_->SetTextNodeValue(args[0].ToInt32(), + webkit_glue::StdStringToString(args[1].ToString())); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsHighlightDOMNode( + const CppArgumentList& args, + CppVariant* result) { + tools_agent_stub_->HighlightDOMNode(args[0].ToInt32()); + result->SetNull(); +} + +void WebDevToolsClientImpl::JsHideDOMNodeHighlight(const CppArgumentList& args, + CppVariant* result) { + tools_agent_stub_->HideDOMNodeHighlight(); + result->SetNull(); +} + +void WebDevToolsClientImpl::EvaluateJs(const String& expr) { + web_view_impl_->GetMainFrame()->ExecuteJavaScript( + webkit_glue::StringToStdString(expr), + GURL(), // script url + 1); // base line number +} + +void WebDevToolsClientImpl::DispatchMessageFromAgent( + const std::string& raw_msg) { + if (dom_agent_delegate_dispatch_.Dispatch(this, raw_msg)) + return; + if (net_agent_delegate_dispatch_.Dispatch(this, raw_msg)) + return; + if (tools_agent_delegate_dispatch_.Dispatch(this, raw_msg)) + return; +} + +void WebDevToolsClientImpl::SendRpcMessage(const std::string& raw_msg) { + delegate_->SendMessageToAgent(raw_msg); +} + +// static +CString WebDevToolsClientImpl::ToJSON(const String& value) { + StringValue str(webkit_glue::StringToStdString(value)); + return ToJSON(&str); +} + +// static +CString WebDevToolsClientImpl::ToJSON(int value) { + FundamentalValue fund(value); + return ToJSON(&fund); +} + +// static +CString WebDevToolsClientImpl::ToJSON(const Value* value) { + std::string json; + JSONWriter::Write(value, false, &json); + return webkit_glue::StdStringToString(json).utf8(); +} |