OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_SIDEBAR_SIDEBAR_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_ |
6 #define CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_ | 6 #define CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "chrome/browser/sidebar/sidebar_container.h" | 14 #include "chrome/browser/sidebar/sidebar_container.h" |
| 15 #include "chrome/browser/sidebar/sidebar_model.h" |
14 #include "chrome/common/notification_observer.h" | 16 #include "chrome/common/notification_observer.h" |
15 #include "chrome/common/notification_registrar.h" | 17 #include "chrome/common/notification_registrar.h" |
16 | 18 |
17 class GURL; | 19 class GURL; |
18 class PrefService; | |
19 class Profile; | |
20 class SidebarContainer; | |
21 class SkBitmap; | 20 class SkBitmap; |
22 class TabContents; | 21 class TabContents; |
| 22 class TabContentsWrapper; |
23 | 23 |
24 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
25 // SidebarManager | 25 // SidebarManager |
26 // | 26 // |
27 // This class is a singleton that manages SidebarContainer instances and | 27 // This class is a singleton that manages SidebarContainer instances and |
28 // maintains a connection between tabs and sidebars. | 28 // maintains a connection between tabs and sidebars. |
29 // | 29 // |
30 class SidebarManager : public NotificationObserver, | 30 class SidebarManager : public SidebarModel, |
| 31 public NotificationObserver, |
31 public base::RefCounted<SidebarManager>, | 32 public base::RefCounted<SidebarManager>, |
32 private SidebarContainer::Delegate { | 33 private SidebarContainer::Delegate { |
33 public: | 34 public: |
34 // Returns s singleton instance. | 35 // Returns s singleton instance. |
35 static SidebarManager* GetInstance(); | 36 static SidebarManager* GetInstance(); |
36 | 37 |
37 // Returns true if sidebar is allowed to be displayed in the browser. | 38 // Returns true if sidebar is allowed to be displayed in the browser. |
38 static bool IsSidebarAllowed(); | 39 static bool IsSidebarAllowed(); |
39 | 40 |
40 SidebarManager(); | 41 SidebarManager(); |
41 | 42 |
42 // Returns SidebarContainer registered for |tab| and active or NULL if | 43 // SidebarModel overrides. |
43 // there is no alive and active SidebarContainer registered for |tab|. | 44 virtual std::vector<SidebarContainer*> GetAllSidebarsFor( |
44 SidebarContainer* GetActiveSidebarContainerFor(TabContents* tab); | 45 TabContentsWrapper* tab); |
| 46 virtual SidebarContainer* GetActiveSidebarContainerFor( |
| 47 TabContentsWrapper* tab); |
| 48 virtual SidebarContainer* GetSidebarContainerFor( |
| 49 TabContentsWrapper* tab, const std::string& content_id); |
| 50 virtual TabContents* GetSidebarTabContents( |
| 51 TabContentsWrapper* tab, const std::string& content_id); |
| 52 virtual void ToggleSidebar( |
| 53 TabContentsWrapper* tab, const std::string& content_id); |
| 54 virtual void NotifyStateChanges( |
| 55 TabContents* was_active_sidebar_contents, |
| 56 TabContents* active_sidebar_contents); |
| 57 virtual void ShowSidebar(TabContentsWrapper* tab, |
| 58 const std::string& content_id); |
| 59 virtual void ExpandSidebar(TabContentsWrapper* tab, |
| 60 const std::string& content_id); |
| 61 virtual void CollapseSidebar(TabContentsWrapper* tab, |
| 62 const std::string& content_id); |
| 63 virtual void HideSidebar(TabContentsWrapper* tab, |
| 64 const std::string& content_id); |
| 65 virtual void NavigateSidebar(TabContentsWrapper* tab, |
| 66 const std::string& content_id, |
| 67 const GURL& url); |
| 68 virtual void SetSidebarBadgeText(TabContentsWrapper* tab, |
| 69 const std::string& content_id, |
| 70 const string16& badge_text); |
| 71 virtual void SetSidebarIcon(TabContentsWrapper* tab, |
| 72 const std::string& content_id, |
| 73 const SkBitmap& bitmap); |
| 74 virtual void SetSidebarTitle(TabContentsWrapper* tab, |
| 75 const std::string& content_id, |
| 76 const string16& title); |
45 | 77 |
46 // Returns SidebarContainer registered for |tab| and |content_id| or NULL if | 78 // More efficient than GetAllSidebarsFor when all you need to know |
47 // there is no such SidebarContainer registered. | 79 // is whether any sidebar is defined for the |tab| or not. |
48 SidebarContainer* GetSidebarContainerFor(TabContents* tab, | 80 bool IsAnySidebarDefinedFor(TabContentsWrapper* tab); |
49 const std::string& content_id); | |
50 | |
51 // Returns sidebar's TabContents registered for |tab| and |content_id|. | |
52 TabContents* GetSidebarTabContents(TabContents* tab, | |
53 const std::string& content_id); | |
54 | |
55 // Sends sidebar state change notification to extensions. | |
56 void NotifyStateChanges(TabContents* was_active_sidebar_contents, | |
57 TabContents* active_sidebar_contents); | |
58 | |
59 // Functions supporting chrome.experimental.sidebar API. | |
60 | |
61 // Shows sidebar identified by |tab| and |content_id| (only sidebar's | |
62 // mini tab is visible). | |
63 void ShowSidebar(TabContents* tab, const std::string& content_id); | |
64 | |
65 // Expands sidebar identified by |tab| and |content_id|. | |
66 void ExpandSidebar(TabContents* tab, const std::string& content_id); | |
67 | |
68 // Collapses sidebar identified by |tab| and |content_id| (has no effect | |
69 // if sidebar is not expanded). | |
70 void CollapseSidebar(TabContents* tab, const std::string& content_id); | |
71 | |
72 // Hides sidebar identified by |tab| and |content_id| (removes sidebar's | |
73 // mini tab). | |
74 void HideSidebar(TabContents* tab, const std::string& content_id); | |
75 | |
76 // Navigates sidebar identified by |tab| and |content_id| to |url|. | |
77 void NavigateSidebar(TabContents* tab, | |
78 const std::string& content_id, | |
79 const GURL& url); | |
80 | |
81 // Changes sidebar's badge text (displayed on the mini tab). | |
82 void SetSidebarBadgeText(TabContents* tab, | |
83 const std::string& content_id, | |
84 const string16& badge_text); | |
85 | |
86 // Changes sidebar's icon (displayed on the mini tab). | |
87 void SetSidebarIcon(TabContents* tab, | |
88 const std::string& content_id, | |
89 const SkBitmap& bitmap); | |
90 | |
91 // Changes sidebar's title (mini tab's tooltip). | |
92 void SetSidebarTitle(TabContents* tab, | |
93 const std::string& content_id, | |
94 const string16& title); | |
95 | 81 |
96 private: | 82 private: |
97 friend class base::RefCounted<SidebarManager>; | 83 friend class base::RefCounted<SidebarManager>; |
98 | 84 |
99 virtual ~SidebarManager(); | 85 virtual ~SidebarManager(); |
100 | 86 |
101 // Overridden from NotificationObserver. | 87 // Overridden from NotificationObserver. |
102 virtual void Observe(NotificationType type, | 88 virtual void Observe(NotificationType type, |
103 const NotificationSource& source, | 89 const NotificationSource& source, |
104 const NotificationDetails& details); | 90 const NotificationDetails& details); |
105 | 91 |
106 // Overridden from SidebarContainer::Delegate. | 92 // Overridden from SidebarContainer::Delegate. |
107 virtual void UpdateSidebar(SidebarContainer* host); | 93 virtual void UpdateSidebar(SidebarChangedDetails* details); |
108 | 94 |
109 // Hides all sidebars registered for |tab|. | 95 // Hides all sidebars registered for |tab|. |
110 void HideAllSidebars(TabContents* tab); | 96 void HideAllSidebars(TabContentsWrapper* tab); |
111 | 97 |
112 // Returns SidebarContainer corresponding to |sidebar_contents|. | 98 // Returns SidebarContainer corresponding to |sidebar_contents|. |
113 SidebarContainer* FindSidebarContainerFor(TabContents* sidebar_contents); | 99 SidebarContainer* FindSidebarContainerFor(TabContents* sidebar_contents); |
114 | 100 |
| 101 // Returns TabContentsWrapper corresponding to |tab_contents|. |
| 102 TabContentsWrapper* FindTabContentsWrapperFor(TabContents* tab_contents); |
| 103 |
115 // Registers new SidebarContainer for |tab|. There must be no | 104 // Registers new SidebarContainer for |tab|. There must be no |
116 // other SidebarContainers registered for the RenderViewHost at the moment. | 105 // other SidebarContainers registered for the RenderViewHost at the moment. |
117 void RegisterSidebarContainerFor(TabContents* tab, | 106 void RegisterSidebarContainerFor(TabContentsWrapper* tab, |
118 SidebarContainer* container); | 107 SidebarContainer* container); |
119 | 108 |
120 // Unregisters SidebarContainer identified by |tab| and |content_id|. | 109 // Unregisters SidebarContainer identified by |tab| and |content_id|. |
121 void UnregisterSidebarContainerFor(TabContents* tab, | 110 void UnregisterSidebarContainerFor(TabContentsWrapper* tab, |
122 const std::string& content_id); | 111 const std::string& content_id); |
123 | 112 |
124 // Records the link between |tab| and |sidebar_host|. | 113 // Records the link between |tab| and |sidebar_host|. |
125 void BindSidebarHost(TabContents* tab, SidebarContainer* sidebar_host); | 114 void BindSidebarHost(TabContentsWrapper* tab, SidebarContainer* sidebar_host); |
126 | 115 |
127 // Forgets the link between |tab| and |sidebar_host|. | 116 // Forgets the link between |tab| and |sidebar_host|. |
128 void UnbindSidebarHost(TabContents* tab, SidebarContainer* sidebar_host); | 117 void UnbindSidebarHost(TabContentsWrapper* tab, |
| 118 SidebarContainer* sidebar_host); |
129 | 119 |
130 NotificationRegistrar registrar_; | 120 NotificationRegistrar registrar_; |
131 | 121 |
132 // This map stores sidebars linked to a particular tab. Sidebars are | 122 // This map stores sidebars linked to a particular tab. Sidebars are |
133 // identified by their unique content id (string). | 123 // identified by their unique content id (string). |
134 typedef std::map<std::string, SidebarContainer*> ContentIdToSidebarHostMap; | 124 typedef std::map<std::string, SidebarContainer*> ContentIdToSidebarHostMap; |
135 | 125 |
136 // These two maps are for tracking dependencies between tabs and | 126 // These two maps are for tracking dependencies between tabs and |
137 // their SidebarContainers. | 127 // their SidebarContainers. |
138 // | 128 // |
139 // SidebarManager start listening to SidebarContainers when they are put | 129 // SidebarManager start listening to SidebarContainers when they are put |
140 // into these maps and removes them when they are closing. | 130 // into these maps and removes them when they are closing. |
141 struct SidebarStateForTab; | 131 struct SidebarStateForTab; |
142 typedef std::map<TabContents*, SidebarStateForTab> TabToSidebarHostMap; | 132 typedef std::map<TabContentsWrapper*, SidebarStateForTab> TabToSidebarHostMap; |
143 TabToSidebarHostMap tab_to_sidebar_host_; | 133 TabToSidebarHostMap tab_to_sidebar_host_; |
144 | 134 |
145 typedef std::map<SidebarContainer*, TabContents*> SidebarHostToTabMap; | 135 typedef std::map<SidebarContainer*, TabContentsWrapper*> SidebarHostToTabMap; |
146 SidebarHostToTabMap sidebar_host_to_tab_; | 136 SidebarHostToTabMap sidebar_host_to_tab_; |
147 | 137 |
148 DISALLOW_COPY_AND_ASSIGN(SidebarManager); | 138 DISALLOW_COPY_AND_ASSIGN(SidebarManager); |
149 }; | 139 }; |
150 | 140 |
151 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_ | 141 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_ |
152 | 142 |
OLD | NEW |