diff options
author | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 10:26:45 +0000 |
---|---|---|
committer | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-21 10:26:45 +0000 |
commit | 2e8a996ad3d029cba5a8d7d6332419af67e032ef (patch) | |
tree | a5de12d043ac73562948a52a5f49d66717627d5d /webkit | |
parent | c66117012c0cc936c9b494eccccdbca31a09f379 (diff) | |
download | chromium_src-2e8a996ad3d029cba5a8d7d6332419af67e032ef.zip chromium_src-2e8a996ad3d029cba5a8d7d6332419af67e032ef.tar.gz chromium_src-2e8a996ad3d029cba5a8d7d6332419af67e032ef.tar.bz2 |
DevTools: Reverting 16586. Necessary v8 changes are not rolled yet.
Review URL: http://codereview.chromium.org/115630
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16593 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/debugger_agent_manager.cc | 121 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_manager.h | 8 |
2 files changed, 80 insertions, 49 deletions
diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc index ae54973..3cdd09d 100644 --- a/webkit/glue/devtools/debugger_agent_manager.cc +++ b/webkit/glue/devtools/debugger_agent_manager.cc @@ -51,7 +51,7 @@ class CallerIdWrapper : public v8::Debug::ClientData { void DebuggerAgentManager::V8DebugHostDispatchHandler() { if (!DebuggerAgentManager::message_loop_dispatch_handler_ || - !attached_agents_map_) { + !attached_agents_) { return; } if (in_host_dispatch_handler_) { @@ -61,10 +61,10 @@ void DebuggerAgentManager::V8DebugHostDispatchHandler() { Vector<WebViewImpl*> views; // 1. Disable active objects and input events. - for (AttachedAgentsMap::iterator it = attached_agents_map_->begin(); - it != attached_agents_map_->end(); + for (AttachedAgentsSet::iterator it = attached_agents_->begin(); + it != attached_agents_->end(); ++it) { - DebuggerAgentImpl* agent = it->second; + DebuggerAgentImpl* agent = *it; page_deferrers_.set( agent->web_view(), new WebCore::PageGroupLoadDeferrer(agent->GetPage(), true)); @@ -88,7 +88,7 @@ void DebuggerAgentManager::V8DebugHostDispatchHandler() { page_deferrers_.clear(); in_host_dispatch_handler_ = false; - if (!attached_agents_map_) { + if (!attached_agents_) { // Remove handlers if all agents were detached within host dispatch. v8::Debug::SetMessageHandler(NULL); v8::Debug::SetHostDispatchHandler(NULL); @@ -96,35 +96,34 @@ void DebuggerAgentManager::V8DebugHostDispatchHandler() { } // static -DebuggerAgentManager::AttachedAgentsMap* - DebuggerAgentManager::attached_agents_map_ = NULL; +DebuggerAgentManager::AttachedAgentsSet* + DebuggerAgentManager::attached_agents_ = NULL; // static void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) { - if (!attached_agents_map_) { - attached_agents_map_ = new AttachedAgentsMap(); +#if USE(V8) + if (!attached_agents_) { + attached_agents_ = new AttachedAgentsSet(); v8::Debug::SetMessageHandler2(&DebuggerAgentManager::OnV8DebugMessage); v8::Debug::SetHostDispatchHandler( &DebuggerAgentManager::V8DebugHostDispatchHandler, 100 /* ms */); } - int host_id = debugger_agent->webdevtools_agent()->host_id(); - DCHECK(host_id != 0); - attached_agents_map_->set(host_id, debugger_agent); + attached_agents_->add(debugger_agent); +#endif } // static void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { - if (!attached_agents_map_) { +#if USE(V8) + if (!attached_agents_) { NOTREACHED(); return; } - int host_id = debugger_agent->webdevtools_agent()->host_id(); - DCHECK(attached_agents_map_->get(host_id) == debugger_agent); - attached_agents_map_->remove(host_id); - - if (attached_agents_map_->isEmpty()) { - delete attached_agents_map_; - attached_agents_map_ = NULL; + DCHECK(attached_agents_->contains(debugger_agent)); + attached_agents_->remove(debugger_agent); + if (attached_agents_->isEmpty()) { + delete attached_agents_; + attached_agents_ = NULL; // Note that we do not empty handlers while in dispatch - we schedule // continue and do removal once we are out of the dispatch. if (!in_host_dispatch_handler_) { @@ -135,13 +134,13 @@ void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { SendContinueCommandToV8(); } } +#endif } // static void DebuggerAgentManager::DebugBreak(DebuggerAgentImpl* debugger_agent) { #if USE(V8) - DCHECK(DebuggerAgentForHostId(debugger_agent->webdevtools_agent()->host_id()) - == debugger_agent); + DCHECK(attached_agents_->contains(debugger_agent)); v8::Debug::DebugBreak(); #endif } @@ -159,13 +158,10 @@ void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) { // Just ignore messages sent by this manager. return; } - DebuggerAgentImpl* debugger_agent = - DebuggerAgentForHostId(wrapper->caller_id()); + DebuggerAgentImpl* debugger_agent = FindDebuggerAgentForToolsAgent( + wrapper->caller_id()); if (debugger_agent) { debugger_agent->DebuggerOutput(out); - } else if (!message.WillStartRunning()) { - // Autocontinue execution if there is no handler. - SendContinueCommandToV8(); } return; } // Otherwise it's an event message. @@ -178,15 +174,44 @@ void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) { return; } - 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()) { - // Unknown context, skip the event. - return; + // Filter out events from the utility context. + // TODO(yurys): add global context accessor to v8 API. + if (message.GetEvent() == v8::AfterCompile) { + // Note that message.GetEventContext() will return context active when we + // entered the debugger. It's not necessarily the global context where the + // script is compiled so to get the scripts' context we call JS methods on + // the event data. + v8::Handle<v8::Object> compileEvent = message.GetEventData(); + v8::Handle<v8::Value> scriptGetter = + compileEvent->Get(v8::String::New("script")); + v8::Local<v8::Function> fun = v8::Function::Cast(*scriptGetter); + v8::Local<v8::Object> script_mirror = + v8::Object::Cast(*fun->Call(compileEvent, 0, NULL)); + + v8::Handle<v8::Value> contextGetter = + script_mirror->Get(v8::String::New("context")); + v8::Local<v8::Function> contextGetterFunc = + v8::Function::Cast(*contextGetter); + v8::Local<v8::Object> context_mirror = + v8::Object::Cast(*contextGetterFunc->Call(script_mirror, 0, NULL)); + + v8::Handle<v8::Value> dataGetter = + context_mirror->Get(v8::String::New("data")); + v8::Local<v8::Function> dataGetterFunc = + v8::Function::Cast(*dataGetter); + v8::Local<v8::Value> data = + *dataGetterFunc->Call(context_mirror, 0, NULL); + + // 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 (data.IsEmpty() || !data->IsInt32()) { + return; + } } - int host_id = context->GetData()->Int32Value(); - DebuggerAgentImpl* agent = DebuggerAgentForHostId(host_id); + + // Agent that should be used for sending events is determined based + // on the active Frame. + DebuggerAgentImpl* agent = FindAgentForCurrentV8Context(); if (agent) { agent->DebuggerOutput(out); } else if (!message.WillStartRunning()) { @@ -196,6 +221,7 @@ void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) { } } + // static void DebuggerAgentManager::ExecuteDebuggerCommand( const std::string& command, @@ -249,29 +275,32 @@ void DebuggerAgentManager::SendContinueCommandToV8() { // static DebuggerAgentImpl* DebuggerAgentManager::FindAgentForCurrentV8Context() { - if (!attached_agents_map_) { + if (!attached_agents_) { return NULL; } - DCHECK(!attached_agents_map_->isEmpty()); + DCHECK(!attached_agents_->isEmpty()); WebCore::Frame* frame = WebCore::V8Proxy::retrieveFrameForEnteredContext(); if (!frame) { return NULL; } WebCore::Page* page = frame->page(); - for (AttachedAgentsMap::iterator it = attached_agents_map_->begin(); - it != attached_agents_map_->end(); ++it) { - if (it->second->GetPage() == page) { - return it->second; + for (AttachedAgentsSet::iterator it = attached_agents_->begin(); + it != attached_agents_->end(); ++it) { + if ((*it)->GetPage() == page) { + return *it; } } return NULL; } -// static -DebuggerAgentImpl* DebuggerAgentManager::DebuggerAgentForHostId(int host_id) { - if (!attached_agents_map_) { - return NULL; +DebuggerAgentImpl* DebuggerAgentManager::FindDebuggerAgentForToolsAgent( + int caller_id) { + for (AttachedAgentsSet::iterator it = attached_agents_->begin(); + it != attached_agents_->end(); ++it) { + if ((*it)->webdevtools_agent()->host_id() == caller_id) { + return *it; + } } - return attached_agents_map_->get(host_id); + return NULL; } diff --git a/webkit/glue/devtools/debugger_agent_manager.h b/webkit/glue/devtools/debugger_agent_manager.h index 3726eb6..e0774bb 100644 --- a/webkit/glue/devtools/debugger_agent_manager.h +++ b/webkit/glue/devtools/debugger_agent_manager.h @@ -6,6 +6,7 @@ #define WEBKIT_GLUE_DEVTOOLS_DEBUGGER_AGENT_MANAGER_H_ #include <wtf/HashMap.h> +#include <wtf/HashSet.h> #include "base/basictypes.h" #include "v8/include/v8-debug.h" @@ -61,10 +62,11 @@ class DebuggerAgentManager { static void SendContinueCommandToV8(); static DebuggerAgentImpl* FindAgentForCurrentV8Context(); - static DebuggerAgentImpl* DebuggerAgentForHostId(int host_id); + static DebuggerAgentImpl* FindDebuggerAgentForToolsAgent( + int caller_id); - typedef HashMap<int, DebuggerAgentImpl*> AttachedAgentsMap; - static AttachedAgentsMap* attached_agents_map_; + typedef HashSet<DebuggerAgentImpl*> AttachedAgentsSet; + static AttachedAgentsSet* attached_agents_; static WebDevToolsAgent::MessageLoopDispatchHandler message_loop_dispatch_handler_; |