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

Side by Side Diff: chrome/browser/extensions/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: Move SidebarManager to ExtensionSystem and remove notifications Created 5 years, 6 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_EXTENSIONS_SIDEBAR_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_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/extensions/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 BrowserContext;
24 class WebContents;
25 }
26
27 namespace extensions {
28 ///////////////////////////////////////////////////////////////////////////////
29 // SidebarManager
30 //
31 // This class is a singleton that manages SidebarContainer instances and
32 // maintains a connection between tabs and sidebars.
33 //
34 class SidebarManager : public content::NotificationObserver,
35 public base::RefCounted<SidebarManager> {
Devlin 2015/06/04 18:00:14 Is there a reason this is refcounted?
36 public:
37 // Returns SidebarManager instance registered with BrowserContext.
38 static SidebarManager* GetFromContext(content::BrowserContext* context);
39
40 SidebarManager();
41
42 // Returns SidebarContainer registered for |tab| and active or NULL if
43 // there is no alive and active SidebarContainer registered for |tab|.
44 SidebarContainer* GetActiveSidebarContainerFor(content::WebContents* tab);
45
46 // Returns SidebarContainer registered for |tab| and |content_id| or NULL if
47 // there is no such SidebarContainer registered.
48 SidebarContainer* GetSidebarContainerFor(content::WebContents* tab,
49 const std::string& content_id);
50
51 // Returns sidebar's TabContents registered for |tab| and |content_id|.
52 content::WebContents* GetSidebarTabContents(content::WebContents* tab,
53 const std::string& content_id);
54
55 // Sends sidebar state change notification to extensions.
56 void NotifyStateChanges(content::WebContents* was_active_sidebar_contents,
57 content::WebContents* active_sidebar_contents);
58
59 // Shows sidebar identified by |tab| and |content_id| (only sidebar's
60 // mini tab is visible).
61 void ShowSidebar(content::WebContents* tab,
62 const std::string& content_id,
63 const GURL& url,
64 Browser* browser);
65
66 // Expands sidebar identified by |tab| and |content_id|.
67 void ExpandSidebar(content::WebContents* tab, const std::string& content_id);
68
69 // Collapses sidebar identified by |tab| and |content_id| (has no effect
70 // if sidebar is not expanded).
71 void CollapseSidebar(content::WebContents* tab,
72 const std::string& content_id);
73
74 SidebarContainer* MigrateSidebarTo(content::WebContents* tab);
75 // Hides sidebar identified by |tab| and |content_id| (removes sidebar's
76 // mini tab).
77 void HideSidebar(content::WebContents* tab, const std::string& content_id);
78
79 // Navigates sidebar identified by |tab| and |content_id| to |url|.
80 void NavigateSidebar(content::WebContents* tab,
81 const std::string& content_id,
82 const GURL& url);
83
84 void AddObserver(SidebarManagerObserver* observer);
85 void RemoveObserver(SidebarManagerObserver* observer);
86
87 private:
88 friend class base::RefCounted<SidebarManager>;
89
90 ~SidebarManager() override;
91
92 // Overridden from content::NotificationObserver.
93 void Observe(int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) override;
96
97 // Hides all sidebars registered for |tab|.
98 void HideAllSidebars(content::WebContents* tab);
99
100 // Returns SidebarContainer corresponding to |sidebar_contents|.
101 SidebarContainer* FindSidebarContainerFor(
102 content::WebContents* sidebar_contents);
103
104 // Registers new SidebarContainer for |tab|. There must be no
105 // other SidebarContainers registered for the RenderViewHost at the moment.
106 void RegisterSidebarContainerFor(content::WebContents* tab,
107 SidebarContainer* container);
108
109 // Unregisters SidebarContainer identified by |tab| and |content_id|.
110 void UnregisterSidebarContainerFor(content::WebContents* tab,
111 const std::string& content_id);
112
113 // Records the link between |tab| and |container|.
114 void BindSidebarContainer(content::WebContents* tab,
115 SidebarContainer* container);
116
117 // Forgets the link between |tab| and |container|.
118 void UnbindSidebarContainer(content::WebContents* tab,
119 SidebarContainer* container);
120
121 content::NotificationRegistrar registrar_;
122
123 // This map stores sidebars linked to a particular tab. Sidebars are
124 // identified by their unique content id (string).
125 typedef std::map<std::string, SidebarContainer*>
126 ContentIdToSidebarContainerMap;
127
128 // These two maps are for tracking dependencies between tabs and
129 // their SidebarContainers.
130 //
131 // SidebarManager start listening to SidebarContainers when they are put
132 // into these maps and removes them when they are closing.
133 struct SidebarStateForTab;
134 typedef std::map<content::WebContents*, SidebarStateForTab>
135 TabToSidebarContainerMap;
136 TabToSidebarContainerMap tab_to_sidebar_container_;
137
138 typedef std::map<SidebarContainer*, content::WebContents*>
139 SidebarContainerToTabMap;
140 SidebarContainerToTabMap sidebar_container_to_tab_;
141
142 ObserverList<SidebarManagerObserver> observer_list_;
143
144 DISALLOW_COPY_AND_ASSIGN(SidebarManager);
145 };
146
147 } // namespace extensions
148
149 #endif // CHROME_BROWSER_EXTENSIONS_SIDEBAR_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698