chrome_extension_message_filter.h revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1// Copyright 2014 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_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_ 6#define CHROME_BROWSER_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_ 7 8#include <string> 9 10#include "base/sequenced_task_runner_helpers.h" 11#include "content/public/browser/browser_message_filter.h" 12 13class GURL; 14class Profile; 15struct ExtensionHostMsg_APIActionOrEvent_Params; 16struct ExtensionHostMsg_DOMAction_Params; 17struct ExtensionMsg_ExternalConnectionInfo; 18 19namespace base { 20class FilePath; 21} 22 23namespace extensions { 24class InfoMap; 25} 26 27// This class filters out incoming Chrome-specific IPC messages from the 28// extension process on the IPC thread. 29class ChromeExtensionMessageFilter : public content::BrowserMessageFilter { 30 public: 31 ChromeExtensionMessageFilter(int render_process_id, Profile* profile); 32 33 // content::BrowserMessageFilter methods: 34 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 35 virtual void OverrideThreadForMessage( 36 const IPC::Message& message, 37 content::BrowserThread::ID* thread) OVERRIDE; 38 39 private: 40 friend class content::BrowserThread; 41 friend class base::DeleteHelper<ChromeExtensionMessageFilter>; 42 43 virtual ~ChromeExtensionMessageFilter(); 44 45 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed); 46 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed); 47 48 // TODO(jamescook): Move these functions into the extensions module. Ideally 49 // this would be in extensions::ExtensionMessageFilter but that will require 50 // resolving the MessageService and ActivityLog dependencies on src/chrome. 51 // http://crbug.com/339637 52 void OnOpenChannelToExtension(int routing_id, 53 const ExtensionMsg_ExternalConnectionInfo& info, 54 const std::string& channel_name, 55 bool include_tls_channel_id, 56 int* port_id); 57 void OpenChannelToExtensionOnUIThread( 58 int source_process_id, 59 int source_routing_id, 60 int receiver_port_id, 61 const ExtensionMsg_ExternalConnectionInfo& info, 62 const std::string& channel_name, 63 bool include_tls_channel_id); 64 void OnOpenChannelToNativeApp(int routing_id, 65 const std::string& source_extension_id, 66 const std::string& native_app_name, 67 int* port_id); 68 void OpenChannelToNativeAppOnUIThread(int source_routing_id, 69 int receiver_port_id, 70 const std::string& source_extension_id, 71 const std::string& native_app_name); 72 void OnOpenChannelToTab(int routing_id, int tab_id, 73 const std::string& extension_id, 74 const std::string& channel_name, int* port_id); 75 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id, 76 int receiver_port_id, 77 int tab_id, const std::string& extension_id, 78 const std::string& channel_name); 79 void OnGetExtMessageBundle(const std::string& extension_id, 80 IPC::Message* reply_msg); 81 void OnGetExtMessageBundleOnBlockingPool( 82 const base::FilePath& extension_path, 83 const std::string& extension_id, 84 const std::string& default_locale, 85 IPC::Message* reply_msg); 86 void OnExtensionCloseChannel(int port_id, const std::string& error_message); 87 void OnAddAPIActionToExtensionActivityLog( 88 const std::string& extension_id, 89 const ExtensionHostMsg_APIActionOrEvent_Params& params); 90 void OnAddBlockedCallToExtensionActivityLog( 91 const std::string& extension_id, 92 const std::string& function_name); 93 void OnAddDOMActionToExtensionActivityLog( 94 const std::string& extension_id, 95 const ExtensionHostMsg_DOMAction_Params& params); 96 void OnAddEventToExtensionActivityLog( 97 const std::string& extension_id, 98 const ExtensionHostMsg_APIActionOrEvent_Params& params); 99 100 const int render_process_id_; 101 102 // The Profile associated with our renderer process. This should only be 103 // accessed on the UI thread! 104 Profile* profile_; 105 106 scoped_refptr<extensions::InfoMap> extension_info_map_; 107 108 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionMessageFilter); 109}; 110 111#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_ 112