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 "DRTDevToolsClient.h" |
|
33 |
|
34 #include "DRTDevToolsAgent.h" |
|
35 #include "DRTDevToolsCallArgs.h" |
|
36 |
|
37 #include "public/WebDevToolsAgent.h" |
|
38 #include "public/WebDevToolsFrontend.h" |
|
39 #include "public/WebFrame.h" |
|
40 #include "public/WebScriptSource.h" |
|
41 #include "public/WebString.h" |
|
42 #include "public/WebView.h" |
|
43 #include "webkit/support/webkit_support.h" |
|
44 |
|
45 using namespace WebKit; |
|
46 |
|
47 DRTDevToolsClient::DRTDevToolsClient(DRTDevToolsAgent* agent, WebView* webView) |
|
48 : m_callMethodFactory(this) |
|
49 , m_drtDevToolsAgent(agent) |
|
50 , m_webView(webView) |
|
51 { |
|
52 m_webDevToolsFrontend.set(WebDevToolsFrontend::create(m_webView, |
|
53 this, |
|
54 WebString::fromUTF8("en-US"))); |
|
55 m_drtDevToolsAgent->attach(this); |
|
56 } |
|
57 |
|
58 DRTDevToolsClient::~DRTDevToolsClient() |
|
59 { |
|
60 // There is a chance that the page will be destroyed at detach step of |
|
61 // m_drtDevToolsAgent and we should clean pending requests a bit earlier. |
|
62 m_callMethodFactory.RevokeAll(); |
|
63 if (m_drtDevToolsAgent) |
|
64 m_drtDevToolsAgent->detach(this); |
|
65 } |
|
66 |
|
67 void DRTDevToolsClient::sendMessageToAgent(const WebDevToolsMessageData& data) |
|
68 { |
|
69 if (m_drtDevToolsAgent) |
|
70 m_drtDevToolsAgent->asyncCall(DRTDevToolsCallArgs(data)); |
|
71 } |
|
72 |
|
73 void DRTDevToolsClient::sendDebuggerCommandToAgent(const WebString& command) |
|
74 { |
|
75 WebDevToolsAgent::executeDebuggerCommand(command, 1); |
|
76 } |
|
77 |
|
78 void DRTDevToolsClient::activateWindow() |
|
79 { |
|
80 // Not implemented. |
|
81 } |
|
82 |
|
83 void DRTDevToolsClient::closeWindow() |
|
84 { |
|
85 // Not implemented. |
|
86 } |
|
87 |
|
88 void DRTDevToolsClient::dockWindow() |
|
89 { |
|
90 // Not implemented. |
|
91 } |
|
92 |
|
93 void DRTDevToolsClient::undockWindow() |
|
94 { |
|
95 // Not implemented. |
|
96 } |
|
97 |
|
98 void DRTDevToolsClient::asyncCall(const DRTDevToolsCallArgs& args) |
|
99 { |
|
100 webkit_support::PostTaskFromHere( |
|
101 m_callMethodFactory.NewRunnableMethod(&DRTDevToolsClient::call, args)); |
|
102 } |
|
103 |
|
104 void DRTDevToolsClient::call(const DRTDevToolsCallArgs& args) |
|
105 { |
|
106 m_webDevToolsFrontend->dispatchMessageFromAgent(args.m_data); |
|
107 if (DRTDevToolsCallArgs::callsCount() == 1) |
|
108 allMessagesProcessed(); |
|
109 } |
|
110 |
|
111 void DRTDevToolsClient::allMessagesProcessed() |
|
112 { |
|
113 m_webView->mainFrame()->executeScript( |
|
114 WebKit::WebScriptSource(WebString::fromUTF8( |
|
115 "if (window.WebInspector && WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();"))); |
|
116 } |
|