summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 15:36:05 +0000
committeryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-11 15:36:05 +0000
commitc75e714bd7bbbf83618fa9f5cfc79619e6530f77 (patch)
treeedd832dd14c8045226316c1132c143b0ea8dca6e
parentf4fbe8bf4d1df0530c807072707036a3e20a02f0 (diff)
downloadchromium_src-c75e714bd7bbbf83618fa9f5cfc79619e6530f77.zip
chromium_src-c75e714bd7bbbf83618fa9f5cfc79619e6530f77.tar.gz
chromium_src-c75e714bd7bbbf83618fa9f5cfc79619e6530f77.tar.bz2
DevTools: when injected script context is created its context data is set to the value derived from the context data of the page it's injected in. It allows to match injected scripts with the inspected page.
BUG=13676 Review URL: http://codereview.chromium.org/122036 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18164 0039d316-1c4b-4281-b951-d872f2087c98
-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();