OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Implementation of the manager for infobar windows. | 5 // Implementation of the manager for infobar windows. |
6 | 6 |
7 #include "ceee/ie/plugin/bho/infobar_manager.h" | 7 #include "ceee/ie/plugin/bho/infobar_manager.h" |
8 | 8 |
9 #include <atlbase.h> | 9 #include <atlbase.h> |
10 #include <atlapp.h> // Must be included AFTER base. | 10 #include <atlapp.h> // Must be included AFTER base. |
(...skipping 13 matching lines...) Expand all Loading... |
24 }; | 24 }; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 namespace infobar_api { | 28 namespace infobar_api { |
29 | 29 |
30 // ContainerWindow subclasses IE content window's container window, handles | 30 // ContainerWindow subclasses IE content window's container window, handles |
31 // WM_NCCALCSIZE to resize its client area. It also handles WM_SIZE and WM_MOVE | 31 // WM_NCCALCSIZE to resize its client area. It also handles WM_SIZE and WM_MOVE |
32 // messages to make infobars consistent with IE content window's size and | 32 // messages to make infobars consistent with IE content window's size and |
33 // position. | 33 // position. |
34 class InfobarManager::ContainerWindow : public CWindowImpl<ContainerWindow> { | 34 class InfobarManager::ContainerWindow |
| 35 : public InfobarManager::ContainerWindowInterface, |
| 36 public CWindowImpl<ContainerWindow> { |
35 public: | 37 public: |
36 ContainerWindow(HWND container, InfobarManager* manager) | 38 ContainerWindow(HWND container, InfobarManager* manager) |
37 : infobar_manager_(manager) { | 39 : infobar_manager_(manager) { |
38 PinModule(); | 40 PinModule(); |
39 destroyed_ = !::IsWindow(container) || !SubclassWindow(container); | 41 destroyed_ = !::IsWindow(container) || !SubclassWindow(container); |
40 } | 42 } |
41 | 43 |
42 virtual ~ContainerWindow() { | 44 virtual ~ContainerWindow() { |
43 if (!destroyed_) | 45 if (!destroyed_) |
44 UnsubclassWindow(); | 46 UnsubclassWindow(); |
45 } | 47 } |
46 | 48 |
47 bool destroyed() const { | 49 virtual bool IsDestroyed() const { |
48 return destroyed_; | 50 return destroyed_; |
49 } | 51 } |
50 | 52 |
| 53 virtual HWND GetWindowHandle() const { |
| 54 return IsWindow() ? m_hWnd : NULL; |
| 55 } |
| 56 |
| 57 virtual bool PostWindowsMessage(UINT msg, WPARAM wparam, LPARAM lparam) { |
| 58 return PostMessage(msg, wparam, lparam) != 0; |
| 59 } |
| 60 |
51 BEGIN_MSG_MAP_EX(ContainerWindow) | 61 BEGIN_MSG_MAP_EX(ContainerWindow) |
52 MSG_WM_NCCALCSIZE(OnNcCalcSize) | 62 MSG_WM_NCCALCSIZE(OnNcCalcSize) |
53 MSG_WM_SIZE(OnSize) | 63 MSG_WM_SIZE(OnSize) |
54 MSG_WM_MOVE(OnMove) | 64 MSG_WM_MOVE(OnMove) |
55 MSG_WM_DESTROY(OnDestroy) | 65 MSG_WM_DESTROY(OnDestroy) |
56 MESSAGE_HANDLER(TM_NOTIFY_UPDATE_POSITION, OnNotifyUpdatePosition) | 66 MESSAGE_HANDLER(TM_NOTIFY_UPDATE_POSITION, OnNotifyUpdatePosition) |
57 MESSAGE_HANDLER(TM_DELAYED_CLOSE_INFOBAR, OnDelayedCloseInfobar) | 67 MESSAGE_HANDLER(TM_DELAYED_CLOSE_INFOBAR, OnDelayedCloseInfobar) |
58 END_MSG_MAP() | 68 END_MSG_MAP() |
59 | 69 |
60 private: | 70 private: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 InfobarManager* infobar_manager_; | 138 InfobarManager* infobar_manager_; |
129 | 139 |
130 // True is this window was destroyed or not subclassed. | 140 // True is this window was destroyed or not subclassed. |
131 bool destroyed_; | 141 bool destroyed_; |
132 | 142 |
133 DISALLOW_COPY_AND_ASSIGN(ContainerWindow); | 143 DISALLOW_COPY_AND_ASSIGN(ContainerWindow); |
134 }; | 144 }; |
135 | 145 |
136 InfobarManager::InfobarManager(HWND tab_window) | 146 InfobarManager::InfobarManager(HWND tab_window) |
137 : tab_window_(tab_window) { | 147 : tab_window_(tab_window) { |
138 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { | |
139 // Note that when InfobarManager is being initialized the IE has not created | |
140 // the tab. Therefore we cannot find the container window here and have to | |
141 // pass interface for a function that finds windows to be called later. | |
142 infobars_[index].reset( | |
143 InfobarWindow::CreateInfobar(static_cast<InfobarType>(index), this)); | |
144 } | |
145 } | 148 } |
146 | 149 |
147 HRESULT InfobarManager::Show(InfobarType type, int max_height, | 150 HRESULT InfobarManager::Show(InfobarType type, int max_height, |
148 const std::wstring& url, bool slide) { | 151 const std::wstring& url, bool slide) { |
| 152 LazyInitialize(type); |
149 if (type < FIRST_INFOBAR_TYPE || type >= END_OF_INFOBAR_TYPE || | 153 if (type < FIRST_INFOBAR_TYPE || type >= END_OF_INFOBAR_TYPE || |
150 infobars_[type] == NULL) { | 154 infobars_[type] == NULL) { |
151 return E_INVALIDARG; | 155 return E_INVALIDARG; |
152 } | 156 } |
153 // Set the URL. If the window is not created it will navigate there as soon as | 157 // Set the URL. If the window is not created it will navigate there as soon as |
154 // it is created. | 158 // it is created. |
155 infobars_[type]->Navigate(url); | 159 infobars_[type]->Navigate(url); |
156 // Create the window if not created. | 160 // Create the window if not created. |
157 if (!infobars_[type]->IsWindow()) { | 161 if (!infobars_[type]->IsWindow()) { |
158 infobars_[type]->Create(tab_window_, NULL, NULL, | 162 infobars_[type]->InternalCreate(tab_window_, WS_CHILD | WS_CLIPCHILDREN); |
159 WS_CHILD | WS_CLIPCHILDREN); | |
160 } | 163 } |
161 if (!infobars_[type]->IsWindow()) | 164 if (!infobars_[type]->IsWindow()) |
162 return E_UNEXPECTED; | 165 return E_UNEXPECTED; |
163 | 166 |
164 HRESULT hr = infobars_[type]->Show(max_height, slide); | 167 HRESULT hr = infobars_[type]->Show(max_height, slide); |
165 return hr; | 168 return hr; |
166 } | 169 } |
167 | 170 |
168 HRESULT InfobarManager::Hide(InfobarType type) { | 171 HRESULT InfobarManager::Hide(InfobarType type) { |
169 if (type < FIRST_INFOBAR_TYPE || type >= END_OF_INFOBAR_TYPE || | 172 if (type < FIRST_INFOBAR_TYPE || type >= END_OF_INFOBAR_TYPE) |
170 infobars_[type] == NULL) { | |
171 return E_INVALIDARG; | 173 return E_INVALIDARG; |
172 } | 174 // No lazy initialization here - if the infobar has not been created just |
| 175 // return; |
| 176 if (infobars_[type] == NULL) |
| 177 return E_UNEXPECTED; |
173 // There is a choice either to hide or to destroy the infobar window. | 178 // There is a choice either to hide or to destroy the infobar window. |
174 // This implementation destroys the infobar to save resources and stop all | 179 // This implementation destroys the infobar to save resources and stop all |
175 // scripts that possibly still run in the window. If we want to just hide the | 180 // scripts that possibly still run in the window. If we want to just hide the |
176 // infobar window instead then we should change Reset to Hide here, possibly | 181 // infobar window instead then we should change Reset to Hide here, possibly |
177 // navigate the infobar window to "about:blank" and make sure that the code | 182 // navigate the infobar window to "about:blank" and make sure that the code |
178 // in Show() does not try to create the chrome frame window again. | 183 // in Show() does not try to create the chrome frame window again. |
179 infobars_[type]->Reset(); | 184 infobars_[type]->Reset(); |
180 return S_OK; | 185 return S_OK; |
181 } | 186 } |
182 | 187 |
(...skipping 18 matching lines...) Expand all Loading... |
201 if (::GetClassName(hwnd, class_name, arraysize(class_name)) && | 206 if (::GetClassName(hwnd, class_name, arraysize(class_name)) && |
202 lstrcmpi(windows::kIeTabContentParentWindowClass, class_name) == 0) { | 207 lstrcmpi(windows::kIeTabContentParentWindowClass, class_name) == 0) { |
203 // We found the window. Return its handle and stop enumeration. | 208 // We found the window. Return its handle and stop enumeration. |
204 *window_handle = hwnd; | 209 *window_handle = hwnd; |
205 return FALSE; | 210 return FALSE; |
206 } | 211 } |
207 return TRUE; | 212 return TRUE; |
208 } | 213 } |
209 | 214 |
210 HWND InfobarManager::GetContainerWindow() { | 215 HWND InfobarManager::GetContainerWindow() { |
211 if (container_window_ != NULL && container_window_->destroyed()) | 216 if (container_window_ != NULL && container_window_->IsDestroyed()) |
212 container_window_.reset(NULL); | 217 container_window_.reset(NULL); |
213 | 218 |
214 if (container_window_ == NULL) { | 219 if (container_window_ == NULL) { |
215 if (tab_window_ != NULL && ::IsWindow(tab_window_)) { | 220 if (tab_window_ != NULL && ::IsWindow(tab_window_)) { |
216 // Find the window which is the container for the HTML view (parent of | 221 // Find the window which is the container for the HTML view (parent of |
217 // the content). | 222 // the content). |
218 HWND content_parent_window = NULL; | 223 HWND content_parent_window = NULL; |
219 ::EnumChildWindows(tab_window_, FindContentParentWindowsProc, | 224 ::EnumChildWindows(tab_window_, FindContentParentWindowsProc, |
220 reinterpret_cast<LPARAM>(&content_parent_window)); | 225 reinterpret_cast<LPARAM>(&content_parent_window)); |
221 DCHECK(content_parent_window); | 226 DCHECK(content_parent_window); |
222 if (content_parent_window != NULL) { | 227 if (content_parent_window != NULL) { |
223 container_window_.reset( | 228 container_window_.reset( |
224 new ContainerWindow(content_parent_window, this)); | 229 CreateContainerWindow(content_parent_window, this)); |
225 } | 230 } |
226 } | 231 } |
227 } | 232 } |
228 DCHECK(container_window_ != NULL && container_window_->IsWindow()); | 233 DCHECK(container_window_ != NULL && |
229 return container_window_->m_hWnd; | 234 container_window_->GetWindowHandle() != NULL); |
| 235 return container_window_->GetWindowHandle(); |
230 } | 236 } |
231 | 237 |
232 void InfobarManager::OnWindowClose(InfobarType type) { | 238 void InfobarManager::OnWindowClose(InfobarType type) { |
233 // This callback is called from CF callback so we should not destroy the | 239 // This callback is called from CF callback so we should not destroy the |
234 // infobar window right away as it may result on deleting the object that | 240 // infobar window right away as it may result on deleting the object that |
235 // started this callback. So instead we post ourtselves the message. | 241 // started this callback. So instead we post ourtselves the message. |
236 if (container_window_ != NULL) | 242 if (container_window_ != NULL) |
237 container_window_->PostMessage(TM_DELAYED_CLOSE_INFOBAR, | 243 container_window_->PostWindowsMessage(TM_DELAYED_CLOSE_INFOBAR, |
238 static_cast<WPARAM>(type), 0); | 244 static_cast<WPARAM>(type), 0); |
239 } | 245 } |
240 | 246 |
241 void InfobarManager::OnContainerWindowNcCalcSize(RECT* rect) { | 247 void InfobarManager::OnContainerWindowNcCalcSize(RECT* rect) { |
242 if (rect == NULL) | 248 if (rect == NULL) |
243 return; | 249 return; |
244 | 250 |
245 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { | 251 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { |
246 if (infobars_[index] != NULL) | 252 if (infobars_[index] != NULL) |
247 infobars_[index]->ReserveSpace(rect); | 253 infobars_[index]->ReserveSpace(rect); |
248 } | 254 } |
(...skipping 11 matching lines...) Expand all Loading... |
260 Hide(type); | 266 Hide(type); |
261 } | 267 } |
262 | 268 |
263 void InfobarManager::OnContainerWindowDestroy() { | 269 void InfobarManager::OnContainerWindowDestroy() { |
264 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { | 270 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { |
265 if (infobars_[index] != NULL) | 271 if (infobars_[index] != NULL) |
266 infobars_[index]->Reset(); | 272 infobars_[index]->Reset(); |
267 } | 273 } |
268 } | 274 } |
269 | 275 |
| 276 void InfobarManager::LazyInitialize(InfobarType type) { |
| 277 DCHECK(type >= FIRST_INFOBAR_TYPE && type < END_OF_INFOBAR_TYPE); |
| 278 if (type < FIRST_INFOBAR_TYPE || type >= END_OF_INFOBAR_TYPE) |
| 279 return; |
| 280 |
| 281 if (infobars_[type] != NULL) |
| 282 return; |
| 283 |
| 284 // Note that when InfobarManager is being initialized the IE has not created |
| 285 // the tab. Therefore we cannot find the container window here and have to |
| 286 // pass interface for a function that finds windows to be called later. |
| 287 infobars_[type].reset(InfobarWindow::CreateInfobar(type, this)); |
| 288 } |
| 289 |
| 290 InfobarManager::ContainerWindowInterface* InfobarManager::CreateContainerWindow( |
| 291 HWND container, InfobarManager* manager) { |
| 292 return new ContainerWindow(container, manager); |
| 293 } |
| 294 |
270 } // namespace infobar_api | 295 } // namespace infobar_api |
OLD | NEW |