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