Chromium Code Reviews| 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 "extensions/browser/event_router.h" | 5 #include "extensions/browser/event_router.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 // Notify the ApiActivityMonitor about the event dispatch. | 70 // Notify the ApiActivityMonitor about the event dispatch. |
| 71 BrowserContext* context = static_cast<BrowserContext*>(browser_context_id); | 71 BrowserContext* context = static_cast<BrowserContext*>(browser_context_id); |
| 72 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) | 72 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) |
| 73 return; | 73 return; |
| 74 ApiActivityMonitor* monitor = | 74 ApiActivityMonitor* monitor = |
| 75 ExtensionsBrowserClient::Get()->GetApiActivityMonitor(context); | 75 ExtensionsBrowserClient::Get()->GetApiActivityMonitor(context); |
| 76 if (monitor) | 76 if (monitor) |
| 77 monitor->OnApiEventDispatched(extension_id, event_name, args.Pass()); | 77 monitor->OnApiEventDispatched(extension_id, event_name, args.Pass()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // A global identifier used to distinguish extension events and is | |
| 81 // incremented every time an event is dispatched. | |
| 82 int g_extension_message_id = 0; | |
| 83 | |
| 80 } // namespace | 84 } // namespace |
| 81 | 85 |
| 82 const char EventRouter::kRegisteredEvents[] = "events"; | 86 const char EventRouter::kRegisteredEvents[] = "events"; |
| 83 | 87 |
| 88 EventRouter::DispatchDetails::DispatchDetails(const std::string& extension_id, | |
| 89 const std::string& event_name, | |
| 90 int message_id) | |
| 91 : extension_id_(extension_id), | |
| 92 event_name_(event_name), | |
| 93 message_id_(message_id) { | |
| 94 } | |
| 95 | |
| 96 EventRouter::DispatchDetails::~DispatchDetails() { | |
| 97 } | |
| 98 | |
| 84 struct EventRouter::ListenerProcess { | 99 struct EventRouter::ListenerProcess { |
| 85 content::RenderProcessHost* process; | 100 content::RenderProcessHost* process; |
| 86 std::string extension_id; | 101 std::string extension_id; |
| 87 | 102 |
| 88 ListenerProcess(content::RenderProcessHost* process, | 103 ListenerProcess(content::RenderProcessHost* process, |
| 89 const std::string& extension_id) | 104 const std::string& extension_id) |
| 90 : process(process), extension_id(extension_id) {} | 105 : process(process), extension_id(extension_id) {} |
| 91 | 106 |
| 92 bool operator<(const ListenerProcess& that) const { | 107 bool operator<(const ListenerProcess& that) const { |
| 93 if (process < that.process) | 108 if (process < that.process) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 104 const std::string& extension_id, | 119 const std::string& extension_id, |
| 105 const std::string& event_name, | 120 const std::string& event_name, |
| 106 ListValue* event_args, | 121 ListValue* event_args, |
| 107 UserGestureState user_gesture, | 122 UserGestureState user_gesture, |
| 108 const EventFilteringInfo& info) { | 123 const EventFilteringInfo& info) { |
| 109 NotifyApiEventDispatched(browser_context_id, | 124 NotifyApiEventDispatched(browser_context_id, |
| 110 extension_id, | 125 extension_id, |
| 111 event_name, | 126 event_name, |
| 112 make_scoped_ptr(event_args->DeepCopy())); | 127 make_scoped_ptr(event_args->DeepCopy())); |
| 113 | 128 |
| 129 int message_id = g_extension_message_id++; | |
| 114 ListValue args; | 130 ListValue args; |
| 115 args.Set(0, new base::StringValue(event_name)); | 131 args.Set(0, new base::StringValue(event_name)); |
| 116 args.Set(1, event_args); | 132 args.Set(1, event_args); |
| 117 args.Set(2, info.AsValue().release()); | 133 args.Set(2, info.AsValue().release()); |
| 134 args.Set(3, new base::FundamentalValue(message_id)); | |
| 118 ipc_sender->Send(new ExtensionMsg_MessageInvoke( | 135 ipc_sender->Send(new ExtensionMsg_MessageInvoke( |
| 119 MSG_ROUTING_CONTROL, | 136 MSG_ROUTING_CONTROL, |
| 120 extension_id, | 137 extension_id, |
| 121 kEventBindings, | 138 kEventBindings, |
| 122 "dispatchEvent", | 139 "dispatchEvent", |
| 123 args, | 140 args, |
| 124 user_gesture == USER_GESTURE_ENABLED)); | 141 user_gesture == USER_GESTURE_ENABLED)); |
| 125 | 142 |
| 143 DispatchDetails details(extension_id, event_name, message_id); | |
| 144 content::NotificationService::current()->Notify( | |
|
Ken Rockot(use gerrit already)
2015/01/08 01:24:02
This function runs on the IO thread, but Notificat
Ken Rockot(use gerrit already)
2015/01/08 01:25:58
I realize my pronoun may be ambiguous here. What I
| |
| 145 NOTIFICATION_EXTENSION_MESSAGE_DISPATCHED, | |
| 146 content::Source<content::BrowserContext>( | |
| 147 static_cast<content::BrowserContext*>(browser_context_id)), | |
| 148 content::Details<EventRouter::DispatchDetails>(&details)); | |
| 149 | |
| 126 // DispatchExtensionMessage does _not_ take ownership of event_args, so we | 150 // DispatchExtensionMessage does _not_ take ownership of event_args, so we |
| 127 // must ensure that the destruction of args does not attempt to free it. | 151 // must ensure that the destruction of args does not attempt to free it. |
| 128 scoped_ptr<base::Value> removed_event_args; | 152 scoped_ptr<base::Value> removed_event_args; |
| 129 args.Remove(1, &removed_event_args); | 153 args.Remove(1, &removed_event_args); |
| 130 ignore_result(removed_event_args.release()); | 154 ignore_result(removed_event_args.release()); |
| 131 } | 155 } |
| 132 | 156 |
| 133 // static | 157 // static |
| 134 EventRouter* EventRouter::Get(content::BrowserContext* browser_context) { | 158 EventRouter* EventRouter::Get(content::BrowserContext* browser_context) { |
| 135 return ExtensionSystem::Get(browser_context)->event_router(); | 159 return ExtensionSystem::Get(browser_context)->event_router(); |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 const std::string& extension_id, | 842 const std::string& extension_id, |
| 819 const GURL& listener_url, | 843 const GURL& listener_url, |
| 820 content::BrowserContext* browser_context) | 844 content::BrowserContext* browser_context) |
| 821 : event_name(event_name), | 845 : event_name(event_name), |
| 822 extension_id(extension_id), | 846 extension_id(extension_id), |
| 823 listener_url(listener_url), | 847 listener_url(listener_url), |
| 824 browser_context(browser_context) { | 848 browser_context(browser_context) { |
| 825 } | 849 } |
| 826 | 850 |
| 827 } // namespace extensions | 851 } // namespace extensions |
| OLD | NEW |