OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sidebar/sidebar_manager.h" | 5 #include "chrome/browser/sidebar/sidebar_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/extensions/extension_sidebar_api.h" | 11 #include "chrome/browser/extensions/extension_sidebar_api.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/sidebar/sidebar_container.h" | 13 #include "chrome/browser/sidebar/sidebar_container.h" |
| 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
19 struct SidebarManager::SidebarStateForTab { | 20 struct SidebarManager::SidebarStateForTab { |
20 // Sidebars linked to this tab. | 21 // Sidebars linked to this tab. |
21 ContentIdToSidebarHostMap content_id_to_sidebar_host; | 22 ContentIdToSidebarHostMap content_id_to_sidebar_host; |
22 // Content id of the currently active (expanded and visible) sidebar. | 23 // Content id of the currently active (expanded and visible) sidebar. |
23 std::string active_content_id; | 24 std::string active_content_id; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (!host) | 213 if (!host) |
213 return; | 214 return; |
214 host->SetTitle(title); | 215 host->SetTitle(title); |
215 } | 216 } |
216 | 217 |
217 SidebarManager::~SidebarManager() { | 218 SidebarManager::~SidebarManager() { |
218 DCHECK(tab_to_sidebar_host_.empty()); | 219 DCHECK(tab_to_sidebar_host_.empty()); |
219 DCHECK(sidebar_host_to_tab_.empty()); | 220 DCHECK(sidebar_host_to_tab_.empty()); |
220 } | 221 } |
221 | 222 |
222 void SidebarManager::Observe(NotificationType type, | 223 void SidebarManager::Observe(int type, |
223 const NotificationSource& source, | 224 const NotificationSource& source, |
224 const NotificationDetails& details) { | 225 const NotificationDetails& details) { |
225 if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 226 if (type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED) { |
226 HideAllSidebars(Source<TabContents>(source).ptr()); | 227 HideAllSidebars(Source<TabContents>(source).ptr()); |
227 } else { | 228 } else { |
228 NOTREACHED() << "Got a notification we didn't register for!"; | 229 NOTREACHED() << "Got a notification we didn't register for!"; |
229 } | 230 } |
230 } | 231 } |
231 | 232 |
232 void SidebarManager::UpdateSidebar(SidebarContainer* host) { | 233 void SidebarManager::UpdateSidebar(SidebarContainer* host) { |
233 NotificationService::current()->Notify( | 234 NotificationService::current()->Notify( |
234 NotificationType::SIDEBAR_CHANGED, | 235 chrome::NOTIFICATION_SIDEBAR_CHANGED, |
235 Source<SidebarManager>(this), | 236 Source<SidebarManager>(this), |
236 Details<SidebarContainer>(host)); | 237 Details<SidebarContainer>(host)); |
237 } | 238 } |
238 | 239 |
239 void SidebarManager::HideAllSidebars(TabContents* tab) { | 240 void SidebarManager::HideAllSidebars(TabContents* tab) { |
240 TabToSidebarHostMap::iterator tab_it = tab_to_sidebar_host_.find(tab); | 241 TabToSidebarHostMap::iterator tab_it = tab_to_sidebar_host_.find(tab); |
241 if (tab_it == tab_to_sidebar_host_.end()) | 242 if (tab_it == tab_to_sidebar_host_.end()) |
242 return; | 243 return; |
243 const ContentIdToSidebarHostMap& hosts = | 244 const ContentIdToSidebarHostMap& hosts = |
244 tab_it->second.content_id_to_sidebar_host; | 245 tab_it->second.content_id_to_sidebar_host; |
(...skipping 21 matching lines...) Expand all Loading... |
266 return NULL; | 267 return NULL; |
267 } | 268 } |
268 | 269 |
269 void SidebarManager::RegisterSidebarContainerFor( | 270 void SidebarManager::RegisterSidebarContainerFor( |
270 TabContents* tab, SidebarContainer* sidebar_host) { | 271 TabContents* tab, SidebarContainer* sidebar_host) { |
271 DCHECK(!GetSidebarContainerFor(tab, sidebar_host->content_id())); | 272 DCHECK(!GetSidebarContainerFor(tab, sidebar_host->content_id())); |
272 | 273 |
273 // If it's a first sidebar for this tab, register destroy notification. | 274 // If it's a first sidebar for this tab, register destroy notification. |
274 if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) { | 275 if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) { |
275 registrar_.Add(this, | 276 registrar_.Add(this, |
276 NotificationType::TAB_CONTENTS_DESTROYED, | 277 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
277 Source<TabContents>(tab)); | 278 Source<TabContents>(tab)); |
278 } | 279 } |
279 | 280 |
280 BindSidebarHost(tab, sidebar_host); | 281 BindSidebarHost(tab, sidebar_host); |
281 } | 282 } |
282 | 283 |
283 void SidebarManager::UnregisterSidebarContainerFor( | 284 void SidebarManager::UnregisterSidebarContainerFor( |
284 TabContents* tab, const std::string& content_id) { | 285 TabContents* tab, const std::string& content_id) { |
285 SidebarContainer* host = GetSidebarContainerFor(tab, content_id); | 286 SidebarContainer* host = GetSidebarContainerFor(tab, content_id); |
286 DCHECK(host); | 287 DCHECK(host); |
287 if (!host) | 288 if (!host) |
288 return; | 289 return; |
289 | 290 |
290 UnbindSidebarHost(tab, host); | 291 UnbindSidebarHost(tab, host); |
291 | 292 |
292 // If there's no more sidebars linked to this tab, unsubscribe. | 293 // If there's no more sidebars linked to this tab, unsubscribe. |
293 if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) { | 294 if (tab_to_sidebar_host_.find(tab) == tab_to_sidebar_host_.end()) { |
294 registrar_.Remove(this, | 295 registrar_.Remove(this, |
295 NotificationType::TAB_CONTENTS_DESTROYED, | 296 content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
296 Source<TabContents>(tab)); | 297 Source<TabContents>(tab)); |
297 } | 298 } |
298 | 299 |
299 // Issue tab closing event post unbound. | 300 // Issue tab closing event post unbound. |
300 host->SidebarClosing(); | 301 host->SidebarClosing(); |
301 // Destroy sidebar container. | 302 // Destroy sidebar container. |
302 delete host; | 303 delete host; |
303 } | 304 } |
304 | 305 |
305 void SidebarManager::BindSidebarHost(TabContents* tab, | 306 void SidebarManager::BindSidebarHost(TabContents* tab, |
(...skipping 15 matching lines...) Expand all Loading... |
321 | 322 |
322 DCHECK(GetSidebarContainerFor(tab, content_id) == sidebar_host); | 323 DCHECK(GetSidebarContainerFor(tab, content_id) == sidebar_host); |
323 DCHECK(sidebar_host_to_tab_.find(sidebar_host)->second == tab); | 324 DCHECK(sidebar_host_to_tab_.find(sidebar_host)->second == tab); |
324 DCHECK(tab_to_sidebar_host_[tab].active_content_id != content_id); | 325 DCHECK(tab_to_sidebar_host_[tab].active_content_id != content_id); |
325 | 326 |
326 tab_to_sidebar_host_[tab].content_id_to_sidebar_host.erase(content_id); | 327 tab_to_sidebar_host_[tab].content_id_to_sidebar_host.erase(content_id); |
327 if (tab_to_sidebar_host_[tab].content_id_to_sidebar_host.empty()) | 328 if (tab_to_sidebar_host_[tab].content_id_to_sidebar_host.empty()) |
328 tab_to_sidebar_host_.erase(tab); | 329 tab_to_sidebar_host_.erase(tab); |
329 sidebar_host_to_tab_.erase(sidebar_host); | 330 sidebar_host_to_tab_.erase(sidebar_host); |
330 } | 331 } |
OLD | NEW |