• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 "content/child/shared_worker_devtools_agent.h"
6 
7 #include "content/child/child_thread.h"
8 #include "content/common/devtools_messages.h"
9 #include "third_party/WebKit/public/platform/WebCString.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebSharedWorker.h"
12 
13 using blink::WebSharedWorker;
14 using blink::WebString;
15 
16 namespace content {
17 
SharedWorkerDevToolsAgent(int route_id,WebSharedWorker * webworker)18 SharedWorkerDevToolsAgent::SharedWorkerDevToolsAgent(
19     int route_id,
20     WebSharedWorker* webworker)
21     : route_id_(route_id),
22       webworker_(webworker) {
23 }
24 
~SharedWorkerDevToolsAgent()25 SharedWorkerDevToolsAgent::~SharedWorkerDevToolsAgent() {
26 }
27 
28 // Called on the Worker thread.
OnMessageReceived(const IPC::Message & message)29 bool SharedWorkerDevToolsAgent::OnMessageReceived(const IPC::Message& message) {
30   bool handled = true;
31   IPC_BEGIN_MESSAGE_MAP(SharedWorkerDevToolsAgent, message)
32     IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Attach, OnAttach)
33     IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Reattach, OnReattach)
34     IPC_MESSAGE_HANDLER(DevToolsAgentMsg_Detach, OnDetach)
35     IPC_MESSAGE_HANDLER(DevToolsAgentMsg_DispatchOnInspectorBackend,
36                         OnDispatchOnInspectorBackend)
37     IPC_MESSAGE_HANDLER(DevToolsAgentMsg_ResumeWorkerContext,
38                         OnResumeWorkerContext)
39     IPC_MESSAGE_UNHANDLED(handled = false)
40   IPC_END_MESSAGE_MAP()
41   return handled;
42 }
43 
SendDevToolsMessage(const blink::WebString & message)44 void SharedWorkerDevToolsAgent::SendDevToolsMessage(
45     const blink::WebString& message) {
46     Send(new DevToolsClientMsg_DispatchOnInspectorFrontend(
47         route_id_,
48         message.utf8()));
49 }
50 
SaveDevToolsAgentState(const blink::WebString & state)51 void SharedWorkerDevToolsAgent::SaveDevToolsAgentState(
52     const blink::WebString& state) {
53   Send(new DevToolsHostMsg_SaveAgentRuntimeState(route_id_,
54                                                  state.utf8()));
55 }
56 
OnAttach(const std::string & host_id)57 void SharedWorkerDevToolsAgent::OnAttach(const std::string& host_id) {
58   webworker_->attachDevTools(WebString::fromUTF8(host_id));
59 }
60 
OnReattach(const std::string & host_id,const std::string & state)61 void SharedWorkerDevToolsAgent::OnReattach(const std::string& host_id,
62                                            const std::string& state) {
63   webworker_->reattachDevTools(WebString::fromUTF8(host_id),
64                                WebString::fromUTF8(state));
65 }
66 
OnDetach()67 void SharedWorkerDevToolsAgent::OnDetach() {
68   webworker_->detachDevTools();
69 }
70 
OnDispatchOnInspectorBackend(const std::string & message)71 void SharedWorkerDevToolsAgent::OnDispatchOnInspectorBackend(
72     const std::string& message) {
73   webworker_->dispatchDevToolsMessage(WebString::fromUTF8(message));
74 }
75 
OnResumeWorkerContext()76 void SharedWorkerDevToolsAgent::OnResumeWorkerContext() {
77   webworker_->resumeWorkerContext();
78 }
79 
Send(IPC::Message * message)80 bool SharedWorkerDevToolsAgent::Send(IPC::Message* message) {
81   return ChildThread::current()->Send(message);
82 }
83 
84 }  // namespace content
85