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 "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/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 event_args->Append(tab_value); | 194 event_args->Append(tab_value); |
195 tab_value->SetBoolean(tabs_constants::kSelectedKey, active); | 195 tab_value->SetBoolean(tabs_constants::kSelectedKey, active); |
196 return true; | 196 return true; |
197 } | 197 } |
198 | 198 |
199 void TabsEventRouter::TabCreatedAt(WebContents* contents, | 199 void TabsEventRouter::TabCreatedAt(WebContents* contents, |
200 int index, | 200 int index, |
201 bool active) { | 201 bool active) { |
202 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 202 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
203 scoped_ptr<base::ListValue> args(new base::ListValue); | 203 scoped_ptr<base::ListValue> args(new base::ListValue); |
204 scoped_ptr<Event> event(new Event(tabs::OnCreated::kEventName, args.Pass())); | 204 scoped_ptr<Event> event( |
| 205 new Event(events::UNKNOWN, tabs::OnCreated::kEventName, args.Pass())); |
205 event->restrict_to_browser_context = profile; | 206 event->restrict_to_browser_context = profile; |
206 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 207 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
207 event->will_dispatch_callback = | 208 event->will_dispatch_callback = |
208 base::Bind(&WillDispatchTabCreatedEvent, contents, active); | 209 base::Bind(&WillDispatchTabCreatedEvent, contents, active); |
209 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 210 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); |
210 | 211 |
211 RegisterForTabNotifications(contents); | 212 RegisterForTabNotifications(contents); |
212 } | 213 } |
213 | 214 |
214 void TabsEventRouter::TabInsertedAt(WebContents* contents, | 215 void TabsEventRouter::TabInsertedAt(WebContents* contents, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 424 |
424 void TabsEventRouter::DispatchEvent( | 425 void TabsEventRouter::DispatchEvent( |
425 Profile* profile, | 426 Profile* profile, |
426 const std::string& event_name, | 427 const std::string& event_name, |
427 scoped_ptr<base::ListValue> args, | 428 scoped_ptr<base::ListValue> args, |
428 EventRouter::UserGestureState user_gesture) { | 429 EventRouter::UserGestureState user_gesture) { |
429 EventRouter* event_router = EventRouter::Get(profile); | 430 EventRouter* event_router = EventRouter::Get(profile); |
430 if (!profile_->IsSameProfile(profile) || !event_router) | 431 if (!profile_->IsSameProfile(profile) || !event_router) |
431 return; | 432 return; |
432 | 433 |
433 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 434 scoped_ptr<Event> event(new Event(events::UNKNOWN, event_name, args.Pass())); |
434 event->restrict_to_browser_context = profile; | 435 event->restrict_to_browser_context = profile; |
435 event->user_gesture = user_gesture; | 436 event->user_gesture = user_gesture; |
436 event_router->BroadcastEvent(event.Pass()); | 437 event_router->BroadcastEvent(event.Pass()); |
437 } | 438 } |
438 | 439 |
439 void TabsEventRouter::DispatchSimpleBrowserEvent( | 440 void TabsEventRouter::DispatchSimpleBrowserEvent( |
440 Profile* profile, const int window_id, const std::string& event_name) { | 441 Profile* profile, const int window_id, const std::string& event_name) { |
441 if (!profile_->IsSameProfile(profile)) | 442 if (!profile_->IsSameProfile(profile)) |
442 return; | 443 return; |
443 | 444 |
(...skipping 20 matching lines...) Expand all Loading... |
464 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 465 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
465 | 466 |
466 // Second arg: An object containing the changes to the tab state. Filled in | 467 // Second arg: An object containing the changes to the tab state. Filled in |
467 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the | 468 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
468 // extension has the tabs permission. | 469 // extension has the tabs permission. |
469 | 470 |
470 // Third arg: An object containing the state of the tab. Filled in by | 471 // Third arg: An object containing the state of the tab. Filled in by |
471 // WillDispatchTabUpdatedEvent. | 472 // WillDispatchTabUpdatedEvent. |
472 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 473 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
473 | 474 |
474 scoped_ptr<Event> event( | 475 scoped_ptr<Event> event(new Event( |
475 new Event(tabs::OnUpdated::kEventName, args_base.Pass())); | 476 events::UNKNOWN, tabs::OnUpdated::kEventName, args_base.Pass())); |
476 event->restrict_to_browser_context = profile; | 477 event->restrict_to_browser_context = profile; |
477 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 478 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
478 event->will_dispatch_callback = | 479 event->will_dispatch_callback = |
479 base::Bind(&WillDispatchTabUpdatedEvent, | 480 base::Bind(&WillDispatchTabUpdatedEvent, |
480 contents, | 481 contents, |
481 changed_properties.get()); | 482 changed_properties.get()); |
482 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 483 EventRouter::Get(profile)->BroadcastEvent(event.Pass()); |
483 } | 484 } |
484 | 485 |
485 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { | 486 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(WebContents* contents) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 void TabsEventRouter::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, | 591 void TabsEventRouter::OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, |
591 bool icon_url_changed) { | 592 bool icon_url_changed) { |
592 if (icon_url_changed) { | 593 if (icon_url_changed) { |
593 favicon::ContentFaviconDriver* content_favicon_driver = | 594 favicon::ContentFaviconDriver* content_favicon_driver = |
594 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); | 595 static_cast<favicon::ContentFaviconDriver*>(favicon_driver); |
595 FaviconUrlUpdated(content_favicon_driver->web_contents()); | 596 FaviconUrlUpdated(content_favicon_driver->web_contents()); |
596 } | 597 } |
597 } | 598 } |
598 | 599 |
599 } // namespace extensions | 600 } // namespace extensions |
OLD | NEW |