| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <htiframe.h> | 5 #include <htiframe.h> |
| 6 | 6 |
| 7 #include "chrome_frame/protocol_sink_wrap.h" | 7 #include "chrome_frame/protocol_sink_wrap.h" |
| 8 | 8 |
| 9 #include "base/scoped_bstr_win.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/registry.h" | 10 #include "base/registry.h" |
| 12 #include "base/scoped_bstr_win.h" | 11 #include "base/scoped_bstr_win.h" |
| 13 #include "base/singleton.h" | 12 #include "base/singleton.h" |
| 14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 15 | 14 |
| 16 #include "chrome_frame/utils.h" | 15 #include "chrome_frame/utils.h" |
| 17 | 16 |
| 18 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE == 54. Introduced in IE 8, so | 17 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE == 54. Introduced in IE 8, so |
| 19 // not in everyone's headers yet. See: | 18 // not in everyone's headers yet. See: |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (url) | 225 if (url) |
| 227 url_ = url; | 226 url_ = url; |
| 228 | 227 |
| 229 CComCritSecLock<CComAutoCriticalSection> lock(sink_map_lock_); | 228 CComCritSecLock<CComAutoCriticalSection> lock(sink_map_lock_); |
| 230 DCHECK(sink_map_.end() == sink_map_.find(protocol)); | 229 DCHECK(sink_map_.end() == sink_map_.find(protocol)); |
| 231 sink_map_[protocol] = this; | 230 sink_map_[protocol] = this; |
| 232 DLOG(INFO) << "ProtocolSinkWrap: active sinks: " << sink_map_.size(); | 231 DLOG(INFO) << "ProtocolSinkWrap: active sinks: " << sink_map_.size(); |
| 233 return true; | 232 return true; |
| 234 } | 233 } |
| 235 | 234 |
| 236 HRESULT WINAPI ProtocolSinkWrap::CheckOutgoingInterface(void* obj, | |
| 237 REFIID iid, LPVOID* ret, DWORD cookie) { | |
| 238 ProtocolSinkWrap* instance = reinterpret_cast<ProtocolSinkWrap*>(obj); | |
| 239 HRESULT hr = E_NOINTERFACE; | |
| 240 if (instance && instance->delegate_) | |
| 241 hr = instance->delegate_->QueryInterface(iid, ret); | |
| 242 | |
| 243 #ifndef NDEBUG | |
| 244 if (SUCCEEDED(hr)) { | |
| 245 wchar_t iid_string[64] = {0}; | |
| 246 StringFromGUID2(iid, iid_string, arraysize(iid_string)); | |
| 247 DLOG(INFO) << "Giving out wrapped interface: " << iid_string; | |
| 248 } | |
| 249 #endif | |
| 250 | |
| 251 return hr; | |
| 252 } | |
| 253 | |
| 254 HRESULT WINAPI ProtocolSinkWrap::IfDelegateSupports(void* obj, | |
| 255 REFIID iid, LPVOID* ret, DWORD cookie) { | |
| 256 HRESULT hr = E_NOINTERFACE; | |
| 257 ProtocolSinkWrap* instance = reinterpret_cast<ProtocolSinkWrap*>(obj); | |
| 258 if (instance && instance->delegate_) { | |
| 259 ScopedComPtr<IUnknown> original; | |
| 260 hr = instance->delegate_->QueryInterface(iid, | |
| 261 reinterpret_cast<void**>(original.Receive())); | |
| 262 if (original) { | |
| 263 IUnknown* supported_interface = reinterpret_cast<IUnknown*>( | |
| 264 reinterpret_cast<DWORD_PTR>(obj) + cookie); | |
| 265 supported_interface->AddRef(); | |
| 266 *ret = supported_interface; | |
| 267 hr = S_OK; | |
| 268 } | |
| 269 } | |
| 270 | |
| 271 return hr; | |
| 272 } | |
| 273 | |
| 274 // IInternetProtocolSink methods | 235 // IInternetProtocolSink methods |
| 275 STDMETHODIMP ProtocolSinkWrap::Switch(PROTOCOLDATA* protocol_data) { | 236 STDMETHODIMP ProtocolSinkWrap::Switch(PROTOCOLDATA* protocol_data) { |
| 276 HRESULT hr = E_FAIL; | 237 HRESULT hr = E_FAIL; |
| 277 if (delegate_) | 238 if (delegate_) |
| 278 hr = delegate_->Switch(protocol_data); | 239 hr = delegate_->Switch(protocol_data); |
| 279 return hr; | 240 return hr; |
| 280 } | 241 } |
| 281 | 242 |
| 282 STDMETHODIMP ProtocolSinkWrap::ReportProgress(ULONG status_code, | 243 STDMETHODIMP ProtocolSinkWrap::ReportProgress(ULONG status_code, |
| 283 LPCWSTR status_text) { | 244 LPCWSTR status_text) { |
| 284 DLOG(INFO) << "ProtocolSinkWrap::ReportProgress: Code:" << status_code << | 245 DLOG(INFO) << "ProtocolSinkWrap::ReportProgress: Code:" << status_code << |
| 285 " Text: " << (status_text ? status_text : L""); | 246 " Text: " << (status_text ? status_text : L""); |
| 286 if ((BINDSTATUS_MIMETYPEAVAILABLE == status_code) || | 247 if ((BINDSTATUS_MIMETYPEAVAILABLE == status_code) || |
| 287 (BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE == status_code)) { | 248 (BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE == status_code)) { |
| 288 // If we have a MIMETYPE and that MIMETYPE is not "text/html". we don't | 249 // If we have a MIMETYPE and that MIMETYPE is not "text/html". we don't |
| 289 // want to do anything with this. | 250 // want to do anything with this. |
| 290 if (status_text) { | 251 if (status_text) { |
| 291 size_t status_text_length = lstrlenW(status_text); | 252 size_t status_text_length = lstrlenW(status_text); |
| 292 const wchar_t* status_text_end = status_text + std::min( | 253 const wchar_t* status_text_end = status_text + std::min( |
| 293 status_text_length, arraysize(kTextHtmlMimeType) - 1); | 254 status_text_length, arraysize(kTextHtmlMimeType) - 1); |
| 294 if (!LowerCaseEqualsASCII(status_text, status_text_end, | 255 if (!LowerCaseEqualsASCII(status_text, status_text_end, |
| 295 kTextHtmlMimeType)) { | 256 kTextHtmlMimeType)) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 366 } |
| 406 | 367 |
| 407 HRESULT hr = E_FAIL; | 368 HRESULT hr = E_FAIL; |
| 408 if (delegate_) | 369 if (delegate_) |
| 409 hr = delegate_->ReportResult(result, error, result_text); | 370 hr = delegate_->ReportResult(result, error, result_text); |
| 410 | 371 |
| 411 return hr; | 372 return hr; |
| 412 } | 373 } |
| 413 | 374 |
| 414 // IInternetBindInfoEx | 375 // IInternetBindInfoEx |
| 415 STDMETHODIMP ProtocolSinkWrap::GetBindInfo( | 376 STDMETHODIMP ProtocolSinkWrap::GetBindInfo(DWORD* flags, |
| 416 DWORD* flags, BINDINFO* bind_info_ret) { | 377 BINDINFO* bind_info_ret) { |
| 417 ScopedComPtr<IInternetBindInfo> bind_info; | 378 ScopedComPtr<IInternetBindInfo> bind_info; |
| 418 HRESULT hr = bind_info.QueryFrom(delegate_); | 379 HRESULT hr = bind_info.QueryFrom(delegate_); |
| 419 if (bind_info) | 380 if (bind_info) |
| 420 hr = bind_info->GetBindInfo(flags, bind_info_ret); | 381 hr = bind_info->GetBindInfo(flags, bind_info_ret); |
| 421 return hr; | 382 return hr; |
| 422 } | 383 } |
| 423 | 384 |
| 424 STDMETHODIMP ProtocolSinkWrap::GetBindString(ULONG string_type, | 385 STDMETHODIMP ProtocolSinkWrap::GetBindString(ULONG string_type, |
| 425 LPOLESTR* string_array, ULONG array_size, ULONG* size_returned) { | 386 LPOLESTR* string_array, ULONG array_size, ULONG* size_returned) { |
| 426 ScopedComPtr<IInternetBindInfo> bind_info; | 387 ScopedComPtr<IInternetBindInfo> bind_info; |
| 427 HRESULT hr = bind_info.QueryFrom(delegate_); | 388 HRESULT hr = bind_info.QueryFrom(delegate_); |
| 428 if (bind_info) | 389 if (bind_info) |
| 429 hr = bind_info->GetBindString(string_type, string_array, | 390 hr = bind_info->GetBindString(string_type, string_array, |
| 430 array_size, size_returned); | 391 array_size, size_returned); |
| 431 return hr; | 392 return hr; |
| 432 } | 393 } |
| 433 | 394 |
| 434 STDMETHODIMP ProtocolSinkWrap::GetBindInfoEx(DWORD *flags, BINDINFO* bind_info, | 395 STDMETHODIMP ProtocolSinkWrap::GetBindInfoEx(DWORD* flags, BINDINFO* bind_info, |
| 435 DWORD* bindf2, DWORD *reserved) { | 396 DWORD* bindf2, DWORD* reserved) { |
| 436 ScopedComPtr<IInternetBindInfoEx> bind_info_ex; | 397 ScopedComPtr<IInternetBindInfoEx> bind_info_ex; |
| 437 HRESULT hr = bind_info_ex.QueryFrom(delegate_); | 398 HRESULT hr = bind_info_ex.QueryFrom(delegate_); |
| 438 if (bind_info_ex) | 399 if (bind_info_ex) |
| 439 hr = bind_info_ex->GetBindInfoEx(flags, bind_info, bindf2, reserved); | 400 hr = bind_info_ex->GetBindInfoEx(flags, bind_info, bindf2, reserved); |
| 440 return hr; | 401 return hr; |
| 441 } | 402 } |
| 442 | 403 |
| 443 // IServiceProvider | 404 // IServiceProvider |
| 444 STDMETHODIMP ProtocolSinkWrap::QueryService(REFGUID service_guid, | 405 STDMETHODIMP ProtocolSinkWrap::QueryService(REFGUID service_guid, |
| 445 REFIID riid, void** service) { | 406 REFIID riid, void** service) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 HRESULT hr = DoQueryService(GUID_NULL, sink, http_negotiate.Receive()); | 618 HRESULT hr = DoQueryService(GUID_NULL, sink, http_negotiate.Receive()); |
| 658 if (http_negotiate) | 619 if (http_negotiate) |
| 659 hr = DoQueryService(IID_ITargetFrame2, http_negotiate, web_browser); | 620 hr = DoQueryService(IID_ITargetFrame2, http_negotiate, web_browser); |
| 660 | 621 |
| 661 return hr; | 622 return hr; |
| 662 } | 623 } |
| 663 | 624 |
| 664 ScopedComPtr<IInternetProtocolSink> ProtocolSinkWrap::MaybeWrapSink( | 625 ScopedComPtr<IInternetProtocolSink> ProtocolSinkWrap::MaybeWrapSink( |
| 665 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, | 626 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, |
| 666 const wchar_t* url) { | 627 const wchar_t* url) { |
| 667 ScopedComPtr<IInternetProtocolSink> sink_to_use; | 628 ScopedComPtr<IInternetProtocolSink> sink_to_use(prot_sink); |
| 668 sink_to_use.QueryFrom(prot_sink); | |
| 669 ScopedComPtr<IWebBrowser2> web_browser; | 629 ScopedComPtr<IWebBrowser2> web_browser; |
| 670 WebBrowserFromProtocolSink(prot_sink, web_browser.Receive()); | 630 WebBrowserFromProtocolSink(prot_sink, web_browser.Receive()); |
| 671 if (web_browser) { | 631 if (web_browser) { |
| 672 CComObject<ProtocolSinkWrap>* wrap = NULL; | 632 CComObject<ProtocolSinkWrap>* wrap = NULL; |
| 673 CComObject<ProtocolSinkWrap>::CreateInstance(&wrap); | 633 CComObject<ProtocolSinkWrap>::CreateInstance(&wrap); |
| 674 DCHECK(wrap); | 634 DCHECK(wrap); |
| 675 if (wrap->Initialize(protocol, prot_sink, url)) { | 635 if (wrap->Initialize(protocol, prot_sink, url)) { |
| 676 sink_to_use = wrap; | 636 sink_to_use = wrap; |
| 677 } | 637 } |
| 678 } | 638 } |
| 679 | 639 |
| 680 return sink_to_use; | 640 return sink_to_use; |
| 681 } | 641 } |
| OLD | NEW |