OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_event_router.h" | 5 #include "chrome/browser/extensions/extension_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/extension_devtools_manager.h" | 10 #include "chrome/browser/extensions/extension_devtools_manager.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return false; | 60 return false; |
61 } | 61 } |
62 }; | 62 }; |
63 | 63 |
64 struct ExtensionEventRouter::ExtensionEvent { | 64 struct ExtensionEventRouter::ExtensionEvent { |
65 std::string event_name; | 65 std::string event_name; |
66 std::string event_args; | 66 std::string event_args; |
67 GURL event_url; | 67 GURL event_url; |
68 Profile* restrict_to_profile; | 68 Profile* restrict_to_profile; |
69 std::string cross_incognito_args; | 69 std::string cross_incognito_args; |
| 70 UserGestureState user_gesture; |
70 | 71 |
71 ExtensionEvent(const std::string& event_name, | 72 ExtensionEvent(const std::string& event_name, |
72 const std::string& event_args, | 73 const std::string& event_args, |
73 const GURL& event_url, | 74 const GURL& event_url, |
74 Profile* restrict_to_profile, | 75 Profile* restrict_to_profile, |
75 const std::string& cross_incognito_args) | 76 const std::string& cross_incognito_args, |
| 77 UserGestureState user_gesture) |
76 : event_name(event_name), | 78 : event_name(event_name), |
77 event_args(event_args), | 79 event_args(event_args), |
78 event_url(event_url), | 80 event_url(event_url), |
79 restrict_to_profile(restrict_to_profile), | 81 restrict_to_profile(restrict_to_profile), |
80 cross_incognito_args(cross_incognito_args) {} | 82 cross_incognito_args(cross_incognito_args), |
| 83 user_gesture(user_gesture) {} |
81 }; | 84 }; |
82 | 85 |
83 // static | 86 // static |
84 void ExtensionEventRouter::DispatchEvent(IPC::Message::Sender* ipc_sender, | 87 void ExtensionEventRouter::DispatchEvent(IPC::Message::Sender* ipc_sender, |
85 const std::string& extension_id, | 88 const std::string& extension_id, |
86 const std::string& event_name, | 89 const std::string& event_name, |
87 const std::string& event_args, | 90 const std::string& event_args, |
88 const GURL& event_url) { | 91 const GURL& event_url, |
| 92 UserGestureState user_gesture) { |
89 ListValue args; | 93 ListValue args; |
90 args.Set(0, Value::CreateStringValue(event_name)); | 94 args.Set(0, Value::CreateStringValue(event_name)); |
91 args.Set(1, Value::CreateStringValue(event_args)); | 95 args.Set(1, Value::CreateStringValue(event_args)); |
92 ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, | 96 ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, |
93 extension_id, kDispatchEvent, args, event_url)); | 97 extension_id, kDispatchEvent, args, event_url, |
| 98 user_gesture == USER_GESTURE_ENABLED)); |
94 } | 99 } |
95 | 100 |
96 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) | 101 ExtensionEventRouter::ExtensionEventRouter(Profile* profile) |
97 : profile_(profile), | 102 : profile_(profile), |
98 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { | 103 extension_devtools_manager_(profile->GetExtensionDevToolsManager()) { |
99 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 104 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
100 content::NotificationService::AllSources()); | 105 content::NotificationService::AllSources()); |
101 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 106 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
102 content::NotificationService::AllSources()); | 107 content::NotificationService::AllSources()); |
103 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 108 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return false; | 223 return false; |
219 } | 224 } |
220 | 225 |
221 void ExtensionEventRouter::DispatchEventToRenderers( | 226 void ExtensionEventRouter::DispatchEventToRenderers( |
222 const std::string& event_name, | 227 const std::string& event_name, |
223 const std::string& event_args, | 228 const std::string& event_args, |
224 Profile* restrict_to_profile, | 229 Profile* restrict_to_profile, |
225 const GURL& event_url) { | 230 const GURL& event_url) { |
226 linked_ptr<ExtensionEvent> event( | 231 linked_ptr<ExtensionEvent> event( |
227 new ExtensionEvent(event_name, event_args, event_url, | 232 new ExtensionEvent(event_name, event_args, event_url, |
228 restrict_to_profile, "")); | 233 restrict_to_profile, "", USER_GESTURE_UNKNOWN)); |
229 DispatchEventImpl("", event, false); | 234 DispatchEventImpl("", event, false); |
230 } | 235 } |
231 | 236 |
232 void ExtensionEventRouter::DispatchEventToExtension( | 237 void ExtensionEventRouter::DispatchEventToExtension( |
233 const std::string& extension_id, | 238 const std::string& extension_id, |
234 const std::string& event_name, | 239 const std::string& event_name, |
235 const std::string& event_args, | 240 const std::string& event_args, |
236 Profile* restrict_to_profile, | 241 Profile* restrict_to_profile, |
237 const GURL& event_url) { | 242 const GURL& event_url) { |
238 DCHECK(!extension_id.empty()); | 243 DCHECK(!extension_id.empty()); |
239 linked_ptr<ExtensionEvent> event( | 244 linked_ptr<ExtensionEvent> event( |
240 new ExtensionEvent(event_name, event_args, event_url, | 245 new ExtensionEvent(event_name, event_args, event_url, |
241 restrict_to_profile, "")); | 246 restrict_to_profile, "", USER_GESTURE_UNKNOWN)); |
242 DispatchEventImpl(extension_id, event, false); | 247 DispatchEventImpl(extension_id, event, false); |
243 } | 248 } |
244 | 249 |
| 250 void ExtensionEventRouter::DispatchEventToExtension( |
| 251 const std::string& extension_id, |
| 252 const std::string& event_name, |
| 253 const std::string& event_args, |
| 254 Profile* restrict_to_profile, |
| 255 const GURL& event_url, |
| 256 UserGestureState user_gesture) { |
| 257 DCHECK(!extension_id.empty()); |
| 258 linked_ptr<ExtensionEvent> event( |
| 259 new ExtensionEvent(event_name, event_args, event_url, |
| 260 restrict_to_profile, "", user_gesture)); |
| 261 DispatchEventImpl(extension_id, event, false); |
| 262 } |
| 263 |
245 void ExtensionEventRouter::DispatchEventsToRenderersAcrossIncognito( | 264 void ExtensionEventRouter::DispatchEventsToRenderersAcrossIncognito( |
246 const std::string& event_name, | 265 const std::string& event_name, |
247 const std::string& event_args, | 266 const std::string& event_args, |
248 Profile* restrict_to_profile, | 267 Profile* restrict_to_profile, |
249 const std::string& cross_incognito_args, | 268 const std::string& cross_incognito_args, |
250 const GURL& event_url) { | 269 const GURL& event_url) { |
251 linked_ptr<ExtensionEvent> event( | 270 linked_ptr<ExtensionEvent> event( |
252 new ExtensionEvent(event_name, event_args, event_url, | 271 new ExtensionEvent(event_name, event_args, event_url, |
253 restrict_to_profile, cross_incognito_args)); | 272 restrict_to_profile, cross_incognito_args, |
| 273 USER_GESTURE_UNKNOWN)); |
254 DispatchEventImpl("", event, false); | 274 DispatchEventImpl("", event, false); |
255 } | 275 } |
256 | 276 |
257 bool ExtensionEventRouter::CanDispatchEventNow(const Extension* extension) { | 277 bool ExtensionEventRouter::CanDispatchEventNow(const Extension* extension) { |
258 DCHECK(extension); | 278 DCHECK(extension); |
259 if (extension->has_background_page() && | 279 if (extension->has_background_page() && |
260 !extension->background_page_persists()) { | 280 !extension->background_page_persists()) { |
261 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager(); | 281 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager(); |
262 ExtensionHost* background_host = | 282 ExtensionHost* background_host = |
263 pm->GetBackgroundHostForExtension(extension->id()); | 283 pm->GetBackgroundHostForExtension(extension->id()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // Is this event from a different profile than the renderer (ie, an | 341 // Is this event from a different profile than the renderer (ie, an |
322 // incognito tab event sent to a normal process, or vice versa). | 342 // incognito tab event sent to a normal process, or vice versa). |
323 bool cross_incognito = event->restrict_to_profile && | 343 bool cross_incognito = event->restrict_to_profile && |
324 listener_profile != event->restrict_to_profile; | 344 listener_profile != event->restrict_to_profile; |
325 // Send the event with different arguments to extensions that can't | 345 // Send the event with different arguments to extensions that can't |
326 // cross incognito, if necessary. | 346 // cross incognito, if necessary. |
327 if (cross_incognito && !service->CanCrossIncognito(extension)) { | 347 if (cross_incognito && !service->CanCrossIncognito(extension)) { |
328 if (!event->cross_incognito_args.empty()) { | 348 if (!event->cross_incognito_args.empty()) { |
329 DispatchEvent(listener->process, listener->extension_id, | 349 DispatchEvent(listener->process, listener->extension_id, |
330 event->event_name, event->cross_incognito_args, | 350 event->event_name, event->cross_incognito_args, |
331 event->event_url); | 351 event->event_url, event->user_gesture); |
332 IncrementInFlightEvents(extension); | 352 IncrementInFlightEvents(extension); |
333 } | 353 } |
334 continue; | 354 continue; |
335 } | 355 } |
336 | 356 |
337 DispatchEvent(listener->process, listener->extension_id, | 357 DispatchEvent(listener->process, listener->extension_id, |
338 event->event_name, event->event_args, event->event_url); | 358 event->event_name, event->event_args, |
| 359 event->event_url, event->user_gesture); |
339 IncrementInFlightEvents(extension); | 360 IncrementInFlightEvents(extension); |
340 } | 361 } |
341 } | 362 } |
342 | 363 |
343 void ExtensionEventRouter::LoadLazyBackgroundPagesForEvent( | 364 void ExtensionEventRouter::LoadLazyBackgroundPagesForEvent( |
344 const std::string& extension_id, | 365 const std::string& extension_id, |
345 const linked_ptr<ExtensionEvent>& event) { | 366 const linked_ptr<ExtensionEvent>& event) { |
346 ExtensionService* service = profile_->GetExtensionService(); | 367 ExtensionService* service = profile_->GetExtensionService(); |
347 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager(); | 368 ExtensionProcessManager* pm = profile_->GetExtensionProcessManager(); |
348 | 369 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 extension->id(), kOnInstalledEvent, "[]", NULL, GURL()); | 520 extension->id(), kOnInstalledEvent, "[]", NULL, GURL()); |
500 break; | 521 break; |
501 } | 522 } |
502 | 523 |
503 // TODO(tessamac): if background page crashed/failed clear queue. | 524 // TODO(tessamac): if background page crashed/failed clear queue. |
504 default: | 525 default: |
505 NOTREACHED(); | 526 NOTREACHED(); |
506 return; | 527 return; |
507 } | 528 } |
508 } | 529 } |
OLD | NEW |