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