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

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

Issue 1152613003: Implement sidebar support for extension action popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright (c) 2015 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/observer_list.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/sidebar/sidebar_container.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17
18 class GURL;
19 class SidebarContainer;
20 class SidebarManagerObserver;
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 SidebarManager();
40
41 // Returns SidebarContainer registered for |tab| and active or NULL if
42 // there is no alive and active SidebarContainer registered for |tab|.
43 SidebarContainer* GetActiveSidebarContainerFor(content::WebContents* tab);
44
45 // Returns SidebarContainer registered for |tab| and |content_id| or NULL if
46 // there is no such SidebarContainer registered.
47 SidebarContainer* GetSidebarContainerFor(content::WebContents* tab,
48 const std::string& content_id);
49
50 // Returns sidebar's TabContents registered for |tab| and |content_id|.
51 content::WebContents* GetSidebarTabContents(content::WebContents* tab,
52 const std::string& content_id);
53
54 // Sends sidebar state change notification to extensions.
55 void NotifyStateChanges(content::WebContents* was_active_sidebar_contents,
56 content::WebContents* active_sidebar_contents);
57
58 // Shows sidebar identified by |tab| and |content_id| (only sidebar's
59 // mini tab is visible).
60 void ShowSidebar(content::WebContents* tab,
61 const std::string& content_id,
62 const GURL& url,
63 Browser* browser);
64
65 // Expands sidebar identified by |tab| and |content_id|.
66 void ExpandSidebar(content::WebContents* 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(content::WebContents* tab,
71 const std::string& content_id);
72
73 SidebarContainer* MigrateSidebarTo(content::WebContents* tab);
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(content::WebContents* tab,
80 const std::string& content_id,
81 const GURL& url);
82
83 void AddObserver(SidebarManagerObserver* observer);
84 void RemoveObserver(SidebarManagerObserver* observer);
85
86 private:
87 friend class base::RefCounted<SidebarManager>;
88
89 ~SidebarManager() override;
90
91 // Overridden from content::NotificationObserver.
92 void Observe(int type,
93 const content::NotificationSource& source,
94 const content::NotificationDetails& details) override;
95
96 // Overridden from SidebarContainer::Delegate.
97 void UpdateSidebar(SidebarContainer* container) override;
98
99 // Hides all sidebars registered for |tab|.
100 void HideAllSidebars(content::WebContents* tab);
101
102 // Returns SidebarContainer corresponding to |sidebar_contents|.
103 SidebarContainer* FindSidebarContainerFor(
104 content::WebContents* sidebar_contents);
105
106 // Registers new SidebarContainer for |tab|. There must be no
107 // other SidebarContainers registered for the RenderViewHost at the moment.
108 void RegisterSidebarContainerFor(content::WebContents* tab,
109 SidebarContainer* container);
110
111 // Unregisters SidebarContainer identified by |tab| and |content_id|.
112 void UnregisterSidebarContainerFor(content::WebContents* tab,
113 const std::string& content_id);
114
115 // Records the link between |tab| and |container|.
116 void BindSidebarContainer(content::WebContents* tab,
117 SidebarContainer* container);
118
119 // Forgets the link between |tab| and |container|.
120 void UnbindSidebarContainer(content::WebContents* tab,
121 SidebarContainer* container);
122
123 content::NotificationRegistrar registrar_;
124
125 // This map stores sidebars linked to a particular tab. Sidebars are
126 // identified by their unique content id (string).
127 typedef std::map<std::string, SidebarContainer*>
128 ContentIdToSidebarContainerMap;
129
130 // These two maps are for tracking dependencies between tabs and
131 // their SidebarContainers.
132 //
133 // SidebarManager start listening to SidebarContainers when they are put
134 // into these maps and removes them when they are closing.
135 struct SidebarStateForTab;
136 typedef std::map<content::WebContents*, SidebarStateForTab>
137 TabToSidebarContainerMap;
138 TabToSidebarContainerMap tab_to_sidebar_container_;
139
140 typedef std::map<SidebarContainer*, content::WebContents*>
141 SidebarContainerToTabMap;
142 SidebarContainerToTabMap sidebar_container_to_tab_;
143
144 ObserverList<SidebarManagerObserver> observer_list_;
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