OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" | 11 #include "content/browser/devtools/protocol/devtools_protocol_handler.h" |
| 12 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
12 #include "content/browser/devtools/service_worker_devtools_manager.h" | 13 #include "content/browser/devtools/service_worker_devtools_manager.h" |
13 #include "content/browser/service_worker/service_worker_info.h" | 14 #include "content/browser/service_worker/service_worker_info.h" |
14 #include "content/public/browser/devtools_agent_host.h" | 15 #include "content/public/browser/devtools_agent_host.h" |
15 #include "content/public/browser/devtools_agent_host_client.h" | 16 #include "content/public/browser/devtools_agent_host_client.h" |
16 | 17 |
17 // Windows headers will redefine SendMessage. | 18 // Windows headers will redefine SendMessage. |
18 #ifdef SendMessage | 19 #ifdef SendMessage |
19 #undef SendMessage | 20 #undef SendMessage |
20 #endif | 21 #endif |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 | 24 |
24 class RenderFrameHost; | 25 class RenderFrameHostImpl; |
25 class ServiceWorkerContextWrapper; | 26 class ServiceWorkerContextWrapper; |
26 class ServiceWorkerDevToolsAgentHost; | |
27 | 27 |
28 namespace devtools { | 28 namespace devtools { |
29 namespace service_worker { | 29 namespace service_worker { |
30 | 30 |
31 class ServiceWorkerHandler : public DevToolsAgentHostClient, | 31 class ServiceWorkerHandler : public DevToolsAgentHostClient, |
32 public ServiceWorkerDevToolsManager::Observer { | 32 public ServiceWorkerDevToolsManager::Observer { |
33 public: | 33 public: |
34 typedef DevToolsProtocolClient::Response Response; | 34 typedef DevToolsProtocolClient::Response Response; |
35 | 35 |
36 ServiceWorkerHandler(); | 36 ServiceWorkerHandler(); |
37 ~ServiceWorkerHandler() override; | 37 ~ServiceWorkerHandler() override; |
38 | 38 |
39 void SetRenderFrameHost(RenderFrameHost* render_frame_host); | 39 void SetRenderFrameHost(RenderFrameHostImpl* render_frame_host); |
40 void SetClient(scoped_ptr<Client> client); | 40 void SetClient(scoped_ptr<Client> client); |
41 void SetURL(const GURL& url); | 41 void UpdateHosts(); |
42 void Detached(); | 42 void Detached(); |
43 | 43 |
44 // Protocol 'service worker' domain implementation. | 44 // Protocol 'service worker' domain implementation. |
45 Response Enable(); | 45 Response Enable(); |
46 Response Disable(); | 46 Response Disable(); |
47 Response SendMessage(const std::string& worker_id, | 47 Response SendMessage(const std::string& worker_id, |
48 const std::string& message); | 48 const std::string& message); |
49 Response Stop(const std::string& worker_id); | 49 Response Stop(const std::string& worker_id); |
50 | 50 |
51 // WorkerDevToolsManager::Observer implementation. | 51 // WorkerDevToolsManager::Observer implementation. |
52 void WorkerCreated(ServiceWorkerDevToolsAgentHost* host) override; | 52 void WorkerCreated(ServiceWorkerDevToolsAgentHost* host) override; |
53 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost* host) override; | 53 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost* host) override; |
54 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) override; | 54 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) override; |
55 | 55 |
56 private: | 56 private: |
57 class ContextObserver; | 57 class ContextObserver; |
58 | 58 |
59 // DevToolsAgentHostClient overrides. | 59 // DevToolsAgentHostClient overrides. |
60 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 60 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
61 const std::string& message) override; | 61 const std::string& message) override; |
62 void AgentHostClosed(DevToolsAgentHost* agent_host, | 62 void AgentHostClosed(DevToolsAgentHost* agent_host, |
63 bool replaced_with_another_client) override; | 63 bool replaced_with_another_client) override; |
64 | 64 |
65 void ReportWorkerCreated(DevToolsAgentHost* host, bool new_worker); | 65 void ReportWorkerCreated(ServiceWorkerDevToolsAgentHost* host); |
66 | 66 void ReportWorkerTerminated(ServiceWorkerDevToolsAgentHost* host); |
67 bool MatchesInspectedPage(ServiceWorkerDevToolsAgentHost* host); | |
68 | 67 |
69 void OnWorkerRegistrationUpdated( | 68 void OnWorkerRegistrationUpdated( |
70 const std::vector<ServiceWorkerRegistrationInfo>& registrations); | 69 const std::vector<ServiceWorkerRegistrationInfo>& registrations); |
71 void OnWorkerVersionUpdated( | 70 void OnWorkerVersionUpdated( |
72 const std::vector<ServiceWorkerVersionInfo>& registrations); | 71 const std::vector<ServiceWorkerVersionInfo>& registrations); |
73 void OnWorkerRegistrationDeleted(int64 registration_id); | 72 void OnWorkerRegistrationDeleted(int64 registration_id); |
74 | 73 |
75 scoped_refptr<ServiceWorkerContextWrapper> context_; | 74 scoped_refptr<ServiceWorkerContextWrapper> context_; |
76 scoped_ptr<Client> client_; | 75 scoped_ptr<Client> client_; |
77 using AttachedHosts = std::map< | 76 ServiceWorkerDevToolsAgentHost::Map attached_hosts_; |
78 std::string, scoped_refptr<ServiceWorkerDevToolsAgentHost>>; | |
79 AttachedHosts attached_hosts_; | |
80 bool enabled_; | 77 bool enabled_; |
81 GURL url_; | 78 std::set<GURL> urls_; |
82 scoped_refptr<ContextObserver> context_observer_; | 79 scoped_refptr<ContextObserver> context_observer_; |
| 80 RenderFrameHostImpl* render_frame_host_; |
83 | 81 |
84 base::WeakPtrFactory<ServiceWorkerHandler> weak_factory_; | 82 base::WeakPtrFactory<ServiceWorkerHandler> weak_factory_; |
85 | 83 |
86 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandler); | 84 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandler); |
87 }; | 85 }; |
88 | 86 |
89 } // namespace service_worker | 87 } // namespace service_worker |
90 } // namespace devtools | 88 } // namespace devtools |
91 } // namespace content | 89 } // namespace content |
92 | 90 |
93 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ | 91 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_ |
OLD | NEW |