OLD | NEW |
(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, |
| 46 content::WebContents* active_sidebar_contents); |
| 47 |
| 48 // Shows sidebar identified by |tab| (only sidebar's |
| 49 // mini tab is visible). |
| 50 void ShowSidebar(content::WebContents* tab, |
| 51 const GURL& url, |
| 52 Browser* browser); |
| 53 |
| 54 // Hides sidebar identified by |tab| (removes sidebar's |
| 55 // mini tab). |
| 56 void HideSidebar(content::WebContents* tab); |
| 57 |
| 58 // Navigates sidebar identified by |tab|. |
| 59 void NavigateSidebar(content::WebContents* tab); |
| 60 |
| 61 void AddObserver(SidebarManagerObserver* observer); |
| 62 void RemoveObserver(SidebarManagerObserver* observer); |
| 63 |
| 64 ~SidebarManager() override; |
| 65 |
| 66 private: |
| 67 // Overridden from content::NotificationObserver. |
| 68 void Observe(int type, |
| 69 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) override; |
| 71 |
| 72 // Returns SidebarContainer corresponding to |sidebar_contents|. |
| 73 SidebarContainer* FindSidebarContainerFor( |
| 74 content::WebContents* sidebar_contents); |
| 75 |
| 76 // Records the link between |tab| and |container|. |
| 77 void BindSidebarContainer(content::WebContents* tab, |
| 78 SidebarContainer* container); |
| 79 |
| 80 // Forgets the link between |tab| and |container|. |
| 81 void UnbindSidebarContainer(content::WebContents* tab, |
| 82 SidebarContainer* container); |
| 83 |
| 84 content::NotificationRegistrar registrar_; |
| 85 |
| 86 // This map stores sidebars linked to a particular tab. Sidebars are |
| 87 // identified by their unique content id (string). |
| 88 typedef std::map<std::string, SidebarContainer*> |
| 89 ContentIdToSidebarContainerMap; |
| 90 |
| 91 // These two maps are for tracking dependencies between tabs and |
| 92 // their SidebarContainers. |
| 93 // |
| 94 // SidebarManager start listening to SidebarContainers when they are put |
| 95 // into these maps and removes them when they are closing. |
| 96 typedef std::map<content::WebContents*, SidebarContainer*> |
| 97 TabToSidebarContainerMap; |
| 98 TabToSidebarContainerMap tab_to_sidebar_container_; |
| 99 |
| 100 typedef std::map<SidebarContainer*, content::WebContents*> |
| 101 SidebarContainerToTabMap; |
| 102 SidebarContainerToTabMap sidebar_container_to_tab_; |
| 103 |
| 104 base::ObserverList<SidebarManagerObserver> observer_list_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(SidebarManager); |
| 107 }; |
| 108 |
| 109 } // namespace extensions |
| 110 |
| 111 #endif // CHROME_BROWSER_EXTENSIONS_SIDEBAR_MANAGER_H_ |
OLD | NEW |