| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_BROWSER_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_BROWSER_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/extensions/event_router.h" | 14 #include "chrome/browser/extensions/event_router.h" |
| 15 #include "chrome/browser/ui/browser_list_observer.h" | 15 #include "chrome/browser/ui/browser_list_observer.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class WebContents; | 20 class WebContents; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 | 24 |
| 25 // The BrowserEventRouter listens to Browser window & tab events | 25 // The TabsEventRouter listens to tab events and routes them to listeners inside |
| 26 // and routes them to listeners inside extension process renderers. | 26 // extension process renderers. |
| 27 // BrowserEventRouter listens to *all* events, but will only route | 27 // TabsEventRouter will only route events from windows/tabs within a profile to |
| 28 // events from windows/tabs within a profile to extension processes in the same | 28 // extension processes in the same profile. |
| 29 // profile. | 29 class TabsEventRouter : public TabStripModelObserver, |
| 30 class BrowserEventRouter : public TabStripModelObserver, | 30 public chrome::BrowserListObserver, |
| 31 public chrome::BrowserListObserver, | 31 public content::NotificationObserver { |
| 32 public content::NotificationObserver { | |
| 33 public: | 32 public: |
| 34 explicit BrowserEventRouter(Profile* profile); | 33 explicit TabsEventRouter(Profile* profile); |
| 35 virtual ~BrowserEventRouter(); | 34 virtual ~TabsEventRouter(); |
| 36 | 35 |
| 37 // chrome::BrowserListObserver | 36 // chrome::BrowserListObserver |
| 38 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 37 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 39 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 38 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 40 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; | 39 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; |
| 41 | 40 |
| 42 // TabStripModelObserver | 41 // TabStripModelObserver |
| 43 virtual void TabInsertedAt(content::WebContents* contents, int index, | 42 virtual void TabInsertedAt(content::WebContents* contents, int index, |
| 44 bool active) OVERRIDE; | 43 bool active) OVERRIDE; |
| 45 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 44 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 59 int to_index) OVERRIDE; | 58 int to_index) OVERRIDE; |
| 60 virtual void TabChangedAt(content::WebContents* contents, | 59 virtual void TabChangedAt(content::WebContents* contents, |
| 61 int index, | 60 int index, |
| 62 TabChangeType change_type) OVERRIDE; | 61 TabChangeType change_type) OVERRIDE; |
| 63 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | 62 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
| 64 content::WebContents* old_contents, | 63 content::WebContents* old_contents, |
| 65 content::WebContents* new_contents, | 64 content::WebContents* new_contents, |
| 66 int index) OVERRIDE; | 65 int index) OVERRIDE; |
| 67 virtual void TabPinnedStateChanged(content::WebContents* contents, | 66 virtual void TabPinnedStateChanged(content::WebContents* contents, |
| 68 int index) OVERRIDE; | 67 int index) OVERRIDE; |
| 69 virtual void TabStripEmpty() OVERRIDE; | |
| 70 | 68 |
| 71 // content::NotificationObserver. | 69 // content::NotificationObserver. |
| 72 virtual void Observe(int type, | 70 virtual void Observe(int type, |
| 73 const content::NotificationSource& source, | 71 const content::NotificationSource& source, |
| 74 const content::NotificationDetails& details) OVERRIDE; | 72 const content::NotificationDetails& details) OVERRIDE; |
| 75 private: | 73 private: |
| 76 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. | 74 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. |
| 77 void TabCreatedAt(content::WebContents* contents, int index, bool active); | 75 void TabCreatedAt(content::WebContents* contents, int index, bool active); |
| 78 | 76 |
| 79 // Internal processing of tab updated events. Is called by both TabChangedAt | 77 // Internal processing of tab updated events. Is called by both TabChangedAt |
| 80 // and Observe/NAV_ENTRY_COMMITTED. | 78 // and Observe/NAV_ENTRY_COMMITTED. |
| 81 void TabUpdated(content::WebContents* contents, bool did_navigate); | 79 void TabUpdated(content::WebContents* contents, bool did_navigate); |
| 82 | 80 |
| 83 // Triggers a tab updated event if the favicon URL changes. | 81 // Triggers a tab updated event if the favicon URL changes. |
| 84 void FaviconUrlUpdated(content::WebContents* contents, | 82 void FaviconUrlUpdated(content::WebContents* contents); |
| 85 const bool* icon_url_changed); | |
| 86 | 83 |
| 87 // The DispatchEvent methods forward events to the |profile|'s event router. | 84 // The DispatchEvent methods forward events to the |profile|'s event router. |
| 88 // The BrowserEventRouter listens to events for all profiles, | 85 // The TabsEventRouter listens to events for all profiles, |
| 89 // so we avoid duplication by dropping events destined for other profiles. | 86 // so we avoid duplication by dropping events destined for other profiles. |
| 90 void DispatchEvent(Profile* profile, | 87 void DispatchEvent(Profile* profile, |
| 91 const char* event_name, | 88 const char* event_name, |
| 92 scoped_ptr<base::ListValue> args, | 89 scoped_ptr<base::ListValue> args, |
| 93 EventRouter::UserGestureState user_gesture); | 90 EventRouter::UserGestureState user_gesture); |
| 94 | 91 |
| 95 void DispatchEventsAcrossIncognito( | 92 void DispatchEventsAcrossIncognito( |
| 96 Profile* profile, | 93 Profile* profile, |
| 97 const char* event_name, | 94 const char* event_name, |
| 98 scoped_ptr<base::ListValue> event_args, | 95 scoped_ptr<base::ListValue> event_args, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 154 |
| 158 // Gets the TabEntry for the given |contents|. Returns TabEntry* if | 155 // Gets the TabEntry for the given |contents|. Returns TabEntry* if |
| 159 // found, NULL if not. | 156 // found, NULL if not. |
| 160 TabEntry* GetTabEntry(const content::WebContents* contents); | 157 TabEntry* GetTabEntry(const content::WebContents* contents); |
| 161 | 158 |
| 162 std::map<int, TabEntry> tab_entries_; | 159 std::map<int, TabEntry> tab_entries_; |
| 163 | 160 |
| 164 // The main profile that owns this event router. | 161 // The main profile that owns this event router. |
| 165 Profile* profile_; | 162 Profile* profile_; |
| 166 | 163 |
| 167 DISALLOW_COPY_AND_ASSIGN(BrowserEventRouter); | 164 DISALLOW_COPY_AND_ASSIGN(TabsEventRouter); |
| 168 }; | 165 }; |
| 169 | 166 |
| 170 } // namespace extensions | 167 } // namespace extensions |
| 171 | 168 |
| 172 #endif // CHROME_BROWSER_EXTENSIONS_BROWSER_EVENT_ROUTER_H_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_TABS_EVENT_ROUTER_H_ |
| OLD | NEW |