[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / devtools / protocol / service_worker_handler.h
bloba46c5e42a5b1a5630647599ee71240c698931c0b
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_
8 #include <set>
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.
20 #ifdef SendMessage
21 #undef SendMessage
22 #endif
24 namespace content {
26 class RenderFrameHostImpl;
27 class ServiceWorkerContextWatcher;
28 class ServiceWorkerContextWrapper;
30 namespace devtools {
31 namespace service_worker {
33 class ServiceWorkerHandler : public DevToolsAgentHostClient,
34 public ServiceWorkerDevToolsManager::Observer {
35 public:
36 typedef DevToolsProtocolClient::Response Response;
38 ServiceWorkerHandler();
39 ~ServiceWorkerHandler() override;
41 void SetRenderFrameHost(RenderFrameHostImpl* render_frame_host);
42 void SetClient(scoped_ptr<Client> client);
43 void UpdateHosts();
44 void Detached();
46 // Protocol 'service worker' domain implementation.
47 Response Enable();
48 Response Disable();
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;
74 private:
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,
89 int64 version_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_;
97 bool enabled_;
98 std::set<GURL> urls_;
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_