OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
6 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" | |
7 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsFrontend.h
" | |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
11 | |
12 #undef LOG | |
13 #include "webkit/tools/test_shell/test_shell_devtools_agent.h" | |
14 #include "webkit/tools/test_shell/test_shell_devtools_callargs.h" | |
15 #include "webkit/tools/test_shell/test_shell_devtools_client.h" | |
16 | |
17 #include "base/bind.h" | |
18 #include "base/command_line.h" | |
19 #include "base/message_loop.h" | |
20 | |
21 using WebKit::WebDevToolsAgent; | |
22 using WebKit::WebDevToolsFrontend; | |
23 using WebKit::WebDevToolsMessageData; | |
24 using WebKit::WebString; | |
25 using WebKit::WebView; | |
26 | |
27 TestShellDevToolsClient::TestShellDevToolsClient(TestShellDevToolsAgent *agent, | |
28 WebView* web_view) | |
29 : weak_factory_(this), | |
30 dev_tools_agent_(agent), | |
31 web_view_(web_view) { | |
32 web_tools_frontend_.reset(WebDevToolsFrontend::create(web_view_, this, | |
33 WebString::fromUTF8("en-US"))); | |
34 dev_tools_agent_->attach(this); | |
35 } | |
36 | |
37 TestShellDevToolsClient::~TestShellDevToolsClient() { | |
38 // It is a chance that page will be destroyed at detach step of | |
39 // dev_tools_agent_ and we should clean pending requests a bit earlier. | |
40 weak_factory_.InvalidateWeakPtrs(); | |
41 if (dev_tools_agent_) | |
42 dev_tools_agent_->detach(); | |
43 } | |
44 | |
45 void TestShellDevToolsClient::sendMessageToBackend( | |
46 const WebString& data) { | |
47 if (dev_tools_agent_) | |
48 dev_tools_agent_->AsyncCall(TestShellDevToolsCallArgs(data)); | |
49 } | |
50 | |
51 void TestShellDevToolsClient::activateWindow() { | |
52 NOTIMPLEMENTED(); | |
53 } | |
54 | |
55 void TestShellDevToolsClient::closeWindow() { | |
56 NOTIMPLEMENTED(); | |
57 } | |
58 | |
59 void TestShellDevToolsClient::dockWindow() { | |
60 NOTIMPLEMENTED(); | |
61 } | |
62 | |
63 void TestShellDevToolsClient::undockWindow() { | |
64 NOTIMPLEMENTED(); | |
65 } | |
66 | |
67 void TestShellDevToolsClient::AsyncCall(const TestShellDevToolsCallArgs &args) { | |
68 MessageLoop::current()->PostTask( | |
69 FROM_HERE, | |
70 base::Bind(&TestShellDevToolsClient::Call, weak_factory_.GetWeakPtr(), | |
71 args)); | |
72 } | |
73 | |
74 void TestShellDevToolsClient::Call(const TestShellDevToolsCallArgs &args) { | |
75 web_tools_frontend_->dispatchOnInspectorFrontend(args.data_); | |
76 if (TestShellDevToolsCallArgs::calls_count() == 1) | |
77 all_messages_processed(); | |
78 } | |
79 | |
80 void TestShellDevToolsClient::all_messages_processed() { | |
81 web_view_->mainFrame()->executeScript(WebKit::WebScriptSource( | |
82 WebString::fromUTF8("if (window.WebInspector && " | |
83 "WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();"))); | |
84 } | |
OLD | NEW |