Chromium Code Reviews| 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 #include "chrome/browser/extensions/sidebar_manager.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/command_line.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | |
| 12 #include "chrome/browser/extensions/extension_service.h" | |
| 13 #include "chrome/browser/extensions/sidebar_container.h" | |
| 14 #include "chrome/browser/extensions/sidebar_manager_observer.h" | |
| 15 #include "content/public/browser/notification_service.h" | |
| 16 #include "content/public/browser/web_contents.h" | |
| 17 #include "extensions/browser/extension_system.h" | |
| 18 #include "extensions/common/switches.h" | |
| 19 #include "url/gurl.h" | |
| 20 | |
| 21 using content::BrowserContext; | |
|
Devlin
2015/06/19 19:56:09
use "using" like this sparingly (a good rule of th
ltilve
2015/06/28 22:44:20
Done.
| |
| 22 using content::WebContents; | |
| 23 | |
| 24 namespace extensions { | |
|
Devlin
2015/06/19 19:56:09
\n
ltilve
2015/06/28 22:44:20
Done.
| |
| 25 // static | |
| 26 SidebarManager* SidebarManager::GetFromContext(BrowserContext* context) { | |
| 27 return ExtensionSystem::Get(context)->sidebar_manager(); | |
| 28 } | |
| 29 | |
| 30 SidebarManager::SidebarManager() { | |
| 31 } | |
| 32 | |
| 33 SidebarContainer* SidebarManager::GetSidebarContainerFor( | |
| 34 content::WebContents* tab) { | |
| 35 TabToSidebarContainerMap::iterator it = tab_to_sidebar_container_.find(tab); | |
| 36 if (it == tab_to_sidebar_container_.end()) | |
|
Devlin
2015/06/19 19:56:09
return it == tab_to_sidebar_container_.end() ? nul
ltilve
2015/06/28 22:44:20
Done.
| |
| 37 return nullptr; | |
| 38 return it->second; | |
| 39 } | |
| 40 | |
| 41 void SidebarManager::CreateSidebar(content::WebContents* tab, | |
| 42 const GURL& url, | |
| 43 Browser* browser) { | |
| 44 SidebarContainer* container = GetSidebarContainerFor(tab); | |
| 45 if (container) | |
| 46 HideSidebar(tab); | |
| 47 | |
| 48 container = new SidebarContainer(browser, tab, url); | |
| 49 tab_to_sidebar_container_[tab] = container; | |
| 50 | |
| 51 const std::string id = container->extension_id(); | |
| 52 FOR_EACH_OBSERVER(SidebarManagerObserver, observer_list_, | |
| 53 OnSidebarShown(tab, id)); | |
| 54 } | |
| 55 | |
| 56 void SidebarManager::HideSidebar(WebContents* tab) { | |
| 57 SidebarContainer* container = GetSidebarContainerFor(tab); | |
| 58 if (!container) | |
| 59 return; | |
| 60 | |
| 61 const std::string content_id = container->extension_id(); | |
| 62 tab_to_sidebar_container_.erase(tab); | |
| 63 delete container; | |
| 64 | |
| 65 FOR_EACH_OBSERVER(SidebarManagerObserver, observer_list_, | |
| 66 OnSidebarHidden(tab, content_id)); | |
| 67 } | |
| 68 | |
| 69 bool SidebarManager::HasSidebar(WebContents* tab) { | |
| 70 return GetSidebarContainerFor(tab) != nullptr; | |
| 71 } | |
| 72 | |
| 73 SidebarManager::~SidebarManager() { | |
| 74 DCHECK(tab_to_sidebar_container_.empty()); | |
| 75 } | |
| 76 | |
| 77 SidebarContainer* SidebarManager::FindSidebarContainerFor( | |
| 78 content::WebContents* sidebar_contents) { | |
| 79 for (TabToSidebarContainerMap::iterator it = | |
| 80 tab_to_sidebar_container_.begin(); | |
| 81 it != tab_to_sidebar_container_.end(); ++it) { | |
| 82 if (sidebar_contents == it->second->host_contents()) | |
| 83 return it->second; | |
| 84 } | |
| 85 return nullptr; | |
| 86 } | |
| 87 | |
| 88 void SidebarManager::AddObserver(SidebarManagerObserver* observer) { | |
| 89 observer_list_.AddObserver(observer); | |
| 90 } | |
| 91 | |
| 92 void SidebarManager::RemoveObserver(SidebarManagerObserver* observer) { | |
| 93 observer_list_.RemoveObserver(observer); | |
| 94 } | |
| 95 | |
| 96 } // namespace extensions | |
| OLD | NEW |