1// Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_
7#pragma once
8
9#include <string>
10
11#include "base/memory/ref_counted.h"
12#include "chrome/browser/debugger/devtools_client_host.h"
13#include "chrome/browser/extensions/extension_devtools_manager.h"
14#include "chrome/browser/extensions/extension_message_service.h"
15
16class Profile;
17
18// This class is a DevToolsClientHost that fires extension events.
19class ExtensionDevToolsBridge : public DevToolsClientHost {
20 public:
21  ExtensionDevToolsBridge(int tab_id, Profile* profile);
22  virtual ~ExtensionDevToolsBridge();
23
24  bool RegisterAsDevToolsClientHost();
25  void UnregisterAsDevToolsClientHost();
26
27  // DevToolsClientHost, called when the tab inspected by this client is
28  // closing.
29  virtual void InspectedTabClosing();
30
31  // DevToolsClientHost, called to send a message to this host.
32  virtual void SendMessageToClient(const IPC::Message& msg);
33
34  virtual void TabReplaced(TabContentsWrapper* new_tab);
35
36 private:
37  void OnDispatchOnInspectorFrontend(const std::string& data);
38
39  virtual void FrameNavigating(const std::string& url) {}
40
41  // ID of the tab we are monitoring.
42  int tab_id_;
43
44  scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;
45  scoped_refptr<ExtensionMessageService> extension_message_service_;
46
47  // Profile that owns our tab
48  Profile* profile_;
49
50  // The names of the events fired at extensions depend on the tab id,
51  // so we store the various event names in each bridge.
52  const std::string on_page_event_name_;
53  const std::string on_tab_close_event_name_;
54
55  DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsBridge);
56};
57
58#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_
59
60