1// Copyright (c) 2012 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_MESSAGE_HANDLER_H_ 6#define CHROME_BROWSER_EXTENSIONS_MESSAGE_HANDLER_H_ 7 8#include <string> 9 10#include "content/public/browser/render_view_host_observer.h" 11 12namespace extensions { 13 14// Filters and dispatches extension-related IPC messages that arrive from 15// renderers. There is one of these objects for each RenderViewHost in Chrome. 16// Contrast this with extensions::TabHelper, which is only created for 17// WebContents. 18// 19// TODO(aa): Handling of content script messaging should be able to move to EFD 20// once there is an EFD for every RVHD where extension code can run. Then we 21// could eliminate this class. Right now, we don't end up with an EFD for tab 22// contents unless that tab contents is hosting chrome-extension:// URLs. That 23// still leaves content scripts. See also: crbug.com/80307. 24class MessageHandler : public content::RenderViewHostObserver { 25 public: 26 // |sender| is guaranteed to outlive this object. 27 explicit MessageHandler(content::RenderViewHost* render_view_host); 28 virtual ~MessageHandler(); 29 30 // RenderViewHostObserver overrides. 31 virtual void RenderViewHostInitialized() OVERRIDE; 32 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 33 34 private: 35 // Message handlers. 36 void OnPostMessage(int port_id, const std::string& message); 37 38 DISALLOW_COPY_AND_ASSIGN(MessageHandler); 39}; 40 41} // namespace extensions 42 43#endif // CHROME_BROWSER_EXTENSIONS_MESSAGE_HANDLER_H_ 44