summaryrefslogtreecommitdiffstats
path: root/content/renderer/worker_devtools_agent_proxy.cc
blob: db09e0d045abcac374c2cc6ce3edfb6cdecac8dc (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
// Copyright (c) 2011 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 "content/renderer/worker_devtools_agent_proxy.h"

#include "content/common/devtools_messages.h"
#include "content/renderer/webworker_base.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebWorkerClient.h"

using WebKit::WebString;
using WebKit::WebWorkerClient;

WorkerDevToolsAgentProxy::WorkerDevToolsAgentProxy(WebWorkerBase* webworker,
                                                   int route_id,
                                                   WebWorkerClient* client)
    : route_id_(route_id),
      webworker_(webworker),
      webworker_client_(client) {
}

WorkerDevToolsAgentProxy::~WorkerDevToolsAgentProxy() {
}

void WorkerDevToolsAgentProxy::WorkerProxyDestroyed() {
  delete this;
}

void WorkerDevToolsAgentProxy::SetRouteId(int route_id) {
  route_id_ = route_id;
}

// Called on the Renderer thread.
bool WorkerDevToolsAgentProxy::OnMessageReceived(const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgentProxy, message)
    IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchMessageFromWorker,
                        OnDispatchMessageFromWorker)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void WorkerDevToolsAgentProxy::AttachDevTools() {
  Send(new WorkerDevToolsAgentMsg_Attach(route_id_));
}

void WorkerDevToolsAgentProxy::DetachDevTools() {
  Send(new WorkerDevToolsAgentMsg_Detach(route_id_));
}

void WorkerDevToolsAgentProxy::SendDevToolsMessage(
    const std::string& message) {
  Send(new DevToolsAgentMsg_DispatchOnInspectorBackend(route_id_, message));
}

void WorkerDevToolsAgentProxy::OnDispatchMessageFromWorker(
    const std::string& message) {
  webworker_client_->dispatchDevToolsMessage(WebString::fromUTF8(message));
}

void WorkerDevToolsAgentProxy::Send(IPC::Message* message) {
  webworker_->Send(message);
}