OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 5 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | |
7 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/browser/devtools/devtools_manager.h" | |
10 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | |
8 #include "content/browser/devtools/service_worker_devtools_manager.h" | 11 #include "content/browser/devtools/service_worker_devtools_manager.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 12 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_version.h" | 13 #include "content/browser/service_worker/service_worker_version.h" |
11 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/devtools_manager_delegate.h" | |
12 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
13 | 17 |
14 namespace content { | 18 namespace content { |
15 | 19 |
16 namespace { | 20 namespace { |
17 | 21 |
18 void StatusNoOp(ServiceWorkerStatusCode status) {} | 22 void StatusNoOp(ServiceWorkerStatusCode status) {} |
19 | 23 |
20 void TerminateServiceWorkerOnIO( | 24 void TerminateServiceWorkerOnIO( |
21 base::WeakPtr<ServiceWorkerContextCore> context_weak, | 25 base::WeakPtr<ServiceWorkerContextCore> context_weak, |
(...skipping 25 matching lines...) Expand all Loading... | |
47 version->SetDevToolsAttached(attached); | 51 version->SetDevToolsAttached(attached); |
48 } | 52 } |
49 } | 53 } |
50 | 54 |
51 } // namespace | 55 } // namespace |
52 | 56 |
53 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost( | 57 ServiceWorkerDevToolsAgentHost::ServiceWorkerDevToolsAgentHost( |
54 WorkerId worker_id, | 58 WorkerId worker_id, |
55 const ServiceWorkerIdentifier& service_worker) | 59 const ServiceWorkerIdentifier& service_worker) |
56 : WorkerDevToolsAgentHost(worker_id), | 60 : WorkerDevToolsAgentHost(worker_id), |
57 service_worker_(new ServiceWorkerIdentifier(service_worker)) { | 61 service_worker_(new ServiceWorkerIdentifier(service_worker)), |
62 protocol_handler_(new DevToolsProtocolHandler( | |
63 base::Bind( | |
64 &ServiceWorkerDevToolsAgentHost::DispatchOnInspectorFrontend, | |
65 base::Unretained(this)))) { | |
58 } | 66 } |
59 | 67 |
60 DevToolsAgentHost::Type ServiceWorkerDevToolsAgentHost::GetType() { | 68 DevToolsAgentHost::Type ServiceWorkerDevToolsAgentHost::GetType() { |
61 return TYPE_SERVICE_WORKER; | 69 return TYPE_SERVICE_WORKER; |
62 } | 70 } |
63 | 71 |
64 std::string ServiceWorkerDevToolsAgentHost::GetTitle() { | 72 std::string ServiceWorkerDevToolsAgentHost::GetTitle() { |
65 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id().first)) { | 73 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id().first)) { |
66 return base::StringPrintf("Worker pid:%d", | 74 return base::StringPrintf("Worker pid:%d", |
67 base::GetProcId(host->GetHandle())); | 75 base::GetProcId(host->GetHandle())); |
(...skipping 17 matching lines...) Expand all Loading... | |
85 return true; | 93 return true; |
86 } | 94 } |
87 | 95 |
88 void ServiceWorkerDevToolsAgentHost::UnregisterWorker() { | 96 void ServiceWorkerDevToolsAgentHost::UnregisterWorker() { |
89 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 97 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
90 base::Bind(&UnregisterServiceWorkerOnIO, | 98 base::Bind(&UnregisterServiceWorkerOnIO, |
91 service_worker_->context_weak(), | 99 service_worker_->context_weak(), |
92 service_worker_->version_id())); | 100 service_worker_->version_id())); |
93 } | 101 } |
94 | 102 |
103 void ServiceWorkerDevToolsAgentHost::DispatchProtocolMessage( | |
pfeldman
2015/03/23 09:05:25
Lets have this implemented in the devtools_agent_h
| |
104 const std::string& message) { | |
105 scoped_ptr<base::DictionaryValue> command = | |
106 protocol_handler_->ParseCommand(message); | |
107 if (!command) | |
108 return; | |
109 | |
110 DevToolsManagerDelegate* delegate = | |
111 DevToolsManager::GetInstance()->delegate(); | |
112 if (delegate) { | |
113 scoped_ptr<base::DictionaryValue> response( | |
114 delegate->HandleCommand(this, command.get())); | |
115 if (response) { | |
116 std::string json_response; | |
117 base::JSONWriter::Write(response.get(), &json_response); | |
118 DispatchOnInspectorFrontend(json_response); | |
119 return; | |
120 } | |
121 } | |
122 | |
123 if (protocol_handler_->HandleOptionalCommand(command.Pass())) | |
124 return; | |
125 | |
126 IPCDevToolsAgentHost::DispatchProtocolMessage(message); | |
127 } | |
128 | |
95 void ServiceWorkerDevToolsAgentHost::OnClientAttached() { | 129 void ServiceWorkerDevToolsAgentHost::OnClientAttached() { |
96 WorkerDevToolsAgentHost::OnClientAttached(); | 130 WorkerDevToolsAgentHost::OnClientAttached(); |
97 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 131 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
98 base::Bind(&SetDevToolsAttachedOnIO, | 132 base::Bind(&SetDevToolsAttachedOnIO, |
99 service_worker_->context_weak(), | 133 service_worker_->context_weak(), |
100 service_worker_->version_id(), | 134 service_worker_->version_id(), |
101 true)); | 135 true)); |
102 } | 136 } |
103 | 137 |
104 void ServiceWorkerDevToolsAgentHost::OnClientDetached() { | 138 void ServiceWorkerDevToolsAgentHost::OnClientDetached() { |
105 WorkerDevToolsAgentHost::OnClientDetached(); | 139 WorkerDevToolsAgentHost::OnClientDetached(); |
106 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 140 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
107 base::Bind(&SetDevToolsAttachedOnIO, | 141 base::Bind(&SetDevToolsAttachedOnIO, |
108 service_worker_->context_weak(), | 142 service_worker_->context_weak(), |
109 service_worker_->version_id(), | 143 service_worker_->version_id(), |
110 false)); | 144 false)); |
111 } | 145 } |
112 | 146 |
113 bool ServiceWorkerDevToolsAgentHost::Matches( | 147 bool ServiceWorkerDevToolsAgentHost::Matches( |
114 const ServiceWorkerIdentifier& other) { | 148 const ServiceWorkerIdentifier& other) { |
115 return service_worker_->Matches(other); | 149 return service_worker_->Matches(other); |
116 } | 150 } |
117 | 151 |
152 void ServiceWorkerDevToolsAgentHost::DispatchOnInspectorFrontend( | |
153 const std::string& message) { | |
154 if (!IsAttached()) | |
155 return; | |
156 SendMessageToClient(message); | |
157 } | |
158 | |
118 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { | 159 ServiceWorkerDevToolsAgentHost::~ServiceWorkerDevToolsAgentHost() { |
119 ServiceWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | 160 ServiceWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
120 worker_id()); | 161 worker_id()); |
121 } | 162 } |
122 | 163 |
123 } // namespace content | 164 } // namespace content |
OLD | NEW |