OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" | 5 #include "chrome/browser/renderer_host/chrome_extension_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 bool ChromeExtensionMessageFilter::OnMessageReceived( | 78 bool ChromeExtensionMessageFilter::OnMessageReceived( |
79 const IPC::Message& message) { | 79 const IPC::Message& message) { |
80 bool handled = true; | 80 bool handled = true; |
81 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionMessageFilter, message) | 81 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionMessageFilter, message) |
82 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, | 82 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, |
83 OnOpenChannelToExtension) | 83 OnOpenChannelToExtension) |
84 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab) | 84 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab) |
85 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp, | 85 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp, |
86 OnOpenChannelToNativeApp) | 86 OnOpenChannelToNativeApp) |
| 87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenMessagePort, OnOpenMessagePort) |
| 88 IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseMessagePort, OnCloseMessagePort) |
87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) | 89 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) |
88 IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle, | 90 IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle, |
89 OnGetExtMessageBundle) | 91 OnGetExtMessageBundle) |
90 IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel) | |
91 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddAPIActionToActivityLog, | 92 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddAPIActionToActivityLog, |
92 OnAddAPIActionToExtensionActivityLog); | 93 OnAddAPIActionToExtensionActivityLog); |
93 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddDOMActionToActivityLog, | 94 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddDOMActionToActivityLog, |
94 OnAddDOMActionToExtensionActivityLog); | 95 OnAddDOMActionToExtensionActivityLog); |
95 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddEventToActivityLog, | 96 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddEventToActivityLog, |
96 OnAddEventToExtensionActivityLog); | 97 OnAddEventToExtensionActivityLog); |
97 IPC_MESSAGE_UNHANDLED(handled = false) | 98 IPC_MESSAGE_UNHANDLED(handled = false) |
98 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
99 | 100 |
100 return handled; | 101 return handled; |
101 } | 102 } |
102 | 103 |
103 void ChromeExtensionMessageFilter::OverrideThreadForMessage( | 104 void ChromeExtensionMessageFilter::OverrideThreadForMessage( |
104 const IPC::Message& message, BrowserThread::ID* thread) { | 105 const IPC::Message& message, BrowserThread::ID* thread) { |
105 switch (message.type()) { | 106 switch (message.type()) { |
| 107 case ExtensionHostMsg_OpenMessagePort::ID: |
| 108 case ExtensionHostMsg_CloseMessagePort::ID: |
106 case ExtensionHostMsg_PostMessage::ID: | 109 case ExtensionHostMsg_PostMessage::ID: |
107 case ExtensionHostMsg_CloseChannel::ID: | |
108 case ExtensionHostMsg_AddAPIActionToActivityLog::ID: | 110 case ExtensionHostMsg_AddAPIActionToActivityLog::ID: |
109 case ExtensionHostMsg_AddDOMActionToActivityLog::ID: | 111 case ExtensionHostMsg_AddDOMActionToActivityLog::ID: |
110 case ExtensionHostMsg_AddEventToActivityLog::ID: | 112 case ExtensionHostMsg_AddEventToActivityLog::ID: |
111 *thread = BrowserThread::UI; | 113 *thread = BrowserThread::UI; |
112 break; | 114 break; |
113 default: | 115 default: |
114 break; | 116 break; |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 extensions::MessageService::Get(profile_) | 187 extensions::MessageService::Get(profile_) |
186 ->OpenChannelToNativeApp(render_process_id_, | 188 ->OpenChannelToNativeApp(render_process_id_, |
187 source_routing_id, | 189 source_routing_id, |
188 receiver_port_id, | 190 receiver_port_id, |
189 source_extension_id, | 191 source_extension_id, |
190 native_app_name); | 192 native_app_name); |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 void ChromeExtensionMessageFilter::OnOpenChannelToTab( | 196 void ChromeExtensionMessageFilter::OnOpenChannelToTab( |
| 197 int routing_id, |
195 const ExtensionMsg_TabTargetConnectionInfo& info, | 198 const ExtensionMsg_TabTargetConnectionInfo& info, |
196 const std::string& extension_id, | 199 const std::string& extension_id, |
197 const std::string& channel_name, | 200 const std::string& channel_name, |
198 int* port_id) { | 201 int* port_id) { |
199 int port2_id; | 202 int port2_id; |
200 extensions::MessageService::AllocatePortIdPair(port_id, &port2_id); | 203 extensions::MessageService::AllocatePortIdPair(port_id, &port2_id); |
201 | 204 |
202 BrowserThread::PostTask( | 205 BrowserThread::PostTask( |
203 BrowserThread::UI, FROM_HERE, | 206 BrowserThread::UI, FROM_HERE, |
204 base::Bind(&ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread, | 207 base::Bind(&ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread, |
205 this, render_process_id_, port2_id, info, extension_id, | 208 this, render_process_id_, routing_id, port2_id, info, |
206 channel_name)); | 209 extension_id, channel_name)); |
207 } | 210 } |
208 | 211 |
209 void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread( | 212 void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread( |
210 int source_process_id, | 213 int source_process_id, |
| 214 int source_routing_id, |
211 int receiver_port_id, | 215 int receiver_port_id, |
212 const ExtensionMsg_TabTargetConnectionInfo& info, | 216 const ExtensionMsg_TabTargetConnectionInfo& info, |
213 const std::string& extension_id, | 217 const std::string& extension_id, |
214 const std::string& channel_name) { | 218 const std::string& channel_name) { |
215 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 219 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
216 if (profile_) { | 220 if (profile_) { |
217 extensions::MessageService::Get(profile_) | 221 extensions::MessageService::Get(profile_) |
218 ->OpenChannelToTab(source_process_id, | 222 ->OpenChannelToTab(source_process_id, |
| 223 source_routing_id, |
219 receiver_port_id, | 224 receiver_port_id, |
220 info.tab_id, | 225 info.tab_id, |
221 info.frame_id, | 226 info.frame_id, |
222 extension_id, | 227 extension_id, |
223 channel_name); | 228 channel_name); |
224 } | 229 } |
225 } | 230 } |
226 | 231 |
| 232 void ChromeExtensionMessageFilter::OnOpenMessagePort(int routing_id, |
| 233 int port_id) { |
| 234 if (!profile_) |
| 235 return; |
| 236 |
| 237 extensions::MessageService::Get(profile_)->OpenPort( |
| 238 port_id, render_process_id_, routing_id); |
| 239 } |
| 240 |
| 241 void ChromeExtensionMessageFilter::OnCloseMessagePort(int routing_id, |
| 242 int port_id, |
| 243 bool force_close) { |
| 244 if (!profile_) |
| 245 return; |
| 246 |
| 247 extensions::MessageService::Get(profile_)->ClosePort( |
| 248 port_id, render_process_id_, routing_id, force_close); |
| 249 } |
| 250 |
227 void ChromeExtensionMessageFilter::OnPostMessage( | 251 void ChromeExtensionMessageFilter::OnPostMessage( |
228 int port_id, | 252 int port_id, |
229 const extensions::Message& message) { | 253 const extensions::Message& message) { |
230 if (!profile_) | 254 if (!profile_) |
231 return; | 255 return; |
232 | 256 |
233 extensions::MessageService::Get(profile_)->PostMessage(port_id, message); | 257 extensions::MessageService::Get(profile_)->PostMessage(port_id, message); |
234 } | 258 } |
235 | 259 |
236 void ChromeExtensionMessageFilter::OnGetExtMessageBundle( | 260 void ChromeExtensionMessageFilter::OnGetExtMessageBundle( |
(...skipping 15 matching lines...) Expand all Loading... |
252 | 276 |
253 scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( | 277 scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( |
254 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( | 278 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( |
255 extension_id, extension_set)); | 279 extension_id, extension_set)); |
256 | 280 |
257 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, | 281 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, |
258 *dictionary_map); | 282 *dictionary_map); |
259 Send(reply_msg); | 283 Send(reply_msg); |
260 } | 284 } |
261 | 285 |
262 void ChromeExtensionMessageFilter::OnExtensionCloseChannel( | |
263 int port_id, | |
264 const std::string& error_message) { | |
265 if (!profile_) | |
266 return; | |
267 | |
268 if (!content::RenderProcessHost::FromID(render_process_id_)) | |
269 return; // To guard against crash in browser_tests shutdown. | |
270 | |
271 extensions::MessageService* message_service = | |
272 extensions::MessageService::Get(profile_); | |
273 if (message_service) | |
274 message_service->CloseChannel(port_id, error_message); | |
275 } | |
276 | |
277 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( | 286 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( |
278 const std::string& extension_id, | 287 const std::string& extension_id, |
279 const ExtensionHostMsg_APIActionOrEvent_Params& params) { | 288 const ExtensionHostMsg_APIActionOrEvent_Params& params) { |
280 scoped_refptr<extensions::Action> action = new extensions::Action( | 289 scoped_refptr<extensions::Action> action = new extensions::Action( |
281 extension_id, base::Time::Now(), extensions::Action::ACTION_API_CALL, | 290 extension_id, base::Time::Now(), extensions::Action::ACTION_API_CALL, |
282 params.api_call); | 291 params.api_call); |
283 action->set_args(make_scoped_ptr(params.arguments.DeepCopy())); | 292 action->set_args(make_scoped_ptr(params.arguments.DeepCopy())); |
284 if (!params.extra.empty()) { | 293 if (!params.extra.empty()) { |
285 action->mutable_other()->SetString( | 294 action->mutable_other()->SetString( |
286 activity_log_constants::kActionExtra, params.extra); | 295 activity_log_constants::kActionExtra, params.extra); |
(...skipping 29 matching lines...) Expand all Loading... |
316 AddActionToExtensionActivityLog(profile_, action); | 325 AddActionToExtensionActivityLog(profile_, action); |
317 } | 326 } |
318 | 327 |
319 void ChromeExtensionMessageFilter::Observe( | 328 void ChromeExtensionMessageFilter::Observe( |
320 int type, | 329 int type, |
321 const content::NotificationSource& source, | 330 const content::NotificationSource& source, |
322 const content::NotificationDetails& details) { | 331 const content::NotificationDetails& details) { |
323 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 332 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
324 profile_ = NULL; | 333 profile_ = NULL; |
325 } | 334 } |
OLD | NEW |