Add startup_cold, startup_cold_dirty, startup_warm, and startup_warm_dirty test info.
[chromium-blink-merge.git] / chrome_frame / infobars / infobar_manager.cc
blob0dea3ac9fc8e58f9b53156e23994390062a632f6
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
3 // found in the LICENSE file.
5 #include "chrome_frame/infobars/infobar_manager.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome_frame/infobars/internal/host_window_manager.h"
10 #include "chrome_frame/infobars/internal/infobar_window.h"
12 // Connects InfobarWindow to HostWindowManager, and exposes the result as an
13 // InfobarManager.
14 class InfobarManagerImpl
15 : public InfobarManager,
16 public InfobarWindow::Host,
17 public HostWindowManager::Delegate {
18 public:
19 explicit InfobarManagerImpl(HostWindowManager* manager);
21 // Implementation of InfobarManager
22 virtual bool Show(InfobarContent* content, InfobarType type);
23 virtual void Hide(InfobarType type);
24 virtual void HideAll();
26 // Implementation of HostWindowManager::Delegate
27 virtual void AdjustDisplacedWindowDimensions(RECT* rect);
29 // Implementation of InfobarWindow::Host
30 virtual HWND GetContainerWindow();
31 virtual void UpdateLayout();
33 private:
34 // Not owned by this instance.
35 HostWindowManager* manager_;
36 // Infobar windows.
37 scoped_ptr<InfobarWindow> infobars_[END_OF_INFOBAR_TYPE];
38 DISALLOW_COPY_AND_ASSIGN(InfobarManagerImpl);
39 }; // class InfobarManagerImpl
41 InfobarManagerImpl::InfobarManagerImpl(HostWindowManager* manager)
42 : manager_(manager) {
43 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) {
44 infobars_[index].reset(
45 new InfobarWindow(static_cast<InfobarType>(index)));
46 infobars_[index]->SetHost(this);
50 bool InfobarManagerImpl::Show(InfobarContent* content, InfobarType type) {
51 DCHECK(type >= FIRST_INFOBAR_TYPE && type < END_OF_INFOBAR_TYPE);
52 return infobars_[type]->Show(content);
55 void InfobarManagerImpl::Hide(InfobarType type) {
56 DCHECK(type >= FIRST_INFOBAR_TYPE && type < END_OF_INFOBAR_TYPE);
57 infobars_[type]->Hide();
60 void InfobarManagerImpl::HideAll() {
61 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index)
62 Hide(static_cast<InfobarType>(index));
65 void InfobarManagerImpl::AdjustDisplacedWindowDimensions(RECT* rect) {
66 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) {
67 if (infobars_[index] != NULL)
68 infobars_[index]->ReserveSpace(rect);
72 HWND InfobarManagerImpl::GetContainerWindow() {
73 return *manager_;
76 void InfobarManagerImpl::UpdateLayout() {
77 manager_->UpdateLayout();
80 InfobarManager::~InfobarManager() {
83 InfobarManager* InfobarManager::Get(HWND tab_window) {
84 HostWindowManager::Delegate* delegate =
85 HostWindowManager::GetDelegateForHwnd(tab_window);
87 if (delegate != NULL)
88 return static_cast<InfobarManagerImpl*>(delegate);
90 scoped_ptr<HostWindowManager> host_manager(new HostWindowManager());
92 // Transferred to host_manager in call to Initialize.
93 InfobarManagerImpl* infobar_manager = new InfobarManagerImpl(
94 host_manager.get());
96 if (host_manager->Initialize(tab_window, infobar_manager)) {
97 host_manager.release(); // takes ownership of itself
98 return infobar_manager;
101 return NULL;