summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/dom_agent_impl.h
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-12 13:03:51 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-12 13:03:51 +0000
commit097e38421957bcdf84a79fbed193570fbb2e647e (patch)
tree088062f435d940d67b06a1b7a35a5b0850cb9243 /webkit/glue/devtools/dom_agent_impl.h
parent31d58b18c3ae0bc157eab12371f5777f3340cabc (diff)
downloadchromium_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/devtools/dom_agent_impl.h')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.h b/webkit/glue/devtools/dom_agent_impl.h
new file mode 100644
index 0000000..12d7540
--- /dev/null
+++ b/webkit/glue/devtools/dom_agent_impl.h
@@ -0,0 +1,119 @@
+// 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.
+
+#ifndef WEBKIT_GLUE_DEVTOOLS_DOM_AGENT_IMPL_H_
+#define WEBKIT_GLUE_DEVTOOLS_DOM_AGENT_IMPL_H_
+
+#include "config.h"
+
+#include "EventListener.h"
+#include <wtf/ListHashSet.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+#include "webkit/glue/devtools/dom_agent.h"
+
+namespace WebCore {
+class Document;
+class Element;
+class Event;
+class Node;
+}
+
+class ListValue;
+class Value;
+
+// DomAgent implementation.
+class DomAgentImpl : public DomAgent {
+ public:
+ explicit DomAgentImpl(DomAgentDelegate* delegate);
+ virtual ~DomAgentImpl();
+
+ // DomAgent implementation.
+ void GetDocumentElement();
+ void GetChildNodes(int element_id);
+ void SetAttribute(
+ int element_id,
+ const WebCore::String& name,
+ const WebCore::String& value);
+ void RemoveAttribute(int element_id, const WebCore::String& name);
+ void SetTextNodeValue(int element_id, const WebCore::String& value);
+ void DiscardBindings();
+
+ // Initializes dom agent with the given document.
+ void SetDocument(WebCore::Document* document);
+
+ // Returns node for given id according to the present binding.
+ WebCore::Node* GetNodeForId(int id);
+
+ // Returns id for given node according to the present binding.
+ int GetIdForNode(WebCore::Node* node);
+
+ // Sends path to a given node to the client. Returns node's id according to
+ // the resulting binding.
+ int GetPathToNode(WebCore::Node* node);
+
+ private:
+ // Convenience EventListner wrapper for cleaner Ref management.
+ class EventListenerWrapper : public WebCore::EventListener {
+ public:
+ static PassRefPtr<EventListenerWrapper> Create(
+ DomAgentImpl* dom_agent_impl);
+ virtual ~EventListenerWrapper() {}
+ virtual void handleEvent(WebCore::Event* event, bool isWindowEvent);
+ private:
+ explicit EventListenerWrapper(DomAgentImpl* dom_agent_impl);
+ DomAgentImpl* dom_agent_impl_;
+ DISALLOW_COPY_AND_ASSIGN(EventListenerWrapper);
+ };
+
+ void StartListening(WebCore::Document* document);
+
+ void StopListening(WebCore::Document* document);
+
+ // EventListener implementation
+ friend class EventListenerWrapper;
+ virtual void handleEvent(WebCore::Event* event, bool isWindowEvent);
+
+ // Binds given node and returns its generated id.
+ int Bind(WebCore::Node* node);
+
+ // Releases Node to int binding.
+ void Unbind(WebCore::Node* node);
+
+ // Serializes given node into the list value.
+ ListValue* BuildValueForNode(
+ WebCore::Node* node,
+ int depth);
+
+ // Serializes given element's attributes into the list value.
+ ListValue* BuildValueForElementAttributes(WebCore::Element* elemen);
+
+ // Serializes given elements's children into the list value.
+ ListValue* BuildValueForElementChildren(
+ WebCore::Element* element,
+ int depth);
+
+ // We represent embedded doms as a part of the same hierarchy. Hence we
+ // treat children of frame owners differently. Following two methods
+ // encapsulate frame owner specifics.
+ WebCore::Node* InnerFirstChild(WebCore::Node* node);
+ int InnerChildNodeCount(WebCore::Node* node);
+ WebCore::Element* InnerParentElement(WebCore::Node* node);
+
+ DomAgentDelegate* delegate_;
+ HashMap<WebCore::Node*, int> node_to_id_;
+ HashMap<int, WebCore::Node*> id_to_node_;
+ HashSet<int> children_requested_;
+ int last_node_id_;
+ ListHashSet<RefPtr<WebCore::Document> > documents_;
+ RefPtr<WebCore::EventListener> event_listener_;
+ bool document_element_requested_;
+
+ DISALLOW_COPY_AND_ASSIGN(DomAgentImpl);
+};
+
+#endif // WEBKIT_GLUE_DEVTOOLS_DOM_AGENT_IMPL_H_