| 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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 HRESULT hr = host.QueryHost(host_with_site.Receive()); | 323 HRESULT hr = host.QueryHost(host_with_site.Receive()); |
| 324 if (SUCCEEDED(hr)) | 324 if (SUCCEEDED(hr)) |
| 325 host_with_site->SetSite(NULL); | 325 host_with_site->SetSite(NULL); |
| 326 | 326 |
| 327 DestroyWindow(); | 327 DestroyWindow(); |
| 328 } | 328 } |
| 329 | 329 |
| 330 if (chrome_frame_) { | 330 if (chrome_frame_) { |
| 331 ChromeFrameEvents::DispEventUnadvise(chrome_frame_); | 331 ChromeFrameEvents::DispEventUnadvise(chrome_frame_); |
| 332 } | 332 } |
| 333 chrome_frame_window_ = NULL; | |
| 334 | 333 |
| 335 if (web_browser_ && listening_to_browser_events_) { | 334 if (web_browser_ && listening_to_browser_events_) { |
| 336 HostingBrowserEvents::DispEventUnadvise(web_browser_, | 335 HostingBrowserEvents::DispEventUnadvise(web_browser_, |
| 337 &DIID_DWebBrowserEvents2); | 336 &DIID_DWebBrowserEvents2); |
| 338 } | 337 } |
| 339 listening_to_browser_events_ = false; | 338 listening_to_browser_events_ = false; |
| 340 | 339 |
| 341 return S_OK; | 340 return S_OK; |
| 342 } | 341 } |
| 343 | 342 |
| 344 void ToolBand::OnFinalMessage(HWND window) { | 343 void ToolBand::OnFinalMessage(HWND window) { |
| 345 GetUnknown()->Release(); | 344 GetUnknown()->Release(); |
| 346 } | 345 } |
| 347 | 346 |
| 348 LRESULT ToolBand::OnCreate(LPCREATESTRUCT lpCreateStruct) { | 347 LRESULT ToolBand::OnCreate(LPCREATESTRUCT lpCreateStruct) { |
| 349 // Grab a self-reference. | 348 // Grab a self-reference. |
| 350 GetUnknown()->AddRef(); | 349 GetUnknown()->AddRef(); |
| 351 | 350 |
| 351 if (NULL == chrome_frame_container_window_.Create(m_hWnd)) { |
| 352 LOG(ERROR) << "Failed to create window. " << com::LogWe(); |
| 353 return -1; |
| 354 } |
| 355 |
| 352 // Create a host window instance. | 356 // Create a host window instance. |
| 353 base::win::ScopedComPtr<IAxWinHostWindow> host; | 357 base::win::ScopedComPtr<IAxWinHostWindow> host; |
| 354 HRESULT hr = CAxHostWindow::CreateInstance(host.Receive()); | 358 HRESULT hr = CAxHostWindow::CreateInstance(host.Receive()); |
| 355 if (FAILED(hr)) { | 359 if (FAILED(hr)) { |
| 356 LOG(ERROR) << "Failed to create ActiveX host window. " << com::LogHr(hr); | 360 LOG(ERROR) << "Failed to create ActiveX host window. " << com::LogHr(hr); |
| 357 return 1; | 361 return 1; |
| 358 } | 362 } |
| 359 | 363 |
| 360 // We're the site for the host window, this needs to be in place | 364 // 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 | 365 // before we attach ChromeFrame to the ActiveX control window, so |
| 362 // as to allow it to probe our service provider. | 366 // as to allow it to probe our service provider. |
| 363 hr = SetChildSite(host); | 367 hr = SetChildSite(host); |
| 364 DCHECK(SUCCEEDED(hr)); | 368 DCHECK(SUCCEEDED(hr)); |
| 365 | 369 |
| 366 // Create the chrome frame instance. | 370 // Create the chrome frame instance. |
| 367 hr = chrome_frame_.CoCreateInstance(L"ChromeTab.ChromeFrame"); | 371 hr = chrome_frame_.CoCreateInstance(L"ChromeTab.ChromeFrame"); |
| 368 if (FAILED(hr)) { | 372 if (FAILED(hr)) { |
| 369 LOG(ERROR) << "Failed to create the Chrome Frame instance. " << | 373 LOG(ERROR) << "Failed to create the Chrome Frame instance. " << |
| 370 com::LogHr(hr); | 374 com::LogHr(hr); |
| 371 return 1; | 375 return 1; |
| 372 } | 376 } |
| 373 | 377 |
| 374 // And attach it to our window. | 378 // And attach it to our window. |
| 375 hr = host->AttachControl(chrome_frame_, m_hWnd); | 379 hr = host->AttachControl(chrome_frame_, |
| 380 chrome_frame_container_window_.m_hWnd); |
| 376 if (FAILED(hr)) { | 381 if (FAILED(hr)) { |
| 377 LOG(ERROR) << "Failed to attach Chrome Frame to the host. " << | 382 LOG(ERROR) << "Failed to attach Chrome Frame to the host. " << |
| 378 com::LogHr(hr); | 383 com::LogHr(hr); |
| 379 return 1; | 384 return 1; |
| 380 } | 385 } |
| 381 | 386 |
| 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. | 387 // Hook up the chrome frame event listener. |
| 393 hr = ChromeFrameEvents::DispEventAdvise(chrome_frame_); | 388 hr = ChromeFrameEvents::DispEventAdvise(chrome_frame_); |
| 394 if (FAILED(hr)) { | 389 if (FAILED(hr)) { |
| 395 LOG(ERROR) << "Failed to hook up event sink. " << com::LogHr(hr); | 390 LOG(ERROR) << "Failed to hook up event sink. " << com::LogHr(hr); |
| 396 } | 391 } |
| 397 | 392 |
| 398 return 0; | 393 return 0; |
| 399 } | 394 } |
| 400 | 395 |
| 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) { | 396 void ToolBand::OnSize(UINT type, CSize size) { |
| 419 LOG(INFO) << "ToolBand::OnSize(" << type << ", " | 397 LOG(INFO) << "ToolBand::OnSize(" << type << ", " |
| 420 << size.cx << "x" << size.cy << ")"; | 398 << size.cx << "x" << size.cy << ")"; |
| 421 CWindow chrome_window = ::GetWindow(m_hWnd, GW_CHILD); | 399 CWindow chrome_window = ::GetWindow(m_hWnd, GW_CHILD); |
| 422 if (!chrome_window) { | 400 if (!chrome_window) { |
| 423 LOG(ERROR) << "Failed to retrieve Chrome Frame window"; | 401 LOG(ERROR) << "Failed to retrieve Chrome Frame window"; |
| 424 return; | 402 return; |
| 425 } | 403 } |
| 426 | 404 |
| 427 BOOL resized = chrome_window.ResizeClient(size.cx, size.cy); | 405 BOOL resized = chrome_window.ResizeClient(size.cx, size.cy); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 555 } |
| 578 } else { | 556 } else { |
| 579 LOG(ERROR) << "Failed to obtain OleCommandTarget. Error Code: " | 557 LOG(ERROR) << "Failed to obtain OleCommandTarget. Error Code: " |
| 580 << com::LogHr(hr); | 558 << com::LogHr(hr); |
| 581 } | 559 } |
| 582 } | 560 } |
| 583 directories.Detach(); | 561 directories.Detach(); |
| 584 } | 562 } |
| 585 | 563 |
| 586 STDMETHODIMP_(void) ToolBand::OnCfOnload(IDispatch* event) { | 564 STDMETHODIMP_(void) ToolBand::OnCfOnload(IDispatch* event) { |
| 587 if (chrome_frame_window_.IsWindow()) { | 565 if (chrome_frame_container_window_.IsWindow()) { |
| 588 VLOG(1) << "Showing the Chrome Frame window."; | 566 VLOG(1) << "Showing the Chrome Frame window."; |
| 589 chrome_frame_window_.ShowWindow(SW_SHOW); | 567 chrome_frame_container_window_.ShowWindow(SW_SHOW); |
| 590 } | 568 } |
| 591 } | 569 } |
| 592 | 570 |
| 593 STDMETHODIMP_(void) ToolBand::OnCfOnloadError(IDispatch* event) { | 571 STDMETHODIMP_(void) ToolBand::OnCfOnloadError(IDispatch* event) { |
| 594 // Handle error the same way as OnLoad. | 572 // Handle error the same way as OnLoad. |
| 595 LOG(ERROR) << "Chrome Frame reports onload error"; | 573 LOG(ERROR) << "Chrome Frame reports onload error"; |
| 596 OnCfOnload(event); | 574 OnCfOnload(event); |
| 597 } | 575 } |
| 598 | 576 |
| 599 STDMETHODIMP_(void) ToolBand::OnIeNavigateComplete2(IDispatch* dispatch, | 577 STDMETHODIMP_(void) ToolBand::OnIeNavigateComplete2(IDispatch* dispatch, |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 hr = GetSessionId(&session_id); | 737 hr = GetSessionId(&session_id); |
| 760 if (SUCCEEDED(hr)) { | 738 if (SUCCEEDED(hr)) { |
| 761 hr = ceee_bho->SetToolBandSessionId(session_id); | 739 hr = ceee_bho->SetToolBandSessionId(session_id); |
| 762 if (SUCCEEDED(hr)) | 740 if (SUCCEEDED(hr)) |
| 763 already_sent_id_to_bho_ = true; | 741 already_sent_id_to_bho_ = true; |
| 764 return hr; | 742 return hr; |
| 765 } | 743 } |
| 766 } | 744 } |
| 767 return E_FAIL; | 745 return E_FAIL; |
| 768 } | 746 } |
| OLD | NEW |