| 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_frame/chrome_frame_activex.h" | 5 #include "chrome_frame/chrome_frame_activex.h" |
| 6 | 6 |
| 7 #include <wininet.h> | 7 #include <wininet.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 20 #include "base/string_split.h" | 20 #include "base/string_split.h" |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/scoped_bstr.h" | 24 #include "base/win/scoped_bstr.h" |
| 25 #include "base/win/scoped_variant.h" | 25 #include "base/win/scoped_variant.h" |
| 26 #include "chrome/common/automation_messages.h" | 26 #include "chrome/common/automation_messages.h" |
| 27 #include "chrome/common/chrome_constants.h" | 27 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/test/automation/tab_proxy.h" | 29 #include "chrome/test/automation/tab_proxy.h" |
| 30 #include "chrome_frame/utils.h" |
| 30 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
| 31 #include "chrome_frame/utils.h" | |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Class used to maintain a mapping from top-level windows to ChromeFrameActivex | 35 // Class used to maintain a mapping from top-level windows to ChromeFrameActivex |
| 36 // instances. | 36 // instances. |
| 37 class TopLevelWindowMapping { | 37 class TopLevelWindowMapping { |
| 38 public: | 38 public: |
| 39 typedef std::vector<HWND> WindowList; | 39 typedef std::vector<HWND> WindowList; |
| 40 | 40 |
| 41 static TopLevelWindowMapping* GetInstance() { | 41 static TopLevelWindowMapping* GetInstance() { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return 0; | 191 return 0; |
| 192 } | 192 } |
| 193 | 193 |
| 194 LRESULT ChromeFrameActivex::OnHostMoved(UINT message, WPARAM wparam, | 194 LRESULT ChromeFrameActivex::OnHostMoved(UINT message, WPARAM wparam, |
| 195 LPARAM lparam, BOOL& handled) { | 195 LPARAM lparam, BOOL& handled) { |
| 196 Base::OnHostMoved(); | 196 Base::OnHostMoved(); |
| 197 return 0; | 197 return 0; |
| 198 } | 198 } |
| 199 | 199 |
| 200 HRESULT ChromeFrameActivex::GetContainingDocument(IHTMLDocument2** doc) { | 200 HRESULT ChromeFrameActivex::GetContainingDocument(IHTMLDocument2** doc) { |
| 201 ScopedComPtr<IOleContainer> container; | 201 base::win::ScopedComPtr<IOleContainer> container; |
| 202 HRESULT hr = m_spClientSite->GetContainer(container.Receive()); | 202 HRESULT hr = m_spClientSite->GetContainer(container.Receive()); |
| 203 if (container) | 203 if (container) |
| 204 hr = container.QueryInterface(doc); | 204 hr = container.QueryInterface(doc); |
| 205 return hr; | 205 return hr; |
| 206 } | 206 } |
| 207 | 207 |
| 208 HRESULT ChromeFrameActivex::GetDocumentWindow(IHTMLWindow2** window) { | 208 HRESULT ChromeFrameActivex::GetDocumentWindow(IHTMLWindow2** window) { |
| 209 ScopedComPtr<IHTMLDocument2> document; | 209 base::win::ScopedComPtr<IHTMLDocument2> document; |
| 210 HRESULT hr = GetContainingDocument(document.Receive()); | 210 HRESULT hr = GetContainingDocument(document.Receive()); |
| 211 if (document) | 211 if (document) |
| 212 hr = document->get_parentWindow(window); | 212 hr = document->get_parentWindow(window); |
| 213 return hr; | 213 return hr; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void ChromeFrameActivex::OnLoad(const GURL& gurl) { | 216 void ChromeFrameActivex::OnLoad(const GURL& gurl) { |
| 217 ScopedComPtr<IDispatch> event; | 217 base::win::ScopedComPtr<IDispatch> event; |
| 218 std::string url = gurl.spec(); | 218 std::string url = gurl.spec(); |
| 219 if (SUCCEEDED(CreateDomEvent("event", url, "", event.Receive()))) | 219 if (SUCCEEDED(CreateDomEvent("event", url, "", event.Receive()))) |
| 220 Fire_onload(event); | 220 Fire_onload(event); |
| 221 | 221 |
| 222 FireEvent(onload_, url); | 222 FireEvent(onload_, url); |
| 223 Base::OnLoad(gurl); | 223 Base::OnLoad(gurl); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void ChromeFrameActivex::OnLoadFailed(int error_code, const std::string& url) { | 226 void ChromeFrameActivex::OnLoadFailed(int error_code, const std::string& url) { |
| 227 ScopedComPtr<IDispatch> event; | 227 base::win::ScopedComPtr<IDispatch> event; |
| 228 if (SUCCEEDED(CreateDomEvent("event", url, "", event.Receive()))) | 228 if (SUCCEEDED(CreateDomEvent("event", url, "", event.Receive()))) |
| 229 Fire_onloaderror(event); | 229 Fire_onloaderror(event); |
| 230 | 230 |
| 231 FireEvent(onloaderror_, url); | 231 FireEvent(onloaderror_, url); |
| 232 Base::OnLoadFailed(error_code, url); | 232 Base::OnLoadFailed(error_code, url); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void ChromeFrameActivex::OnMessageFromChromeFrame(const std::string& message, | 235 void ChromeFrameActivex::OnMessageFromChromeFrame(const std::string& message, |
| 236 const std::string& origin, | 236 const std::string& origin, |
| 237 const std::string& target) { | 237 const std::string& target) { |
| 238 DVLOG(1) << __FUNCTION__; | 238 DVLOG(1) << __FUNCTION__; |
| 239 | 239 |
| 240 if (target.compare("*") != 0) { | 240 if (target.compare("*") != 0) { |
| 241 bool drop = true; | 241 bool drop = true; |
| 242 | 242 |
| 243 if (is_privileged()) { | 243 if (is_privileged()) { |
| 244 // Forward messages if the control is in privileged mode. | 244 // Forward messages if the control is in privileged mode. |
| 245 ScopedComPtr<IDispatch> message_event; | 245 base::win::ScopedComPtr<IDispatch> message_event; |
| 246 if (SUCCEEDED(CreateDomEvent("message", message, origin, | 246 if (SUCCEEDED(CreateDomEvent("message", message, origin, |
| 247 message_event.Receive()))) { | 247 message_event.Receive()))) { |
| 248 base::win::ScopedBstr target_bstr(UTF8ToWide(target).c_str()); | 248 base::win::ScopedBstr target_bstr(UTF8ToWide(target).c_str()); |
| 249 Fire_onprivatemessage(message_event, target_bstr); | 249 Fire_onprivatemessage(message_event, target_bstr); |
| 250 | 250 |
| 251 FireEvent(onprivatemessage_, message_event, target_bstr); | 251 FireEvent(onprivatemessage_, message_event, target_bstr); |
| 252 } | 252 } |
| 253 } else { | 253 } else { |
| 254 if (HaveSameOrigin(target, document_url_)) { | 254 if (HaveSameOrigin(target, document_url_)) { |
| 255 drop = false; | 255 drop = false; |
| 256 } else { | 256 } else { |
| 257 DLOG(WARNING) << "Dropping posted message since target doesn't match " | 257 DLOG(WARNING) << "Dropping posted message since target doesn't match " |
| 258 "the current document's origin. target=" << target; | 258 "the current document's origin. target=" << target; |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 if (drop) | 262 if (drop) |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 | 265 |
| 266 ScopedComPtr<IDispatch> message_event; | 266 base::win::ScopedComPtr<IDispatch> message_event; |
| 267 if (SUCCEEDED(CreateDomEvent("message", message, origin, | 267 if (SUCCEEDED(CreateDomEvent("message", message, origin, |
| 268 message_event.Receive()))) { | 268 message_event.Receive()))) { |
| 269 Fire_onmessage(message_event); | 269 Fire_onmessage(message_event); |
| 270 | 270 |
| 271 FireEvent(onmessage_, message_event); | 271 FireEvent(onmessage_, message_event); |
| 272 | 272 |
| 273 base::win::ScopedVariant event_var; | 273 base::win::ScopedVariant event_var; |
| 274 event_var.Set(static_cast<IDispatch*>(message_event)); | 274 event_var.Set(static_cast<IDispatch*>(message_event)); |
| 275 InvokeScriptFunction(onmessage_handler_, event_var.AsInput()); | 275 InvokeScriptFunction(onmessage_handler_, event_var.AsInput()); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool ChromeFrameActivex::ShouldShowVersionMismatchDialog( | 279 bool ChromeFrameActivex::ShouldShowVersionMismatchDialog( |
| 280 bool is_privileged, | 280 bool is_privileged, |
| 281 IOleClientSite* client_site) { | 281 IOleClientSite* client_site) { |
| 282 if (!is_privileged) { | 282 if (!is_privileged) { |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| 285 | 285 |
| 286 if (client_site) { | 286 if (client_site) { |
| 287 ScopedComPtr<IChromeFramePrivileged> service; | 287 base::win::ScopedComPtr<IChromeFramePrivileged> service; |
| 288 HRESULT hr = DoQueryService(SID_ChromeFramePrivileged, | 288 HRESULT hr = DoQueryService(SID_ChromeFramePrivileged, |
| 289 client_site, | 289 client_site, |
| 290 service.Receive()); | 290 service.Receive()); |
| 291 if (SUCCEEDED(hr) && service) { | 291 if (SUCCEEDED(hr) && service) { |
| 292 return (S_FALSE != service->ShouldShowVersionMismatchDialog()); | 292 return (S_FALSE != service->ShouldShowVersionMismatchDialog()); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 NOTREACHED(); | 296 NOTREACHED(); |
| 297 return true; | 297 return true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 (L"onmessage"), | 339 (L"onmessage"), |
| 340 (L"onreadystatechanged"), | 340 (L"onreadystatechanged"), |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 base::win::ScopedComPtr<IHTMLObjectElement> obj_element; | 343 base::win::ScopedComPtr<IHTMLObjectElement> obj_element; |
| 344 GetObjectElement(obj_element.Receive()); | 344 GetObjectElement(obj_element.Receive()); |
| 345 | 345 |
| 346 base::win::ScopedBstr object_id; | 346 base::win::ScopedBstr object_id; |
| 347 GetObjectScriptId(obj_element, object_id.Receive()); | 347 GetObjectScriptId(obj_element, object_id.Receive()); |
| 348 | 348 |
| 349 ScopedComPtr<IHTMLElement2> element; | 349 base::win::ScopedComPtr<IHTMLElement2> element; |
| 350 element.QueryFrom(obj_element); | 350 element.QueryFrom(obj_element); |
| 351 HRESULT hr = S_OK; | 351 HRESULT hr = S_OK; |
| 352 | 352 |
| 353 for (int i = 0; SUCCEEDED(hr) && i < arraysize(event_props); ++i) { | 353 for (int i = 0; SUCCEEDED(hr) && i < arraysize(event_props); ++i) { |
| 354 base::win::ScopedBstr prop(event_props[i]); | 354 base::win::ScopedBstr prop(event_props[i]); |
| 355 base::win::ScopedVariant value; | 355 base::win::ScopedVariant value; |
| 356 if (SUCCEEDED(bag->Read(prop, value.Receive(), error_log))) { | 356 if (SUCCEEDED(bag->Read(prop, value.Receive(), error_log))) { |
| 357 if (value.type() != VT_BSTR || | 357 if (value.type() != VT_BSTR || |
| 358 FAILED(hr = CreateScriptBlockForEvent(element, object_id, | 358 FAILED(hr = CreateScriptBlockForEvent(element, object_id, |
| 359 V_BSTR(&value), prop))) { | 359 V_BSTR(&value), prop))) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 &onreadystatechanged_, | 424 &onreadystatechanged_, |
| 425 &onextensionready_, | 425 &onextensionready_, |
| 426 }; | 426 }; |
| 427 | 427 |
| 428 for (int i = 0; i < arraysize(handlers); ++i) | 428 for (int i = 0; i < arraysize(handlers); ++i) |
| 429 handlers[i]->clear(); | 429 handlers[i]->clear(); |
| 430 | 430 |
| 431 // Drop privileged mode on uninitialization. | 431 // Drop privileged mode on uninitialization. |
| 432 set_is_privileged(false); | 432 set_is_privileged(false); |
| 433 } else { | 433 } else { |
| 434 ScopedComPtr<IHTMLDocument2> document; | 434 base::win::ScopedComPtr<IHTMLDocument2> document; |
| 435 GetContainingDocument(document.Receive()); | 435 GetContainingDocument(document.Receive()); |
| 436 if (document) { | 436 if (document) { |
| 437 base::win::ScopedBstr url; | 437 base::win::ScopedBstr url; |
| 438 if (SUCCEEDED(document->get_URL(url.Receive()))) | 438 if (SUCCEEDED(document->get_URL(url.Receive()))) |
| 439 WideToUTF8(url, url.Length(), &document_url_); | 439 WideToUTF8(url, url.Length(), &document_url_); |
| 440 } | 440 } |
| 441 | 441 |
| 442 // Probe to see whether the host implements the privileged service. | 442 // Probe to see whether the host implements the privileged service. |
| 443 ScopedComPtr<IChromeFramePrivileged> service; | 443 base::win::ScopedComPtr<IChromeFramePrivileged> service; |
| 444 HRESULT service_hr = DoQueryService(SID_ChromeFramePrivileged, | 444 HRESULT service_hr = DoQueryService(SID_ChromeFramePrivileged, |
| 445 m_spClientSite, | 445 m_spClientSite, |
| 446 service.Receive()); | 446 service.Receive()); |
| 447 if (SUCCEEDED(service_hr) && service) { | 447 if (SUCCEEDED(service_hr) && service) { |
| 448 // Does the host want privileged mode? | 448 // Does the host want privileged mode? |
| 449 boolean wants_privileged = false; | 449 boolean wants_privileged = false; |
| 450 service_hr = service->GetWantsPrivileged(&wants_privileged); | 450 service_hr = service->GetWantsPrivileged(&wants_privileged); |
| 451 | 451 |
| 452 if (SUCCEEDED(service_hr) && wants_privileged) | 452 if (SUCCEEDED(service_hr) && wants_privileged) |
| 453 set_is_privileged(true); | 453 set_is_privileged(true); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 return hr; | 495 return hr; |
| 496 } | 496 } |
| 497 | 497 |
| 498 HRESULT ChromeFrameActivex::GetObjectScriptId(IHTMLObjectElement* object_elem, | 498 HRESULT ChromeFrameActivex::GetObjectScriptId(IHTMLObjectElement* object_elem, |
| 499 BSTR* id) { | 499 BSTR* id) { |
| 500 DCHECK(object_elem != NULL); | 500 DCHECK(object_elem != NULL); |
| 501 DCHECK(id != NULL); | 501 DCHECK(id != NULL); |
| 502 | 502 |
| 503 HRESULT hr = E_FAIL; | 503 HRESULT hr = E_FAIL; |
| 504 if (object_elem) { | 504 if (object_elem) { |
| 505 ScopedComPtr<IHTMLElement> elem; | 505 base::win::ScopedComPtr<IHTMLElement> elem; |
| 506 hr = elem.QueryFrom(object_elem); | 506 hr = elem.QueryFrom(object_elem); |
| 507 if (elem) { | 507 if (elem) { |
| 508 hr = elem->get_id(id); | 508 hr = elem->get_id(id); |
| 509 } | 509 } |
| 510 } | 510 } |
| 511 | 511 |
| 512 return hr; | 512 return hr; |
| 513 } | 513 } |
| 514 | 514 |
| 515 HRESULT ChromeFrameActivex::GetObjectElement(IHTMLObjectElement** element) { | 515 HRESULT ChromeFrameActivex::GetObjectElement(IHTMLObjectElement** element) { |
| 516 DCHECK(m_spClientSite); | 516 DCHECK(m_spClientSite); |
| 517 if (!m_spClientSite) | 517 if (!m_spClientSite) |
| 518 return E_UNEXPECTED; | 518 return E_UNEXPECTED; |
| 519 | 519 |
| 520 ScopedComPtr<IOleControlSite> site; | 520 base::win::ScopedComPtr<IOleControlSite> site; |
| 521 HRESULT hr = site.QueryFrom(m_spClientSite); | 521 HRESULT hr = site.QueryFrom(m_spClientSite); |
| 522 if (site) { | 522 if (site) { |
| 523 ScopedComPtr<IDispatch> disp; | 523 base::win::ScopedComPtr<IDispatch> disp; |
| 524 hr = site->GetExtendedControl(disp.Receive()); | 524 hr = site->GetExtendedControl(disp.Receive()); |
| 525 if (disp) { | 525 if (disp) { |
| 526 hr = disp.QueryInterface(element); | 526 hr = disp.QueryInterface(element); |
| 527 } else { | 527 } else { |
| 528 DCHECK(FAILED(hr)); | 528 DCHECK(FAILED(hr)); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 return hr; | 532 return hr; |
| 533 } | 533 } |
| 534 | 534 |
| 535 HRESULT ChromeFrameActivex::CreateScriptBlockForEvent( | 535 HRESULT ChromeFrameActivex::CreateScriptBlockForEvent( |
| 536 IHTMLElement2* insert_after, BSTR instance_id, BSTR script, | 536 IHTMLElement2* insert_after, BSTR instance_id, BSTR script, |
| 537 BSTR event_name) { | 537 BSTR event_name) { |
| 538 DCHECK(insert_after); | 538 DCHECK(insert_after); |
| 539 DCHECK_GT(::SysStringLen(event_name), 0UL); // should always have this | 539 DCHECK_GT(::SysStringLen(event_name), 0UL); // should always have this |
| 540 | 540 |
| 541 // This might be 0 if not specified in the HTML document. | 541 // This might be 0 if not specified in the HTML document. |
| 542 if (!::SysStringLen(instance_id)) { | 542 if (!::SysStringLen(instance_id)) { |
| 543 // TODO(tommi): Should we give ourselves an ID if this happens? | 543 // TODO(tommi): Should we give ourselves an ID if this happens? |
| 544 NOTREACHED() << "Need to handle this"; | 544 NOTREACHED() << "Need to handle this"; |
| 545 return E_INVALIDARG; | 545 return E_INVALIDARG; |
| 546 } | 546 } |
| 547 | 547 |
| 548 ScopedComPtr<IHTMLDocument2> document; | 548 base::win::ScopedComPtr<IHTMLDocument2> document; |
| 549 HRESULT hr = GetContainingDocument(document.Receive()); | 549 HRESULT hr = GetContainingDocument(document.Receive()); |
| 550 if (SUCCEEDED(hr)) { | 550 if (SUCCEEDED(hr)) { |
| 551 ScopedComPtr<IHTMLElement> element, new_element; | 551 base::win::ScopedComPtr<IHTMLElement> element, new_element; |
| 552 document->createElement(base::win::ScopedBstr(L"script"), | 552 document->createElement(base::win::ScopedBstr(L"script"), |
| 553 element.Receive()); | 553 element.Receive()); |
| 554 if (element) { | 554 if (element) { |
| 555 ScopedComPtr<IHTMLScriptElement> script_element; | 555 base::win::ScopedComPtr<IHTMLScriptElement> script_element; |
| 556 if (SUCCEEDED(hr = script_element.QueryFrom(element))) { | 556 if (SUCCEEDED(hr = script_element.QueryFrom(element))) { |
| 557 script_element->put_htmlFor(instance_id); | 557 script_element->put_htmlFor(instance_id); |
| 558 script_element->put_event(event_name); | 558 script_element->put_event(event_name); |
| 559 script_element->put_text(script); | 559 script_element->put_text(script); |
| 560 | 560 |
| 561 hr = insert_after->insertAdjacentElement( | 561 hr = insert_after->insertAdjacentElement( |
| 562 base::win::ScopedBstr(L"afterEnd"), | 562 base::win::ScopedBstr(L"afterEnd"), |
| 563 element, | 563 element, |
| 564 new_element.Receive()); | 564 new_element.Receive()); |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 return hr; | 569 return hr; |
| 570 } | 570 } |
| 571 | 571 |
| 572 void ChromeFrameActivex::FireEvent(const EventHandlers& handlers, | 572 void ChromeFrameActivex::FireEvent(const EventHandlers& handlers, |
| 573 const std::string& arg) { | 573 const std::string& arg) { |
| 574 if (handlers.size()) { | 574 if (handlers.size()) { |
| 575 ScopedComPtr<IDispatch> event; | 575 base::win::ScopedComPtr<IDispatch> event; |
| 576 if (SUCCEEDED(CreateDomEvent("event", arg, "", event.Receive()))) { | 576 if (SUCCEEDED(CreateDomEvent("event", arg, "", event.Receive()))) { |
| 577 FireEvent(handlers, event); | 577 FireEvent(handlers, event); |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 void ChromeFrameActivex::FireEvent(const EventHandlers& handlers, | 582 void ChromeFrameActivex::FireEvent(const EventHandlers& handlers, |
| 583 IDispatch* event) { | 583 IDispatch* event) { |
| 584 DCHECK(event != NULL); | 584 DCHECK(event != NULL); |
| 585 VARIANT arg = { VT_DISPATCH }; | 585 VARIANT arg = { VT_DISPATCH }; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 614 // 0x80020101 == SCRIPT_E_REPORTED. | 614 // 0x80020101 == SCRIPT_E_REPORTED. |
| 615 // When the script we're invoking has an error, we get this error back. | 615 // When the script we're invoking has an error, we get this error back. |
| 616 DLOG_IF(ERROR, FAILED(hr) && hr != 0x80020101) | 616 DLOG_IF(ERROR, FAILED(hr) && hr != 0x80020101) |
| 617 << base::StringPrintf(L"Failed to invoke script: 0x%08X", hr); | 617 << base::StringPrintf(L"Failed to invoke script: 0x%08X", hr); |
| 618 } | 618 } |
| 619 } | 619 } |
| 620 | 620 |
| 621 HRESULT ChromeFrameActivex::InstallTopLevelHook(IOleClientSite* client_site) { | 621 HRESULT ChromeFrameActivex::InstallTopLevelHook(IOleClientSite* client_site) { |
| 622 // Get the parent window of the site, and install our hook on the topmost | 622 // Get the parent window of the site, and install our hook on the topmost |
| 623 // window of the parent. | 623 // window of the parent. |
| 624 ScopedComPtr<IOleWindow> ole_window; | 624 base::win::ScopedComPtr<IOleWindow> ole_window; |
| 625 HRESULT hr = ole_window.QueryFrom(client_site); | 625 HRESULT hr = ole_window.QueryFrom(client_site); |
| 626 if (FAILED(hr)) | 626 if (FAILED(hr)) |
| 627 return hr; | 627 return hr; |
| 628 | 628 |
| 629 HWND parent_wnd; | 629 HWND parent_wnd; |
| 630 hr = ole_window->GetWindow(&parent_wnd); | 630 hr = ole_window->GetWindow(&parent_wnd); |
| 631 if (FAILED(hr)) | 631 if (FAILED(hr)) |
| 632 return hr; | 632 return hr; |
| 633 | 633 |
| 634 HWND top_window = ::GetAncestor(parent_wnd, GA_ROOT); | 634 HWND top_window = ::GetAncestor(parent_wnd, GA_ROOT); |
| 635 chrome_wndproc_hook_ = InstallLocalWindowHook(top_window); | 635 chrome_wndproc_hook_ = InstallLocalWindowHook(top_window); |
| 636 if (chrome_wndproc_hook_) | 636 if (chrome_wndproc_hook_) |
| 637 TopLevelWindowMapping::GetInstance()->AddMapping(top_window, m_hWnd); | 637 TopLevelWindowMapping::GetInstance()->AddMapping(top_window, m_hWnd); |
| 638 | 638 |
| 639 return chrome_wndproc_hook_ ? S_OK : E_FAIL; | 639 return chrome_wndproc_hook_ ? S_OK : E_FAIL; |
| 640 } | 640 } |
| 641 | 641 |
| 642 HRESULT ChromeFrameActivex::registerBhoIfNeeded() { | 642 HRESULT ChromeFrameActivex::registerBhoIfNeeded() { |
| 643 if (!m_spUnkSite) { | 643 if (!m_spUnkSite) { |
| 644 NOTREACHED() << "Invalid client site"; | 644 NOTREACHED() << "Invalid client site"; |
| 645 return E_FAIL; | 645 return E_FAIL; |
| 646 } | 646 } |
| 647 | 647 |
| 648 if (NavigationManager::GetThreadInstance() != NULL) { | 648 if (NavigationManager::GetThreadInstance() != NULL) { |
| 649 DVLOG(1) << "BHO already loaded"; | 649 DVLOG(1) << "BHO already loaded"; |
| 650 return S_OK; | 650 return S_OK; |
| 651 } | 651 } |
| 652 | 652 |
| 653 ScopedComPtr<IWebBrowser2> web_browser2; | 653 base::win::ScopedComPtr<IWebBrowser2> web_browser2; |
| 654 HRESULT hr = DoQueryService(SID_SWebBrowserApp, m_spUnkSite, | 654 HRESULT hr = DoQueryService(SID_SWebBrowserApp, m_spUnkSite, |
| 655 web_browser2.Receive()); | 655 web_browser2.Receive()); |
| 656 if (FAILED(hr) || web_browser2.get() == NULL) { | 656 if (FAILED(hr) || web_browser2.get() == NULL) { |
| 657 DLOG(WARNING) << "Failed to get IWebBrowser2 from client site. Error:" | 657 DLOG(WARNING) << "Failed to get IWebBrowser2 from client site. Error:" |
| 658 << base::StringPrintf(" 0x%08X", hr); | 658 << base::StringPrintf(" 0x%08X", hr); |
| 659 return hr; | 659 return hr; |
| 660 } | 660 } |
| 661 | 661 |
| 662 wchar_t bho_class_id_as_string[MAX_PATH] = {0}; | 662 wchar_t bho_class_id_as_string[MAX_PATH] = {0}; |
| 663 StringFromGUID2(CLSID_ChromeFrameBHO, bho_class_id_as_string, | 663 StringFromGUID2(CLSID_ChromeFrameBHO, bho_class_id_as_string, |
| 664 arraysize(bho_class_id_as_string)); | 664 arraysize(bho_class_id_as_string)); |
| 665 | 665 |
| 666 ScopedComPtr<IObjectWithSite> bho; | 666 base::win::ScopedComPtr<IObjectWithSite> bho; |
| 667 hr = bho.CreateInstance(CLSID_ChromeFrameBHO, NULL, CLSCTX_INPROC_SERVER); | 667 hr = bho.CreateInstance(CLSID_ChromeFrameBHO, NULL, CLSCTX_INPROC_SERVER); |
| 668 if (FAILED(hr)) { | 668 if (FAILED(hr)) { |
| 669 NOTREACHED() << "Failed to register ChromeFrame BHO. Error:" | 669 NOTREACHED() << "Failed to register ChromeFrame BHO. Error:" |
| 670 << base::StringPrintf(" 0x%08X", hr); | 670 << base::StringPrintf(" 0x%08X", hr); |
| 671 return hr; | 671 return hr; |
| 672 } | 672 } |
| 673 | 673 |
| 674 hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, NULL, 0, 0); | 674 hr = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT_REFRESH, NULL, 0, 0); |
| 675 if (FAILED(hr)) { | 675 if (FAILED(hr)) { |
| 676 DLOG(ERROR) << "Failed to refresh user agent string from registry. " | 676 DLOG(ERROR) << "Failed to refresh user agent string from registry. " |
| 677 << "UrlMkSetSessionOption returned " | 677 << "UrlMkSetSessionOption returned " |
| 678 << base::StringPrintf("0x%08x", hr); | 678 << base::StringPrintf("0x%08x", hr); |
| 679 return hr; | 679 return hr; |
| 680 } | 680 } |
| 681 | 681 |
| 682 hr = bho->SetSite(web_browser2); | 682 hr = bho->SetSite(web_browser2); |
| 683 if (FAILED(hr)) { | 683 if (FAILED(hr)) { |
| 684 NOTREACHED() << "ChromeFrame BHO SetSite failed. Error:" | 684 NOTREACHED() << "ChromeFrame BHO SetSite failed. Error:" |
| 685 << base::StringPrintf(" 0x%08X", hr); | 685 << base::StringPrintf(" 0x%08X", hr); |
| 686 return hr; | 686 return hr; |
| 687 } | 687 } |
| 688 | 688 |
| 689 web_browser2->PutProperty(base::win::ScopedBstr(bho_class_id_as_string), | 689 web_browser2->PutProperty(base::win::ScopedBstr(bho_class_id_as_string), |
| 690 base::win::ScopedVariant(bho)); | 690 base::win::ScopedVariant(bho)); |
| 691 return S_OK; | 691 return S_OK; |
| 692 } | 692 } |
| OLD | NEW |