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
SetForceUpdateOnPageLoad(const std::string
& registration_id
,
60 bool force_update_on_page_load
);
61 Response
DeliverPushMessage(const std::string
& origin
,
62 const std::string
& registration_id
,
63 const std::string
& data
);
64 Response
GetTargetInfo(const std::string
& target_id
,
65 scoped_refptr
<TargetInfo
>* target_info
);
66 Response
ActivateTarget(const std::string
& target_id
);
68 // WorkerDevToolsManager::Observer implementation.
69 void WorkerCreated(ServiceWorkerDevToolsAgentHost
* host
) override
;
70 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost
* host
) override
;
71 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost
* host
) override
;
72 void DebugOnStartUpdated(bool debug_on_start
) override
;
75 // DevToolsAgentHostClient overrides.
76 void DispatchProtocolMessage(DevToolsAgentHost
* agent_host
,
77 const std::string
& message
) override
;
78 void AgentHostClosed(DevToolsAgentHost
* agent_host
,
79 bool replaced_with_another_client
) override
;
81 void ReportWorkerCreated(ServiceWorkerDevToolsAgentHost
* host
);
82 void ReportWorkerTerminated(ServiceWorkerDevToolsAgentHost
* host
);
84 void OnWorkerRegistrationUpdated(
85 const std::vector
<ServiceWorkerRegistrationInfo
>& registrations
);
86 void OnWorkerVersionUpdated(
87 const std::vector
<ServiceWorkerVersionInfo
>& registrations
);
88 void OnErrorReported(int64 registration_id
,
90 const ServiceWorkerContextObserver::ErrorInfo
& info
);
92 void OpenNewDevToolsWindow(int process_id
, int devtools_agent_route_id
);
94 scoped_refptr
<ServiceWorkerContextWrapper
> context_
;
95 scoped_ptr
<Client
> client_
;
96 ServiceWorkerDevToolsAgentHost::Map attached_hosts_
;
99 scoped_refptr
<ServiceWorkerContextWatcher
> context_watcher_
;
100 RenderFrameHostImpl
* render_frame_host_
;
102 base::WeakPtrFactory
<ServiceWorkerHandler
> weak_factory_
;
104 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerHandler
);
107 } // namespace service_worker
108 } // namespace devtools
109 } // namespace content
111 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SERVICE_WORKER_HANDLER_H_