| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_TARGET_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TARGET_AUTO_ATTACHER_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TARGET_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TARGET_AUTO_ATTACHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include "base/containers/flat_set.h" |
| 9 #include <set> | |
| 10 | |
| 11 #include "content/browser/devtools/protocol/devtools_domain_handler.h" | |
| 12 #include "content/browser/devtools/protocol/target.h" | |
| 13 #include "content/browser/devtools/service_worker_devtools_manager.h" | 9 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 14 #include "content/public/browser/devtools_agent_host_client.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
| 15 #include "content/public/browser/devtools_agent_host_observer.h" | |
| 16 | 11 |
| 17 namespace content { | 12 namespace content { |
| 18 | 13 |
| 19 class DevToolsAgentHostImpl; | |
| 20 class RenderFrameHostImpl; | 14 class RenderFrameHostImpl; |
| 21 | 15 |
| 22 namespace protocol { | 16 namespace protocol { |
| 23 | 17 |
| 24 class TargetHandler : public DevToolsDomainHandler, | 18 class TargetAutoAttacher : public ServiceWorkerDevToolsManager::Observer { |
| 25 public Target::Backend, | |
| 26 public DevToolsAgentHostClient, | |
| 27 public ServiceWorkerDevToolsManager::Observer, | |
| 28 public DevToolsAgentHostObserver { | |
| 29 public: | 19 public: |
| 30 TargetHandler(); | 20 // Second parameter is |waiting_for_debugger|, returns whether it succeeded. |
| 31 ~TargetHandler() override; | 21 using AttachCallback = base::Callback<bool(DevToolsAgentHost*, bool)>; |
| 22 using DetachCallback = base::Callback<void(DevToolsAgentHost*)>; |
| 32 | 23 |
| 33 static std::vector<TargetHandler*> ForAgentHost(DevToolsAgentHostImpl* host); | 24 TargetAutoAttacher(AttachCallback attach_callback, |
| 25 DetachCallback detach_callback); |
| 26 ~TargetAutoAttacher() override; |
| 34 | 27 |
| 35 void Wire(UberDispatcher* dispatcher) override; | 28 void SetRenderFrameHost(RenderFrameHostImpl* host); |
| 36 void SetRenderFrameHost(RenderFrameHostImpl* host) override; | 29 void SetAutoAttach(bool auto_attach, bool wait_for_debugger_on_start); |
| 37 Response Disable() override; | 30 void SetAttachToFrames(bool attach_to_frames); |
| 38 | 31 |
| 39 void UpdateServiceWorkers(); | 32 void UpdateServiceWorkers(); |
| 40 void UpdateFrames(); | 33 void UpdateFrames(); |
| 41 | 34 void AgentHostClosed(DevToolsAgentHost* host); |
| 42 // Domain implementation. | |
| 43 Response SetDiscoverTargets(bool discover) override; | |
| 44 Response SetAutoAttach(bool auto_attach, | |
| 45 bool wait_for_debugger_on_start) override; | |
| 46 Response SetAttachToFrames(bool value) override; | |
| 47 Response SetRemoteLocations( | |
| 48 std::unique_ptr<protocol::Array<Target::RemoteLocation>>) override; | |
| 49 Response AttachToTarget(const std::string& target_id, | |
| 50 bool* out_success) override; | |
| 51 Response DetachFromTarget(const std::string& target_id) override; | |
| 52 Response SendMessageToTarget(const std::string& target_id, | |
| 53 const std::string& message) override; | |
| 54 Response GetTargetInfo( | |
| 55 const std::string& target_id, | |
| 56 std::unique_ptr<Target::TargetInfo>* target_info) override; | |
| 57 Response ActivateTarget(const std::string& target_id) override; | |
| 58 Response CloseTarget(const std::string& target_id, | |
| 59 bool* out_success) override; | |
| 60 Response CreateBrowserContext(std::string* out_context_id) override; | |
| 61 Response DisposeBrowserContext(const std::string& context_id, | |
| 62 bool* out_success) override; | |
| 63 Response CreateTarget(const std::string& url, | |
| 64 Maybe<int> width, | |
| 65 Maybe<int> height, | |
| 66 Maybe<std::string> context_id, | |
| 67 std::string* out_target_id) override; | |
| 68 Response GetTargets( | |
| 69 std::unique_ptr<protocol::Array<Target::TargetInfo>>* target_infos) | |
| 70 override; | |
| 71 | 35 |
| 72 private: | 36 private: |
| 73 using HostsMap = std::map<std::string, scoped_refptr<DevToolsAgentHost>>; | 37 using Hosts = base::flat_set<scoped_refptr<DevToolsAgentHost>>; |
| 74 using RawHostsMap = std::map<std::string, DevToolsAgentHost*>; | |
| 75 | 38 |
| 76 void UpdateServiceWorkers(bool waiting_for_debugger); | 39 void ReattachServiceWorkers(bool waiting_for_debugger); |
| 77 void ReattachTargetsOfType(const HostsMap& new_hosts, | 40 void ReattachTargetsOfType(const Hosts& new_hosts, |
| 78 const std::string& type, | 41 const std::string& type, |
| 79 bool waiting_for_debugger); | 42 bool waiting_for_debugger); |
| 80 void TargetCreatedInternal(DevToolsAgentHost* host); | |
| 81 void TargetInfoChangedInternal(DevToolsAgentHost* host); | |
| 82 void TargetDestroyedInternal(DevToolsAgentHost* host); | |
| 83 bool AttachToTargetInternal(DevToolsAgentHost* host, | |
| 84 bool waiting_for_debugger); | |
| 85 void DetachFromTargetInternal(DevToolsAgentHost* host); | |
| 86 | 43 |
| 87 // ServiceWorkerDevToolsManager::Observer implementation. | 44 // ServiceWorkerDevToolsManager::Observer implementation. |
| 88 void WorkerCreated(ServiceWorkerDevToolsAgentHost* host) override; | 45 void WorkerCreated(ServiceWorkerDevToolsAgentHost* host) override; |
| 89 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost* host) override; | 46 void WorkerReadyForInspection(ServiceWorkerDevToolsAgentHost* host) override; |
| 90 void WorkerVersionInstalled(ServiceWorkerDevToolsAgentHost* host) override; | 47 void WorkerVersionInstalled(ServiceWorkerDevToolsAgentHost* host) override; |
| 91 void WorkerVersionDoomed(ServiceWorkerDevToolsAgentHost* host) override; | 48 void WorkerVersionDoomed(ServiceWorkerDevToolsAgentHost* host) override; |
| 92 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) override; | 49 void WorkerDestroyed(ServiceWorkerDevToolsAgentHost* host) override; |
| 93 | 50 |
| 94 // DevToolsAgentHostObserver implementation. | 51 AttachCallback attach_callback_; |
| 95 bool ShouldForceDevToolsAgentHostCreation() override; | 52 DetachCallback detach_callback_; |
| 96 void DevToolsAgentHostCreated(DevToolsAgentHost* agent_host) override; | 53 RenderFrameHostImpl* render_frame_host_; |
| 97 void DevToolsAgentHostDestroyed(DevToolsAgentHost* agent_host) override; | 54 base::flat_set<GURL> frame_urls_; |
| 98 void DevToolsAgentHostAttached(DevToolsAgentHost* agent_host) override; | |
| 99 void DevToolsAgentHostDetached(DevToolsAgentHost* agent_host) override; | |
| 100 | 55 |
| 101 // DevToolsAgentHostClient implementation. | |
| 102 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | |
| 103 const std::string& message) override; | |
| 104 void AgentHostClosed(DevToolsAgentHost* agent_host, | |
| 105 bool replaced_with_another_client) override; | |
| 106 | |
| 107 std::unique_ptr<Target::Frontend> frontend_; | |
| 108 bool discover_; | |
| 109 bool auto_attach_; | 56 bool auto_attach_; |
| 110 bool wait_for_debugger_on_start_; | 57 bool wait_for_debugger_on_start_; |
| 111 bool attach_to_frames_; | 58 bool attach_to_frames_; |
| 112 RenderFrameHostImpl* render_frame_host_; | |
| 113 HostsMap attached_hosts_; | |
| 114 std::set<GURL> frame_urls_; | |
| 115 RawHostsMap reported_hosts_; | |
| 116 | 59 |
| 117 DISALLOW_COPY_AND_ASSIGN(TargetHandler); | 60 Hosts auto_attached_hosts_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(TargetAutoAttacher); |
| 118 }; | 63 }; |
| 119 | 64 |
| 120 } // namespace protocol | 65 } // namespace protocol |
| 121 } // namespace content | 66 } // namespace content |
| 122 | 67 |
| 123 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TARGET_HANDLER_H_ | 68 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_TARGET_AUTO_ATTACHER_H_ |
| OLD | NEW |