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

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

Issue 1168383002: Implement sidebar support for extension action popups Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add sidebar handling logic and browser_tests 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/observer_list.h"
12 #include "base/strings/string16.h"
13 #include "chrome/browser/extensions/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 SidebarManagerObserver;
20
21 namespace content {
22 class BrowserContext;
23 class WebContents;
24 }
25
26 namespace extensions {
27 ///////////////////////////////////////////////////////////////////////////////
28 // SidebarManager
29 //
30 // This class is a singleton that manages SidebarContainer instances and
31 // maintains a connection between tabs and sidebars.
32 //
33 class SidebarManager : public content::NotificationObserver {
34 public:
35 // Returns SidebarManager instance registered with BrowserContext.
36 static SidebarManager* GetFromContext(content::BrowserContext* context);
37
38 SidebarManager();
39
40 // Returns SidebarContainer registered for |tab| or nullptr if there is no
41 // SidebarContainer registered for |tab|.
42 SidebarContainer* GetSidebarContainerFor(content::WebContents* tab);
43
44 // Sends sidebar state change notification to extensions.
45 void NotifyStateChanges(content::WebContents* was_active_sidebar_contents,
Devlin 2015/06/16 17:56:12 When is this used?
46 content::WebContents* active_sidebar_contents);
47
48 // Creates a new sidebar identified by |tab| (adds sidebar's mini tab).
49 void CreateSidebar(content::WebContents* tab,
50 const GURL& url,
51 Browser* browser);
52
53 // Hides and destroys sidebar identified by |tab| (removes sidebar's mini
54 // tab).
55 void HideSidebar(content::WebContents* tab);
56
57 // Check if |tab| has a sidebar assigned.
58 bool HasSidebar(content::WebContents* tab);
59
60 void AddObserver(SidebarManagerObserver* observer);
61 void RemoveObserver(SidebarManagerObserver* observer);
62
63 ~SidebarManager() override;
64
65 private:
66 // Overridden from content::NotificationObserver.
67 void Observe(int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) override;
70
71 // Returns SidebarContainer corresponding to |sidebar_contents|.
72 SidebarContainer* FindSidebarContainerFor(
73 content::WebContents* sidebar_contents);
74
75 // Records the link between |tab| and |container|.
76 void BindSidebarContainer(content::WebContents* tab,
77 SidebarContainer* container);
78
79 // Forgets the link between |tab| and |container|.
80 void UnbindSidebarContainer(content::WebContents* tab,
81 SidebarContainer* container);
82
83 content::NotificationRegistrar registrar_;
84
85 // This map stores sidebars linked to a particular tab. Sidebars are
86 // identified by their unique content id (string).
87 typedef std::map<std::string, SidebarContainer*>
88 ContentIdToSidebarContainerMap;
89
90 // These two maps are for tracking dependencies between tabs and
91 // their SidebarContainers.
92 //
93 // SidebarManager start listening to SidebarContainers when they are put
94 // into these maps and removes them when they are closing.
95 typedef std::map<content::WebContents*, SidebarContainer*>
Devlin 2015/06/16 17:56:12 Having two maps is probably excessive, since most
96 TabToSidebarContainerMap;
97 TabToSidebarContainerMap tab_to_sidebar_container_;
98
99 typedef std::map<SidebarContainer*, content::WebContents*>
100 SidebarContainerToTabMap;
101 SidebarContainerToTabMap sidebar_container_to_tab_;
102
103 base::ObserverList<SidebarManagerObserver> observer_list_;
104
105 DISALLOW_COPY_AND_ASSIGN(SidebarManager);
106 };
107
108 } // namespace extensions
109
110 #endif // CHROME_BROWSER_EXTENSIONS_SIDEBAR_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698