Chromium Code Reviews| 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 // IE toolband implementation. | 5 // IE toolband implementation. |
| 6 #include "ceee/ie/plugin/toolband/tool_band.h" | 6 #include "ceee/ie/plugin/toolband/tool_band.h" |
| 7 | 7 |
| 8 #include <atlsafe.h> | 8 #include <atlsafe.h> |
| 9 #include <atlstr.h> | 9 #include <atlstr.h> |
| 10 #include <shlguid.h> | 10 #include <shlguid.h> |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 DCHECK(NULL != site_window.get()); | 297 DCHECK(NULL != site_window.get()); |
| 298 hr = site_window->GetWindow(&parent_window_.m_hWnd); | 298 hr = site_window->GetWindow(&parent_window_.m_hWnd); |
| 299 if (FAILED(hr)) { | 299 if (FAILED(hr)) { |
| 300 LOG(ERROR) << "Failed to get parent window handle: " << com::LogHr(hr); | 300 LOG(ERROR) << "Failed to get parent window handle: " << com::LogHr(hr); |
| 301 return hr; | 301 return hr; |
| 302 } | 302 } |
| 303 DCHECK(parent_window_); | 303 DCHECK(parent_window_); |
| 304 if (!parent_window_) | 304 if (!parent_window_) |
| 305 return E_FAIL; | 305 return E_FAIL; |
| 306 | 306 |
| 307 if (NULL == Create(parent_window_)) | 307 // WS_CHILD | WS_VISIBLE | TBSTYLE_TRANSPARENT | CCS_NODIVIDER are critical |
| 308 // for painting toolband background while chrome frame is hidden. | |
|
Sigurður Ásgeirsson
2011/01/13 14:42:55
nice, thanks. Do you prefer this to specifying a s
Vitaly Buka (NO REVIEWS)
2011/01/14 00:06:30
Done.
| |
| 309 // Rest was copied from IE favorite bar. | |
| 310 DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | |
| 311 style += TBSTYLE_TOOLTIPS | TBSTYLE_TRANSPARENT | TBSTYLE_LIST | TBSTYLE_FLAT; | |
| 312 style += CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_TOP; | |
| 313 | |
| 314 if (NULL == Create(parent_window_, NULL, NULL, style)) | |
| 308 return E_FAIL; | 315 return E_FAIL; |
| 309 | 316 |
| 310 BOOL shown = ShowWindow(SW_SHOW); | 317 BOOL shown = ShowWindow(SW_SHOW); |
| 311 DCHECK(shown); | 318 DCHECK(shown); |
| 312 | 319 |
| 313 return hr; | 320 return hr; |
| 314 } | 321 } |
| 315 | 322 |
| 316 HRESULT ToolBand::Teardown() { | 323 HRESULT ToolBand::Teardown() { |
| 317 TRACE_EVENT_INSTANT("ceee.toolband.teardown", this, ""); | 324 TRACE_EVENT_INSTANT("ceee.toolband.teardown", this, ""); |
| 318 | 325 |
| 319 if (IsWindow()) { | 326 if (IsWindow()) { |
| 320 // Teardown the ActiveX host window. | 327 // Teardown the ActiveX host window. |
| 321 CAxWindow host(m_hWnd); | 328 CAxWindow host(m_hWnd); |
| 322 base::win::ScopedComPtr<IObjectWithSite> host_with_site; | 329 base::win::ScopedComPtr<IObjectWithSite> host_with_site; |
| 323 HRESULT hr = host.QueryHost(host_with_site.Receive()); | 330 HRESULT hr = host.QueryHost(host_with_site.Receive()); |
| 324 if (SUCCEEDED(hr)) | 331 if (SUCCEEDED(hr)) |
| 325 host_with_site->SetSite(NULL); | 332 host_with_site->SetSite(NULL); |
| 326 | 333 |
| 327 DestroyWindow(); | 334 DestroyWindow(); |
| 328 } | 335 } |
| 329 | 336 |
| 330 if (chrome_frame_) { | 337 if (chrome_frame_) { |
| 331 ChromeFrameEvents::DispEventUnadvise(chrome_frame_); | 338 ChromeFrameEvents::DispEventUnadvise(chrome_frame_); |
| 332 } | 339 } |
| 333 chrome_frame_window_ = NULL; | |
| 334 | 340 |
| 335 if (web_browser_ && listening_to_browser_events_) { | 341 if (web_browser_ && listening_to_browser_events_) { |
| 336 HostingBrowserEvents::DispEventUnadvise(web_browser_, | 342 HostingBrowserEvents::DispEventUnadvise(web_browser_, |
| 337 &DIID_DWebBrowserEvents2); | 343 &DIID_DWebBrowserEvents2); |
| 338 } | 344 } |
| 339 listening_to_browser_events_ = false; | 345 listening_to_browser_events_ = false; |
| 340 | 346 |
| 341 return S_OK; | 347 return S_OK; |
| 342 } | 348 } |
| 343 | 349 |
| 344 void ToolBand::OnFinalMessage(HWND window) { | 350 void ToolBand::OnFinalMessage(HWND window) { |
| 345 GetUnknown()->Release(); | 351 GetUnknown()->Release(); |
| 346 } | 352 } |
| 347 | 353 |
| 348 LRESULT ToolBand::OnCreate(LPCREATESTRUCT lpCreateStruct) { | 354 LRESULT ToolBand::OnCreate(LPCREATESTRUCT lpCreateStruct) { |
| 349 // Grab a self-reference. | 355 // Grab a self-reference. |
| 350 GetUnknown()->AddRef(); | 356 GetUnknown()->AddRef(); |
| 351 | 357 |
| 358 chrome_frame_container_window_.Create(m_hWnd, NULL, NULL, WS_CHILD); | |
|
Sigurður Ásgeirsson
2011/01/13 14:42:55
Please retrieve the result and error check it.
Vitaly Buka (NO REVIEWS)
2011/01/14 00:06:30
Done.
| |
| 359 | |
| 352 // Create a host window instance. | 360 // Create a host window instance. |
| 353 base::win::ScopedComPtr<IAxWinHostWindow> host; | 361 base::win::ScopedComPtr<IAxWinHostWindow> host; |
| 354 HRESULT hr = CAxHostWindow::CreateInstance(host.Receive()); | 362 HRESULT hr = CAxHostWindow::CreateInstance(host.Receive()); |
| 355 if (FAILED(hr)) { | 363 if (FAILED(hr)) { |
| 356 LOG(ERROR) << "Failed to create ActiveX host window. " << com::LogHr(hr); | 364 LOG(ERROR) << "Failed to create ActiveX host window. " << com::LogHr(hr); |
| 357 return 1; | 365 return 1; |
| 358 } | 366 } |
| 359 | 367 |
| 360 // We're the site for the host window, this needs to be in place | 368 // We're the site for the host window, this needs to be in place |
| 361 // before we attach ChromeFrame to the ActiveX control window, so | 369 // before we attach ChromeFrame to the ActiveX control window, so |
| 362 // as to allow it to probe our service provider. | 370 // as to allow it to probe our service provider. |
| 363 hr = SetChildSite(host); | 371 hr = SetChildSite(host); |
| 364 DCHECK(SUCCEEDED(hr)); | 372 DCHECK(SUCCEEDED(hr)); |
| 365 | 373 |
| 366 // Create the chrome frame instance. | 374 // Create the chrome frame instance. |
| 367 hr = chrome_frame_.CoCreateInstance(L"ChromeTab.ChromeFrame"); | 375 hr = chrome_frame_.CoCreateInstance(L"ChromeTab.ChromeFrame"); |
| 368 if (FAILED(hr)) { | 376 if (FAILED(hr)) { |
| 369 LOG(ERROR) << "Failed to create the Chrome Frame instance. " << | 377 LOG(ERROR) << "Failed to create the Chrome Frame instance. " << |
| 370 com::LogHr(hr); | 378 com::LogHr(hr); |
| 371 return 1; | 379 return 1; |
| 372 } | 380 } |
| 373 | 381 |
| 374 // And attach it to our window. | 382 // And attach it to our window. |
| 375 hr = host->AttachControl(chrome_frame_, m_hWnd); | 383 hr = host->AttachControl(chrome_frame_, |
| 384 chrome_frame_container_window_.m_hWnd); | |
| 376 if (FAILED(hr)) { | 385 if (FAILED(hr)) { |
| 377 LOG(ERROR) << "Failed to attach Chrome Frame to the host. " << | 386 LOG(ERROR) << "Failed to attach Chrome Frame to the host. " << |
| 378 com::LogHr(hr); | 387 com::LogHr(hr); |
| 379 return 1; | 388 return 1; |
| 380 } | 389 } |
| 381 | 390 |
| 382 // Get the GCF window and hide it for now. | |
| 383 CComQIPtr<IOleWindow> ole_window(chrome_frame_); | |
| 384 DCHECK(ole_window != NULL); | |
| 385 if (SUCCEEDED(ole_window->GetWindow(&chrome_frame_window_.m_hWnd))) { | |
| 386 // We hide the chrome frame window until onload in order to avoid | |
| 387 // seeing the "Aw Snap" that sometimes otherwise occurs during Chrome | |
| 388 // initialization. | |
| 389 chrome_frame_window_.ShowWindow(SW_HIDE); | |
| 390 } | |
| 391 | |
| 392 // Hook up the chrome frame event listener. | 391 // Hook up the chrome frame event listener. |
| 393 hr = ChromeFrameEvents::DispEventAdvise(chrome_frame_); | 392 hr = ChromeFrameEvents::DispEventAdvise(chrome_frame_); |
| 394 if (FAILED(hr)) { | 393 if (FAILED(hr)) { |
| 395 LOG(ERROR) << "Failed to hook up event sink. " << com::LogHr(hr); | 394 LOG(ERROR) << "Failed to hook up event sink. " << com::LogHr(hr); |
| 396 } | 395 } |
| 397 | 396 |
| 398 return 0; | 397 return 0; |
| 399 } | 398 } |
| 400 | 399 |
| 401 void ToolBand::OnPaint(CDCHandle dc) { | |
| 402 RECT rc = {}; | |
| 403 if (GetUpdateRect(&rc, FALSE)) { | |
| 404 PAINTSTRUCT ps = {}; | |
| 405 BeginPaint(&ps); | |
| 406 | |
| 407 BOOL ret = GetClientRect(&rc); | |
| 408 DCHECK(ret); | |
| 409 CString text; | |
| 410 text.Format(L"Google CEEE. No Chrome Frame found. Instance: 0x%p. ID: %d!)", | |
| 411 this, band_id_); | |
| 412 ::DrawText(ps.hdc, text, -1, &rc, DT_SINGLELINE | DT_BOTTOM | DT_CENTER); | |
| 413 | |
| 414 EndPaint(&ps); | |
| 415 } | |
| 416 } | |
| 417 | |
| 418 void ToolBand::OnSize(UINT type, CSize size) { | 400 void ToolBand::OnSize(UINT type, CSize size) { |
| 419 LOG(INFO) << "ToolBand::OnSize(" << type << ", " | 401 LOG(INFO) << "ToolBand::OnSize(" << type << ", " |
| 420 << size.cx << "x" << size.cy << ")"; | 402 << size.cx << "x" << size.cy << ")"; |
| 421 CWindow chrome_window = ::GetWindow(m_hWnd, GW_CHILD); | 403 CWindow chrome_window = ::GetWindow(m_hWnd, GW_CHILD); |
| 422 if (!chrome_window) { | 404 if (!chrome_window) { |
| 423 LOG(ERROR) << "Failed to retrieve Chrome Frame window"; | 405 LOG(ERROR) << "Failed to retrieve Chrome Frame window"; |
| 424 return; | 406 return; |
| 425 } | 407 } |
| 426 | 408 |
| 427 BOOL resized = chrome_window.ResizeClient(size.cx, size.cy); | 409 BOOL resized = chrome_window.ResizeClient(size.cx, size.cy); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 } | 559 } |
| 578 } else { | 560 } else { |
| 579 LOG(ERROR) << "Failed to obtain OleCommandTarget. Error Code: " | 561 LOG(ERROR) << "Failed to obtain OleCommandTarget. Error Code: " |
| 580 << com::LogHr(hr); | 562 << com::LogHr(hr); |
| 581 } | 563 } |
| 582 } | 564 } |
| 583 directories.Detach(); | 565 directories.Detach(); |
| 584 } | 566 } |
| 585 | 567 |
| 586 STDMETHODIMP_(void) ToolBand::OnCfOnload(IDispatch* event) { | 568 STDMETHODIMP_(void) ToolBand::OnCfOnload(IDispatch* event) { |
| 587 if (chrome_frame_window_.IsWindow()) { | 569 if (chrome_frame_container_window_.IsWindow()) { |
| 588 VLOG(1) << "Showing the Chrome Frame window."; | 570 VLOG(1) << "Showing the Chrome Frame window."; |
| 589 chrome_frame_window_.ShowWindow(SW_SHOW); | 571 chrome_frame_container_window_.ShowWindow(SW_SHOW); |
| 590 } | 572 } |
| 591 } | 573 } |
| 592 | 574 |
| 593 STDMETHODIMP_(void) ToolBand::OnCfOnloadError(IDispatch* event) { | 575 STDMETHODIMP_(void) ToolBand::OnCfOnloadError(IDispatch* event) { |
| 594 // Handle error the same way as OnLoad. | 576 // Handle error the same way as OnLoad. |
| 595 LOG(ERROR) << "Chrome Frame reports onload error"; | 577 LOG(ERROR) << "Chrome Frame reports onload error"; |
| 596 OnCfOnload(event); | 578 OnCfOnload(event); |
| 597 } | 579 } |
| 598 | 580 |
| 599 STDMETHODIMP_(void) ToolBand::OnIeNavigateComplete2(IDispatch* dispatch, | 581 STDMETHODIMP_(void) ToolBand::OnIeNavigateComplete2(IDispatch* dispatch, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 hr = GetSessionId(&session_id); | 741 hr = GetSessionId(&session_id); |
| 760 if (SUCCEEDED(hr)) { | 742 if (SUCCEEDED(hr)) { |
| 761 hr = ceee_bho->SetToolBandSessionId(session_id); | 743 hr = ceee_bho->SetToolBandSessionId(session_id); |
| 762 if (SUCCEEDED(hr)) | 744 if (SUCCEEDED(hr)) |
| 763 already_sent_id_to_bho_ = true; | 745 already_sent_id_to_bho_ = true; |
| 764 return hr; | 746 return hr; |
| 765 } | 747 } |
| 766 } | 748 } |
| 767 return E_FAIL; | 749 return E_FAIL; |
| 768 } | 750 } |
| OLD | NEW |