| 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/event_router.h" | 5 #include "chrome/browser/extensions/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/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 12 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
| 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 13 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 13 #include "chrome/browser/extensions/extension_devtools_manager.h" | 14 #include "chrome/browser/extensions/extension_devtools_manager.h" |
| 14 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_process_manager.h" | 16 #include "chrome/browser/extensions/extension_process_manager.h" |
| 16 #include "chrome/browser/extensions/extension_processes_api.h" | 17 #include "chrome/browser/extensions/extension_processes_api.h" |
| 17 #include "chrome/browser/extensions/extension_processes_api_constants.h" | 18 #include "chrome/browser/extensions/extension_processes_api_constants.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_system.h" | 20 #include "chrome/browser/extensions/extension_system.h" |
| 20 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 21 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| 21 #include "chrome/browser/extensions/process_map.h" | 22 #include "chrome/browser/extensions/process_map.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/extensions/extension.h" | 27 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/extensions/extension_messages.h" | 28 #include "chrome/common/extensions/extension_messages.h" |
| 27 #include "chrome/common/extensions/api/extension_api.h" | 29 #include "chrome/common/extensions/api/extension_api.h" |
| 28 #include "chrome/common/view_type.h" | 30 #include "chrome/common/view_type.h" |
| 29 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
| 31 | 33 |
| 32 using base::Value; | 34 using base::Value; |
| 33 using content::BrowserThread; | 35 using content::BrowserThread; |
| 34 | 36 |
| 37 namespace extensions { |
| 38 |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 37 const char kDispatchEvent[] = "Event.dispatchEvent"; | 41 const char kDispatchEvent[] = "Event.dispatchEvent"; |
| 38 | 42 |
| 39 void NotifyEventListenerRemovedOnIOThread( | 43 void NotifyEventListenerRemovedOnIOThread( |
| 40 void* profile, | 44 void* profile, |
| 41 const std::string& extension_id, | 45 const std::string& extension_id, |
| 42 const std::string& sub_event_name) { | 46 const std::string& sub_event_name) { |
| 43 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( | 47 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( |
| 44 profile, extension_id, sub_event_name); | 48 profile, extension_id, sub_event_name); |
| 45 } | 49 } |
| 46 | 50 |
| 51 void DispatchOnInstalledEvent( |
| 52 Profile* profile, const std::string& extension_id) { |
| 53 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
| 54 return; |
| 55 |
| 56 RuntimeEventRouter::DispatchOnInstalledEvent(profile, extension_id); |
| 57 } |
| 58 |
| 47 } // namespace | 59 } // namespace |
| 48 | 60 |
| 49 namespace extensions { | |
| 50 | |
| 51 struct EventRouter::ListenerProcess { | 61 struct EventRouter::ListenerProcess { |
| 52 content::RenderProcessHost* process; | 62 content::RenderProcessHost* process; |
| 53 std::string extension_id; | 63 std::string extension_id; |
| 54 | 64 |
| 55 ListenerProcess(content::RenderProcessHost* process, | 65 ListenerProcess(content::RenderProcessHost* process, |
| 56 const std::string& extension_id) | 66 const std::string& extension_id) |
| 57 : process(process), extension_id(extension_id) {} | 67 : process(process), extension_id(extension_id) {} |
| 58 | 68 |
| 59 bool operator<(const ListenerProcess& that) const { | 69 bool operator<(const ListenerProcess& that) const { |
| 60 if (process < that.process) | 70 if (process < that.process) |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 UnloadedExtensionInfo* unloaded = | 561 UnloadedExtensionInfo* unloaded = |
| 552 content::Details<UnloadedExtensionInfo>(details).ptr(); | 562 content::Details<UnloadedExtensionInfo>(details).ptr(); |
| 553 listeners_.RemoveLazyListenersForExtension(unloaded->extension->id()); | 563 listeners_.RemoveLazyListenersForExtension(unloaded->extension->id()); |
| 554 break; | 564 break; |
| 555 } | 565 } |
| 556 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { | 566 case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| 557 // Dispatch the onInstalled event. | 567 // Dispatch the onInstalled event. |
| 558 const Extension* extension = | 568 const Extension* extension = |
| 559 content::Details<const Extension>(details).ptr(); | 569 content::Details<const Extension>(details).ptr(); |
| 560 MessageLoop::current()->PostTask(FROM_HERE, | 570 MessageLoop::current()->PostTask(FROM_HERE, |
| 561 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 571 base::Bind(&DispatchOnInstalledEvent, profile_, extension->id())); |
| 562 profile_, extension->id())); | |
| 563 break; | 572 break; |
| 564 } | 573 } |
| 565 default: | 574 default: |
| 566 NOTREACHED(); | 575 NOTREACHED(); |
| 567 return; | 576 return; |
| 568 } | 577 } |
| 569 } | 578 } |
| 570 | 579 |
| 571 Event::Event(const std::string& event_name, | 580 Event::Event(const std::string& event_name, |
| 572 scoped_ptr<ListValue> event_args, | 581 scoped_ptr<ListValue> event_args, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 593 event_args(event_args.Pass()), | 602 event_args(event_args.Pass()), |
| 594 event_url(event_url), | 603 event_url(event_url), |
| 595 restrict_to_profile(restrict_to_profile), | 604 restrict_to_profile(restrict_to_profile), |
| 596 cross_incognito_args(NULL), | 605 cross_incognito_args(NULL), |
| 597 user_gesture(user_gesture), | 606 user_gesture(user_gesture), |
| 598 info(info) {} | 607 info(info) {} |
| 599 | 608 |
| 600 Event::~Event() {} | 609 Event::~Event() {} |
| 601 | 610 |
| 602 } // namespace extensions | 611 } // namespace extensions |
| OLD | NEW |