• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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.
4 
5 #ifndef CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_AGENT_HOST_H_
6 #define CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_AGENT_HOST_H_
7 
8 #include "content/browser/devtools/embedded_worker_devtools_manager.h"
9 #include "content/browser/devtools/ipc_devtools_agent_host.h"
10 #include "ipc/ipc_listener.h"
11 
12 namespace content {
13 
14 class SharedWorkerInstance;
15 
16 class EmbeddedWorkerDevToolsAgentHost : public IPCDevToolsAgentHost,
17                                         public IPC::Listener {
18  public:
19   typedef EmbeddedWorkerDevToolsManager::WorkerId WorkerId;
20   typedef EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier
21       ServiceWorkerIdentifier;
22 
23   EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id,
24                                   const SharedWorkerInstance& shared_worker);
25 
26   EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id,
27                                   const ServiceWorkerIdentifier& service_worker,
28                                   bool debug_service_worker_on_start);
29 
30   // DevToolsAgentHost override.
31   virtual bool IsWorker() const OVERRIDE;
32   virtual Type GetType() OVERRIDE;
33   virtual std::string GetTitle() OVERRIDE;
34   virtual GURL GetURL() OVERRIDE;
35   virtual bool Activate() OVERRIDE;
36   virtual bool Close() OVERRIDE;
37 
38   // IPCDevToolsAgentHost implementation.
39   virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE;
40   virtual void Attach() OVERRIDE;
OnClientAttached()41   virtual void OnClientAttached() OVERRIDE {}
42   virtual void OnClientDetached() OVERRIDE;
43 
44   // IPC::Listener implementation.
45   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
46 
47   void WorkerReadyForInspection();
48   void WorkerContextStarted();
49   void WorkerRestarted(WorkerId worker_id);
50   void WorkerDestroyed();
51   bool Matches(const SharedWorkerInstance& other);
52   bool Matches(const ServiceWorkerIdentifier& other);
53   bool IsTerminated();
54 
55  private:
56   friend class EmbeddedWorkerDevToolsManagerTest;
57 
58   virtual ~EmbeddedWorkerDevToolsAgentHost();
59 
60   enum WorkerState {
61     WORKER_UNINSPECTED,
62     WORKER_INSPECTED,
63     WORKER_TERMINATED,
64     WORKER_PAUSED_FOR_DEBUG_ON_START,
65     WORKER_PAUSED_FOR_REATTACH,
66   };
67 
68   void AttachToWorker();
69   void DetachFromWorker();
70   void WorkerCreated();
71   void OnDispatchOnInspectorFrontend(const std::string& message);
72   void OnSaveAgentRuntimeState(const std::string& state);
73 
74   scoped_ptr<SharedWorkerInstance> shared_worker_;
75   scoped_ptr<ServiceWorkerIdentifier> service_worker_;
76   WorkerState state_;
77   WorkerId worker_id_;
78   std::string saved_agent_state_;
79   DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost);
80 };
81 
82 }  // namespace content
83 
84 #endif  // CONTENT_BROWSER_DEVTOOLS_EMBEDDED_WORKER_DEVTOOLS_AGENT_HOST_H_
85