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 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 5 #ifndef EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 6 #define EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/scoped_observer.h" | 18 #include "base/scoped_observer.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/render_process_host_observer.h" | 23 #include "content/public/browser/render_process_host_observer.h" |
24 #include "extensions/browser/event_listener_map.h" | 24 #include "extensions/browser/event_listener_map.h" |
| 25 #include "extensions/browser/extension_event_histogram_value.h" |
25 #include "extensions/browser/extension_registry_observer.h" | 26 #include "extensions/browser/extension_registry_observer.h" |
26 #include "extensions/common/event_filtering_info.h" | 27 #include "extensions/common/event_filtering_info.h" |
27 #include "ipc/ipc_sender.h" | 28 #include "ipc/ipc_sender.h" |
28 | 29 |
29 class GURL; | 30 class GURL; |
30 class PrefService; | 31 class PrefService; |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 class BrowserContext; | 34 class BrowserContext; |
34 class RenderProcessHost; | 35 class RenderProcessHost; |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 DISALLOW_COPY_AND_ASSIGN(EventRouter); | 329 DISALLOW_COPY_AND_ASSIGN(EventRouter); |
329 }; | 330 }; |
330 | 331 |
331 struct Event { | 332 struct Event { |
332 // This callback should return true if the event should be dispatched to the | 333 // This callback should return true if the event should be dispatched to the |
333 // given context and extension, and false otherwise. | 334 // given context and extension, and false otherwise. |
334 typedef base::Callback<bool(content::BrowserContext*, | 335 typedef base::Callback<bool(content::BrowserContext*, |
335 const Extension*, | 336 const Extension*, |
336 base::ListValue*)> WillDispatchCallback; | 337 base::ListValue*)> WillDispatchCallback; |
337 | 338 |
| 339 // The identifier for the event, for histograms. In most cases this |
| 340 // correlates 1:1 with |event_name|, in some cases events will generate |
| 341 // their own names, but they cannot generate their own identifier. |
| 342 events::HistogramValue histogram_value; |
| 343 |
338 // The event to dispatch. | 344 // The event to dispatch. |
339 std::string event_name; | 345 std::string event_name; |
340 | 346 |
341 // Arguments to send to the event listener. | 347 // Arguments to send to the event listener. |
342 scoped_ptr<base::ListValue> event_args; | 348 scoped_ptr<base::ListValue> event_args; |
343 | 349 |
344 // If non-NULL, then the event will not be sent to other BrowserContexts | 350 // If non-NULL, then the event will not be sent to other BrowserContexts |
345 // unless the extension has permission (e.g. incognito tab update -> normal | 351 // unless the extension has permission (e.g. incognito tab update -> normal |
346 // tab only works if extension is allowed incognito access). | 352 // tab only works if extension is allowed incognito access). |
347 content::BrowserContext* restrict_to_browser_context; | 353 content::BrowserContext* restrict_to_browser_context; |
(...skipping 11 matching lines...) Expand all Loading... |
359 // If specified, this is called before dispatching an event to each | 365 // If specified, this is called before dispatching an event to each |
360 // extension. The third argument is a mutable reference to event_args, | 366 // extension. The third argument is a mutable reference to event_args, |
361 // allowing the caller to provide different arguments depending on the | 367 // allowing the caller to provide different arguments depending on the |
362 // extension and profile. This is guaranteed to be called synchronously with | 368 // extension and profile. This is guaranteed to be called synchronously with |
363 // DispatchEvent, so callers don't need to worry about lifetime. | 369 // DispatchEvent, so callers don't need to worry about lifetime. |
364 // | 370 // |
365 // NOTE: the Extension argument to this may be NULL because it's possible for | 371 // NOTE: the Extension argument to this may be NULL because it's possible for |
366 // this event to be dispatched to non-extension processes, like WebUI. | 372 // this event to be dispatched to non-extension processes, like WebUI. |
367 WillDispatchCallback will_dispatch_callback; | 373 WillDispatchCallback will_dispatch_callback; |
368 | 374 |
369 Event(const std::string& event_name, | 375 Event(events::HistogramValue histogram_value, |
| 376 const std::string& event_name, |
370 scoped_ptr<base::ListValue> event_args); | 377 scoped_ptr<base::ListValue> event_args); |
371 | 378 |
372 Event(const std::string& event_name, | 379 Event(events::HistogramValue histogram_value, |
| 380 const std::string& event_name, |
373 scoped_ptr<base::ListValue> event_args, | 381 scoped_ptr<base::ListValue> event_args, |
374 content::BrowserContext* restrict_to_browser_context); | 382 content::BrowserContext* restrict_to_browser_context); |
375 | 383 |
376 Event(const std::string& event_name, | 384 Event(events::HistogramValue histogram_value, |
| 385 const std::string& event_name, |
377 scoped_ptr<base::ListValue> event_args, | 386 scoped_ptr<base::ListValue> event_args, |
378 content::BrowserContext* restrict_to_browser_context, | 387 content::BrowserContext* restrict_to_browser_context, |
379 const GURL& event_url, | 388 const GURL& event_url, |
380 EventRouter::UserGestureState user_gesture, | 389 EventRouter::UserGestureState user_gesture, |
381 const EventFilteringInfo& info); | 390 const EventFilteringInfo& info); |
382 | 391 |
383 ~Event(); | 392 ~Event(); |
384 | 393 |
385 // Makes a deep copy of this instance. Ownership is transferred to the | 394 // Makes a deep copy of this instance. Ownership is transferred to the |
386 // caller. | 395 // caller. |
(...skipping 10 matching lines...) Expand all Loading... |
397 const std::string event_name; | 406 const std::string event_name; |
398 | 407 |
399 const std::string extension_id; | 408 const std::string extension_id; |
400 const GURL listener_url; | 409 const GURL listener_url; |
401 content::BrowserContext* browser_context; | 410 content::BrowserContext* browser_context; |
402 }; | 411 }; |
403 | 412 |
404 } // namespace extensions | 413 } // namespace extensions |
405 | 414 |
406 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 415 #endif // EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |