| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/api/tabs/tabs_event_router.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 tab_value->SetBoolean(tabs_constants::kActiveKey, active); | 197 tab_value->SetBoolean(tabs_constants::kActiveKey, active); |
| 198 event->event_args->Append(std::move(tab_value)); | 198 event->event_args->Append(std::move(tab_value)); |
| 199 return true; | 199 return true; |
| 200 } | 200 } |
| 201 | 201 |
| 202 void TabsEventRouter::TabCreatedAt(WebContents* contents, | 202 void TabsEventRouter::TabCreatedAt(WebContents* contents, |
| 203 int index, | 203 int index, |
| 204 bool active) { | 204 bool active) { |
| 205 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 205 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 206 std::unique_ptr<base::ListValue> args(new base::ListValue); | 206 std::unique_ptr<base::ListValue> args(new base::ListValue); |
| 207 std::unique_ptr<Event> event(new Event( | 207 auto event = base::MakeUnique<Event>(events::TABS_ON_CREATED, |
| 208 events::TABS_ON_CREATED, tabs::OnCreated::kEventName, std::move(args))); | 208 tabs::OnCreated::kEventName, |
| 209 event->restrict_to_browser_context = profile; | 209 std::move(args), profile); |
| 210 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 210 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
| 211 event->will_dispatch_callback = | 211 event->will_dispatch_callback = |
| 212 base::Bind(&WillDispatchTabCreatedEvent, contents, active); | 212 base::Bind(&WillDispatchTabCreatedEvent, contents, active); |
| 213 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); | 213 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
| 214 | 214 |
| 215 RegisterForTabNotifications(contents); | 215 RegisterForTabNotifications(contents); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model, | 218 void TabsEventRouter::TabInsertedAt(TabStripModel* tab_strip_model, |
| 219 WebContents* contents, | 219 WebContents* contents, |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 void TabsEventRouter::DispatchEvent( | 420 void TabsEventRouter::DispatchEvent( |
| 421 Profile* profile, | 421 Profile* profile, |
| 422 events::HistogramValue histogram_value, | 422 events::HistogramValue histogram_value, |
| 423 const std::string& event_name, | 423 const std::string& event_name, |
| 424 std::unique_ptr<base::ListValue> args, | 424 std::unique_ptr<base::ListValue> args, |
| 425 EventRouter::UserGestureState user_gesture) { | 425 EventRouter::UserGestureState user_gesture) { |
| 426 EventRouter* event_router = EventRouter::Get(profile); | 426 EventRouter* event_router = EventRouter::Get(profile); |
| 427 if (!profile_->IsSameProfile(profile) || !event_router) | 427 if (!profile_->IsSameProfile(profile) || !event_router) |
| 428 return; | 428 return; |
| 429 | 429 |
| 430 std::unique_ptr<Event> event( | 430 auto event = base::MakeUnique<Event>(histogram_value, event_name, |
| 431 new Event(histogram_value, event_name, std::move(args))); | 431 std::move(args), profile); |
| 432 event->restrict_to_browser_context = profile; | |
| 433 event->user_gesture = user_gesture; | 432 event->user_gesture = user_gesture; |
| 434 event_router->BroadcastEvent(std::move(event)); | 433 event_router->BroadcastEvent(std::move(event)); |
| 435 } | 434 } |
| 436 | 435 |
| 437 void TabsEventRouter::DispatchTabUpdatedEvent( | 436 void TabsEventRouter::DispatchTabUpdatedEvent( |
| 438 WebContents* contents, | 437 WebContents* contents, |
| 439 const std::set<std::string> changed_property_names) { | 438 const std::set<std::string> changed_property_names) { |
| 440 DCHECK(!changed_property_names.empty()); | 439 DCHECK(!changed_property_names.empty()); |
| 441 DCHECK(contents); | 440 DCHECK(contents); |
| 442 | 441 |
| 443 // The state of the tab (as seen from the extension point of view) has | 442 // The state of the tab (as seen from the extension point of view) has |
| 444 // changed. Send a notification to the extension. | 443 // changed. Send a notification to the extension. |
| 445 std::unique_ptr<base::ListValue> args_base(new base::ListValue); | 444 std::unique_ptr<base::ListValue> args_base(new base::ListValue); |
| 446 | 445 |
| 447 // First arg: The id of the tab that changed. | 446 // First arg: The id of the tab that changed. |
| 448 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 447 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 449 | 448 |
| 450 // Second arg: An object containing the changes to the tab state. Filled in | 449 // Second arg: An object containing the changes to the tab state. Filled in |
| 451 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the | 450 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
| 452 // extension has the tabs permission. | 451 // extension has the tabs permission. |
| 453 | 452 |
| 454 // Third arg: An object containing the state of the tab. Filled in by | 453 // Third arg: An object containing the state of the tab. Filled in by |
| 455 // WillDispatchTabUpdatedEvent. | 454 // WillDispatchTabUpdatedEvent. |
| 456 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 455 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 457 | 456 |
| 458 std::unique_ptr<Event> event(new Event(events::TABS_ON_UPDATED, | 457 auto event = base::MakeUnique<Event>(events::TABS_ON_UPDATED, |
| 459 tabs::OnUpdated::kEventName, | 458 tabs::OnUpdated::kEventName, |
| 460 std::move(args_base))); | 459 std::move(args_base), profile); |
| 461 event->restrict_to_browser_context = profile; | |
| 462 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 460 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
| 463 event->will_dispatch_callback = | 461 event->will_dispatch_callback = |
| 464 base::Bind(&WillDispatchTabUpdatedEvent, contents, | 462 base::Bind(&WillDispatchTabUpdatedEvent, contents, |
| 465 std::move(changed_property_names)); | 463 std::move(changed_property_names)); |
| 466 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); | 464 EventRouter::Get(profile)->BroadcastEvent(std::move(event)); |
| 467 } | 465 } |
| 468 | 466 |
| 469 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { | 467 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { |
| 470 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); | 468 const auto it = tab_entries_.find(ExtensionTabUtil::GetTabId(contents)); |
| 471 | 469 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 } | 557 } |
| 560 | 558 |
| 561 void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents, | 559 void TabsEventRouter::OnAutoDiscardableStateChange(WebContents* contents, |
| 562 bool is_auto_discardable) { | 560 bool is_auto_discardable) { |
| 563 std::set<std::string> changed_property_names; | 561 std::set<std::string> changed_property_names; |
| 564 changed_property_names.insert(tabs_constants::kAutoDiscardableKey); | 562 changed_property_names.insert(tabs_constants::kAutoDiscardableKey); |
| 565 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); | 563 DispatchTabUpdatedEvent(contents, std::move(changed_property_names)); |
| 566 } | 564 } |
| 567 | 565 |
| 568 } // namespace extensions | 566 } // namespace extensions |
| OLD | NEW |