WebKitTools/DumpRenderTree/chromium/DRTDevToolsAgent.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     1 /*
       
     2  * Copyright (C) 2010 Google Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #include "config.h"
       
    32 #include "DRTDevToolsAgent.h"
       
    33 
       
    34 #include "DRTDevToolsCallArgs.h"
       
    35 #include "DRTDevToolsClient.h"
       
    36 
       
    37 #include "public/WebCString.h"
       
    38 #include "public/WebDevToolsAgent.h"
       
    39 #include "public/WebDevToolsMessageData.h"
       
    40 #include "public/WebString.h"
       
    41 #include "public/WebView.h"
       
    42 #include "webkit/support/webkit_support.h"
       
    43 
       
    44 using namespace WebKit;
       
    45 
       
    46 DRTDevToolsAgent::DRTDevToolsAgent()
       
    47     : m_callMethodFactory(this)
       
    48     , m_drtDevToolsClient(0)
       
    49     , m_webView(0)
       
    50 {
       
    51     static int devToolsAgentCounter = 0;
       
    52 
       
    53     m_routingID = ++devToolsAgentCounter;
       
    54     if (m_routingID == 1)
       
    55         WebDevToolsAgent::setMessageLoopDispatchHandler(&DRTDevToolsAgent::dispatchMessageLoop);
       
    56 }
       
    57 
       
    58 void DRTDevToolsAgent::setWebView(WebView* webView)
       
    59 {
       
    60     m_webView = webView;
       
    61 }
       
    62 
       
    63 void DRTDevToolsAgent::sendMessageToFrontend(const WebDevToolsMessageData& data)
       
    64 {
       
    65     if (m_drtDevToolsClient)
       
    66          m_drtDevToolsClient->asyncCall(DRTDevToolsCallArgs(data));
       
    67 }
       
    68 
       
    69 void DRTDevToolsAgent::forceRepaint()
       
    70 {
       
    71 }
       
    72 
       
    73 void DRTDevToolsAgent::runtimeFeatureStateChanged(const WebKit::WebString& feature, bool enabled)
       
    74 {
       
    75     // FIXME: implement this.
       
    76 }
       
    77 
       
    78 WebCString DRTDevToolsAgent::injectedScriptSource()
       
    79 {
       
    80     return webkit_support::GetDevToolsInjectedScriptSource();
       
    81 }
       
    82 
       
    83 WebCString DRTDevToolsAgent::injectedScriptDispatcherSource()
       
    84 {
       
    85     return webkit_support::GetDevToolsInjectedScriptDispatcherSource();
       
    86 }
       
    87 
       
    88 WebCString DRTDevToolsAgent::debuggerScriptSource()
       
    89 {
       
    90     return webkit_support::GetDevToolsDebuggerScriptSource();
       
    91 }
       
    92 
       
    93 void DRTDevToolsAgent::asyncCall(const DRTDevToolsCallArgs &args)
       
    94 {
       
    95     webkit_support::PostTaskFromHere(
       
    96         m_callMethodFactory.NewRunnableMethod(&DRTDevToolsAgent::call, args));
       
    97 }
       
    98 
       
    99 void DRTDevToolsAgent::call(const DRTDevToolsCallArgs &args)
       
   100 {
       
   101     WebDevToolsAgent* agent = webDevToolsAgent();
       
   102     if (agent)
       
   103         agent->dispatchMessageFromFrontend(args.m_data);
       
   104     if (DRTDevToolsCallArgs::callsCount() == 1 && m_drtDevToolsClient)
       
   105         m_drtDevToolsClient->allMessagesProcessed();
       
   106 }
       
   107 
       
   108 WebDevToolsAgent* DRTDevToolsAgent::webDevToolsAgent()
       
   109 {
       
   110     if (!m_webView)
       
   111         return 0;
       
   112     return m_webView->devToolsAgent();
       
   113 }
       
   114 
       
   115 void DRTDevToolsAgent::attach(DRTDevToolsClient* client)
       
   116 {
       
   117     ASSERT(!m_drtDevToolsClient);
       
   118     m_drtDevToolsClient = client;
       
   119     WebDevToolsAgent* agent = webDevToolsAgent();
       
   120     if (agent)
       
   121         agent->attach();
       
   122 }
       
   123 
       
   124 void DRTDevToolsAgent::detach(DRTDevToolsClient* client)
       
   125 {
       
   126     ASSERT(m_drtDevToolsClient);
       
   127     WebDevToolsAgent* agent = webDevToolsAgent();
       
   128     if (agent)
       
   129         agent->detach();
       
   130     m_drtDevToolsClient = 0;
       
   131 }
       
   132 
       
   133 bool DRTDevToolsAgent::setTimelineProfilingEnabled(bool enabled)
       
   134 {
       
   135     WebDevToolsAgent* agent = webDevToolsAgent();
       
   136     if (!agent)
       
   137         return false;
       
   138     agent->setTimelineProfilingEnabled(enabled);
       
   139     return true;
       
   140 }
       
   141 
       
   142 bool DRTDevToolsAgent::evaluateInWebInspector(long callID, const std::string& script)
       
   143 {
       
   144     WebDevToolsAgent* agent = webDevToolsAgent();
       
   145     if (!agent)
       
   146         return false;
       
   147     agent->evaluateInWebInspector(callID, WebString::fromUTF8(script));
       
   148     return true;
       
   149 }
       
   150 
       
   151 // static method
       
   152 void DRTDevToolsAgent::dispatchMessageLoop()
       
   153 {
       
   154     webkit_support::DispatchMessageLoop();
       
   155 }