summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.cc2
-rw-r--r--webkit/glue/devtools/debugger_agent_impl.h8
-rw-r--r--webkit/glue/devtools/debugger_agent_manager.cc43
-rw-r--r--webkit/glue/devtools/debugger_agent_manager.h13
-rw-r--r--webkit/glue/webdevtoolsagent.h17
-rw-r--r--webkit/glue/webdevtoolsagent_delegate.h3
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc12
-rw-r--r--webkit/glue/webdevtoolsagent_impl.h2
8 files changed, 74 insertions, 26 deletions
diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc
index 299af72..88fc171 100644
--- a/webkit/glue/devtools/debugger_agent_impl.cc
+++ b/webkit/glue/devtools/debugger_agent_impl.cc
@@ -31,7 +31,7 @@ using WebCore::V8Proxy;
DebuggerAgentImpl::DebuggerAgentImpl(
WebViewImpl* web_view_impl,
DebuggerAgentDelegate* delegate,
- WebDevToolsAgent* webdevtools_agent)
+ WebDevToolsAgentImpl* webdevtools_agent)
: web_view_impl_(web_view_impl),
delegate_(delegate),
webdevtools_agent_(webdevtools_agent) {
diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h
index 664d506..acce569 100644
--- a/webkit/glue/devtools/debugger_agent_impl.h
+++ b/webkit/glue/devtools/debugger_agent_impl.h
@@ -8,7 +8,7 @@
#include "v8.h"
#include "webkit/glue/devtools/debugger_agent.h"
-class WebDevToolsAgent;
+class WebDevToolsAgentImpl;
class WebViewImpl;
namespace WebCore {
@@ -22,7 +22,7 @@ class DebuggerAgentImpl : public DebuggerAgent {
public:
DebuggerAgentImpl(WebViewImpl* web_view_impl,
DebuggerAgentDelegate* delegate,
- WebDevToolsAgent* webdevtools_agent);
+ WebDevToolsAgentImpl* webdevtools_agent);
virtual ~DebuggerAgentImpl();
// Initializes dom agent with the given document.
@@ -42,13 +42,13 @@ class DebuggerAgentImpl : public DebuggerAgent {
const WebCore::String& json_args);
WebCore::Page* GetPage();
- WebDevToolsAgent* webdevtools_agent() { return webdevtools_agent_; };
+ WebDevToolsAgentImpl* webdevtools_agent() { return webdevtools_agent_; };
private:
v8::Persistent<v8::Context> context_;
WebViewImpl* web_view_impl_;
DebuggerAgentDelegate* delegate_;
- WebDevToolsAgent* webdevtools_agent_;
+ WebDevToolsAgentImpl* webdevtools_agent_;
DISALLOW_COPY_AND_ASSIGN(DebuggerAgentImpl);
};
diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc
index 678c904..ef37b7d 100644
--- a/webkit/glue/devtools/debugger_agent_manager.cc
+++ b/webkit/glue/devtools/debugger_agent_manager.cc
@@ -15,6 +15,7 @@
#include "base/values.h"
#include "webkit/glue/devtools/debugger_agent_impl.h"
#include "webkit/glue/devtools/debugger_agent_manager.h"
+#include "webkit/glue/webdevtoolsagent_impl.h"
#if USE(V8)
#include "v8/include/v8-debug.h"
@@ -32,6 +33,15 @@ void DebuggerAgentManager::V8DebugMessageHandler(const uint16_t* message,
#endif
}
+void DebuggerAgentManager::V8DebugHostDispatchHandler(
+ void* dispatch,
+ void* data) {
+ WebDevToolsAgent::Message* m =
+ reinterpret_cast<WebDevToolsAgent::Message*>(dispatch);
+ m->Dispatch();
+ delete m;
+}
+
// static
DebuggerAgentManager::AttachedAgentsSet*
DebuggerAgentManager::attached_agents_ = NULL;
@@ -45,6 +55,9 @@ void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) {
&DebuggerAgentManager::V8DebugMessageHandler,
NULL, /* no additional data */
false /* don't create separate thread for sending debugger output */);
+ v8::Debug::SetHostDispatchHandler(
+ &DebuggerAgentManager::V8DebugHostDispatchHandler,
+ NULL /* no additional data */);
}
attached_agents_->add(debugger_agent);
#endif
@@ -61,6 +74,7 @@ void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) {
attached_agents_->remove(debugger_agent);
if (attached_agents_->isEmpty()) {
v8::Debug::SetMessageHandler(NULL);
+ v8::Debug::SetHostDispatchHandler(NULL);
delete attached_agents_;
attached_agents_ = NULL;
}
@@ -126,8 +140,8 @@ bool DebuggerAgentManager::SendCommandResponse(DictionaryValue* response) {
return false;
}
- int agent_ptr;
- if (!request_seq->GetInteger(L"webdevtools_agent", &agent_ptr)) {
+ int caller_id;
+ if (!request_seq->GetInteger(L"caller_id", &caller_id)) {
NOTREACHED();
return false;
}
@@ -140,7 +154,7 @@ bool DebuggerAgentManager::SendCommandResponse(DictionaryValue* response) {
}
DebuggerAgentImpl* debugger_agent = FindDebuggerAgentForToolsAgent(
- reinterpret_cast<WebDevToolsAgent*>(agent_ptr));
+ caller_id);
if (!debugger_agent) {
return false;
}
@@ -155,15 +169,23 @@ bool DebuggerAgentManager::SendCommandResponse(DictionaryValue* response) {
// static
void DebuggerAgentManager::ExecuteDebuggerCommand(
const std::string& command,
- WebDevToolsAgent* webdevtools_agent) {
+ int caller_id) {
const std::string cmd = DebuggerAgentManager::ReplaceRequestSequenceId(
command,
- webdevtools_agent);
+ caller_id);
SendCommandToV8(UTF8ToWide(cmd));
}
// static
+void DebuggerAgentManager::ScheduleMessageDispatch(
+ WebDevToolsAgent::Message* message) {
+#if USE(V8)
+ v8::Debug::SendHostDispatch(message);
+#endif
+}
+
+// static
void DebuggerAgentManager::SendCommandToV8(const std::wstring& cmd) {
#if USE(V8)
v8::Debug::SendCommand(reinterpret_cast<const uint16_t*>(cmd.data()),
@@ -195,7 +217,7 @@ DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() {
const std::string DebuggerAgentManager::ReplaceRequestSequenceId(
const std::string& request,
- WebDevToolsAgent* webdevtools_agent) {
+ int caller_id) {
OwnPtr<Value> message(JSONReader::Read(request,
false /* allow_trailing_comma */));
if (!message.get()) {
@@ -219,8 +241,7 @@ const std::string DebuggerAgentManager::ReplaceRequestSequenceId(
// TODO(yurys): get rid of this hack, handler pointer should be passed
// into v8::Debug::SendCommand along with the command.
- int agent_ptr = reinterpret_cast<int>(webdevtools_agent);
- new_seq.Set(L"webdevtools_agent", Value::CreateIntegerValue(agent_ptr));
+ new_seq.SetInteger(L"caller_id", caller_id);
// TODO(yurys): fix v8 parser so that it handle objects as ids correctly.
std::string new_seq_str;
@@ -232,13 +253,11 @@ const std::string DebuggerAgentManager::ReplaceRequestSequenceId(
return json;
}
-// Note that we cannot safely dereference 'webdevtools_agent' bacause the
-// referenced agent may already have been detached and destroyed.
DebuggerAgentImpl* DebuggerAgentManager::FindDebuggerAgentForToolsAgent(
- WebDevToolsAgent* webdevtools_agent) {
+ int caller_id) {
for (AttachedAgentsSet::iterator it = attached_agents_->begin();
it != attached_agents_->end(); ++it) {
- if ((*it)->webdevtools_agent() == webdevtools_agent) {
+ if ((*it)->webdevtools_agent()->host_id() == caller_id) {
return *it;
}
}
diff --git a/webkit/glue/devtools/debugger_agent_manager.h b/webkit/glue/devtools/debugger_agent_manager.h
index 39469b8..42f03cc 100644
--- a/webkit/glue/devtools/debugger_agent_manager.h
+++ b/webkit/glue/devtools/debugger_agent_manager.h
@@ -10,10 +10,10 @@
#include "base/basictypes.h"
#include "v8/include/v8-debug.h"
+#include "webkit/glue/webdevtoolsagent.h"
class DebuggerAgentImpl;
class DictionaryValue;
-class WebDevToolsAgent;
// There is single v8 instance per render process. Also there may be several
// RenderViews and consequently devtools agents in the process that want to talk
@@ -38,7 +38,11 @@ class DebuggerAgentManager {
static void DebugCommand(const std::string& command);
static void ExecuteDebuggerCommand(const std::string& command,
- WebDevToolsAgent* webdevtools_agent);
+ int caller_id);
+
+ // Requests that debugger makes a callback on the render thread while on
+ // breakpoint.
+ static void ScheduleMessageDispatch(WebDevToolsAgent::Message* message);
private:
DebuggerAgentManager();
@@ -47,17 +51,18 @@ class DebuggerAgentManager {
static void V8DebugMessageHandler(const uint16_t* message,
int length,
void* data);
+ static void V8DebugHostDispatchHandler(void* dispatch, void* data);
static void DebuggerOutput(const std::string& out);
static void SendCommandToV8(const std::wstring& cmd);
static bool SendCommandResponse(DictionaryValue* response);
static DebuggerAgentImpl* FindAgentForCurrentV8Context();
static DebuggerAgentImpl* FindDebuggerAgentForToolsAgent(
- WebDevToolsAgent* webdevtools_agent);
+ int caller_id);
static const std::string ReplaceRequestSequenceId(
const std::string& request,
- WebDevToolsAgent* webdevtools_agent);
+ int caller_id);
typedef HashSet<DebuggerAgentImpl*> AttachedAgentsSet;
static AttachedAgentsSet* attached_agents_;
diff --git a/webkit/glue/webdevtoolsagent.h b/webkit/glue/webdevtoolsagent.h
index 30b7b5d5..049964b 100644
--- a/webkit/glue/webdevtoolsagent.h
+++ b/webkit/glue/webdevtoolsagent.h
@@ -12,6 +12,15 @@
// direct and delegate Apis to the host.
class WebDevToolsAgent {
public:
+ class Message {
+ public:
+ Message() {}
+ virtual ~Message() {}
+ virtual void Dispatch() = 0;
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Message);
+ };
+
WebDevToolsAgent() {}
virtual ~WebDevToolsAgent() {}
@@ -24,9 +33,13 @@ class WebDevToolsAgent {
virtual void InspectElement(int x, int y) = 0;
// Asynchronously executes debugger command in the render thread.
- // |webdevtools_agent| will be used for sending response.
+ // |caller_id| will be used for sending response.
static void ExecuteDebuggerCommand(const std::string& command,
- WebDevToolsAgent* webdevtools_agent);
+ int caller_id);
+
+ // Requests that debugger makes a callback on the render thread while on
+ // breakpoint. Takes ownership of message.
+ static void ScheduleMessageDispatch(Message* message);
private:
DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgent);
diff --git a/webkit/glue/webdevtoolsagent_delegate.h b/webkit/glue/webdevtoolsagent_delegate.h
index d1305a3..4112e4f 100644
--- a/webkit/glue/webdevtoolsagent_delegate.h
+++ b/webkit/glue/webdevtoolsagent_delegate.h
@@ -15,6 +15,9 @@ class WebDevToolsAgentDelegate {
virtual void SendMessageToClient(const std::string& raw_msg) = 0;
+ // Returns the id of the entity hosting this agent.
+ virtual int GetHostId() = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(WebDevToolsAgentDelegate);
};
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 5602f45..11c64764 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -41,7 +41,8 @@ static const size_t kMaxConsoleMessages = 200;
WebDevToolsAgentImpl::WebDevToolsAgentImpl(
WebViewImpl* web_view_impl,
WebDevToolsAgentDelegate* delegate)
- : delegate_(delegate),
+ : host_id_(delegate->GetHostId()),
+ delegate_(delegate),
web_view_impl_(web_view_impl),
document_(NULL),
attached_(false) {
@@ -246,6 +247,11 @@ void WebDevToolsAgentImpl::SendRpcMessage(const std::string& raw_msg) {
// static
void WebDevToolsAgent::ExecuteDebuggerCommand(
const std::string& command,
- WebDevToolsAgent* webdevtools_agent) {
- DebuggerAgentManager::ExecuteDebuggerCommand(command, webdevtools_agent);
+ int caller_id) {
+ DebuggerAgentManager::ExecuteDebuggerCommand(command, caller_id);
+}
+
+// static
+void WebDevToolsAgent::ScheduleMessageDispatch(Message* message) {
+ DebuggerAgentManager::ScheduleMessageDispatch(message);
}
diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h
index 216bf9c..232e8e3 100644
--- a/webkit/glue/webdevtoolsagent_impl.h
+++ b/webkit/glue/webdevtoolsagent_impl.h
@@ -71,6 +71,7 @@ class WebDevToolsAgentImpl
const WebCore::String& source_id,
unsigned int line_no);
+ int host_id() { return host_id_; }
NetAgentImpl* net_agent_impl() { return net_agent_impl_.get(); }
private:
@@ -84,6 +85,7 @@ class WebDevToolsAgentImpl
WebCore::String source_id;
unsigned int line_no;
};
+ int host_id_;
WebDevToolsAgentDelegate* delegate_;
WebViewImpl* web_view_impl_;
WebCore::Document* document_;