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