summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/test_shell_devtools_client.cc
blob: f1caaf7bc2897d9353edfa2313ff350f9141c009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDevToolsFrontend.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h"
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"

#undef LOG
#include "webkit/tools/test_shell/test_shell_devtools_agent.h"
#include "webkit/tools/test_shell/test_shell_devtools_callargs.h"
#include "webkit/tools/test_shell/test_shell_devtools_client.h"

#include "base/command_line.h"
#include "base/message_loop.h"

using WebKit::WebDevToolsAgent;
using WebKit::WebDevToolsFrontend;
using WebKit::WebDevToolsMessageData;
using WebKit::WebString;
using WebKit::WebView;

// Warning at call_method_factory_(this) treated as error and is switched off.

#if defined(OS_WIN)
#pragma warning(disable : 4355)
#endif // defined(OS_WIN)

TestShellDevToolsClient::TestShellDevToolsClient(TestShellDevToolsAgent *agent,
                                                 WebView* web_view)
  : call_method_factory_(this),
    dev_tools_agent_(agent),
    web_view_(web_view) {
  web_tools_frontend_.reset(
    WebDevToolsFrontend::create(web_view_,
                                this,
                                WebString::fromUTF8("en-US")));
  dev_tools_agent_->attach(this);
}

TestShellDevToolsClient::~TestShellDevToolsClient() {
  // It is a chance that page will be destroyed at detach step of
  // dev_tools_agent_ and we should clean pending requests a bit earlier.
  call_method_factory_.RevokeAll();
  if (dev_tools_agent_)
    dev_tools_agent_->detach(this);
}

void TestShellDevToolsClient::sendMessageToAgent(
     const WebDevToolsMessageData& data) {
  if (dev_tools_agent_)
    dev_tools_agent_->AsyncCall(TestShellDevToolsCallArgs(data));
}

void TestShellDevToolsClient::sendDebuggerCommandToAgent(
     const WebString& command) {
  WebDevToolsAgent::executeDebuggerCommand(command, 1);
}

void TestShellDevToolsClient::activateWindow() {
  NOTIMPLEMENTED();
}

void TestShellDevToolsClient::closeWindow() {
  NOTIMPLEMENTED();
}

void TestShellDevToolsClient::dockWindow() {
  NOTIMPLEMENTED();
}

void TestShellDevToolsClient::undockWindow() {
  NOTIMPLEMENTED();
}

void TestShellDevToolsClient::AsyncCall(const TestShellDevToolsCallArgs &args) {
  MessageLoop::current()->PostDelayedTask(
      FROM_HERE,
      call_method_factory_.NewRunnableMethod(&TestShellDevToolsClient::Call,
                                             args),
      0);
}

void TestShellDevToolsClient::Call(const TestShellDevToolsCallArgs &args) {
  web_tools_frontend_->dispatchMessageFromAgent(args.data_);
  if (TestShellDevToolsCallArgs::calls_count() == 1)
    all_messages_processed();
}

void TestShellDevToolsClient::all_messages_processed() {
  web_view_->mainFrame()->executeScript(
    WebKit::WebScriptSource(WebString::fromUTF8(
      "if (window.WebInspector && WebInspector.queuesAreEmpty) WebInspector.queuesAreEmpty();")));
}