OLD | NEW |
(Empty) | |
| 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_MESSAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_HANDLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 10 #include "ipc/ipc_channel.h" |
| 11 |
| 12 class ExtensionFunctionDispatcher; |
| 13 class Profile; |
| 14 struct ExtensionHostMsg_DomMessage_Params; |
| 15 |
| 16 // Filters and dispatches extension-related IPC messages that arrive from |
| 17 // renderer/extension processes. This object is created for renderers and also |
| 18 // ExtensionHost/BackgroundContents. Contrast this with ExtensionTabHelper, |
| 19 // which is only created for TabContents. |
| 20 class ExtensionMessageHandler : public IPC::Channel::Listener { |
| 21 public: |
| 22 // |sender| is guaranteed to outlive this object. |
| 23 ExtensionMessageHandler(int child_id, |
| 24 IPC::Message::Sender* sender, |
| 25 Profile* profile); |
| 26 virtual ~ExtensionMessageHandler(); |
| 27 |
| 28 // IPC::Channel::Listener overrides. |
| 29 virtual bool OnMessageReceived(const IPC::Message& message); |
| 30 |
| 31 // Returns true iff the message can be dispatched. |
| 32 bool CanDispatchRequest(int child_id, |
| 33 int routing_id, |
| 34 const ExtensionHostMsg_DomMessage_Params& params); |
| 35 |
| 36 void set_extension_function_dispatcher(ExtensionFunctionDispatcher* e) { |
| 37 extension_function_dispatcher_ = e; |
| 38 } |
| 39 |
| 40 private: |
| 41 // Message handlers. |
| 42 void OnPostMessage(int port_id, const std::string& message); |
| 43 void OnRequest(const IPC::Message& message, |
| 44 const ExtensionHostMsg_DomMessage_Params& params); |
| 45 |
| 46 // The child id of the corresponding process. Can be 0. |
| 47 int child_id_; |
| 48 |
| 49 // Guaranteed to outlive this object. |
| 50 IPC::Message::Sender* sender_; |
| 51 ExtensionFunctionDispatcher* extension_function_dispatcher_; |
| 52 |
| 53 Profile* profile_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageHandler); |
| 56 }; |
| 57 |
| 58 // A TabContentsObserver that forwards IPCs to ExtensionMessageHandler. |
| 59 class ExtensionMessageObserver : public TabContentsObserver { |
| 60 public: |
| 61 explicit ExtensionMessageObserver(TabContents* tab_contents); |
| 62 ~ExtensionMessageObserver(); |
| 63 |
| 64 private: |
| 65 // TabContentsObserver overrides. |
| 66 virtual bool OnMessageReceived(const IPC::Message& message); |
| 67 |
| 68 void OnRequest(const IPC::Message& message, |
| 69 const ExtensionHostMsg_DomMessage_Params& params); |
| 70 |
| 71 ExtensionMessageHandler handler_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageObserver); |
| 74 }; |
| 75 |
| 76 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_HANDLER_H_ |
OLD | NEW |