Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(984)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_event_router.h

Issue 1400823003: Creates BrowserTabStripTracker to consolidate common code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback and git cl format Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
15 #include "chrome/browser/extensions/api/tabs/tabs_api.h" 15 #include "chrome/browser/extensions/api/tabs/tabs_api.h"
16 #include "chrome/browser/ui/browser_list_observer.h" 16 #include "chrome/browser/ui/browser_list_observer.h"
17 #include "chrome/browser/ui/browser_tab_strip_tracker.h"
18 #include "chrome/browser/ui/browser_tab_strip_tracker_delegate.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
18 #include "components/favicon/core/favicon_driver_observer.h" 20 #include "components/favicon/core/favicon_driver_observer.h"
19 #include "components/ui/zoom/zoom_observer.h" 21 #include "components/ui/zoom/zoom_observer.h"
20 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
21 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
22 24
23 namespace content { 25 namespace content {
24 class WebContents; 26 class WebContents;
25 } 27 }
26 28
27 namespace favicon { 29 namespace favicon {
28 class FaviconDriver; 30 class FaviconDriver;
29 } 31 }
30 32
31 namespace extensions { 33 namespace extensions {
32 34
33 // The TabsEventRouter listens to tab events and routes them to listeners inside 35 // The TabsEventRouter listens to tab events and routes them to listeners inside
34 // extension process renderers. 36 // extension process renderers.
35 // TabsEventRouter will only route events from windows/tabs within a profile to 37 // TabsEventRouter will only route events from windows/tabs within a profile to
36 // extension processes in the same profile. 38 // extension processes in the same profile.
37 class TabsEventRouter : public TabStripModelObserver, 39 class TabsEventRouter : public TabStripModelObserver,
40 public BrowserTabStripTrackerDelegate,
38 public chrome::BrowserListObserver, 41 public chrome::BrowserListObserver,
39 public content::NotificationObserver, 42 public content::NotificationObserver,
40 public favicon::FaviconDriverObserver, 43 public favicon::FaviconDriverObserver,
41 public ui_zoom::ZoomObserver { 44 public ui_zoom::ZoomObserver {
42 public: 45 public:
43 explicit TabsEventRouter(Profile* profile); 46 explicit TabsEventRouter(Profile* profile);
44 ~TabsEventRouter() override; 47 ~TabsEventRouter() override;
45 48
46 // chrome::BrowserListObserver 49 // BrowserTabStripTrackerDelegate:
47 void OnBrowserAdded(Browser* browser) override; 50 bool ShouldTrackBrowser(Browser* browser) override;
48 void OnBrowserRemoved(Browser* browser) override; 51
52 // chrome::BrowserListObserver:
49 void OnBrowserSetLastActive(Browser* browser) override; 53 void OnBrowserSetLastActive(Browser* browser) override;
50 54
51 // TabStripModelObserver 55 // TabStripModelObserver:
52 void TabInsertedAt(content::WebContents* contents, 56 void TabInsertedAt(content::WebContents* contents,
53 int index, 57 int index,
54 bool active) override; 58 bool active) override;
55 void TabClosingAt(TabStripModel* tab_strip_model, 59 void TabClosingAt(TabStripModel* tab_strip_model,
56 content::WebContents* contents, 60 content::WebContents* contents,
57 int index) override; 61 int index) override;
58 void TabDetachedAt(content::WebContents* contents, int index) override; 62 void TabDetachedAt(content::WebContents* contents, int index) override;
59 void ActiveTabChanged(content::WebContents* old_contents, 63 void ActiveTabChanged(content::WebContents* old_contents,
60 content::WebContents* new_contents, 64 content::WebContents* new_contents,
61 int index, 65 int index,
62 int reason) override; 66 int reason) override;
63 void TabSelectionChanged(TabStripModel* tab_strip_model, 67 void TabSelectionChanged(TabStripModel* tab_strip_model,
64 const ui::ListSelectionModel& old_model) override; 68 const ui::ListSelectionModel& old_model) override;
65 void TabMoved(content::WebContents* contents, 69 void TabMoved(content::WebContents* contents,
66 int from_index, 70 int from_index,
67 int to_index) override; 71 int to_index) override;
68 void TabChangedAt(content::WebContents* contents, 72 void TabChangedAt(content::WebContents* contents,
69 int index, 73 int index,
70 TabChangeType change_type) override; 74 TabChangeType change_type) override;
71 void TabReplacedAt(TabStripModel* tab_strip_model, 75 void TabReplacedAt(TabStripModel* tab_strip_model,
72 content::WebContents* old_contents, 76 content::WebContents* old_contents,
73 content::WebContents* new_contents, 77 content::WebContents* new_contents,
74 int index) override; 78 int index) override;
75 void TabPinnedStateChanged(content::WebContents* contents, 79 void TabPinnedStateChanged(content::WebContents* contents,
76 int index) override; 80 int index) override;
77 81
78 // content::NotificationObserver. 82 // content::NotificationObserver:
79 void Observe(int type, 83 void Observe(int type,
80 const content::NotificationSource& source, 84 const content::NotificationSource& source,
81 const content::NotificationDetails& details) override; 85 const content::NotificationDetails& details) override;
82 86
83 // ZoomObserver. 87 // ZoomObserver:
84 void OnZoomChanged( 88 void OnZoomChanged(
85 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; 89 const ui_zoom::ZoomController::ZoomChangedEventData& data) override;
86 90
87 // favicon::FaviconDriverObserver. 91 // favicon::FaviconDriverObserver:
88 void OnFaviconAvailable(const gfx::Image& image) override; 92 void OnFaviconAvailable(const gfx::Image& image) override;
89 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, 93 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver,
90 bool icon_url_changed) override; 94 bool icon_url_changed) override;
91 95
92 private: 96 private:
93 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. 97 // "Synthetic" event. Called from TabInsertedAt if new tab is detected.
94 void TabCreatedAt(content::WebContents* contents, int index, bool active); 98 void TabCreatedAt(content::WebContents* contents, int index, bool active);
95 99
96 // Internal processing of tab updated events. Is called by both TabChangedAt 100 // Internal processing of tab updated events. Is called by both TabChangedAt
97 // and Observe/NAV_ENTRY_COMMITTED. 101 // and Observe/NAV_ENTRY_COMMITTED.
(...skipping 19 matching lines...) Expand all
117 scoped_ptr<base::ListValue> event_args, 121 scoped_ptr<base::ListValue> event_args,
118 scoped_ptr<base::ListValue> cross_incognito_args); 122 scoped_ptr<base::ListValue> cross_incognito_args);
119 123
120 // Packages |changed_properties| as a tab updated event for the tab |contents| 124 // Packages |changed_properties| as a tab updated event for the tab |contents|
121 // and dispatches the event to the extension. 125 // and dispatches the event to the extension.
122 void DispatchTabUpdatedEvent( 126 void DispatchTabUpdatedEvent(
123 content::WebContents* contents, 127 content::WebContents* contents,
124 scoped_ptr<base::DictionaryValue> changed_properties); 128 scoped_ptr<base::DictionaryValue> changed_properties);
125 129
126 // Register ourselves to receive the various notifications we are interested 130 // Register ourselves to receive the various notifications we are interested
127 // in for a browser.
128 void RegisterForBrowserNotifications(Browser* browser);
129
130 // Register ourselves to receive the various notifications we are interested
131 // in for a tab. 131 // in for a tab.
132 void RegisterForTabNotifications(content::WebContents* contents); 132 void RegisterForTabNotifications(content::WebContents* contents);
133 133
134 // Removes notifications added in RegisterForTabNotifications. 134 // Removes notifications added in RegisterForTabNotifications.
135 void UnregisterForTabNotifications(content::WebContents* contents); 135 void UnregisterForTabNotifications(content::WebContents* contents);
136 136
137 content::NotificationRegistrar registrar_; 137 content::NotificationRegistrar registrar_;
138 138
139 // Maintain some information about known tabs, so we can: 139 // Maintain some information about known tabs, so we can:
140 // 140 //
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 using TabEntryMap = std::map<int, linked_ptr<TabEntry>>; 191 using TabEntryMap = std::map<int, linked_ptr<TabEntry>>;
192 TabEntryMap tab_entries_; 192 TabEntryMap tab_entries_;
193 193
194 // The main profile that owns this event router. 194 // The main profile that owns this event router.
195 Profile* profile_; 195 Profile* profile_;
196 196
197 ScopedObserver<favicon::FaviconDriver, TabsEventRouter> 197 ScopedObserver<favicon::FaviconDriver, TabsEventRouter>
198 favicon_scoped_observer_; 198 favicon_scoped_observer_;
199 199
200 BrowserTabStripTracker browser_tab_strip_tracker_;
201
200 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); 202 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter);
201 }; 203 };
202 204
203 } // namespace extensions 205 } // namespace extensions
204 206
205 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ 207 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/debugger/debugger_api.cc ('k') | chrome/browser/extensions/api/tabs/tabs_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698