Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/sidebar/sidebar_manager.h

Issue 9006027: Rip Out the Sidebar API (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 ///////////////////////////////////////////////////////////////////////////////
23 // SidebarManager
24 //
25 // This class is a singleton that manages SidebarContainer instances and
26 // maintains a connection between tabs and sidebars.
27 //
28 class SidebarManager : public content::NotificationObserver,
29 public base::RefCounted<SidebarManager>,
30 private SidebarContainer::Delegate {
31 public:
32 // Returns s singleton instance.
33 static SidebarManager* GetInstance();
34
35 // Returns true if sidebar is allowed to be displayed in the browser.
36 static bool IsSidebarAllowed();
37
38 SidebarManager();
39
40 // Returns SidebarContainer registered for |tab| and active or NULL if
41 // there is no alive and active SidebarContainer registered for |tab|.
42 SidebarContainer* GetActiveSidebarContainerFor(TabContents* tab);
43
44 // Returns SidebarContainer registered for |tab| and |content_id| or NULL if
45 // there is no such SidebarContainer registered.
46 SidebarContainer* GetSidebarContainerFor(TabContents* tab,
47 const std::string& content_id);
48
49 // Returns sidebar's TabContents registered for |tab| and |content_id|.
50 TabContents* GetSidebarTabContents(TabContents* tab,
51 const std::string& content_id);
52
53 // Sends sidebar state change notification to extensions.
54 void NotifyStateChanges(TabContents* was_active_sidebar_contents,
55 TabContents* active_sidebar_contents);
56
57 // Functions supporting chrome.experimental.sidebar API.
58
59 // Shows sidebar identified by |tab| and |content_id| (only sidebar's
60 // mini tab is visible).
61 void ShowSidebar(TabContents* tab, const std::string& content_id);
62
63 // Expands sidebar identified by |tab| and |content_id|.
64 void ExpandSidebar(TabContents* tab, const std::string& content_id);
65
66 // Collapses sidebar identified by |tab| and |content_id| (has no effect
67 // if sidebar is not expanded).
68 void CollapseSidebar(TabContents* tab, const std::string& content_id);
69
70 // Hides sidebar identified by |tab| and |content_id| (removes sidebar's
71 // mini tab).
72 void HideSidebar(TabContents* tab, const std::string& content_id);
73
74 // Navigates sidebar identified by |tab| and |content_id| to |url|.
75 void NavigateSidebar(TabContents* tab,
76 const std::string& content_id,
77 const GURL& url);
78
79 // Changes sidebar's badge text (displayed on the mini tab).
80 void SetSidebarBadgeText(TabContents* tab,
81 const std::string& content_id,
82 const string16& badge_text);
83
84 // Changes sidebar's icon (displayed on the mini tab).
85 void SetSidebarIcon(TabContents* tab,
86 const std::string& content_id,
87 const SkBitmap& bitmap);
88
89 // Changes sidebar's title (mini tab's tooltip).
90 void SetSidebarTitle(TabContents* tab,
91 const std::string& content_id,
92 const string16& title);
93
94 private:
95 friend class base::RefCounted<SidebarManager>;
96
97 virtual ~SidebarManager();
98
99 // Overridden from content::NotificationObserver.
100 virtual void Observe(int type,
101 const content::NotificationSource& source,
102 const content::NotificationDetails& details) OVERRIDE;
103
104 // Overridden from SidebarContainer::Delegate.
105 virtual void UpdateSidebar(SidebarContainer* host) OVERRIDE;
106
107 // Hides all sidebars registered for |tab|.
108 void HideAllSidebars(TabContents* tab);
109
110 // Returns SidebarContainer corresponding to |sidebar_contents|.
111 SidebarContainer* FindSidebarContainerFor(TabContents* sidebar_contents);
112
113 // Registers new SidebarContainer for |tab|. There must be no
114 // other SidebarContainers registered for the RenderViewHost at the moment.
115 void RegisterSidebarContainerFor(TabContents* tab,
116 SidebarContainer* container);
117
118 // Unregisters SidebarContainer identified by |tab| and |content_id|.
119 void UnregisterSidebarContainerFor(TabContents* tab,
120 const std::string& content_id);
121
122 // Records the link between |tab| and |sidebar_host|.
123 void BindSidebarHost(TabContents* tab, SidebarContainer* sidebar_host);
124
125 // Forgets the link between |tab| and |sidebar_host|.
126 void UnbindSidebarHost(TabContents* tab, SidebarContainer* sidebar_host);
127
128 content::NotificationRegistrar registrar_;
129
130 // This map stores sidebars linked to a particular tab. Sidebars are
131 // identified by their unique content id (string).
132 typedef std::map<std::string, SidebarContainer*> ContentIdToSidebarHostMap;
133
134 // These two maps are for tracking dependencies between tabs and
135 // their SidebarContainers.
136 //
137 // SidebarManager start listening to SidebarContainers when they are put
138 // into these maps and removes them when they are closing.
139 struct SidebarStateForTab;
140 typedef std::map<TabContents*, SidebarStateForTab> TabToSidebarHostMap;
141 TabToSidebarHostMap tab_to_sidebar_host_;
142
143 typedef std::map<SidebarContainer*, TabContents*> SidebarHostToTabMap;
144 SidebarHostToTabMap sidebar_host_to_tab_;
145
146 DISALLOW_COPY_AND_ASSIGN(SidebarManager);
147 };
148
149 #endif // CHROME_BROWSER_SIDEBAR_SIDEBAR_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698