Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 #include "chrome/browser/extensions/sidebar_manager.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/sidebar_container.h" | |
| 8 #include "chrome/browser/extensions/sidebar_manager_observer.h" | |
| 9 #include "content/public/browser/web_contents.h" | |
| 10 #include "extensions/browser/extension_system.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 using content::WebContents; | |
| 14 | |
| 15 namespace extensions { | |
| 16 | |
| 17 // static | |
| 18 SidebarManager* SidebarManager::GetFromContext( | |
| 19 content::BrowserContext* context) { | |
| 20 return ExtensionSystem::Get(context)->sidebar_manager(); | |
| 21 } | |
| 22 | |
| 23 SidebarManager::SidebarManager() { | |
| 24 } | |
| 25 | |
| 26 SidebarManager::~SidebarManager() { | |
| 27 DCHECK(tab_to_sidebar_container_.empty()); | |
| 28 } | |
| 29 | |
| 30 SidebarContainer* SidebarManager::GetSidebarContainerFor( | |
| 31 content::WebContents* tab) { | |
| 32 TabToSidebarContainerMap::iterator it = tab_to_sidebar_container_.find(tab); | |
| 33 return it == tab_to_sidebar_container_.end() ? nullptr : it->second; | |
| 34 } | |
| 35 | |
| 36 void SidebarManager::CreateSidebar(content::WebContents* tab, | |
| 37 const GURL& url, | |
| 38 Browser* browser) { | |
| 39 DCHECK(tab); | |
| 40 SidebarContainer* container = GetSidebarContainerFor(tab); | |
| 41 if (container) | |
|
Devlin
2015/07/07 21:39:29
There's a check in HideSidebar() that does this, s
ltilve
2015/07/09 22:15:51
Done.
| |
| 42 HideSidebar(tab); | |
| 43 | |
| 44 container = new SidebarContainer(browser, tab, url); | |
| 45 tab_to_sidebar_container_[tab] = container; | |
| 46 | |
| 47 const std::string id = container->extension_id(); | |
| 48 FOR_EACH_OBSERVER(SidebarManagerObserver, observer_list_, | |
| 49 OnSidebarShown(tab, id)); | |
| 50 } | |
| 51 | |
| 52 void SidebarManager::HideSidebar(WebContents* tab) { | |
| 53 DCHECK(tab); | |
| 54 SidebarContainer* container = GetSidebarContainerFor(tab); | |
| 55 if (!container) | |
| 56 return; | |
| 57 | |
| 58 const std::string content_id = container->extension_id(); | |
| 59 tab_to_sidebar_container_.erase(tab); | |
| 60 delete container; | |
| 61 | |
| 62 FOR_EACH_OBSERVER(SidebarManagerObserver, observer_list_, | |
| 63 OnSidebarHidden(tab, content_id)); | |
| 64 } | |
| 65 | |
| 66 void SidebarManager::AddObserver(SidebarManagerObserver* observer) { | |
| 67 observer_list_.AddObserver(observer); | |
| 68 } | |
| 69 | |
| 70 void SidebarManager::RemoveObserver(SidebarManagerObserver* observer) { | |
| 71 observer_list_.RemoveObserver(observer); | |
| 72 } | |
| 73 | |
| 74 } // namespace extensions | |
| OLD | NEW |