Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: content/browser/devtools/devtools_agent_host_impl.cc

Issue 1029523002: DevTools: Enable network emulation on Service Workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/devtools_agent_host_impl.h" 5 #include "content/browser/devtools/devtools_agent_host_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/json/json_writer.h"
12 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
13 #include "content/browser/devtools/devtools_manager.h" 14 #include "content/browser/devtools/devtools_manager.h"
14 #include "content/browser/devtools/forwarding_agent_host.h" 15 #include "content/browser/devtools/forwarding_agent_host.h"
16 #include "content/browser/devtools/protocol/devtools_protocol_handler.h"
15 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 17 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
16 #include "content/browser/devtools/service_worker_devtools_agent_host.h" 18 #include "content/browser/devtools/service_worker_devtools_agent_host.h"
17 #include "content/browser/devtools/service_worker_devtools_manager.h" 19 #include "content/browser/devtools/service_worker_devtools_manager.h"
18 #include "content/browser/devtools/shared_worker_devtools_agent_host.h" 20 #include "content/browser/devtools/shared_worker_devtools_agent_host.h"
19 #include "content/browser/devtools/shared_worker_devtools_manager.h" 21 #include "content/browser/devtools/shared_worker_devtools_manager.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/devtools_manager_delegate.h" 23 #include "content/public/browser/devtools_manager_delegate.h"
22 24
23 namespace content { 25 namespace content {
24 26
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SharedWorkerDevToolsManager::GetInstance() 60 SharedWorkerDevToolsManager::GetInstance()
59 ->GetDevToolsAgentHostForWorker(worker_process_id, 61 ->GetDevToolsAgentHostForWorker(worker_process_id,
60 worker_route_id)) { 62 worker_route_id)) {
61 return host; 63 return host;
62 } 64 }
63 return ServiceWorkerDevToolsManager::GetInstance() 65 return ServiceWorkerDevToolsManager::GetInstance()
64 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); 66 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id);
65 } 67 }
66 68
67 DevToolsAgentHostImpl::DevToolsAgentHostImpl() 69 DevToolsAgentHostImpl::DevToolsAgentHostImpl()
68 : id_(base::GenerateGUID()), 70 : protocol_handler_(new DevToolsProtocolHandler(
71 base::Bind(&DevToolsAgentHostImpl::SendMessageToClient,
72 base::Unretained(this)))),
73 id_(base::GenerateGUID()),
69 client_(NULL) { 74 client_(NULL) {
70 DCHECK_CURRENTLY_ON(BrowserThread::UI); 75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
71 g_instances.Get()[id_] = this; 76 g_instances.Get()[id_] = this;
72 } 77 }
73 78
74 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { 79 DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {
75 DCHECK_CURRENTLY_ON(BrowserThread::UI); 80 DCHECK_CURRENTLY_ON(BrowserThread::UI);
76 g_instances.Get().erase(g_instances.Get().find(id_)); 81 g_instances.Get().erase(g_instances.Get().find(id_));
77 } 82 }
78 83
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it) 217 for (AgentStateCallbacks::iterator it = copy.begin(); it != copy.end(); ++it)
213 (*it)->Run(agent_host, attached); 218 (*it)->Run(agent_host, attached);
214 } 219 }
215 220
216 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) { 221 void DevToolsAgentHostImpl::Inspect(BrowserContext* browser_context) {
217 DevToolsManager* manager = DevToolsManager::GetInstance(); 222 DevToolsManager* manager = DevToolsManager::GetInstance();
218 if (manager->delegate()) 223 if (manager->delegate())
219 manager->delegate()->Inspect(browser_context, this); 224 manager->delegate()->Inspect(browser_context, this);
220 } 225 }
221 226
227 bool DevToolsAgentHostImpl::DispatchProtocolMessage(
228 const std::string& message) {
229 scoped_ptr<base::DictionaryValue> command =
230 protocol_handler_->ParseCommand(message);
231 if (!command)
232 return true;
233
234 DevToolsManagerDelegate* delegate =
235 DevToolsManager::GetInstance()->delegate();
236 if (delegate) {
237 scoped_ptr<base::DictionaryValue> response(
238 delegate->HandleCommand(this, command.get()));
239 if (response) {
240 std::string json_response;
241 base::JSONWriter::Write(response.get(), &json_response);
242 SendMessageToClient(json_response);
243 return true;
244 }
245 }
246
247 return protocol_handler_->HandleOptionalCommand(command.Pass());
248 }
249
222 } // namespace content 250 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_agent_host_impl.h ('k') | content/browser/devtools/forwarding_agent_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698