| Index: chrome/browser/extensions/event_router.cc
|
| diff --git a/chrome/browser/extensions/event_router.cc b/chrome/browser/extensions/event_router.cc
|
| index 4a3769641f152d5a1773d4e8217edbcc1d6e2677..a6aec97f860f8a5eb7fd18c353c48d0f8cbaa660 100644
|
| --- a/chrome/browser/extensions/event_router.cc
|
| +++ b/chrome/browser/extensions/event_router.cc
|
| @@ -34,7 +34,7 @@ using content::BrowserThread;
|
|
|
| namespace {
|
|
|
| -const char kDispatchEvent[] = "Event.dispatchJSON";
|
| +const char kDispatchEvent[] = "Event.dispatchEvent";
|
|
|
| void NotifyEventListenerRemovedOnIOThread(
|
| void* profile,
|
| @@ -66,36 +66,37 @@ struct EventRouter::ListenerProcess {
|
| };
|
|
|
| // static
|
| -void EventRouter::DispatchEvent(IPC::Sender* ipc_sender,
|
| - const std::string& extension_id,
|
| - const std::string& event_name,
|
| - const Value& event_args,
|
| - const GURL& event_url,
|
| - UserGestureState user_gesture,
|
| - const EventFilteringInfo& info) {
|
| - // TODO(gdk): Reduce number of DeepCopy() calls throughout the event dispatch
|
| - // chain, starting by replacing the event_args with a Value*.
|
| +void EventRouter::DispatchExtensionMessage(IPC::Sender* ipc_sender,
|
| + const std::string& extension_id,
|
| + const std::string& event_name,
|
| + ListValue* event_args,
|
| + const GURL& event_url,
|
| + UserGestureState user_gesture,
|
| + const EventFilteringInfo& info) {
|
| ListValue args;
|
| args.Set(0, Value::CreateStringValue(event_name));
|
| - args.Set(1, event_args.DeepCopy());
|
| + args.Set(1, event_args);
|
| args.Set(2, info.AsValue().release());
|
| -
|
| ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL,
|
| extension_id, kDispatchEvent, args, event_url,
|
| user_gesture == USER_GESTURE_ENABLED));
|
| +
|
| + // DispatchExtensionMessage does _not_ take ownership of event_args, so we
|
| + // must ensure that the destruction of args does not attempt to free it.
|
| + Value* removed_event_args = NULL;
|
| + args.Remove(1, &removed_event_args);
|
| }
|
|
|
| // static
|
| void EventRouter::DispatchEvent(IPC::Sender* ipc_sender,
|
| const std::string& extension_id,
|
| const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| const GURL& event_url,
|
| UserGestureState user_gesture,
|
| const EventFilteringInfo& info) {
|
| - scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args));
|
| - DispatchEvent(ipc_sender, extension_id, event_name, *event_args_value.get(),
|
| - event_url, user_gesture, info);
|
| + DispatchExtensionMessage(ipc_sender, extension_id, event_name,
|
| + event_args.get(), event_url, user_gesture, info);
|
| }
|
|
|
| EventRouter::EventRouter(Profile* profile)
|
| @@ -280,35 +281,31 @@ bool EventRouter::HasEventListenerImpl(const ListenerMap& listener_map,
|
| }
|
|
|
| void EventRouter::DispatchEventToRenderers(const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| const GURL& event_url,
|
| EventFilteringInfo info) {
|
| - DCHECK(!event_args.empty());
|
| - StringValue event_args_value(event_args);
|
| - linked_ptr<Event> event(new Event(event_name, event_args_value,
|
| + linked_ptr<Event> event(new Event(event_name, event_args.Pass(),
|
| event_url, restrict_to_profile,
|
| USER_GESTURE_UNKNOWN, info));
|
| DispatchEventImpl("", event);
|
| }
|
|
|
| void EventRouter::DispatchEventToRenderers(const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| const GURL& event_url) {
|
| - DispatchEventToRenderers(event_name, event_args, restrict_to_profile,
|
| + DispatchEventToRenderers(event_name, event_args.Pass(), restrict_to_profile,
|
| event_url, EventFilteringInfo());
|
| }
|
|
|
| void EventRouter::DispatchEventToRenderers(const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| const GURL& event_url,
|
| UserGestureState user_gesture) {
|
| - DCHECK(!event_args.empty());
|
| - StringValue event_args_value(event_args);
|
| EventFilteringInfo info;
|
| - linked_ptr<Event> event(new Event(event_name, event_args_value,
|
| + linked_ptr<Event> event(new Event(event_name, event_args.Pass(),
|
| event_url, restrict_to_profile,
|
| user_gesture, info));
|
| DispatchEventImpl("", event);
|
| @@ -316,11 +313,11 @@ void EventRouter::DispatchEventToRenderers(const std::string& event_name,
|
|
|
| void EventRouter::DispatchEventToExtension(const std::string& extension_id,
|
| const std::string& event_name,
|
| - const Value& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| const GURL& event_url) {
|
| DCHECK(!extension_id.empty());
|
| - linked_ptr<Event> event(new Event(event_name, event_args, event_url,
|
| + linked_ptr<Event> event(new Event(event_name, event_args.Pass(), event_url,
|
| restrict_to_profile, USER_GESTURE_UNKNOWN,
|
| EventFilteringInfo()));
|
| DispatchEventImpl(extension_id, event);
|
| @@ -328,23 +325,12 @@ void EventRouter::DispatchEventToExtension(const std::string& extension_id,
|
|
|
| void EventRouter::DispatchEventToExtension(const std::string& extension_id,
|
| const std::string& event_name,
|
| - const std::string& event_args,
|
| - Profile* restrict_to_profile,
|
| - const GURL& event_url) {
|
| - StringValue event_args_value(event_args);
|
| - DispatchEventToExtension(extension_id, event_name, event_args_value,
|
| - restrict_to_profile, event_url);
|
| -}
|
| -
|
| -void EventRouter::DispatchEventToExtension(const std::string& extension_id,
|
| - const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| const GURL& event_url,
|
| UserGestureState user_gesture) {
|
| DCHECK(!extension_id.empty());
|
| - StringValue event_args_value(event_args);
|
| - linked_ptr<Event> event(new Event(event_name, event_args_value, event_url,
|
| + linked_ptr<Event> event(new Event(event_name, event_args.Pass(), event_url,
|
| restrict_to_profile, user_gesture,
|
| EventFilteringInfo()));
|
| DispatchEventImpl(extension_id, event);
|
| @@ -352,13 +338,14 @@ void EventRouter::DispatchEventToExtension(const std::string& extension_id,
|
|
|
| void EventRouter::DispatchEventsToRenderersAcrossIncognito(
|
| const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| Profile* restrict_to_profile,
|
| - const std::string& cross_incognito_args,
|
| + scoped_ptr<ListValue> cross_incognito_args,
|
| const GURL& event_url) {
|
| - linked_ptr<Event> event(new Event(event_name, event_args,
|
| - event_url, restrict_to_profile,
|
| - cross_incognito_args, USER_GESTURE_UNKNOWN,
|
| + linked_ptr<Event> event(new Event(event_name, event_args.Pass(), event_url,
|
| + restrict_to_profile,
|
| + cross_incognito_args.Pass(),
|
| + USER_GESTURE_UNKNOWN,
|
| EventFilteringInfo()));
|
| DispatchEventImpl("", event);
|
| }
|
| @@ -440,24 +427,25 @@ void EventRouter::DispatchEventToProcess(const std::string& extension_id,
|
| return;
|
| }
|
|
|
| - const Value* event_args = NULL;
|
| + ListValue* event_args = NULL;
|
| if (!CanDispatchEventToProfile(listener_profile, extension,
|
| event, &event_args)) {
|
| return;
|
| }
|
|
|
| - DispatchEvent(process, extension_id,
|
| - event->event_name, *event_args,
|
| - event->event_url, event->user_gesture,
|
| - event->info);
|
| + DispatchExtensionMessage(process, extension_id,
|
| + event->event_name, event_args,
|
| + event->event_url, event->user_gesture,
|
| + event->info);
|
| IncrementInFlightEvents(listener_profile, extension);
|
| }
|
|
|
| bool EventRouter::CanDispatchEventToProfile(Profile* profile,
|
| const Extension* extension,
|
| const linked_ptr<Event>& event,
|
| - const Value** event_args) {
|
| - *event_args = event->event_args.get();
|
| + ListValue** event_args) {
|
| + if (event_args)
|
| + *event_args = event->event_args.get();
|
|
|
| // Is this event from a different profile than the renderer (ie, an
|
| // incognito tab event sent to a normal process, or vice versa).
|
| @@ -469,7 +457,8 @@ bool EventRouter::CanDispatchEventToProfile(Profile* profile,
|
| return false;
|
| // Send the event with different arguments to extensions that can't
|
| // cross incognito.
|
| - *event_args = event->cross_incognito_args.get();
|
| + if (event_args)
|
| + *event_args = event->cross_incognito_args.get();
|
| }
|
|
|
| return true;
|
| @@ -479,8 +468,7 @@ void EventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent(
|
| Profile* profile,
|
| const Extension* extension,
|
| const linked_ptr<Event>& event) {
|
| - const Value* event_args = NULL;
|
| - if (!CanDispatchEventToProfile(profile, extension, event, &event_args))
|
| + if (!CanDispatchEventToProfile(profile, extension, event, NULL))
|
| return;
|
|
|
| LazyBackgroundTaskQueue* queue =
|
| @@ -581,53 +569,34 @@ void EventRouter::Observe(int type,
|
| }
|
|
|
| Event::Event(const std::string& event_name,
|
| - const Value& event_args,
|
| - const GURL& event_url,
|
| - Profile* restrict_to_profile,
|
| - const Value& cross_incognito_args,
|
| - EventRouter::UserGestureState user_gesture,
|
| - const EventFilteringInfo& info)
|
| - : event_name(event_name),
|
| - event_args(event_args.DeepCopy()),
|
| - event_url(event_url),
|
| - restrict_to_profile(restrict_to_profile),
|
| - cross_incognito_args(cross_incognito_args.DeepCopy()),
|
| - user_gesture(user_gesture),
|
| - info(info) {
|
| -}
|
| -
|
| -Event::Event(const std::string& event_name,
|
| - const std::string& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| const GURL& event_url,
|
| Profile* restrict_to_profile,
|
| - const std::string& cross_incognito_args,
|
| + scoped_ptr<ListValue> cross_incognito_args,
|
| EventRouter::UserGestureState user_gesture,
|
| const EventFilteringInfo& info)
|
| : event_name(event_name),
|
| - event_args(Value::CreateStringValue(event_args)),
|
| + event_args(event_args.Pass()),
|
| event_url(event_url),
|
| restrict_to_profile(restrict_to_profile),
|
| - cross_incognito_args(Value::CreateStringValue(cross_incognito_args)),
|
| + cross_incognito_args(cross_incognito_args.Pass()),
|
| user_gesture(user_gesture),
|
| - info(info) {
|
| -}
|
| + info(info) {}
|
|
|
| Event::Event(const std::string& event_name,
|
| - const Value& event_args,
|
| + scoped_ptr<ListValue> event_args,
|
| const GURL& event_url,
|
| Profile* restrict_to_profile,
|
| EventRouter::UserGestureState user_gesture,
|
| const EventFilteringInfo& info)
|
| : event_name(event_name),
|
| - event_args(event_args.DeepCopy()),
|
| + event_args(event_args.Pass()),
|
| event_url(event_url),
|
| restrict_to_profile(restrict_to_profile),
|
| cross_incognito_args(NULL),
|
| user_gesture(user_gesture),
|
| - info(info) {
|
| -}
|
| + info(info) {}
|
|
|
| -Event::~Event() {
|
| -}
|
| +Event::~Event() {}
|
|
|
| } // namespace extensions
|
|
|