diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-17 05:59:06 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-17 05:59:06 +0000 |
commit | 0c9f326176095aacc0de142746bc485d62082407 (patch) | |
tree | c12fbd1a2b4a32fa1d64282c62cd8d44b86e5380 /chrome/browser/extensions/browser_event_router.cc | |
parent | 61161fdc716423ae44471cb08893977a8ed995ae (diff) | |
download | chromium_src-0c9f326176095aacc0de142746bc485d62082407.zip chromium_src-0c9f326176095aacc0de142746bc485d62082407.tar.gz chromium_src-0c9f326176095aacc0de142746bc485d62082407.tar.bz2 |
Always send the full tab object in ExtensionAction click event.
Along the way, decompose a few swiss army knife functions to
simplify and generalize code.
BUG=149020
Review URL: https://codereview.chromium.org/10909256
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/browser_event_router.cc')
-rw-r--r-- | chrome/browser/extensions/browser_event_router.cc | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/chrome/browser/extensions/browser_event_router.cc b/chrome/browser/extensions/browser_event_router.cc index af5cf9b..7f69f0c 100644 --- a/chrome/browser/extensions/browser_event_router.cc +++ b/chrome/browser/extensions/browser_event_router.cc @@ -166,8 +166,23 @@ void BrowserEventRouter::TabCreatedAt(WebContents* contents, int index, bool active) { Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); - DispatchEventWithTab(profile, "", events::kOnTabCreated, contents, active, - EventRouter::USER_GESTURE_NOT_ENABLED); + const EventListenerMap::ListenerList& listeners( + ExtensionSystem::Get(profile)->event_router()-> + listeners().GetEventListenersByName(events::kOnTabCreated)); + for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); + it != listeners.end(); + ++it) { + scoped_ptr<ListValue> args(new ListValue()); + DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( + contents, + profile->GetExtensionService()->extensions()->GetByID( + (*it)->extension_id)); + args->Append(tab_value); + tab_value->SetBoolean(tab_keys::kSelectedKey, active); + DispatchEventToExtension(profile, (*it)->extension_id, + events::kOnTabCreated, args.Pass(), + EventRouter::USER_GESTURE_NOT_ENABLED); + } RegisterForTabNotifications(contents); } @@ -378,44 +393,6 @@ void BrowserEventRouter::DispatchEventsAcrossIncognito( GURL()); } -void BrowserEventRouter::DispatchEventWithTab( - Profile* profile, - const std::string& extension_id, - const char* event_name, - const WebContents* web_contents, - bool active, - EventRouter::UserGestureState user_gesture, - scoped_ptr<ListValue> event_args) { - if (!profile_->IsSameProfile(profile)) - return; - - if (!extension_id.empty()) { - event_args->Append(ExtensionTabUtil::CreateTabValueActive( - web_contents, - active, - profile->GetExtensionService()->extensions()->GetByID(extension_id))); - DispatchEventToExtension(profile, extension_id, event_name, - event_args.Pass(), user_gesture); - } else { - const EventListenerMap::ListenerList& listeners( - ExtensionSystem::Get(profile)->event_router()-> - listeners().GetEventListenersByName(event_name)); - - for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); - it != listeners.end(); - ++it) { - scoped_ptr<ListValue> args(event_args->DeepCopy()); - args->Append(ExtensionTabUtil::CreateTabValueActive( - web_contents, - active, - profile->GetExtensionService()->extensions()->GetByID( - (*it)->extension_id))); - DispatchEventToExtension(profile, (*it)->extension_id, event_name, - args.Pass(), user_gesture); - } - } -} - void BrowserEventRouter::DispatchSimpleBrowserEvent( Profile* profile, const int window_id, const char* event_name) { if (!profile_->IsSameProfile(profile)) @@ -435,19 +412,33 @@ void BrowserEventRouter::DispatchTabUpdatedEvent( // The state of the tab (as seen from the extension point of view) has // changed. Send a notification to the extension. - scoped_ptr<ListValue> args(new ListValue()); + scoped_ptr<ListValue> args_base(new ListValue()); // First arg: The id of the tab that changed. - args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); + args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); // Second arg: An object containing the changes to the tab state. - args->Append(changed_properties); + args_base->Append(changed_properties); // Third arg: An object containing the state of the tab. Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); - DispatchEventWithTab(profile, "", events::kOnTabUpdated, contents, true, - EventRouter::USER_GESTURE_UNKNOWN, args.Pass()); + const EventListenerMap::ListenerList& listeners( + ExtensionSystem::Get(profile)->event_router()-> + listeners().GetEventListenersByName(events::kOnTabUpdated)); + for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); + it != listeners.end(); + ++it) { + scoped_ptr<ListValue> args(args_base->DeepCopy()); + DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( + contents, + profile->GetExtensionService()->extensions()->GetByID( + (*it)->extension_id)); + args->Append(tab_value); + DispatchEventToExtension(profile, (*it)->extension_id, + events::kOnTabUpdated, args.Pass(), + EventRouter::USER_GESTURE_UNKNOWN); + } } BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( @@ -597,12 +588,17 @@ void BrowserEventRouter::ExtensionActionExecuted( } if (event_name) { - DispatchEventWithTab(profile, - extension_action.extension_id(), - event_name, - tab_contents->web_contents(), - true, - EventRouter::USER_GESTURE_ENABLED); + scoped_ptr<ListValue> args(new ListValue()); + DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( + tab_contents->web_contents(), + ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS); + args->Append(tab_value); + + DispatchEventToExtension(profile, + extension_action.extension_id(), + event_name, + args.Pass(), + EventRouter::USER_GESTURE_ENABLED); } } |