Changeset 65069 in webkit


Ignore:
Timestamp:
Aug 10, 2010 6:23:00 AM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-08-10 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: get rid of utility context
https://bugs.webkit.org/show_bug.cgi?id=43787

  • public/WebDevToolsAgentClient.h:
  • src/DebuggerAgentImpl.cpp:
  • src/DebuggerAgentImpl.h:
  • src/WebDevToolsAgentImpl.cpp: (WebKit::): (WebKit::WebDevToolsAgentImpl::~WebDevToolsAgentImpl): (WebKit::WebDevToolsAgentImpl::attach): (WebKit::WebDevToolsAgentImpl::detach): (WebKit::WebDevToolsAgentImpl::frontendLoaded): (WebKit::WebDevToolsAgentImpl::setRuntimeFeatureEnabled): (WebKit::WebDevToolsAgentImpl::setApuAgentEnabled):
  • src/WebDevToolsAgentImpl.h:
Location:
trunk/WebKit/chromium
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/chromium/ChangeLog

    r65068 r65069  
     12010-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
    1212010-08-10  Yury Semikhatsky  <yurys@chromium.org>
    222
  • trunk/WebKit/chromium/public/WebDevToolsAgentClient.h

    r64534 r65069  
    5555
    5656    virtual WebCString injectedScriptSource() { return WebCString(); }
    57     virtual WebCString injectedScriptDispatcherSource() { return WebCString(); }
    5857    virtual WebCString debuggerScriptSource() { return WebCString(); }
    5958
  • trunk/WebKit/chromium/src/DebuggerAgentImpl.cpp

    r65021 r65069  
    3333
    3434#include "DebuggerAgentManager.h"
    35 #include "Document.h"
    36 #include "Frame.h"
    37 #include "Page.h"
    38 #include "ScriptDebugServer.h"
    39 #include "V8Binding.h"
    4035#include "WebDevToolsAgentClient.h"
    4136#include "WebDevToolsAgentImpl.h"
    4237#include "WebViewImpl.h"
    43 #include <wtf/HashSet.h>
    44 #include <wtf/RefPtr.h>
    45 #include <wtf/Vector.h>
    4638
    47 using WebCore::DOMWindow;
    48 using WebCore::Document;
    49 using WebCore::Frame;
    50 using WebCore::Page;
    5139using WTF::String;
    5240
     
    7664}
    7765
    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         callIdWrapper
    115     };
    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         else
    124             *exception = WebCore::toWebCoreString(message->Get());
    125         return "";
    126     }
    127     return WebCore::toWebCoreStringWithNullCheck(resObj);
    128 }
    129 
    13066WebCore::Page* DebuggerAgentImpl::page()
    13167{
  • trunk/WebKit/chromium/src/DebuggerAgentImpl.h

    r65021 r65069  
    3232#define DebuggerAgentImpl_h
    3333
    34 #include <v8.h>
    3534#include <wtf/Forward.h>
    36 #include <wtf/HashSet.h>
    37 #include <wtf/Noncopyable.h>
    3835
    3936namespace WebCore {
    40 class Document;
    41 class Frame;
    42 class Node;
    4337class Page;
    4438}
     
    6357    bool autoContinueOnException() { return m_autoContinueOnException; }
    6458
    65     // Executes function with the given name in the utility context. Passes node
    66     // and json args as parameters. Note that the function called must be
    67     // 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 
    7859    WebCore::Page* page();
    7960    WebDevToolsAgentImpl* webdevtoolsAgent() { return m_webdevtoolsAgent; }
  • trunk/WebKit/chromium/src/WebDevToolsAgentImpl.cpp

    r65068 r65069  
    3232#include "WebDevToolsAgentImpl.h"
    3333
    34 #include "BoundObject.h"
    3534#include "DebuggerAgentImpl.h"
    3635#include "DebuggerAgentManager.h"
    37 #include "Document.h"
    38 #include "EventListener.h"
    3936#include "InjectedScriptHost.h"
    40 #include "InspectorBackend.h"
    4137#include "InspectorBackendDispatcher.h"
    4238#include "InspectorController.h"
    43 #include "InspectorResource.h"
    44 #include "Node.h"
    4539#include "Page.h"
    4640#include "PageGroup.h"
     
    5044#include "ResourceResponse.h"
    5145#include "ScriptDebugServer.h"
    52 #include "ScriptState.h"
    53 #include "ScriptValue.h"
    5446#include "V8Binding.h"
    5547#include "V8Proxy.h"
     
    6961#include <wtf/OwnPtr.h>
    7062
    71 using WebCore::Document;
    7263using WebCore::DocumentLoader;
    7364using WebCore::FrameLoader;
    7465using WebCore::InjectedScriptHost;
    75 using WebCore::InspectorBackend;
    7666using WebCore::InspectorController;
    77 using WebCore::InspectorResource;
    7867using WebCore::Node;
    7968using WebCore::Page;
     
    8170using WebCore::ResourceRequest;
    8271using WebCore::ResourceResponse;
    83 using WebCore::SafeAllocation;
    84 using WebCore::ScriptState;
    85 using WebCore::ScriptValue;
    8672using WTF::String;
    8773using WebCore::V8DOMWrapper;
     
    9177
    9278namespace {
    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 }
    10079
    10180static const char kFrontendConnectedFeatureName[] = "frontend-connected";
     
    208187    DebuggerAgentManager::onWebViewClosed(m_webViewImpl);
    209188    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     }
    219189}
    220190
     
    229199    m_debuggerAgentImpl.set(
    230200        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
     220void WebDevToolsAgentImpl::detach()
     221{
     222    // Prevent controller from sending messages to the frontend.
    234223    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();
    253224    ic->disconnectFrontend();
    254225    ic->hideHighlight();
    255226    ic->close();
    256     disposeUtilityContext();
    257227    m_debuggerAgentImpl.set(0);
    258228    m_attached = false;
     
    262232void WebDevToolsAgentImpl::frontendLoaded()
    263233{
    264     InspectorController* ic = inspectorController();
    265     ic->connectFrontend();
     234    inspectorController()->connectFrontend();
    266235    m_client->runtimeFeatureStateChanged(kFrontendConnectedFeatureName, true);
    267236}
     
    300269        setTimelineProfilingEnabled(enabled);
    301270    else if (feature == kResourceTrackingFeatureName) {
    302         InspectorController* ic = m_webViewImpl->page()->inspectorController();
     271        InspectorController* ic = inspectorController();
    303272        if (enabled)
    304273          ic->enableResourceTracking(false /* not sticky */, false /* no reload */);
     
    309278}
    310279
    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 
    346280void WebDevToolsAgentImpl::setApuAgentEnabled(bool enabled)
    347281{
    348282    m_apuAgentEnabled = enabled;
    349     InspectorController* ic = m_webViewImpl->page()->inspectorController();
     283    InspectorController* ic = inspectorController();
    350284    if (enabled) {
    351285        m_resourceTrackingWasEnabled = ic->resourceTrackingEnabled();
     
    368302}
    369303
    370 // static
    371 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 
    396304WebCore::InspectorController* WebDevToolsAgentImpl::inspectorController()
    397305{
  • trunk/WebKit/chromium/src/WebDevToolsAgentImpl.h

    r65021 r65069  
    105105
    106106private:
    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();
    114107    void setApuAgentEnabled(bool enabled);
    115108
     
    123116    bool m_resourceTrackingWasEnabled;
    124117    bool m_attached;
    125     // TODO(pfeldman): This should not be needed once GC styles issue is fixed
    126     // for matching rules.
    127     v8::Persistent<v8::Context> m_utilityContext;
    128118};
    129119
Note: See TracChangeset for help on using the changeset viewer.