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 #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 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 void OnFaviconAvailable(const gfx::Image& image) override; | 87 void OnFaviconAvailable(const gfx::Image& image) override; |
88 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, | 88 void OnFaviconUpdated(favicon::FaviconDriver* favicon_driver, |
89 bool icon_url_changed) override; | 89 bool icon_url_changed) override; |
90 | 90 |
91 private: | 91 private: |
92 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. | 92 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. |
93 void TabCreatedAt(content::WebContents* contents, int index, bool active); | 93 void TabCreatedAt(content::WebContents* contents, int index, bool active); |
94 | 94 |
95 // Internal processing of tab updated events. Is called by both TabChangedAt | 95 // Internal processing of tab updated events. Is called by both TabChangedAt |
96 // and Observe/NAV_ENTRY_COMMITTED. | 96 // and Observe/NAV_ENTRY_COMMITTED. |
97 void TabUpdated(content::WebContents* contents, bool did_navigate); | 97 class TabEntry; |
98 void TabUpdated(TabEntry* entry, | |
99 scoped_ptr<base::DictionaryValue> changed_properties); | |
98 | 100 |
99 // Triggers a tab updated event if the favicon URL changes. | 101 // Triggers a tab updated event if the favicon URL changes. |
100 void FaviconUrlUpdated(content::WebContents* contents); | 102 void FaviconUrlUpdated(content::WebContents* contents); |
101 | 103 |
102 // The DispatchEvent methods forward events to the |profile|'s event router. | 104 // The DispatchEvent methods forward events to the |profile|'s event router. |
103 // The TabsEventRouter listens to events for all profiles, | 105 // The TabsEventRouter listens to events for all profiles, |
104 // so we avoid duplication by dropping events destined for other profiles. | 106 // so we avoid duplication by dropping events destined for other profiles. |
105 void DispatchEvent(Profile* profile, | 107 void DispatchEvent(Profile* profile, |
106 const std::string& event_name, | 108 const std::string& event_name, |
107 scoped_ptr<base::ListValue> args, | 109 scoped_ptr<base::ListValue> args, |
(...skipping 26 matching lines...) Expand all Loading... | |
134 // Removes notifications added in RegisterForTabNotifications. | 136 // Removes notifications added in RegisterForTabNotifications. |
135 void UnregisterForTabNotifications(content::WebContents* contents); | 137 void UnregisterForTabNotifications(content::WebContents* contents); |
136 | 138 |
137 content::NotificationRegistrar registrar_; | 139 content::NotificationRegistrar registrar_; |
138 | 140 |
139 // Maintain some information about known tabs, so we can: | 141 // Maintain some information about known tabs, so we can: |
140 // | 142 // |
141 // - distinguish between tab creation and tab insertion | 143 // - distinguish between tab creation and tab insertion |
142 // - not send tab-detached after tab-removed | 144 // - not send tab-detached after tab-removed |
143 // - reduce the "noise" of TabChangedAt() when sending events to extensions | 145 // - reduce the "noise" of TabChangedAt() when sending events to extensions |
146 // - remember last muted and audible states to know if there was a change | |
144 class TabEntry { | 147 class TabEntry { |
145 public: | 148 public: |
149 // Create a TabEntry associated with, and tracking state changes to, | |
150 // |contents|. | |
151 explicit TabEntry(content::WebContents* contents); | |
152 | |
153 // Indicate via a list of key/value pairs if a tab is loading based on its | |
154 // WebContents. Whether the state has changed or not is used to determine | |
155 // if events needs to be sent to extensions during processing of | |
156 // TabChangedAt(). If this method indicates that a tab should "hold" a | |
157 // state-change to "loading", the DidNavigate() method should eventually | |
158 // send a similar message to undo it. If false, the returned key/value | |
159 // pairs list is empty. | |
160 scoped_ptr<base::DictionaryValue> UpdateLoadState(); | |
161 | |
162 // Indicate via a list of key/value pairs that a tab load has resulted in a | |
163 // navigation and the destination url is available for inspection. The list | |
164 // is empty if no updates should be sent. | |
165 scoped_ptr<base::DictionaryValue> DidNavigate(); | |
166 | |
167 // Update the audible and muted states and return whether they were changed | |
168 bool SetAudible(bool new_val); | |
169 bool SetMuted(bool new_val); | |
170 | |
171 content::WebContents* web_contents() { return contents_; } | |
172 | |
173 private: | |
174 friend class std::map<int, TabEntry>; | |
175 friend class TabsEventRouter; | |
176 | |
146 // Create a new tab entry whose initial state is TAB_COMPLETE. This | 177 // Create a new tab entry whose initial state is TAB_COMPLETE. This |
147 // constructor is required because TabEntry objects placed inside an | 178 // constructor is required because TabEntry objects placed inside an |
148 // std::map<> by value. | 179 // std::map<> by value. |
149 TabEntry(); | 180 TabEntry(); |
150 | 181 |
151 // Update the load state of the tab based on its WebContents. Returns true | 182 content::WebContents* contents_; |
152 // if the state changed, false otherwise. Whether the state has changed or | |
153 // not is used to determine if events needs to be sent to extensions during | |
154 // processing of TabChangedAt(). This method will "hold" a state-change | |
155 // to "loading", until the DidNavigate() method which should always follow | |
156 // it. Returns NULL if no updates should be sent. | |
157 base::DictionaryValue* UpdateLoadState( | |
158 const content::WebContents* contents); | |
159 | 183 |
160 // Indicates that a tab load has resulted in a navigation and the | |
161 // destination url is available for inspection. Returns NULL if no updates | |
162 // should be sent. | |
163 base::DictionaryValue* DidNavigate(const content::WebContents* contents); | |
164 | |
165 private: | |
166 // Whether we are waiting to fire the 'complete' status change. This will | 184 // Whether we are waiting to fire the 'complete' status change. This will |
167 // occur the first time the WebContents stops loading after the | 185 // occur the first time the WebContents stops loading after the |
168 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the | 186 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the |
169 // loading state subsequently, but we will ignore those changes. | 187 // loading state subsequently, but we will ignore those changes. |
170 bool complete_waiting_on_load_; | 188 bool complete_waiting_on_load_; |
171 | 189 |
190 // Previous audible and muted states | |
191 bool was_audible_; | |
192 bool was_muted_; | |
193 | |
172 GURL url_; | 194 GURL url_; |
173 }; | 195 }; |
174 | 196 |
175 // Gets the TabEntry for the given |contents|. Returns TabEntry* if | 197 // Gets the TabEntry for the given |contents|. Returns TabEntry* if |
176 // found, NULL if not. | 198 // found, NULL if not. |
177 TabEntry* GetTabEntry(content::WebContents* contents); | 199 TabEntry* GetTabEntry(content::WebContents* contents); |
178 | 200 |
179 std::map<int, TabEntry> tab_entries_; | 201 std::map<int, TabEntry> tab_entries_; |
not at google - send to devlin
2015/06/16 18:40:58
I would do this:
using TabEntryMap = std::map<int
| |
180 | 202 |
181 // The main profile that owns this event router. | 203 // The main profile that owns this event router. |
182 Profile* profile_; | 204 Profile* profile_; |
183 | 205 |
184 ScopedObserver<favicon::FaviconDriver, TabsEventRouter> | 206 ScopedObserver<favicon::FaviconDriver, TabsEventRouter> |
185 favicon_scoped_observer_; | 207 favicon_scoped_observer_; |
186 | 208 |
187 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); | 209 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); |
188 }; | 210 }; |
189 | 211 |
190 } // namespace extensions | 212 } // namespace extensions |
191 | 213 |
192 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ | 214 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ |
OLD | NEW |