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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_
10 #include "base/memory/weak_ptr.h"
11 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h"
12 #include "content/browser/devtools/service_worker_devtools_agent_host.h"
13 #include "content/browser/devtools/service_worker_devtools_manager.h"
14 #include "content/browser/service_worker/service_worker_context_observer.h"
15 #include "content/browser/service_worker/service_worker_info.h"
16 #include "content/public/browser/devtools_agent_host.h"
17 #include "content/public/browser/devtools_agent_host_client.h"
19 // Windows headers will redefine SendMessage.
26 class RenderFrameHostImpl
;
27 class ServiceWorkerContextWatcher
;
28 class ServiceWorkerContextWrapper
;
31 namespace service_worker
{
33 class ServiceWorkerHandler
: public DevToolsAgentHostClient
,
34 public ServiceWorkerDevToolsManager::Observer
{
36 typedef DevToolsProtocolClient::Response Response
;
38 ServiceWorkerHandler();
39 ~ServiceWorkerHandler() override
;
41 void SetRenderFrameHost(RenderFrameHostImpl
* render_frame_host
);
42 void SetClient(scoped_ptr
<Client
> client
);
46 // Protocol 'service worker' domain implementation.
49 Response
SendMessage(const std::string
& worker_id
,
50 const std::string
& message
);
51 Response
Stop(const std::string
& worker_id
);
52 Response
Unregister(const std::string
& scope_url
);
53 Response
StartWorker(const std::string
& scope_url
);
54 Response
StopWorker(const std::string
& version_id
);
55 Response
UpdateRegistration(const std::string
& scope_url
);
56 Response
InspectWorker(const std::string
& version_id
);
57 Response
SkipWaiting(const std::string
& version_id
);
58 Response
SetDebugOnStart(bool debug_on_start
);
59 Response
DeliverPushMessage(const std::string
& origin
,
60 const std::string
& registration_id
,
61 const std::string
& data
);
62 Response
GetTargetInfo(const std::string
& target_id
,
63 scoped_refptr
<TargetInfo
>* target_info
);
64 Response
ActivateTarget(const std::string
& target_id
);
66 // WorkerDevToolsManager::Observer implementation.
67 void WorkerCreated(ServiceWorkerDevToolsAgentHost
* host
) override
;
68 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost
* host
) override
;
69 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost
* host
) override
;
70 void DebugOnStartUpdated(bool debug_on_start
) override
;
73 // DevToolsAgentHostClient overrides.
74 void DispatchProtocolMessage(DevToolsAgentHost
* agent_host
,
75 const std::string
& message
) override
;
76 void AgentHostClosed(DevToolsAgentHost
* agent_host
,
77 bool replaced_with_another_client
) override
;
79 void ReportWorkerCreated(ServiceWorkerDevToolsAgentHost
* host
);
80 void ReportWorkerTerminated(ServiceWorkerDevToolsAgentHost
* host
);
82 void OnWorkerRegistrationUpdated(
83 const std::vector
<ServiceWorkerRegistrationInfo
>& registrations
);
84 void OnWorkerVersionUpdated(
85 const std::vector
<ServiceWorkerVersionInfo
>& registrations
);
86 void OnErrorReported(int64 registration_id
,
88 const ServiceWorkerContextObserver::ErrorInfo
& info
);
90 void OpenNewDevToolsWindow(int process_id
, int devtools_agent_route_id
);
92 scoped_refptr
<ServiceWorkerContextWrapper
> context_
;
93 scoped_ptr
<Client
> client_
;
94 ServiceWorkerDevToolsAgentHost::Map attached_hosts_
;
97 scoped_refptr
<ServiceWorkerContextWatcher
> context_watcher_
;
98 RenderFrameHostImpl
* render_frame_host_
;
100 base::WeakPtrFactory
<ServiceWorkerHandler
> weak_factory_
;
102 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandler
);
105 } // namespace service_worker
106 } // namespace devtools
107 } // namespace content
109 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_