Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / tabs / tabs_windows_api.cc
bloba0efbbfb11a7c4cdab5d8a6ad81e703cc499542c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/browser/extensions/api/tabs/tabs_event_router.h"
9 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/tabs.h"
12 #include "chrome/common/extensions/api/windows.h"
13 #include "extensions/browser/event_router.h"
14 #include "extensions/browser/extension_system.h"
16 namespace extensions {
18 TabsWindowsAPI::TabsWindowsAPI(content::BrowserContext* context)
19 : browser_context_(context),
20 windows_event_router_(
21 new WindowsEventRouter(Profile::FromBrowserContext(context))) {
22 EventRouter* event_router = EventRouter::Get(browser_context_);
24 // Tabs API Events.
25 event_router->RegisterObserver(this, api::tabs::OnCreated::kEventName);
26 event_router->RegisterObserver(this, api::tabs::OnUpdated::kEventName);
27 event_router->RegisterObserver(this, api::tabs::OnMoved::kEventName);
28 event_router->RegisterObserver(this,
29 api::tabs::OnSelectionChanged::kEventName);
30 event_router->RegisterObserver(this, api::tabs::OnActiveChanged::kEventName);
31 event_router->RegisterObserver(this, api::tabs::OnActivated::kEventName);
32 event_router->RegisterObserver(this,
33 api::tabs::OnHighlightChanged::kEventName);
34 event_router->RegisterObserver(this, api::tabs::OnHighlighted::kEventName);
35 event_router->RegisterObserver(this, api::tabs::OnDetached::kEventName);
36 event_router->RegisterObserver(this, api::tabs::OnAttached::kEventName);
37 event_router->RegisterObserver(this, api::tabs::OnRemoved::kEventName);
38 event_router->RegisterObserver(this, api::tabs::OnReplaced::kEventName);
39 event_router->RegisterObserver(this, api::tabs::OnZoomChange::kEventName);
41 // Windows API Events.
42 event_router->RegisterObserver(this, api::windows::OnCreated::kEventName);
43 event_router->RegisterObserver(this, api::windows::OnRemoved::kEventName);
44 event_router->RegisterObserver(this,
45 api::windows::OnFocusChanged::kEventName);
48 TabsWindowsAPI::~TabsWindowsAPI() {
51 // static
52 TabsWindowsAPI* TabsWindowsAPI::Get(content::BrowserContext* context) {
53 return BrowserContextKeyedAPIFactory<TabsWindowsAPI>::Get(context);
56 TabsEventRouter* TabsWindowsAPI::tabs_event_router() {
57 if (!tabs_event_router_.get())
58 tabs_event_router_.reset(
59 new TabsEventRouter(Profile::FromBrowserContext(browser_context_)));
60 return tabs_event_router_.get();
63 WindowsEventRouter* TabsWindowsAPI::windows_event_router() {
64 return windows_event_router_.get();
67 void TabsWindowsAPI::Shutdown() {
68 EventRouter::Get(browser_context_)->UnregisterObserver(this);
71 static base::LazyInstance<BrowserContextKeyedAPIFactory<TabsWindowsAPI> >
72 g_factory = LAZY_INSTANCE_INITIALIZER;
74 BrowserContextKeyedAPIFactory<TabsWindowsAPI>*
75 TabsWindowsAPI::GetFactoryInstance() {
76 return g_factory.Pointer();
79 void TabsWindowsAPI::OnListenerAdded(const EventListenerInfo& details) {
80 // Initialize the event routers.
81 tabs_event_router();
82 EventRouter::Get(browser_context_)->UnregisterObserver(this);
85 } // namespace extensions