15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/devtools_agent_host.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace IPC {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Message;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)class BrowserContext;
2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Describes interface for managing devtools agents from the browser process.
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CONTENT_EXPORT DevToolsAgentHostImpl : public DevToolsAgentHost {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns a list of all existing WebContents that can be debugged.
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static std::vector<WebContents*> GetInspectableWebContents();
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Informs the hosted agent that a client host has attached.
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void Attach() = 0;
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Informs the hosted agent that a client host has detached.
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void Detach() = 0;
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Sends a message to the agent.
3503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void DispatchProtocolMessage(const std::string& message) = 0;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Opens the inspector for this host.
3803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void Inspect(BrowserContext* browser_context);
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // DevToolsAgentHost implementation.
4103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void AttachClient(DevToolsAgentHostClient* client) OVERRIDE;
4203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void DetachClient() OVERRIDE;
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual bool IsAttached() OVERRIDE;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void InspectElement(int x, int y) OVERRIDE;
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual std::string GetId() OVERRIDE;
466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual WebContents* GetWebContents() OVERRIDE;
476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void DisconnectWebContents() OVERRIDE;
4803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  virtual void ConnectWebContents(WebContents* wc) OVERRIDE;
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual bool IsWorker() const OVERRIDE;
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DevToolsAgentHostImpl();
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~DevToolsAgentHostImpl();
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void HostClosed();
5603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void SendMessageToClient(const std::string& message);
5703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  static void NotifyCallbacks(DevToolsAgentHostImpl* agent_host, bool attached);
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
6003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  friend class DevToolsAgentHost; // for static methods
6103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const std::string id_;
6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  DevToolsAgentHostClient* client_;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_AGENT_HOST_IMPL_H_
69