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.
5 #ifndef CHROME_BROWSER_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_
10 #include "base/sequenced_task_runner_helpers.h"
11 #include "content/public/browser/browser_message_filter.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
17 struct ExtensionHostMsg_APIActionOrEvent_Params;
18 struct ExtensionHostMsg_DOMAction_Params;
19 struct ExtensionMsg_ExternalConnectionInfo;
25 namespace extensions {
29 // This class filters out incoming Chrome-specific IPC messages from the
30 // extension process on the IPC thread.
31 class ChromeExtensionMessageFilter : public content::BrowserMessageFilter,
32 public content::NotificationObserver {
34 ChromeExtensionMessageFilter(int render_process_id, Profile* profile);
36 // content::BrowserMessageFilter methods:
37 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
38 virtual void OverrideThreadForMessage(
39 const IPC::Message& message,
40 content::BrowserThread::ID* thread) OVERRIDE;
41 virtual void OnDestruct() const OVERRIDE;
44 friend class content::BrowserThread;
45 friend class base::DeleteHelper<ChromeExtensionMessageFilter>;
47 virtual ~ChromeExtensionMessageFilter();
49 void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed);
50 void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed);
52 // TODO(jamescook): Move these functions into the extensions module. Ideally
53 // this would be in extensions::ExtensionMessageFilter but that will require
54 // resolving the MessageService and ActivityLog dependencies on src/chrome.
55 // http://crbug.com/339637
56 void OnOpenChannelToExtension(int routing_id,
57 const ExtensionMsg_ExternalConnectionInfo& info,
58 const std::string& channel_name,
59 bool include_tls_channel_id,
61 void OpenChannelToExtensionOnUIThread(
62 int source_process_id,
63 int source_routing_id,
65 const ExtensionMsg_ExternalConnectionInfo& info,
66 const std::string& channel_name,
67 bool include_tls_channel_id);
68 void OnOpenChannelToNativeApp(int routing_id,
69 const std::string& source_extension_id,
70 const std::string& native_app_name,
72 void OpenChannelToNativeAppOnUIThread(int source_routing_id,
74 const std::string& source_extension_id,
75 const std::string& native_app_name);
76 void OnOpenChannelToTab(int routing_id, int tab_id,
77 const std::string& extension_id,
78 const std::string& channel_name, int* port_id);
79 void OpenChannelToTabOnUIThread(int source_process_id, int source_routing_id,
81 int tab_id, const std::string& extension_id,
82 const std::string& channel_name);
83 void OnGetExtMessageBundle(const std::string& extension_id,
84 IPC::Message* reply_msg);
85 void OnGetExtMessageBundleOnBlockingPool(
86 const base::FilePath& extension_path,
87 const std::string& extension_id,
88 const std::string& default_locale,
89 IPC::Message* reply_msg);
90 void OnExtensionCloseChannel(int port_id, const std::string& error_message);
91 void OnAddAPIActionToExtensionActivityLog(
92 const std::string& extension_id,
93 const ExtensionHostMsg_APIActionOrEvent_Params& params);
94 void OnAddBlockedCallToExtensionActivityLog(
95 const std::string& extension_id,
96 const std::string& function_name);
97 void OnAddDOMActionToExtensionActivityLog(
98 const std::string& extension_id,
99 const ExtensionHostMsg_DOMAction_Params& params);
100 void OnAddEventToExtensionActivityLog(
101 const std::string& extension_id,
102 const ExtensionHostMsg_APIActionOrEvent_Params& params);
104 // content::NotificationObserver implementation.
105 virtual void Observe(int type,
106 const content::NotificationSource& source,
107 const content::NotificationDetails& details) OVERRIDE;
109 const int render_process_id_;
111 // The Profile associated with our renderer process. This should only be
112 // accessed on the UI thread! Furthermore since this class is refcounted it
113 // may outlive |profile_|, so make sure to NULL check if in doubt; async
114 // calls and the like.
117 scoped_refptr<extensions::InfoMap> extension_info_map_;
119 content::NotificationRegistrar notification_registrar_;
121 DISALLOW_COPY_AND_ASSIGN(ChromeExtensionMessageFilter);
124 #endif // CHROME_BROWSER_RENDERER_HOST_CHROME_EXTENSION_MESSAGE_FILTER_H_