summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webkit/glue/devtools/debugger_agent_manager.cc35
-rw-r--r--webkit/glue/devtools/js/debugger_agent.js2
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp48
-rw-r--r--webkit/port/bindings/v8/v8_proxy.h6
4 files changed, 74 insertions, 17 deletions
diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc
index d0a08b6..102224f 100644
--- a/webkit/glue/devtools/debugger_agent_manager.cc
+++ b/webkit/glue/devtools/debugger_agent_manager.cc
@@ -179,17 +179,25 @@ void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) {
}
v8::Handle<v8::Context> context = message.GetEventContext();
- // If the context is from one of the inpected tabs it must have host_id in
- // the data field. See DebuggerAgentManager::SetHostId for more details.
- if (context.IsEmpty() || !context->GetData()->IsInt32()) {
+ // If the context is from one of the inpected tabs it should have its context
+ // data.
+ if (context.IsEmpty()) {
// Unknown context, skip the event.
return;
}
- int host_id = context->GetData()->Int32Value();
- DebuggerAgentImpl* agent = DebuggerAgentForHostId(host_id);
- if (agent) {
- agent->DebuggerOutput(out);
- } else if (!message.WillStartRunning()) {
+
+ // If the context is from one of the inpected tabs or injected extension
+ // scripts it must have host_id in the data field.
+ int host_id = WebCore::V8Proxy::GetContextDebugId(context);
+ if (host_id != -1) {
+ DebuggerAgentImpl* agent = DebuggerAgentForHostId(host_id);
+ if (agent) {
+ agent->DebuggerOutput(out);
+ return;
+ }
+ }
+
+ if (!message.WillStartRunning()) {
// Autocontinue execution on break and exception events if there is no
// handler.
SendContinueCommandToV8();
@@ -211,16 +219,11 @@ void DebuggerAgentManager::SetMessageLoopDispatchHandler(
// static
void DebuggerAgentManager::SetHostId(WebFrameImpl* webframe, int host_id) {
+ DCHECK(host_id > 0);
WebCore::V8Proxy* proxy = WebCore::V8Proxy::retrieve(webframe->frame());
- if (!proxy || !proxy->ContextInitialized()) {
- return;
- }
- v8::HandleScope scope;
- v8::Handle<v8::Context> context = proxy->GetContext();
- if (context.IsEmpty() || !context->GetData()->IsUndefined()) {
- return;
+ if (proxy) {
+ proxy->SetContextDebugId(host_id);
}
- context->SetData(v8::Integer::New(host_id));
}
// static
diff --git a/webkit/glue/devtools/js/debugger_agent.js b/webkit/glue/devtools/js/debugger_agent.js
index e4cdbba..3e22176 100644
--- a/webkit/glue/devtools/js/debugger_agent.js
+++ b/webkit/glue/devtools/js/debugger_agent.js
@@ -589,7 +589,7 @@ devtools.DebuggerAgent.prototype.isScriptFromInspectedContext_ = function(
if (this.contextId_ === null) {
return true;
}
- return (scriptContextId == this.contextId_);
+ return (scriptContextId.value == this.contextId_);
};
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index 7831b39..706a620 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -57,6 +57,9 @@ v8::Persistent<v8::Context> V8Proxy::m_utilityContext;
// Static list of registered extensions
V8ExtensionList V8Proxy::m_extensions;
+// static
+const char* V8Proxy::kContextDebugDataType = "type";
+const char* V8Proxy::kContextDebugDataValue = "value";
#ifndef NDEBUG
// Keeps track of global handles created (not JS wrappers
@@ -1012,6 +1015,21 @@ void V8Proxy::evaluateInNewContext(const Vector<ScriptSourceCode>& sources)
v8::Persistent<v8::Context> context =
createNewContext(v8::Handle<v8::Object>());
v8::Context::Scope context_scope(context);
+
+ // Setup context id for JS debugger.
+ v8::Handle<v8::Object> context_data = v8::Object::New();
+ v8::Handle<v8::Value> window_context_data = windowContext->GetData();
+ if (window_context_data->IsObject()) {
+ v8::Handle<v8::String> property_name =
+ v8::String::New(kContextDebugDataValue);
+ context_data->Set(
+ property_name,
+ v8::Object::Cast(*window_context_data)->Get(property_name));
+ }
+ context_data->Set(v8::String::New(kContextDebugDataType),
+ v8::String::New("injected"));
+ context->SetData(context_data);
+
v8::Handle<v8::Object> global = context->Global();
v8::Handle<v8::String> implicitProtoString = v8::String::New("__proto__");
@@ -3410,4 +3428,34 @@ void V8Proxy::RegisterExtension(v8::Extension* extension,
m_extensions.push_back(info);
}
+bool V8Proxy::SetContextDebugId(int debug_id) {
+ ASSERT(debug_id > 0);
+ if (m_context.IsEmpty()) {
+ return false;
+ }
+ v8::HandleScope scope;
+ if (!m_context->GetData()->IsUndefined()) {
+ return false;
+ }
+
+ v8::Handle<v8::Object> context_data = v8::Object::New();
+ context_data->Set(v8::String::New(kContextDebugDataType),
+ v8::String::New("page"));
+ context_data->Set(v8::String::New(kContextDebugDataValue),
+ v8::Integer::New(debug_id));
+ m_context->SetData(context_data);
+ return true;
+}
+
+// static
+int V8Proxy::GetContextDebugId(v8::Handle<v8::Context> context) {
+ v8::HandleScope scope;
+ if (!context->GetData()->IsObject()) {
+ return -1;
+ }
+ v8::Handle<v8::Value> data = context->GetData()->ToObject()->Get(
+ v8::String::New(kContextDebugDataValue));
+ return data->IsInt32() ? data->Int32Value() : -1;
+}
+
} // namespace WebCore
diff --git a/webkit/port/bindings/v8/v8_proxy.h b/webkit/port/bindings/v8/v8_proxy.h
index 48e20a9..b1059e9 100644
--- a/webkit/port/bindings/v8/v8_proxy.h
+++ b/webkit/port/bindings/v8/v8_proxy.h
@@ -485,6 +485,9 @@ class V8Proxy {
return v8::Local<v8::Context>::New(m_context);
}
+ bool SetContextDebugId(int id);
+ static int GetContextDebugId(v8::Handle<v8::Context> context);
+
// Registers an extension to be available on webpages with a particular scheme
// If the scheme argument is empty, the extension is available on all pages.
// Will only affect v8 contexts initialized after this call. Takes ownership
@@ -496,6 +499,9 @@ class V8Proxy {
v8::Handle<v8::Value> object);
private:
+ static const char* kContextDebugDataType;
+ static const char* kContextDebugDataValue;
+
v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global);
void InitContextIfNeeded();
void DisconnectEventListeners();