Chromium Code Reviews| Index: chrome/browser/extensions/extension_event_router.cc |
| diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc |
| index 9969514ad7b8901e927cb842874164cc8b0f00c9..e39cc55a1efc2df83f9f30fdbebc0f5cb9d5a01c 100644 |
| --- a/chrome/browser/extensions/extension_event_router.cc |
| +++ b/chrome/browser/extensions/extension_event_router.cc |
| @@ -29,6 +29,7 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/render_process_host.h" |
| +using base::Value; |
| using content::BrowserThread; |
| using extensions::Extension; |
| using extensions::ExtensionAPI; |
| @@ -66,23 +67,50 @@ struct ExtensionEventRouter::ListenerProcess { |
| struct ExtensionEventRouter::ExtensionEvent { |
| std::string event_name; |
| - std::string event_args; |
| + scoped_ptr<Value> event_args; |
| GURL event_url; |
| Profile* restrict_to_profile; |
| - std::string cross_incognito_args; |
| + scoped_ptr<Value> cross_incognito_args; |
| UserGestureState user_gesture; |
| ExtensionEvent(const std::string& event_name, |
| + const Value& event_args, |
| + const GURL& event_url, |
| + Profile* restrict_to_profile, |
| + const Value& cross_incognito_args, |
| + UserGestureState user_gesture) |
| + : 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) {} |
| + |
| + ExtensionEvent(const std::string& event_name, |
| + const Value& event_args, |
| + const GURL& event_url, |
| + Profile* restrict_to_profile, |
| + UserGestureState user_gesture) |
| + : event_name(event_name), |
| + event_args(event_args.DeepCopy()), |
| + event_url(event_url), |
| + restrict_to_profile(restrict_to_profile), |
| + cross_incognito_args(NULL), |
| + user_gesture(user_gesture) {} |
| + |
| + // TODO(gdk): This variant should be retired once the callers are switched to |
| + // providing Values instead of just strings. |
| + ExtensionEvent(const std::string& event_name, |
| const std::string& event_args, |
| const GURL& event_url, |
| Profile* restrict_to_profile, |
| const std::string& cross_incognito_args, |
| UserGestureState user_gesture) |
| : event_name(event_name), |
| - event_args(event_args), |
| + event_args(Value::CreateStringValue(event_args)), |
| event_url(event_url), |
| restrict_to_profile(restrict_to_profile), |
| - cross_incognito_args(cross_incognito_args), |
| + cross_incognito_args(Value::CreateStringValue(cross_incognito_args)), |
| user_gesture(user_gesture) {} |
| }; |
| @@ -90,17 +118,29 @@ struct ExtensionEventRouter::ExtensionEvent { |
| void ExtensionEventRouter::DispatchEvent(IPC::Sender* ipc_sender, |
| const std::string& extension_id, |
| const std::string& event_name, |
| - const std::string& event_args, |
| + const Value& event_args, |
| const GURL& event_url, |
| UserGestureState user_gesture) { |
| ListValue args; |
| args.Set(0, Value::CreateStringValue(event_name)); |
| - args.Set(1, Value::CreateStringValue(event_args)); |
| + args.Set(1, event_args.DeepCopy()); |
|
asargent_no_longer_on_chrome
2012/06/18 16:25:30
It's a bummer to have to copy the arguments just t
Garret Kelly
2012/06/18 18:15:01
I've added a TODO, I'll refactor that as part of t
|
| ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL, |
| extension_id, kDispatchEvent, args, event_url, |
| user_gesture == USER_GESTURE_ENABLED)); |
| } |
| +// static |
| +void ExtensionEventRouter::DispatchEvent(IPC::Sender* ipc_sender, |
| + const std::string& extension_id, |
| + const std::string& event_name, |
| + const std::string& event_args, |
| + const GURL& event_url, |
| + UserGestureState user_gesture) { |
| + 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); |
| +} |
| + |
| ExtensionEventRouter::ExtensionEventRouter(Profile* profile) |
| : profile_(profile), |
| extension_devtools_manager_( |
| @@ -243,13 +283,13 @@ void ExtensionEventRouter::DispatchEventToRenderers( |
| void ExtensionEventRouter::DispatchEventToExtension( |
| const std::string& extension_id, |
| const std::string& event_name, |
| - const std::string& event_args, |
| + const Value& event_args, |
| Profile* restrict_to_profile, |
| const GURL& event_url) { |
| DCHECK(!extension_id.empty()); |
| linked_ptr<ExtensionEvent> event( |
| new ExtensionEvent(event_name, event_args, event_url, |
| - restrict_to_profile, "", USER_GESTURE_UNKNOWN)); |
| + restrict_to_profile, USER_GESTURE_UNKNOWN)); |
| DispatchEventImpl(extension_id, event); |
| } |
| @@ -258,6 +298,17 @@ void ExtensionEventRouter::DispatchEventToExtension( |
| const std::string& event_name, |
| const std::string& event_args, |
| Profile* restrict_to_profile, |
| + const GURL& event_url) { |
| + scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args)); |
| + DispatchEventToExtension(extension_id, event_name, *event_args_value.get(), |
| + restrict_to_profile, event_url); |
| +} |
| + |
| +void ExtensionEventRouter::DispatchEventToExtension( |
| + const std::string& extension_id, |
| + const std::string& event_name, |
| + const std::string& event_args, |
| + Profile* restrict_to_profile, |
| const GURL& event_url, |
| UserGestureState user_gesture) { |
| DCHECK(!extension_id.empty()); |
| @@ -326,7 +377,7 @@ void ExtensionEventRouter::DispatchEventToListener( |
| return; |
| } |
| - const std::string* event_args; |
| + const Value* event_args = NULL; |
| if (!CanDispatchEventToProfile(listener_profile, extension, |
| event, &event_args)) |
| return; |
| @@ -341,8 +392,8 @@ bool ExtensionEventRouter::CanDispatchEventToProfile( |
| Profile* profile, |
| const Extension* extension, |
| const linked_ptr<ExtensionEvent>& event, |
| - const std::string** event_args) { |
| - *event_args = &event->event_args; |
| + const Value** 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). |
| @@ -350,11 +401,11 @@ bool ExtensionEventRouter::CanDispatchEventToProfile( |
| profile != event->restrict_to_profile; |
| if (cross_incognito && |
| !profile->GetExtensionService()->CanCrossIncognito(extension)) { |
| - if (event->cross_incognito_args.empty()) |
| + if (!event->cross_incognito_args.get()) |
| return false; |
| // Send the event with different arguments to extensions that can't |
| // cross incognito. |
| - *event_args = &event->cross_incognito_args; |
| + *event_args = event->cross_incognito_args.get(); |
| } |
| return true; |
| @@ -395,7 +446,7 @@ void ExtensionEventRouter::MaybeLoadLazyBackgroundPage( |
| Profile* profile, |
| const Extension* extension, |
| const linked_ptr<ExtensionEvent>& event) { |
| - const std::string* event_args; |
| + const Value* event_args = NULL; |
| if (!CanDispatchEventToProfile(profile, extension, event, &event_args)) |
| return; |