2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "DRTDevToolsClient.h"
34 #include "DRTDevToolsAgent.h"
35 #include "DRTDevToolsCallArgs.h"
37 #include "WebDevToolsAgent.h"
38 #include "WebDevToolsFrontend.h"
40 #include "WebScriptSource.h"
41 #include "WebString.h"
43 #include "webkit/support/webkit_support.h"
45 using namespace WebKit;
47 DRTDevToolsClient::DRTDevToolsClient(DRTDevToolsAgent* agent, WebView* webView)
49 , m_drtDevToolsAgent(agent)
51 m_webDevToolsFrontend.set(WebDevToolsFrontend::create(m_webView,
53 WebString::fromUTF8("en-US")));
54 m_drtDevToolsAgent->attach(this);
57 DRTDevToolsClient::~DRTDevToolsClient()
59 // There is a chance that the page will be destroyed at detach step of
60 // m_drtDevToolsAgent and we should clean pending requests a bit earlier.
61 m_taskList.revokeAll();
62 if (m_drtDevToolsAgent)
63 m_drtDevToolsAgent->detach();
66 void DRTDevToolsClient::reset()
68 m_taskList.revokeAll();
71 void DRTDevToolsClient::sendFrontendLoaded() {
72 if (m_drtDevToolsAgent)
73 m_drtDevToolsAgent->frontendLoaded();
76 void DRTDevToolsClient::sendMessageToBackend(const WebString& data)
78 if (m_drtDevToolsAgent)
79 m_drtDevToolsAgent->asyncCall(DRTDevToolsCallArgs(data));
82 void DRTDevToolsClient::sendDebuggerCommandToAgent(const WebString& command)
84 WebDevToolsAgent::executeDebuggerCommand(command, 1);
87 void DRTDevToolsClient::activateWindow()
92 void DRTDevToolsClient::closeWindow()
97 void DRTDevToolsClient::dockWindow()
102 void DRTDevToolsClient::undockWindow()
107 void DRTDevToolsClient::asyncCall(const DRTDevToolsCallArgs& args)
109 postTask(new AsyncCallTask(this, args));
112 void DRTDevToolsClient::call(const DRTDevToolsCallArgs& args)
114 m_webDevToolsFrontend->dispatchOnInspectorFrontend(args.m_data);
115 if (DRTDevToolsCallArgs::callsCount() == 1)
116 allMessagesProcessed();
119 void DRTDevToolsClient::allMessagesProcessed()
121 m_webView->mainFrame()->executeScript(
122 WebKit::WebScriptSource(WebString::fromUTF8(
123 "if (window.WebInspector && WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();")));