diff options
author | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 08:18:15 +0000 |
---|---|---|
committer | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-13 08:18:15 +0000 |
commit | 21f565c6b0eee70867af3853e6f8105a2d2b2067 (patch) | |
tree | 4b9e24114e539f1c3b0ea87e13ccd313837ba770 /webkit | |
parent | 62a6c0428093c7aa045c31ee0d9d85a92631d406 (diff) | |
download | chromium_src-21f565c6b0eee70867af3853e6f8105a2d2b2067.zip chromium_src-21f565c6b0eee70867af3853e6f8105a2d2b2067.tar.gz chromium_src-21f565c6b0eee70867af3853e6f8105a2d2b2067.tar.bz2 |
Page global contexts are assigned uniques ids.Script list now contain scripts from the inspected tab only.Also switched DebuggerAgentManager to MessageHandler2 that accepts v8::Debug::Message instead of string.
Review URL: http://codereview.chromium.org/115032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15945 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/devtools/debugger_agent.h | 8 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_impl.h | 1 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_manager.cc | 50 | ||||
-rw-r--r-- | webkit/glue/devtools/debugger_agent_manager.h | 18 | ||||
-rw-r--r-- | webkit/glue/devtools/js/debugger_agent.js | 58 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools_host_stub.js | 13 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 4 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 4 | ||||
-rw-r--r-- | webkit/glue/webframeloaderclient_impl.cc | 5 |
10 files changed, 118 insertions, 47 deletions
diff --git a/webkit/glue/devtools/debugger_agent.h b/webkit/glue/devtools/debugger_agent.h index 213cf28..45dc899 100644 --- a/webkit/glue/devtools/debugger_agent.h +++ b/webkit/glue/devtools/debugger_agent.h @@ -10,13 +10,17 @@ #define DEBUGGER_AGENT_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, \ METHOD4) \ /* Stops v8 execution as soon as it gets control. */ \ - METHOD0(DebugBreak) + METHOD0(DebugBreak) \ + /* Requests global context id of the inspected tab. */ \ + METHOD0(GetContextId) DEFINE_RPC_CLASS(DebuggerAgent, DEBUGGER_AGENT_STRUCT) #define DEBUGGER_AGENT_DELEGATE_STRUCT(METHOD0, METHOD1, METHOD2, METHOD3, \ METHOD4) \ - METHOD1(DebuggerOutput, std::string /* output text */) + METHOD1(DebuggerOutput, std::string /* output text */) \ + /* Response to GetContextId. */ \ + METHOD1(DidGetContextId, int /* context id */) DEFINE_RPC_CLASS(DebuggerAgentDelegate, DEBUGGER_AGENT_DELEGATE_STRUCT) diff --git a/webkit/glue/devtools/debugger_agent_impl.cc b/webkit/glue/devtools/debugger_agent_impl.cc index 1bcbf78..7dabb61 100644 --- a/webkit/glue/devtools/debugger_agent_impl.cc +++ b/webkit/glue/devtools/debugger_agent_impl.cc @@ -54,6 +54,10 @@ void DebuggerAgentImpl::DebugBreak() { DebuggerAgentManager::DebugBreak(this); } +void DebuggerAgentImpl::GetContextId() { + delegate_->DidGetContextId(webdevtools_agent_->host_id()); +} + void DebuggerAgentImpl::DebuggerOutput(const std::string& command) { delegate_->DebuggerOutput(command); webdevtools_agent_->ForceRepaint(); diff --git a/webkit/glue/devtools/debugger_agent_impl.h b/webkit/glue/devtools/debugger_agent_impl.h index 5d8e6f8..2644610 100644 --- a/webkit/glue/devtools/debugger_agent_impl.h +++ b/webkit/glue/devtools/debugger_agent_impl.h @@ -34,6 +34,7 @@ class DebuggerAgentImpl : public DebuggerAgent { // DebuggerAgent implementation. virtual void DebugBreak(); + virtual void GetContextId(); void DebuggerOutput(const std::string& out); diff --git a/webkit/glue/devtools/debugger_agent_manager.cc b/webkit/glue/devtools/debugger_agent_manager.cc index 41461c8..aa96ec8 100644 --- a/webkit/glue/devtools/debugger_agent_manager.cc +++ b/webkit/glue/devtools/debugger_agent_manager.cc @@ -10,10 +10,7 @@ #include <wtf/HashSet.h> #undef LOG -#include "base/json_reader.h" -#include "base/json_writer.h" #include "base/string_util.h" -#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" @@ -52,17 +49,6 @@ class CallerIdWrapper : public v8::Debug::ClientData { } // namespace -// static -void DebuggerAgentManager::V8DebugMessageHandler(const uint16_t* message, - int length, - v8::Debug::ClientData* data) { -#if USE(V8) - std::wstring out(reinterpret_cast<const wchar_t*>(message), length); - std::string out_utf8 = WideToUTF8(out); - DebuggerAgentManager::DebuggerOutput(out_utf8, data); -#endif -} - void DebuggerAgentManager::V8DebugHostDispatchHandler() { if (!DebuggerAgentManager::message_loop_dispatch_handler_ || !attached_agents_) { @@ -118,9 +104,7 @@ void DebuggerAgentManager::DebugAttach(DebuggerAgentImpl* debugger_agent) { #if USE(V8) if (!attached_agents_) { attached_agents_ = new AttachedAgentsSet(); - v8::Debug::SetMessageHandler( - &DebuggerAgentManager::V8DebugMessageHandler, - false /* don't create separate thread for sending debugger output */); + v8::Debug::SetMessageHandler2(&DebuggerAgentManager::OnV8DebugMessage); v8::Debug::SetHostDispatchHandler( &DebuggerAgentManager::V8DebugHostDispatchHandler, 100 /* ms */); } @@ -143,7 +127,7 @@ void DebuggerAgentManager::DebugDetach(DebuggerAgentImpl* debugger_agent) { // 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_) { - v8::Debug::SetMessageHandler(NULL); + v8::Debug::SetMessageHandler2(NULL); v8::Debug::SetHostDispatchHandler(NULL); } else if (FindAgentForCurrentV8Context() == debugger_agent) { // Force continue just in case to handle close while on a breakpoint. @@ -162,10 +146,13 @@ void DebuggerAgentManager::DebugBreak(DebuggerAgentImpl* debugger_agent) { } // static -void DebuggerAgentManager::DebuggerOutput(const std::string& out, - v8::Debug::ClientData* caller_data) { +void DebuggerAgentManager::OnV8DebugMessage(const v8::Debug::Message& message) { + v8::HandleScope scope; + v8::String::Utf8Value value(message.GetJSON()); + std::string out(*value, value.length()); + // If caller_data is not NULL the message is a response to a debugger command. - if (caller_data) { + if (v8::Debug::ClientData* caller_data = message.GetClientData()) { CallerIdWrapper* wrapper = static_cast<CallerIdWrapper*>(caller_data); if (wrapper->caller_is_mananager()) { // Just ignore messages sent by this manager. @@ -178,17 +165,18 @@ void DebuggerAgentManager::DebuggerOutput(const std::string& out, } return; } // Otherwise it's an event message. + DCHECK(message.IsEvent()); // Agent that should be used for sending events is determined based // on the active Frame. DebuggerAgentImpl* agent = FindAgentForCurrentV8Context(); - if (!agent) { + if (agent) { + agent->DebuggerOutput(out); + } else if (!message.WillStartRunning()) { // Autocontinue execution on break and exception events if there is no // handler. SendContinueCommandToV8(); - return; } - agent->DebuggerOutput(out); } // static @@ -205,6 +193,20 @@ void DebuggerAgentManager::SetMessageLoopDispatchHandler( } // static +void DebuggerAgentManager::SetHostId(WebFrameImpl* webframe, int host_id) { + 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; + } + context->SetData(v8::Integer::New(host_id)); +} + +// static void DebuggerAgentManager::OnWebViewClosed(WebViewImpl* webview) { if (page_deferrers_.contains(webview)) { delete page_deferrers_.get(webview); diff --git a/webkit/glue/devtools/debugger_agent_manager.h b/webkit/glue/devtools/debugger_agent_manager.h index 87cf3d8..e0774bb 100644 --- a/webkit/glue/devtools/debugger_agent_manager.h +++ b/webkit/glue/devtools/debugger_agent_manager.h @@ -18,6 +18,7 @@ class PageGroupLoadDeferrer; class DebuggerAgentImpl; class DictionaryValue; +class WebFrameImpl; class WebViewImpl; // There is single v8 instance per render process. Also there may be several @@ -28,13 +29,10 @@ class WebViewImpl; // detached. When message is received from debugger it will route it to the // right debugger agent if there is one otherwise the message will be ignored. // -// TODO(yurys): v8 may send a message(e.g. exception event) after which it +// v8 may send a message(e.g. exception event) after which it // would expect some actions from the handler. If there is no appropriate -// debugger agent to handle such messages the manager should perform the action +// debugger agent to handle such messages the manager will perform the action // itself, otherwise v8 may hang waiting for the action. -// -// TODO(yurys): disable plugin message handling while v8 is paused on a -// breakpoint. class DebuggerAgentManager { public: static void DebugAttach(DebuggerAgentImpl* debugger_agent); @@ -47,18 +45,18 @@ class DebuggerAgentManager { static void SetMessageLoopDispatchHandler( WebDevToolsAgent::MessageLoopDispatchHandler handler); + // Sets |host_id| as the frame context data. This id is used to filter scripts + // related to the inspected page. + static void SetHostId(WebFrameImpl* webframe, int host_id); + static void OnWebViewClosed(WebViewImpl* webview); private: DebuggerAgentManager(); ~DebuggerAgentManager(); - static void V8DebugMessageHandler(const uint16_t* message, - int length, - v8::Debug::ClientData* data); static void V8DebugHostDispatchHandler(); - static void DebuggerOutput(const std::string& out, - v8::Debug::ClientData* caller_data); + static void OnV8DebugMessage(const v8::Debug::Message& message); static void SendCommandToV8(const std::wstring& cmd, v8::Debug::ClientData* data); static void SendContinueCommandToV8(); diff --git a/webkit/glue/devtools/js/debugger_agent.js b/webkit/glue/devtools/js/debugger_agent.js index f1cb176..9670b51 100644 --- a/webkit/glue/devtools/js/debugger_agent.js +++ b/webkit/glue/devtools/js/debugger_agent.js @@ -15,6 +15,14 @@ goog.provide('devtools.DebuggerAgent'); devtools.DebuggerAgent = function() { RemoteDebuggerAgent.DebuggerOutput = goog.bind(this.handleDebuggerOutput_, this); + RemoteDebuggerAgent.DidGetContextId = + goog.bind(this.didGetContextId_, this); + + /** + * Id of the inspected page global context. It is used for filtering scripts. + * @type {number} + */ + this.contextId_ = null; /** * Mapping from script id to script info. @@ -63,6 +71,7 @@ devtools.DebuggerAgent = function() { */ devtools.DebuggerAgent.prototype.reset = function() { this.scriptsCacheInitialized_ = false; + this.contextId_ = null; this.parsedScripts_ = {}; this.requestNumberToBreakpointInfo_ = {}; this.currentCallFrame_ = null; @@ -86,6 +95,11 @@ devtools.DebuggerAgent.prototype.initializeScriptsCache = function() { * processed in handleScriptsResponse_. */ devtools.DebuggerAgent.prototype.requestScripts = function() { + if (this.contextId_ === null) { + // Update context id first to filter the scripts. + RemoteDebuggerAgent.GetContextId(); + return; + } var cmd = new devtools.DebugCommand('scripts', { 'includeSource': true }); @@ -330,6 +344,17 @@ devtools.DebuggerAgent.prototype.requestLookup_ = function(handles, callback) { /** + * Handles GetContextId response. + * @param {number} contextId Id of the inspected page global context. + */ +devtools.DebuggerAgent.prototype.didGetContextId_ = function(contextId) { + this.contextId_ = contextId; + // Update scripts. + this.requestScripts(); +}; + + +/** * Handles output sent by v8 debugger. The output is either asynchronous event * or response to a previously sent request. See protocol definitioun for more * details on the output format. @@ -422,7 +447,12 @@ devtools.DebuggerAgent.prototype.handleScriptsResponse_ = function(msg) { var scripts = msg.getBody(); for (var i = 0; i < scripts.length; i++) { var script = scripts[i]; - + + // Skip scripts from other tabs. + if (!this.isScriptFromInspectedContext_(script, msg)) { + continue; + } + // We may already have received the info in an afterCompile event. if (script.id in this.parsedScripts_) { continue; @@ -433,6 +463,28 @@ devtools.DebuggerAgent.prototype.handleScriptsResponse_ = function(msg) { /** + * @param {Object} script Json object representing script. + * @param {devtools.DebuggerMessage} msg Debugger response. + */ +devtools.DebuggerAgent.prototype.isScriptFromInspectedContext_ = function( + script, msg) { + if (!script.context) { + // Always ignore scripts from the utility context. + return false; + } + var context = msg.lookup(script.context.ref); + var scriptContextId = context.data; + if (!goog.isDef(scriptContextId)) { + return false; // Always ignore scripts from the utility context. + } + if (this.contextId_ === null) { + return true; + } + return (scriptContextId == this.contextId_); +}; + + +/** * @param {devtools.DebuggerMessage} msg */ devtools.DebuggerAgent.prototype.handleSetBreakpointResponse_ = function(msg) { @@ -461,6 +513,10 @@ devtools.DebuggerAgent.prototype.handleSetBreakpointResponse_ = function(msg) { */ devtools.DebuggerAgent.prototype.handleAfterCompileEvent_ = function(msg) { var script = msg.getBody().script; + // Ignore scripts from other tabs. + if (!this.isScriptFromInspectedContext_(script, msg)) { + return; + } this.addScriptInfo_(script); }; diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js index 412850d..b43c802 100644 --- a/webkit/glue/devtools/js/devtools_host_stub.js +++ b/webkit/glue/devtools/js/devtools_host_stub.js @@ -13,16 +13,11 @@ RemoteDebuggerAgentStub = function() { }; -RemoteDebuggerAgentStub.prototype.DebugAttach = function() { -}; - -RemoteDebuggerAgentStub.prototype.DebugDetach = function() { -}; - -RemoteDebuggerAgentStub.prototype.DebugCommand = function() { +RemoteDebuggerAgentStub.prototype.DebugBreak = function() { }; -RemoteDebuggerAgentStub.prototype.DebugBreak = function() { +RemoteDebuggerAgentStub.prototype.GetContextId = function() { + RemoteDebuggerAgent.DidGetContextId(3); }; @@ -217,7 +212,7 @@ RemoteDebuggerCommandExecutorStub = function() { }; -RemoteDebuggerCommandExecutorStub.prototype.DebuggerCommand = function() { +RemoteDebuggerCommandExecutorStub.prototype.DebuggerCommand = function(cmd) { }; diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index 36c1dcf..ad73d28 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -163,6 +163,10 @@ void WebDevToolsAgentImpl::AddMessageToConsole( } } +void WebDevToolsAgentImpl::WindowObjectCleared(WebFrameImpl* webframe) { + DebuggerAgentManager::SetHostId(webframe, host_id_); +} + void WebDevToolsAgentImpl::ForceRepaint() { delegate_->ForceRepaint(); } diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index c8c1f6b..2c5051c7 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -30,7 +30,7 @@ class NetAgentImpl; class Value; class WebDevToolsAgentDelegate; class WebFrame; -class WebFrame; +class WebFrameImpl; class WebViewImpl; class WebDevToolsAgentImpl @@ -74,6 +74,8 @@ class WebDevToolsAgentImpl unsigned int line_no, const WebCore::String& source_id); + void WindowObjectCleared(WebFrameImpl* webframe); + void ForceRepaint(); int host_id() { return host_id_; } diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc index 0ed8a39..6d1b556 100644 --- a/webkit/glue/webframeloaderclient_impl.cc +++ b/webkit/glue/webframeloaderclient_impl.cc @@ -105,6 +105,11 @@ void WebFrameLoaderClient::windowObjectCleared() { WebViewDelegate* d = webview->delegate(); if (d) d->WindowObjectCleared(webframe_); + + WebDevToolsAgentImpl* tools_agent = webview->GetWebDevToolsAgentImpl(); + if (tools_agent) { + tools_agent->WindowObjectCleared(webframe_); + } } void WebFrameLoaderClient::documentElementAvailable() { |