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
3 // found in the LICENSE file.
5 #include "chrome_frame/bind_status_callback_impl.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/threading/platform_thread.h"
12 BSCBImpl::BSCBImpl() {
13 DVLOG(1) << __FUNCTION__
<< me();
16 BSCBImpl::~BSCBImpl() {
17 DVLOG(1) << __FUNCTION__
<< me();
20 std::string
BSCBImpl::me() {
21 return base::StringPrintf(" obj=0x%08X", static_cast<BSCBImpl
*>(this));
24 HRESULT
BSCBImpl::DelegateQI(void* obj
, REFIID iid
, void** ret
, DWORD cookie
) {
25 BSCBImpl
* me
= reinterpret_cast<BSCBImpl
*>(obj
);
26 HRESULT hr
= E_NOINTERFACE
;
28 hr
= me
->delegate_
.QueryInterface(iid
, ret
);
32 void BSCBImpl::Initialize(IBindStatusCallback
* original
) {
37 HRESULT
BSCBImpl::AttachToBind(IBindCtx
* bind_ctx
) {
39 hr
= ::RegisterBindStatusCallback(bind_ctx
, this, delegate_
.Receive(), 0);
47 HRESULT
BSCBImpl::ReleaseBind() {
48 // AddRef ourselves while we release these objects as we might
49 // perish during this operation.
54 hr
= ::RevokeBindStatusCallback(bind_ctx_
, this);
65 HRESULT
BSCBImpl::QueryService(REFGUID service
, REFIID iid
, void** object
) {
66 HRESULT hr
= E_NOINTERFACE
;
68 base::win::ScopedComPtr
<IServiceProvider
> svc
;
69 svc
.QueryFrom(delegate_
);
71 hr
= svc
->QueryService(service
, iid
, object
);
77 // IBindStatusCallback
78 HRESULT
BSCBImpl::OnStartBinding(DWORD reserved
, IBinding
* binding
) {
79 DVLOG(1) << __FUNCTION__
<< me()
80 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
83 hr
= delegate_
->OnStartBinding(reserved
, binding
);
87 HRESULT
BSCBImpl::GetPriority(LONG
* priority
) {
88 DVLOG(1) << __FUNCTION__
<< me()
89 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
92 hr
= delegate_
->GetPriority(priority
);
96 HRESULT
BSCBImpl::OnLowResource(DWORD reserved
) {
97 DVLOG(1) << __FUNCTION__
<< me()
98 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
101 hr
= delegate_
->OnLowResource(reserved
);
105 HRESULT
BSCBImpl::OnProgress(ULONG progress
, ULONG progress_max
,
106 ULONG status_code
, LPCWSTR status_text
) {
107 DVLOG(1) << __FUNCTION__
<< me()
108 << base::StringPrintf(" status=%i tid=%i %ls", status_code
,
109 base::PlatformThread::CurrentId(),
113 delegate_
->OnProgress(progress
, progress_max
, status_code
, status_text
);
117 HRESULT
BSCBImpl::OnStopBinding(HRESULT hresult
, LPCWSTR error
) {
118 DVLOG(1) << __FUNCTION__
<< me()
119 << base::StringPrintf(" hr=0x%08X '%ls' tid=%i", hresult
, error
,
120 base::PlatformThread::CurrentId());
123 delegate_
->OnStopBinding(hresult
, error
);
127 HRESULT
BSCBImpl::GetBindInfo(DWORD
* bindf
, BINDINFO
* bind_info
) {
128 DVLOG(1) << __FUNCTION__
<< me()
129 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
132 delegate_
->GetBindInfo(bindf
, bind_info
);
136 HRESULT
BSCBImpl::OnDataAvailable(DWORD bscf
, DWORD size
,
137 FORMATETC
* format_etc
, STGMEDIUM
* stgmed
) {
138 DVLOG(1) << __FUNCTION__
<< me()
139 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
142 hr
= delegate_
->OnDataAvailable(bscf
, size
, format_etc
, stgmed
);
146 HRESULT
BSCBImpl::OnObjectAvailable(REFIID iid
, IUnknown
* unk
) {
147 DVLOG(1) << __FUNCTION__
<< me()
148 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
151 delegate_
->OnObjectAvailable(iid
, unk
);
155 // IBindStatusCallbackEx
156 HRESULT
BSCBImpl::GetBindInfoEx(DWORD
* bindf
, BINDINFO
* bind_info
,
157 DWORD
* bindf2
, DWORD
* reserved
) {
158 DVLOG(1) << __FUNCTION__
<< me()
159 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
162 base::win::ScopedComPtr
<IBindStatusCallbackEx
> bscbex
;
163 bscbex
.QueryFrom(delegate_
);
165 hr
= bscbex
->GetBindInfoEx(bindf
, bind_info
, bindf2
, reserved
);
170 HRESULT
BSCBImpl::BeginningTransaction(LPCWSTR url
, LPCWSTR headers
,
172 LPWSTR
* additional_headers
) {
173 DVLOG(1) << __FUNCTION__
<< me()
174 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
178 base::win::ScopedComPtr
<IHttpNegotiate
> http_negotiate
;
179 http_negotiate
.QueryFrom(delegate_
);
180 if (http_negotiate
) {
181 hr
= http_negotiate
->BeginningTransaction(url
, headers
, reserved
,
186 DLOG_IF(ERROR
, FAILED(hr
)) << __FUNCTION__
;
190 HRESULT
BSCBImpl::OnResponse(DWORD response_code
, LPCWSTR response_headers
,
191 LPCWSTR request_headers
,
192 LPWSTR
* additional_headers
) {
193 DVLOG(1) << __FUNCTION__
<< me()
194 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
198 base::win::ScopedComPtr
<IHttpNegotiate
> http_negotiate
;
199 http_negotiate
.QueryFrom(delegate_
);
200 if (http_negotiate
) {
201 hr
= http_negotiate
->OnResponse(response_code
, response_headers
,
202 request_headers
, additional_headers
);
208 HRESULT
BSCBImpl::GetRootSecurityId(BYTE
* security_id
, DWORD
* security_id_size
,
209 DWORD_PTR reserved
) {
212 base::win::ScopedComPtr
<IHttpNegotiate2
> http_negotiate
;
213 http_negotiate
.QueryFrom(delegate_
);
214 if (http_negotiate
) {
215 hr
= http_negotiate
->GetRootSecurityId(security_id
, security_id_size
,
222 HRESULT
BSCBImpl::GetSerializedClientCertContext(BYTE
** cert
,
226 base::win::ScopedComPtr
<IHttpNegotiate3
> http_negotiate
;
227 http_negotiate
.QueryFrom(delegate_
);
228 if (http_negotiate
) {
229 return http_negotiate
->GetSerializedClientCertContext(cert
, cert_size
);