summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_web_contents_observer.h
blob: 019dc88c0b9562cd0c886f675ca8186c6ee64db1 (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
// Copyright 2013 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_WEB_CONTENTS_OBSERVER_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_CONTENTS_OBSERVER_H_

#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"

class Profile;

namespace extensions {
class Extension;
struct Message;

// A web contents observer that's used for WebContents in renderer and extension
// processes.
class ExtensionWebContentsObserver
    : public content::WebContentsObserver,
      public content::WebContentsUserData<ExtensionWebContentsObserver> {
 public:
  virtual ~ExtensionWebContentsObserver();

 private:
  explicit ExtensionWebContentsObserver(content::WebContents* web_contents);
  friend class content::WebContentsUserData<ExtensionWebContentsObserver>;

  // content::WebContentsObserver overrides.
  virtual void RenderViewCreated(
      content::RenderViewHost* render_view_host) OVERRIDE;
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  void OnPostMessage(int port_id, const Message& message);

  // Gets the extension or app (if any) that is associated with a RVH.
  const Extension* GetExtension(content::RenderViewHost* render_view_host);

  Profile* profile_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserver);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_CONTENTS_OBSERVER_H_