Changeset 65069 in webkit
- Timestamp:
- Aug 10, 2010 6:23:00 AM (14 years ago)
- Location:
- trunk/WebKit/chromium
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/chromium/ChangeLog
r65068 r65069 1 2010-08-10 Yury Semikhatsky <yurys@chromium.org> 2 3 Reviewed by Pavel Feldman. 4 5 Web Inspector: get rid of utility context 6 https://bugs.webkit.org/show_bug.cgi?id=43787 7 8 * public/WebDevToolsAgentClient.h: 9 * src/DebuggerAgentImpl.cpp: 10 * src/DebuggerAgentImpl.h: 11 * src/WebDevToolsAgentImpl.cpp: 12 (WebKit::): 13 (WebKit::WebDevToolsAgentImpl::~WebDevToolsAgentImpl): 14 (WebKit::WebDevToolsAgentImpl::attach): 15 (WebKit::WebDevToolsAgentImpl::detach): 16 (WebKit::WebDevToolsAgentImpl::frontendLoaded): 17 (WebKit::WebDevToolsAgentImpl::setRuntimeFeatureEnabled): 18 (WebKit::WebDevToolsAgentImpl::setApuAgentEnabled): 19 * src/WebDevToolsAgentImpl.h: 20 1 21 2010-08-10 Yury Semikhatsky <yurys@chromium.org> 2 22 -
trunk/WebKit/chromium/public/WebDevToolsAgentClient.h
r64534 r65069 55 55 56 56 virtual WebCString injectedScriptSource() { return WebCString(); } 57 virtual WebCString injectedScriptDispatcherSource() { return WebCString(); }58 57 virtual WebCString debuggerScriptSource() { return WebCString(); } 59 58 -
trunk/WebKit/chromium/src/DebuggerAgentImpl.cpp
r65021 r65069 33 33 34 34 #include "DebuggerAgentManager.h" 35 #include "Document.h"36 #include "Frame.h"37 #include "Page.h"38 #include "ScriptDebugServer.h"39 #include "V8Binding.h"40 35 #include "WebDevToolsAgentClient.h" 41 36 #include "WebDevToolsAgentImpl.h" 42 37 #include "WebViewImpl.h" 43 #include <wtf/HashSet.h>44 #include <wtf/RefPtr.h>45 #include <wtf/Vector.h>46 38 47 using WebCore::DOMWindow;48 using WebCore::Document;49 using WebCore::Frame;50 using WebCore::Page;51 39 using WTF::String; 52 40 … … 76 64 } 77 65 78 String DebuggerAgentImpl::executeUtilityFunction(79 v8::Handle<v8::Context> context,80 int callId,81 const char* object,82 const String &functionName,83 const String& jsonArgs,84 bool async,85 String* exception)86 {87 v8::HandleScope scope;88 ASSERT(!context.IsEmpty());89 if (context.IsEmpty()) {90 *exception = "No window context.";91 return "";92 }93 v8::Context::Scope contextScope(context);94 95 DebuggerAgentManager::UtilityContextScope utilityScope;96 97 v8::Handle<v8::Object> dispatchObject = v8::Handle<v8::Object>::Cast(98 context->Global()->Get(v8::String::New(object)));99 100 v8::Handle<v8::Value> dispatchFunction = dispatchObject->Get(v8::String::New("dispatch"));101 ASSERT(dispatchFunction->IsFunction());102 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatchFunction);103 104 v8::Handle<v8::String> functionNameWrapper = v8::Handle<v8::String>(105 v8::String::New(functionName.utf8().data()));106 v8::Handle<v8::String> jsonArgsWrapper = v8::Handle<v8::String>(107 v8::String::New(jsonArgs.utf8().data()));108 v8::Handle<v8::Number> callIdWrapper = v8::Handle<v8::Number>(109 v8::Number::New(async ? callId : 0));110 111 v8::Handle<v8::Value> args[] = {112 functionNameWrapper,113 jsonArgsWrapper,114 callIdWrapper115 };116 117 v8::TryCatch tryCatch;118 v8::Handle<v8::Value> resObj = function->Call(context->Global(), 3, args);119 if (tryCatch.HasCaught()) {120 v8::Local<v8::Message> message = tryCatch.Message();121 if (message.IsEmpty())122 *exception = "Unknown exception";123 else124 *exception = WebCore::toWebCoreString(message->Get());125 return "";126 }127 return WebCore::toWebCoreStringWithNullCheck(resObj);128 }129 130 66 WebCore::Page* DebuggerAgentImpl::page() 131 67 { -
trunk/WebKit/chromium/src/DebuggerAgentImpl.h
r65021 r65069 32 32 #define DebuggerAgentImpl_h 33 33 34 #include <v8.h>35 34 #include <wtf/Forward.h> 36 #include <wtf/HashSet.h>37 #include <wtf/Noncopyable.h>38 35 39 36 namespace WebCore { 40 class Document;41 class Frame;42 class Node;43 37 class Page; 44 38 } … … 63 57 bool autoContinueOnException() { return m_autoContinueOnException; } 64 58 65 // Executes function with the given name in the utility context. Passes node66 // and json args as parameters. Note that the function called must be67 // implemented in the inject_dispatch.js file.68 WTF::String executeUtilityFunction(69 v8::Handle<v8::Context> context,70 int callId,71 const char* object,72 const WTF::String& functionName,73 const WTF::String& jsonArgs,74 bool async,75 WTF::String* exception);76 77 78 59 WebCore::Page* page(); 79 60 WebDevToolsAgentImpl* webdevtoolsAgent() { return m_webdevtoolsAgent; } -
trunk/WebKit/chromium/src/WebDevToolsAgentImpl.cpp
r65068 r65069 32 32 #include "WebDevToolsAgentImpl.h" 33 33 34 #include "BoundObject.h"35 34 #include "DebuggerAgentImpl.h" 36 35 #include "DebuggerAgentManager.h" 37 #include "Document.h"38 #include "EventListener.h"39 36 #include "InjectedScriptHost.h" 40 #include "InspectorBackend.h"41 37 #include "InspectorBackendDispatcher.h" 42 38 #include "InspectorController.h" 43 #include "InspectorResource.h"44 #include "Node.h"45 39 #include "Page.h" 46 40 #include "PageGroup.h" … … 50 44 #include "ResourceResponse.h" 51 45 #include "ScriptDebugServer.h" 52 #include "ScriptState.h"53 #include "ScriptValue.h"54 46 #include "V8Binding.h" 55 47 #include "V8Proxy.h" … … 69 61 #include <wtf/OwnPtr.h> 70 62 71 using WebCore::Document;72 63 using WebCore::DocumentLoader; 73 64 using WebCore::FrameLoader; 74 65 using WebCore::InjectedScriptHost; 75 using WebCore::InspectorBackend;76 66 using WebCore::InspectorController; 77 using WebCore::InspectorResource;78 67 using WebCore::Node; 79 68 using WebCore::Page; … … 81 70 using WebCore::ResourceRequest; 82 71 using WebCore::ResourceResponse; 83 using WebCore::SafeAllocation;84 using WebCore::ScriptState;85 using WebCore::ScriptValue;86 72 using WTF::String; 87 73 using WebCore::V8DOMWrapper; … … 91 77 92 78 namespace { 93 94 void InspectorBackendWeakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter)95 {96 InspectorBackend* backend = static_cast<InspectorBackend*>(parameter);97 backend->deref();98 object.Dispose();99 }100 79 101 80 static const char kFrontendConnectedFeatureName[] = "frontend-connected"; … … 208 187 DebuggerAgentManager::onWebViewClosed(m_webViewImpl); 209 188 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); 210 disposeUtilityContext();211 }212 213 void WebDevToolsAgentImpl::disposeUtilityContext()214 {215 if (!m_utilityContext.IsEmpty()) {216 m_utilityContext.Dispose();217 m_utilityContext.Clear();218 }219 189 } 220 190 … … 229 199 m_debuggerAgentImpl.set( 230 200 new DebuggerAgentImpl(m_webViewImpl, this, m_client)); 231 createInspectorFrontendProxy(); 232 233 // Allow controller to send messages to the frontend. 201 WebCString debuggerScriptJs = m_client->debuggerScriptSource(); 202 WebCore::ScriptDebugServer::shared().setDebuggerScriptSource( 203 WTF::String(debuggerScriptJs.data(), debuggerScriptJs.length())); 204 205 // TODO(yurys): the source should have already been pushed by the frontend. 206 WebCString injectedScriptJs = m_client->injectedScriptSource(); 207 String injectedScriptSource = String::fromUTF8(injectedScriptJs.data(), injectedScriptJs.length()); 208 const char* varDefinition = "var injectedScriptConstructor = "; 209 int pos = injectedScriptSource.find(varDefinition); 210 if (pos == -1) { 211 ASSERT_NOT_REACHED(); 212 return; 213 } 214 pos += String(varDefinition).length(); 215 injectedScriptSource = injectedScriptSource.substring(pos); 216 inspectorController()->injectedScriptHost()->setInjectedScriptSource(injectedScriptSource); 217 m_attached = true; 218 } 219 220 void WebDevToolsAgentImpl::detach() 221 { 222 // Prevent controller from sending messages to the frontend. 234 223 InspectorController* ic = inspectorController(); 235 236 { // TODO(yurys): the source should have already been pushed by the frontend.237 v8::HandleScope scope;238 v8::Context::Scope contextScope(m_utilityContext);239 v8::Handle<v8::Value> constructorValue = m_utilityContext->Global()->Get(240 v8::String::New("injectedScriptConstructor"));241 if (constructorValue->IsFunction()) {242 String source = WebCore::toWebCoreString(constructorValue);243 ic->injectedScriptHost()->setInjectedScriptSource("(" + source + ")");244 }245 }246 m_attached = true;247 }248 249 void WebDevToolsAgentImpl::detach()250 {251 // Prevent controller from sending messages to the frontend.252 InspectorController* ic = m_webViewImpl->page()->inspectorController();253 224 ic->disconnectFrontend(); 254 225 ic->hideHighlight(); 255 226 ic->close(); 256 disposeUtilityContext();257 227 m_debuggerAgentImpl.set(0); 258 228 m_attached = false; … … 262 232 void WebDevToolsAgentImpl::frontendLoaded() 263 233 { 264 InspectorController* ic = inspectorController(); 265 ic->connectFrontend(); 234 inspectorController()->connectFrontend(); 266 235 m_client->runtimeFeatureStateChanged(kFrontendConnectedFeatureName, true); 267 236 } … … 300 269 setTimelineProfilingEnabled(enabled); 301 270 else if (feature == kResourceTrackingFeatureName) { 302 InspectorController* ic = m_webViewImpl->page()->inspectorController();271 InspectorController* ic = inspectorController(); 303 272 if (enabled) 304 273 ic->enableResourceTracking(false /* not sticky */, false /* no reload */); … … 309 278 } 310 279 311 void WebDevToolsAgentImpl::compileUtilityScripts()312 {313 v8::HandleScope handleScope;314 v8::Context::Scope contextScope(m_utilityContext);315 // Inject javascript into the context.316 WebCString injectedScriptJs = m_client->injectedScriptSource();317 v8::Script::Compile(v8::String::New(318 injectedScriptJs.data(),319 injectedScriptJs.length()))->Run();320 WebCString injectDispatchJs = m_client->injectedScriptDispatcherSource();321 v8::Script::Compile(v8::String::New(322 injectDispatchJs.data(),323 injectDispatchJs.length()))->Run();324 }325 326 void WebDevToolsAgentImpl::initDevToolsAgentHost()327 {328 BoundObject devtoolsAgentHost(m_utilityContext, this, "DevToolsAgentHost");329 devtoolsAgentHost.addProtoFunction(330 "dispatch",331 WebDevToolsAgentImpl::jsDispatchOnClient);332 devtoolsAgentHost.build();333 }334 335 void WebDevToolsAgentImpl::createInspectorFrontendProxy()336 {337 disposeUtilityContext();338 m_utilityContext = v8::Context::New();339 compileUtilityScripts();340 initDevToolsAgentHost();341 WebCString debuggerScriptJs = m_client->debuggerScriptSource();342 WebCore::ScriptDebugServer::shared().setDebuggerScriptSource(343 WTF::String(debuggerScriptJs.data(), debuggerScriptJs.length()));344 }345 346 280 void WebDevToolsAgentImpl::setApuAgentEnabled(bool enabled) 347 281 { 348 282 m_apuAgentEnabled = enabled; 349 InspectorController* ic = m_webViewImpl->page()->inspectorController();283 InspectorController* ic = inspectorController(); 350 284 if (enabled) { 351 285 m_resourceTrackingWasEnabled = ic->resourceTrackingEnabled(); … … 368 302 } 369 303 370 // static371 v8::Handle<v8::Value> WebDevToolsAgentImpl::jsDispatchOnClient(const v8::Arguments& args)372 {373 v8::TryCatch exceptionCatcher;374 String message = WebCore::toWebCoreStringWithNullCheck(args[0]);375 if (message.isEmpty() || exceptionCatcher.HasCaught())376 return v8::Undefined();377 378 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(v8::External::Cast(*args.Data())->Value());379 380 if (!agent->m_apuAgentEnabled) {381 agent->m_client->sendMessageToInspectorFrontend(message);382 return v8::Undefined();383 }384 385 String method = WebCore::toWebCoreStringWithNullCheck(args[1]);386 if (method.isEmpty() || exceptionCatcher.HasCaught())387 return v8::Undefined();388 389 if (method != "updateResource" && method != "addResource")390 return v8::Undefined();391 392 agent->m_client->sendDispatchToAPU(message);393 return v8::Undefined();394 }395 396 304 WebCore::InspectorController* WebDevToolsAgentImpl::inspectorController() 397 305 { -
trunk/WebKit/chromium/src/WebDevToolsAgentImpl.h
r65021 r65069 105 105 106 106 private: 107 static v8::Handle<v8::Value> jsDispatchOnClient(const v8::Arguments& args);108 109 void disposeUtilityContext();110 111 void compileUtilityScripts();112 void initDevToolsAgentHost();113 void createInspectorFrontendProxy();114 107 void setApuAgentEnabled(bool enabled); 115 108 … … 123 116 bool m_resourceTrackingWasEnabled; 124 117 bool m_attached; 125 // TODO(pfeldman): This should not be needed once GC styles issue is fixed126 // for matching rules.127 v8::Persistent<v8::Context> m_utilityContext;128 118 }; 129 119
Note: See TracChangeset
for help on using the changeset viewer.