summaryrefslogtreecommitdiffstats
path: root/content/worker/worker_devtools_agent.cc
blob: af00871357b73326316bec9ac0753e3a5583b4cb (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
// 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/worker/worker_devtools_agent.h"

#include "content/common/devtools_messages.h"
#include "content/worker/worker_thread.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/WebWorker.h"

using WebKit::WebString;
using WebKit::WebWorker;

WorkerDevToolsAgent::WorkerDevToolsAgent(int route_id, WebWorker* webworker)
    : route_id_(route_id),
      webworker_(webworker) {
}

WorkerDevToolsAgent::~WorkerDevToolsAgent() {
}

// Called on the Worker thread.
bool WorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(WorkerDevToolsAgent, message)
    IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Attach, OnAttach)
    IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_Detach, OnDetach)
    IPC_MESSAGE_HANDLER(WorkerDevToolsAgentMsg_DispatchOnInspectorBackend,
                        OnDispatchOnInspectorBackend)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void WorkerDevToolsAgent::OnAttach() {
  webworker_->attachDevTools();
}

void WorkerDevToolsAgent::OnDetach() {
  webworker_->detachDevTools();
}

void WorkerDevToolsAgent::OnDispatchOnInspectorBackend(
    const std::string& message) {
  webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message));
}

bool WorkerDevToolsAgent::Send(IPC::Message* message) {
  return WorkerThread::current()->Send(message);
}

void WorkerDevToolsAgent::SendDevToolsMessage(const WebString& message) {
  Send(new DevToolsAgentMsg_DispatchMessageFromWorker(route_id_,
                                                      message.utf8()));
}