Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/extensions/extension_event_router.h

Issue 9316102: Update extension events, routing, and delivery to use user gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 10 matching lines...) Expand all
21 class Extension; 21 class Extension;
22 class ExtensionDevToolsManager; 22 class ExtensionDevToolsManager;
23 class Profile; 23 class Profile;
24 24
25 namespace content { 25 namespace content {
26 class RenderProcessHost; 26 class RenderProcessHost;
27 } 27 }
28 28
29 class ExtensionEventRouter : public content::NotificationObserver { 29 class ExtensionEventRouter : public content::NotificationObserver {
30 public: 30 public:
31 // These constants convey the state of our knowledge of whether we're in
32 // a user-caused gesture as part of DispatchEvent.
33 enum UserGesture {
Aaron Boodman 2012/02/29 01:20:37 Naming suggestion: UserGestureState?
Greg Billock 2012/02/29 17:58:08 Done.
34 kUnknownUserGesture = 0,
Aaron Boodman 2012/02/29 01:20:37 according to the style guide (http://www.chromium.
Greg Billock 2012/02/29 17:58:08 I'd read this: "Though the style guide says to use
35 kIsUserGesture = 1,
36 kIsNotUserGesture = 2,
37 };
38
31 // Sends an event via ipc_sender to the given extension. Can be called on 39 // Sends an event via ipc_sender to the given extension. Can be called on
32 // any thread. 40 // any thread.
33 static void DispatchEvent(IPC::Message::Sender* ipc_sender, 41 static void DispatchEvent(IPC::Message::Sender* ipc_sender,
34 const std::string& extension_id, 42 const std::string& extension_id,
35 const std::string& event_name, 43 const std::string& event_name,
36 const std::string& event_args, 44 const std::string& event_args,
37 const GURL& event_url); 45 const GURL& event_url,
46 UserGesture user_gesture);
38 47
39 explicit ExtensionEventRouter(Profile* profile); 48 explicit ExtensionEventRouter(Profile* profile);
40 virtual ~ExtensionEventRouter(); 49 virtual ~ExtensionEventRouter();
41 50
42 // Add or remove the process/extension pair as a listener for |event_name|. 51 // Add or remove the process/extension pair as a listener for |event_name|.
43 // Note that multiple extensions can share a process due to process 52 // Note that multiple extensions can share a process due to process
44 // collapsing. Also, a single extension can have 2 processes if it is a split 53 // collapsing. Also, a single extension can have 2 processes if it is a split
45 // mode extension. 54 // mode extension.
46 void AddEventListener(const std::string& event_name, 55 void AddEventListener(const std::string& event_name,
47 content::RenderProcessHost* process, 56 content::RenderProcessHost* process,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 const GURL& event_url); 88 const GURL& event_url);
80 89
81 // Same as above, except only send the event to the given extension. 90 // Same as above, except only send the event to the given extension.
82 virtual void DispatchEventToExtension( 91 virtual void DispatchEventToExtension(
83 const std::string& extension_id, 92 const std::string& extension_id,
84 const std::string& event_name, 93 const std::string& event_name,
85 const std::string& event_args, 94 const std::string& event_args,
86 Profile* restrict_to_profile, 95 Profile* restrict_to_profile,
87 const GURL& event_url); 96 const GURL& event_url);
88 97
98 // Dispatch an event to particular extension. Also include an
99 // explicit user gesture indicator.
100 virtual void DispatchEventToExtension(
101 const std::string& extension_id,
102 const std::string& event_name,
103 const std::string& event_args,
104 Profile* restrict_to_profile,
105 const GURL& event_url,
106 UserGesture user_gesture);
107
89 // Send different versions of an event to extensions in different profiles. 108 // Send different versions of an event to extensions in different profiles.
90 // This is used in the case of sending one event to extensions that have 109 // This is used in the case of sending one event to extensions that have
91 // incognito access, and another event to extensions that don't (here), 110 // incognito access, and another event to extensions that don't (here),
92 // in order to avoid sending 2 events to "spanning" extensions. 111 // in order to avoid sending 2 events to "spanning" extensions.
93 // If |cross_incognito_profile| is non-NULL and different from 112 // If |cross_incognito_profile| is non-NULL and different from
94 // restrict_to_profile, send the event with cross_incognito_args to the 113 // restrict_to_profile, send the event with cross_incognito_args to the
95 // extensions in that profile that can't cross incognito. 114 // extensions in that profile that can't cross incognito.
96 void DispatchEventsToRenderersAcrossIncognito( 115 void DispatchEventsToRenderersAcrossIncognito(
97 const std::string& event_name, 116 const std::string& event_name,
98 const std::string& event_args, 117 const std::string& event_args,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 197
179 // Track of the number of dispatched events that have not yet sent an 198 // Track of the number of dispatched events that have not yet sent an
180 // ACK from the renderer. 199 // ACK from the renderer.
181 void IncrementInFlightEvents(const Extension* extension); 200 void IncrementInFlightEvents(const Extension* extension);
182 std::map<std::string, int> in_flight_events_; 201 std::map<std::string, int> in_flight_events_;
183 202
184 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); 203 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
185 }; 204 };
186 205
187 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ 206 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698