summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_devtools_bridge.h
blob: 60f4afb4c49ef2636b87542623037e2321217c51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_
#pragma once

#include <string>

#include "base/memory/ref_counted.h"
#include "chrome/browser/extensions/extension_devtools_manager.h"
#include "content/public/browser/devtools_client_host.h"

class Profile;

// This class is a DevToolsClientHost that fires extension events.
class ExtensionDevToolsBridge : public content::DevToolsClientHost {
 public:
  ExtensionDevToolsBridge(int tab_id, Profile* profile);
  virtual ~ExtensionDevToolsBridge();

  bool RegisterAsDevToolsClientHost();
  void UnregisterAsDevToolsClientHost();

  // DevToolsClientHost, called when the tab inspected by this client is
  // closing.
  virtual void InspectedContentsClosing() OVERRIDE;

  // DevToolsClientHost, called to dispatch a message on this client.
  virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE;

  virtual void ContentsReplaced(content::WebContents* new_contents) OVERRIDE;

 private:
  virtual void FrameNavigating(const std::string& url) OVERRIDE {}

  // ID of the tab we are monitoring.
  int tab_id_;

  scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;

  // Profile that owns our tab
  Profile* profile_;

  // The names of the events fired at extensions depend on the tab id,
  // so we store the various event names in each bridge.
  const std::string on_page_event_name_;
  const std::string on_tab_close_event_name_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsBridge);
};

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_DEVTOOLS_BRIDGE_H_