Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: chrome/browser/renderer_host/chrome_extension_message_filter.cc

Issue 1413543005: Use FrameTreeNode ID as frameId in extension APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/:/ / Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 bool ChromeExtensionMessageFilter::OnMessageReceived( 80 bool ChromeExtensionMessageFilter::OnMessageReceived(
81 const IPC::Message& message) { 81 const IPC::Message& message) {
82 bool handled = true; 82 bool handled = true;
83 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionMessageFilter, message) 83 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionMessageFilter, message)
84 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension, 84 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToExtension,
85 OnOpenChannelToExtension) 85 OnOpenChannelToExtension)
86 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab) 86 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToTab, OnOpenChannelToTab)
87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp, 87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenChannelToNativeApp,
88 OnOpenChannelToNativeApp) 88 OnOpenChannelToNativeApp)
89 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OpenMessagePort, OnOpenMessagePort)
90 IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseMessagePort, OnCloseMessagePort)
89 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage) 91 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
90 IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle, 92 IPC_MESSAGE_HANDLER_DELAY_REPLY(ExtensionHostMsg_GetMessageBundle,
91 OnGetExtMessageBundle) 93 OnGetExtMessageBundle)
92 IPC_MESSAGE_HANDLER(ExtensionHostMsg_CloseChannel, OnExtensionCloseChannel)
93 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddAPIActionToActivityLog, 94 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddAPIActionToActivityLog,
94 OnAddAPIActionToExtensionActivityLog); 95 OnAddAPIActionToExtensionActivityLog);
95 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddDOMActionToActivityLog, 96 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddDOMActionToActivityLog,
96 OnAddDOMActionToExtensionActivityLog); 97 OnAddDOMActionToExtensionActivityLog);
97 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddEventToActivityLog, 98 IPC_MESSAGE_HANDLER(ExtensionHostMsg_AddEventToActivityLog,
98 OnAddEventToExtensionActivityLog); 99 OnAddEventToExtensionActivityLog);
99 IPC_MESSAGE_UNHANDLED(handled = false) 100 IPC_MESSAGE_UNHANDLED(handled = false)
100 IPC_END_MESSAGE_MAP() 101 IPC_END_MESSAGE_MAP()
101 102
102 return handled; 103 return handled;
103 } 104 }
104 105
105 void ChromeExtensionMessageFilter::OverrideThreadForMessage( 106 void ChromeExtensionMessageFilter::OverrideThreadForMessage(
106 const IPC::Message& message, BrowserThread::ID* thread) { 107 const IPC::Message& message, BrowserThread::ID* thread) {
107 switch (message.type()) { 108 switch (message.type()) {
109 case ExtensionHostMsg_OpenMessagePort::ID:
110 case ExtensionHostMsg_CloseMessagePort::ID:
108 case ExtensionHostMsg_PostMessage::ID: 111 case ExtensionHostMsg_PostMessage::ID:
109 case ExtensionHostMsg_CloseChannel::ID:
110 case ExtensionHostMsg_AddAPIActionToActivityLog::ID: 112 case ExtensionHostMsg_AddAPIActionToActivityLog::ID:
111 case ExtensionHostMsg_AddDOMActionToActivityLog::ID: 113 case ExtensionHostMsg_AddDOMActionToActivityLog::ID:
112 case ExtensionHostMsg_AddEventToActivityLog::ID: 114 case ExtensionHostMsg_AddEventToActivityLog::ID:
113 *thread = BrowserThread::UI; 115 *thread = BrowserThread::UI;
114 break; 116 break;
115 default: 117 default:
116 break; 118 break;
117 } 119 }
118 } 120 }
119 121
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 extensions::MessageService::Get(profile_) 189 extensions::MessageService::Get(profile_)
188 ->OpenChannelToNativeApp(render_process_id_, 190 ->OpenChannelToNativeApp(render_process_id_,
189 source_routing_id, 191 source_routing_id,
190 receiver_port_id, 192 receiver_port_id,
191 source_extension_id, 193 source_extension_id,
192 native_app_name); 194 native_app_name);
193 } 195 }
194 } 196 }
195 197
196 void ChromeExtensionMessageFilter::OnOpenChannelToTab( 198 void ChromeExtensionMessageFilter::OnOpenChannelToTab(
199 int routing_id,
197 const ExtensionMsg_TabTargetConnectionInfo& info, 200 const ExtensionMsg_TabTargetConnectionInfo& info,
198 const std::string& extension_id, 201 const std::string& extension_id,
199 const std::string& channel_name, 202 const std::string& channel_name,
200 int* port_id) { 203 int* port_id) {
201 int port2_id; 204 int port2_id;
202 extensions::MessageService::AllocatePortIdPair(port_id, &port2_id); 205 extensions::MessageService::AllocatePortIdPair(port_id, &port2_id);
203 206
204 BrowserThread::PostTask( 207 BrowserThread::PostTask(
205 BrowserThread::UI, FROM_HERE, 208 BrowserThread::UI, FROM_HERE,
206 base::Bind(&ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread, 209 base::Bind(&ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread,
207 this, render_process_id_, port2_id, info, extension_id, 210 this, render_process_id_, routing_id, port2_id, info,
208 channel_name)); 211 extension_id, channel_name));
209 } 212 }
210 213
211 void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread( 214 void ChromeExtensionMessageFilter::OpenChannelToTabOnUIThread(
212 int source_process_id, 215 int source_process_id,
216 int source_routing_id,
213 int receiver_port_id, 217 int receiver_port_id,
214 const ExtensionMsg_TabTargetConnectionInfo& info, 218 const ExtensionMsg_TabTargetConnectionInfo& info,
215 const std::string& extension_id, 219 const std::string& extension_id,
216 const std::string& channel_name) { 220 const std::string& channel_name) {
217 DCHECK_CURRENTLY_ON(BrowserThread::UI); 221 DCHECK_CURRENTLY_ON(BrowserThread::UI);
218 if (profile_) { 222 if (profile_) {
219 extensions::MessageService::Get(profile_) 223 extensions::MessageService::Get(profile_)
220 ->OpenChannelToTab(source_process_id, 224 ->OpenChannelToTab(source_process_id,
225 source_routing_id,
221 receiver_port_id, 226 receiver_port_id,
222 info.tab_id, 227 info.tab_id,
223 info.frame_id, 228 info.frame_id,
224 extension_id, 229 extension_id,
225 channel_name); 230 channel_name);
226 } 231 }
227 } 232 }
228 233
234 void ChromeExtensionMessageFilter::OnOpenMessagePort(int routing_id,
235 int port_id) {
236 if (!profile_)
237 return;
238
239 extensions::MessageService::Get(profile_)->OpenPort(
240 port_id, render_process_id_, routing_id);
241 }
242
243 void ChromeExtensionMessageFilter::OnCloseMessagePort(int routing_id,
244 int port_id,
245 bool force_close) {
246 if (!profile_)
247 return;
248
249 extensions::MessageService::Get(profile_)->ClosePort(
250 port_id, render_process_id_, routing_id, force_close);
251 }
252
229 void ChromeExtensionMessageFilter::OnPostMessage( 253 void ChromeExtensionMessageFilter::OnPostMessage(
230 int port_id, 254 int port_id,
231 const extensions::Message& message) { 255 const extensions::Message& message) {
232 if (!profile_) 256 if (!profile_)
233 return; 257 return;
234 258
235 extensions::MessageService::Get(profile_)->PostMessage(port_id, message); 259 extensions::MessageService::Get(profile_)->PostMessage(port_id, message);
236 } 260 }
237 261
238 void ChromeExtensionMessageFilter::OnGetExtMessageBundle( 262 void ChromeExtensionMessageFilter::OnGetExtMessageBundle(
(...skipping 15 matching lines...) Expand all
254 278
255 scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map( 279 scoped_ptr<extensions::MessageBundle::SubstitutionMap> dictionary_map(
256 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports( 280 extensions::file_util::LoadMessageBundleSubstitutionMapWithImports(
257 extension_id, extension_set)); 281 extension_id, extension_set));
258 282
259 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg, 283 ExtensionHostMsg_GetMessageBundle::WriteReplyParams(reply_msg,
260 *dictionary_map); 284 *dictionary_map);
261 Send(reply_msg); 285 Send(reply_msg);
262 } 286 }
263 287
264 void ChromeExtensionMessageFilter::OnExtensionCloseChannel(
265 int port_id,
266 const std::string& error_message) {
267 if (!profile_)
268 return;
269
270 if (!content::RenderProcessHost::FromID(render_process_id_))
271 return; // To guard against crash in browser_tests shutdown.
272
273 extensions::MessageService* message_service =
274 extensions::MessageService::Get(profile_);
275 if (message_service)
276 message_service->CloseChannel(port_id, error_message);
277 }
278
279 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog( 288 void ChromeExtensionMessageFilter::OnAddAPIActionToExtensionActivityLog(
280 const std::string& extension_id, 289 const std::string& extension_id,
281 const ExtensionHostMsg_APIActionOrEvent_Params& params) { 290 const ExtensionHostMsg_APIActionOrEvent_Params& params) {
282 scoped_refptr<extensions::Action> action = new extensions::Action( 291 scoped_refptr<extensions::Action> action = new extensions::Action(
283 extension_id, base::Time::Now(), extensions::Action::ACTION_API_CALL, 292 extension_id, base::Time::Now(), extensions::Action::ACTION_API_CALL,
284 params.api_call); 293 params.api_call);
285 action->set_args(make_scoped_ptr(params.arguments.DeepCopy())); 294 action->set_args(make_scoped_ptr(params.arguments.DeepCopy()));
286 if (!params.extra.empty()) { 295 if (!params.extra.empty()) {
287 action->mutable_other()->SetString( 296 action->mutable_other()->SetString(
288 activity_log_constants::kActionExtra, params.extra); 297 activity_log_constants::kActionExtra, params.extra);
(...skipping 29 matching lines...) Expand all
318 AddActionToExtensionActivityLog(profile_, action); 327 AddActionToExtensionActivityLog(profile_, action);
319 } 328 }
320 329
321 void ChromeExtensionMessageFilter::Observe( 330 void ChromeExtensionMessageFilter::Observe(
322 int type, 331 int type,
323 const content::NotificationSource& source, 332 const content::NotificationSource& source,
324 const content::NotificationDetails& details) { 333 const content::NotificationDetails& details) {
325 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 334 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
326 profile_ = NULL; 335 profile_ = NULL;
327 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698