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 #include "chrome/browser/extensions/browser_event_router.h" | 5 #include "chrome/browser/extensions/browser_event_router.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 Profile* profile, | 382 Profile* profile, |
383 const std::string& extension_id, | 383 const std::string& extension_id, |
384 const char* event_name, | 384 const char* event_name, |
385 const WebContents* web_contents, | 385 const WebContents* web_contents, |
386 bool active, | 386 bool active, |
387 EventRouter::UserGestureState user_gesture) { | 387 EventRouter::UserGestureState user_gesture) { |
388 if (!profile_->IsSameProfile(profile)) | 388 if (!profile_->IsSameProfile(profile)) |
389 return; | 389 return; |
390 | 390 |
391 scoped_ptr<ListValue> args(new ListValue()); | 391 scoped_ptr<ListValue> args(new ListValue()); |
392 args->Append(ExtensionTabUtil::CreateTabValueActive( | |
393 web_contents, active)); | |
394 if (!extension_id.empty()) { | 392 if (!extension_id.empty()) { |
393 args->Append(ExtensionTabUtil::CreateTabValueActive( | |
394 web_contents, | |
395 active, | |
396 profile->GetExtensionService()->extensions()->GetByID(extension_id))); | |
395 DispatchEventToExtension(profile, extension_id, event_name, args.Pass(), | 397 DispatchEventToExtension(profile, extension_id, event_name, args.Pass(), |
396 user_gesture); | 398 user_gesture); |
397 } else { | 399 } else { |
398 DispatchEvent(profile, event_name, args.Pass(), user_gesture); | 400 EventListenerMap::ListenerList listeners( |
401 ExtensionSystem::Get(profile)->event_router()-> | |
402 listeners().listeners(event_name)); | |
Aaron Boodman
2012/08/30 05:45:48
The second 'listeners' should be GetListenersByNam
chebert
2012/08/30 23:17:20
Done.
| |
403 | |
404 for (EventListenerMap::ListenerList::iterator it = listeners.begin(); | |
405 it != listeners.end(); | |
406 ++it) { | |
407 args->Append(ExtensionTabUtil::CreateTabValueActive( | |
408 web_contents, | |
409 active, | |
410 profile->GetExtensionService()->extensions()->GetByID( | |
411 (*it)->extension_id))); | |
412 DispatchEventToExtension(profile, (*it)->extension_id, event_name, | |
413 args.Pass(), user_gesture); | |
414 } | |
399 } | 415 } |
400 } | 416 } |
401 | 417 |
402 void BrowserEventRouter::DispatchSimpleBrowserEvent( | 418 void BrowserEventRouter::DispatchSimpleBrowserEvent( |
403 Profile* profile, const int window_id, const char* event_name) { | 419 Profile* profile, const int window_id, const char* event_name) { |
404 if (!profile_->IsSameProfile(profile)) | 420 if (!profile_->IsSameProfile(profile)) |
405 return; | 421 return; |
406 | 422 |
407 scoped_ptr<ListValue> args(new ListValue()); | 423 scoped_ptr<ListValue> args(new ListValue()); |
408 args->Append(Value::CreateIntegerValue(window_id)); | 424 args->Append(Value::CreateIntegerValue(window_id)); |
(...skipping 11 matching lines...) Expand all Loading... | |
420 // changed. Send a notification to the extension. | 436 // changed. Send a notification to the extension. |
421 scoped_ptr<ListValue> args(new ListValue()); | 437 scoped_ptr<ListValue> args(new ListValue()); |
422 | 438 |
423 // First arg: The id of the tab that changed. | 439 // First arg: The id of the tab that changed. |
424 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); | 440 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); |
425 | 441 |
426 // Second arg: An object containing the changes to the tab state. | 442 // Second arg: An object containing the changes to the tab state. |
427 args->Append(changed_properties); | 443 args->Append(changed_properties); |
428 | 444 |
429 // Third arg: An object containing the state of the tab. | 445 // Third arg: An object containing the state of the tab. |
430 args->Append(ExtensionTabUtil::CreateTabValue(contents)); | 446 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
447 args->Append(ExtensionTabUtil::CreateTabValue(contents, NULL /*extension*/)); | |
Aaron Boodman
2012/08/30 05:45:48
Why no extension here?
I think that CreateTabValu
chebert
2012/08/30 23:17:20
Done.
| |
431 | 448 |
432 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | |
433 DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), | 449 DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), |
434 EventRouter::USER_GESTURE_UNKNOWN); | 450 EventRouter::USER_GESTURE_UNKNOWN); |
435 } | 451 } |
436 | 452 |
437 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( | 453 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( |
438 const WebContents* contents) { | 454 const WebContents* contents) { |
439 int tab_id = ExtensionTabUtil::GetTabId(contents); | 455 int tab_id = ExtensionTabUtil::GetTabId(contents); |
440 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 456 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
441 if (tab_entries_.end() == i) | 457 if (tab_entries_.end() == i) |
442 return NULL; | 458 return NULL; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 DispatchEventWithTab(profile, | 600 DispatchEventWithTab(profile, |
585 extension_action.extension_id(), | 601 extension_action.extension_id(), |
586 event_name, | 602 event_name, |
587 tab_contents->web_contents(), | 603 tab_contents->web_contents(), |
588 true, | 604 true, |
589 EventRouter::USER_GESTURE_ENABLED); | 605 EventRouter::USER_GESTURE_ENABLED); |
590 } | 606 } |
591 } | 607 } |
592 | 608 |
593 } // namespace extensions | 609 } // namespace extensions |
OLD | NEW |