Chromium Code Reviews| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 14 #include "chrome/browser/ui/browser_list_observer.h" | 14 #include "chrome/browser/ui/browser_list_observer.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 16 #include "components/ui/zoom/zoom_observer.h" | 16 #include "components/ui/zoom/zoom_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 19 #include "extensions/common/value_builder.h" | |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 class WebContents; | 22 class WebContents; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 | 26 |
| 26 // The TabsEventRouter listens to tab events and routes them to listeners inside | 27 // The TabsEventRouter listens to tab events and routes them to listeners inside |
| 27 // extension process renderers. | 28 // extension process renderers. |
| 28 // TabsEventRouter will only route events from windows/tabs within a profile to | 29 // TabsEventRouter will only route events from windows/tabs within a profile to |
| 29 // extension processes in the same profile. | 30 // extension processes in the same profile. |
| 30 class TabsEventRouter : public TabStripModelObserver, | 31 class TabsEventRouter : public TabStripModelObserver, |
| 31 public chrome::BrowserListObserver, | 32 public chrome::BrowserListObserver, |
| 32 public content::NotificationObserver, | 33 public content::NotificationObserver, |
| 33 public ui_zoom::ZoomObserver { | 34 public ui_zoom::ZoomObserver { |
| 35 private: | |
| 36 class TabEntry; | |
|
not at google - send to devlin
2015/03/16 18:11:56
Declare this above TabUpdated. Odd having a privat
not at google - send to devlin
2015/03/19 21:23:35
Not addressed?
| |
| 37 | |
| 34 public: | 38 public: |
| 35 explicit TabsEventRouter(Profile* profile); | 39 explicit TabsEventRouter(Profile* profile); |
| 36 ~TabsEventRouter() override; | 40 ~TabsEventRouter() override; |
| 37 | 41 |
| 38 // chrome::BrowserListObserver | 42 // chrome::BrowserListObserver |
| 39 void OnBrowserAdded(Browser* browser) override; | 43 void OnBrowserAdded(Browser* browser) override; |
| 40 void OnBrowserRemoved(Browser* browser) override; | 44 void OnBrowserRemoved(Browser* browser) override; |
| 41 void OnBrowserSetLastActive(Browser* browser) override; | 45 void OnBrowserSetLastActive(Browser* browser) override; |
| 42 | 46 |
| 43 // TabStripModelObserver | 47 // TabStripModelObserver |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 // ZoomObserver. | 79 // ZoomObserver. |
| 76 void OnZoomChanged( | 80 void OnZoomChanged( |
| 77 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; | 81 const ui_zoom::ZoomController::ZoomChangedEventData& data) override; |
| 78 | 82 |
| 79 private: | 83 private: |
| 80 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. | 84 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. |
| 81 void TabCreatedAt(content::WebContents* contents, int index, bool active); | 85 void TabCreatedAt(content::WebContents* contents, int index, bool active); |
| 82 | 86 |
| 83 // Internal processing of tab updated events. Is called by both TabChangedAt | 87 // Internal processing of tab updated events. Is called by both TabChangedAt |
| 84 // and Observe/NAV_ENTRY_COMMITTED. | 88 // and Observe/NAV_ENTRY_COMMITTED. |
| 85 void TabUpdated(content::WebContents* contents, bool did_navigate); | 89 void TabUpdated(TabEntry* entry, DictionaryBuilder* changed_properties); |
| 86 | 90 |
| 87 // Triggers a tab updated event if the favicon URL changes. | 91 // Triggers a tab updated event if the favicon URL changes. |
| 88 void FaviconUrlUpdated(content::WebContents* contents); | 92 void FaviconUrlUpdated(content::WebContents* contents); |
| 89 | 93 |
| 90 // The DispatchEvent methods forward events to the |profile|'s event router. | 94 // The DispatchEvent methods forward events to the |profile|'s event router. |
| 91 // The TabsEventRouter listens to events for all profiles, | 95 // The TabsEventRouter listens to events for all profiles, |
| 92 // so we avoid duplication by dropping events destined for other profiles. | 96 // so we avoid duplication by dropping events destined for other profiles. |
| 93 void DispatchEvent(Profile* profile, | 97 void DispatchEvent(Profile* profile, |
| 94 const std::string& event_name, | 98 const std::string& event_name, |
| 95 scoped_ptr<base::ListValue> args, | 99 scoped_ptr<base::ListValue> args, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 122 // Removes notifications added in RegisterForTabNotifications. | 126 // Removes notifications added in RegisterForTabNotifications. |
| 123 void UnregisterForTabNotifications(content::WebContents* contents); | 127 void UnregisterForTabNotifications(content::WebContents* contents); |
| 124 | 128 |
| 125 content::NotificationRegistrar registrar_; | 129 content::NotificationRegistrar registrar_; |
| 126 | 130 |
| 127 // Maintain some information about known tabs, so we can: | 131 // Maintain some information about known tabs, so we can: |
| 128 // | 132 // |
| 129 // - distinguish between tab creation and tab insertion | 133 // - distinguish between tab creation and tab insertion |
| 130 // - not send tab-detached after tab-removed | 134 // - not send tab-detached after tab-removed |
| 131 // - reduce the "noise" of TabChangedAt() when sending events to extensions | 135 // - reduce the "noise" of TabChangedAt() when sending events to extensions |
| 136 // - remember last muted and audible states to know if there was a change | |
| 132 class TabEntry { | 137 class TabEntry { |
| 133 public: | 138 public: |
| 134 // Create a new tab entry whose initial state is TAB_COMPLETE. This | 139 // Create a new tab entry whose initial state is TAB_COMPLETE. This |
| 135 // constructor is required because TabEntry objects placed inside an | 140 // constructor is required because TabEntry objects placed inside an |
| 136 // std::map<> by value. | 141 // std::map<> by value. |
| 137 TabEntry(); | 142 TabEntry(); |
| 138 | 143 |
| 144 // Allow creating a TabEntry via a webcontents. Used when moving | |
| 145 // tabs between windows. | |
| 146 explicit TabEntry(content::WebContents* contents); | |
| 147 | |
| 139 // Update the load state of the tab based on its WebContents. Returns true | 148 // Update the load state of the tab based on its WebContents. Returns true |
| 140 // if the state changed, false otherwise. Whether the state has changed or | 149 // if the state changed, false otherwise. Whether the state has changed or |
|
not at google - send to devlin
2015/03/16 18:11:55
Comment needs to be rewritten, this doesn't return
| |
| 141 // not is used to determine if events needs to be sent to extensions during | 150 // not is used to determine if events needs to be sent to extensions during |
| 142 // processing of TabChangedAt(). This method will "hold" a state-change | 151 // processing of TabChangedAt(). This method will "hold" a state-change |
| 143 // to "loading", until the DidNavigate() method which should always follow | 152 // to "loading", until the DidNavigate() method which should always follow |
| 144 // it. Returns NULL if no updates should be sent. | 153 // it. Returns NULL if no updates should be sent. |
| 145 base::DictionaryValue* UpdateLoadState( | 154 DictionaryBuilder* UpdateLoadState(); |
|
not at google - send to devlin
2015/03/16 18:11:55
Better to pass a scoped_ptr<DictionaryBuilder> her
| |
| 146 const content::WebContents* contents); | |
| 147 | 155 |
| 148 // Indicates that a tab load has resulted in a navigation and the | 156 // Indicates that a tab load has resulted in a navigation and the |
| 149 // destination url is available for inspection. Returns NULL if no updates | 157 // destination url is available for inspection. Returns NULL if no updates |
| 150 // should be sent. | 158 // should be sent. |
| 151 base::DictionaryValue* DidNavigate(const content::WebContents* contents); | 159 DictionaryBuilder* DidNavigate(); |
| 160 | |
| 161 // Update the audible and muted states and return whether they were changed | |
| 162 bool SetAudible(bool new_val); | |
| 163 bool SetMuted(bool new_val); | |
| 164 | |
| 165 // TODO(jaredsohn): make it private or add public accessor | |
|
not at google - send to devlin
2015/03/16 18:11:55
Please do this now - public web_contents() accesso
| |
| 166 content::WebContents* contents_; | |
| 152 | 167 |
| 153 private: | 168 private: |
| 154 // Whether we are waiting to fire the 'complete' status change. This will | 169 // Whether we are waiting to fire the 'complete' status change. This will |
| 155 // occur the first time the WebContents stops loading after the | 170 // occur the first time the WebContents stops loading after the |
| 156 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the | 171 // NAV_ENTRY_COMMITTED was fired. The tab may go back into and out of the |
| 157 // loading state subsequently, but we will ignore those changes. | 172 // loading state subsequently, but we will ignore those changes. |
| 158 bool complete_waiting_on_load_; | 173 bool complete_waiting_on_load_; |
| 159 | 174 |
| 175 // Previous audible and muted states | |
| 176 bool was_audible_; | |
| 177 bool was_muted_; | |
| 178 | |
| 160 GURL url_; | 179 GURL url_; |
| 161 }; | 180 }; |
| 162 | 181 |
| 163 // Gets the TabEntry for the given |contents|. Returns TabEntry* if | 182 // Gets the TabEntry for the given |contents|. Returns TabEntry* if |
| 164 // found, NULL if not. | 183 // found, NULL if not. |
| 165 TabEntry* GetTabEntry(content::WebContents* contents); | 184 TabEntry* GetTabEntry(content::WebContents* contents); |
| 166 | 185 |
| 167 std::map<int, TabEntry> tab_entries_; | 186 std::map<int, TabEntry> tab_entries_; |
| 168 | 187 |
| 169 // The main profile that owns this event router. | 188 // The main profile that owns this event router. |
| 170 Profile* profile_; | 189 Profile* profile_; |
| 171 | 190 |
| 172 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); | 191 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); |
| 173 }; | 192 }; |
| 174 | 193 |
| 175 } // namespace extensions | 194 } // namespace extensions |
| 176 | 195 |
| 177 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ | 196 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ |
| OLD | NEW |