blob: c85825d2aedfe7fce6a75840d895efc12ec9a0a3 [file] [log] [blame]
[email protected]97965e12010-04-09 00:51:101// 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
3// found in the LICENSE file.
4
5#include "chrome_frame/bind_status_callback_impl.h"
6
7#include "base/logging.h"
8#include "base/string_util.h"
[email protected]d3451d832010-10-01 11:17:379#include "base/stringprintf.h"
[email protected]97965e12010-04-09 00:51:1010
11BSCBImpl::BSCBImpl() {
[email protected]2b9a9f162010-10-19 20:30:4512 DVLOG(1) << __FUNCTION__ << me();
[email protected]97965e12010-04-09 00:51:1013}
14
15BSCBImpl::~BSCBImpl() {
[email protected]2b9a9f162010-10-19 20:30:4516 DVLOG(1) << __FUNCTION__ << me();
[email protected]97965e12010-04-09 00:51:1017}
18
19std::string BSCBImpl::me() {
[email protected]d3451d832010-10-01 11:17:3720 return base::StringPrintf(" obj=0x%08X", static_cast<BSCBImpl*>(this));
[email protected]97965e12010-04-09 00:51:1021}
22
23HRESULT BSCBImpl::DelegateQI(void* obj, REFIID iid, void** ret, DWORD cookie) {
24 BSCBImpl* me = reinterpret_cast<BSCBImpl*>(obj);
25 HRESULT hr = E_NOINTERFACE;
26 if (me->delegate_)
27 hr = me->delegate_.QueryInterface(iid, ret);
28 return hr;
29}
30
31void BSCBImpl::Initialize(IBindStatusCallback* original) {
32 DCHECK(!delegate_);
33 delegate_ = original;
34}
35
36HRESULT BSCBImpl::AttachToBind(IBindCtx* bind_ctx) {
37 HRESULT hr = S_OK;
38 hr = ::RegisterBindStatusCallback(bind_ctx, this, delegate_.Receive(), 0);
39 if (SUCCEEDED(hr)) {
40 bind_ctx_ = bind_ctx;
41 }
42
43 return hr;
44}
45
46HRESULT BSCBImpl::ReleaseBind() {
[email protected]77d7aee2010-05-14 20:31:5547 // AddRef ourselves while we release these objects as we might
48 // perish during this operation.
49 AddRef();
50
[email protected]97965e12010-04-09 00:51:1051 HRESULT hr = S_OK;
[email protected]ffec6bf2010-04-09 23:53:2652 if (bind_ctx_) {
53 hr = ::RevokeBindStatusCallback(bind_ctx_, this);
[email protected]97965e12010-04-09 00:51:1054 }
[email protected]97965e12010-04-09 00:51:1055 delegate_.Release();
56 bind_ctx_.Release();
[email protected]77d7aee2010-05-14 20:31:5557
58 Release();
59
[email protected]97965e12010-04-09 00:51:1060 return hr;
61}
62
63// IServiceProvider
64HRESULT BSCBImpl::QueryService(REFGUID service, REFIID iid, void** object) {
65 HRESULT hr = E_NOINTERFACE;
66 if (delegate_) {
67 ScopedComPtr<IServiceProvider> svc;
68 svc.QueryFrom(delegate_);
69 if (svc) {
70 hr = svc->QueryService(service, iid, object);
71 }
72 }
73 return hr;
74}
75
76// IBindStatusCallback
77HRESULT BSCBImpl::OnStartBinding(DWORD reserved, IBinding* binding) {
[email protected]2b9a9f162010-10-19 20:30:4578 DVLOG(1) << __FUNCTION__ << me()
79 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1080 HRESULT hr = S_OK;
81 if (delegate_)
82 hr = delegate_->OnStartBinding(reserved, binding);
83 return hr;
84}
85
86HRESULT BSCBImpl::GetPriority(LONG* priority) {
[email protected]2b9a9f162010-10-19 20:30:4587 DVLOG(1) << __FUNCTION__ << me()
88 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1089 HRESULT hr = S_OK;
90 if (delegate_)
91 hr = delegate_->GetPriority(priority);
92 return hr;
93}
94
95HRESULT BSCBImpl::OnLowResource(DWORD reserved) {
[email protected]2b9a9f162010-10-19 20:30:4596 DVLOG(1) << __FUNCTION__ << me()
97 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1098 HRESULT hr = S_OK;
99 if (delegate_)
100 hr = delegate_->OnLowResource(reserved);
101 return hr;
102}
103
104HRESULT BSCBImpl::OnProgress(ULONG progress, ULONG progress_max,
105 ULONG status_code, LPCWSTR status_text) {
[email protected]2b9a9f162010-10-19 20:30:45106 DVLOG(1) << __FUNCTION__ << me()
107 << base::StringPrintf(" status=%i tid=%i %ls", status_code,
108 PlatformThread::CurrentId(), status_text);
[email protected]97965e12010-04-09 00:51:10109 HRESULT hr = S_OK;
110 if (delegate_)
111 delegate_->OnProgress(progress, progress_max, status_code, status_text);
112 return hr;
113}
114
115HRESULT BSCBImpl::OnStopBinding(HRESULT hresult, LPCWSTR error) {
[email protected]2b9a9f162010-10-19 20:30:45116 DVLOG(1) << __FUNCTION__ << me()
117 << base::StringPrintf(" hr=0x%08X '%ls' tid=%i", hresult, error,
118 PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10119 HRESULT hr = S_OK;
120 if (delegate_)
121 delegate_->OnStopBinding(hresult, error);
122 return hr;
123}
124
125HRESULT BSCBImpl::GetBindInfo(DWORD* bindf, BINDINFO* bind_info) {
[email protected]2b9a9f162010-10-19 20:30:45126 DVLOG(1) << __FUNCTION__ << me()
127 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10128 HRESULT hr = S_OK;
129 if (delegate_)
130 delegate_->GetBindInfo(bindf, bind_info);
131 return hr;
132}
133
134HRESULT BSCBImpl::OnDataAvailable(DWORD bscf, DWORD size,
135 FORMATETC* format_etc, STGMEDIUM* stgmed) {
[email protected]2b9a9f162010-10-19 20:30:45136 DVLOG(1) << __FUNCTION__ << me()
137 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10138 HRESULT hr = S_OK;
139 if (delegate_)
140 hr = delegate_->OnDataAvailable(bscf, size, format_etc, stgmed);
141 return hr;
142}
143
144HRESULT BSCBImpl::OnObjectAvailable(REFIID iid, IUnknown* unk) {
[email protected]2b9a9f162010-10-19 20:30:45145 DVLOG(1) << __FUNCTION__ << me()
146 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10147 HRESULT hr = S_OK;
148 if (delegate_)
149 delegate_->OnObjectAvailable(iid, unk);
150 return hr;
151}
152
153// IBindStatusCallbackEx
154HRESULT BSCBImpl::GetBindInfoEx(DWORD* bindf, BINDINFO* bind_info,
155 DWORD* bindf2, DWORD* reserved) {
[email protected]2b9a9f162010-10-19 20:30:45156 DVLOG(1) << __FUNCTION__ << me()
157 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10158 HRESULT hr = S_OK;
159 if (delegate_) {
160 ScopedComPtr<IBindStatusCallbackEx> bscbex;
161 bscbex.QueryFrom(delegate_);
162 if (bscbex)
163 hr = bscbex->GetBindInfoEx(bindf, bind_info, bindf2, reserved);
164 }
165 return hr;
166}
167
168HRESULT BSCBImpl::BeginningTransaction(LPCWSTR url, LPCWSTR headers,
169 DWORD reserved,
170 LPWSTR* additional_headers) {
[email protected]2b9a9f162010-10-19 20:30:45171 DVLOG(1) << __FUNCTION__ << me()
172 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10173
174 HRESULT hr = S_OK;
175 if (delegate_) {
176 ScopedComPtr<IHttpNegotiate> http_negotiate;
177 http_negotiate.QueryFrom(delegate_);
178 if (http_negotiate) {
179 hr = http_negotiate->BeginningTransaction(url, headers, reserved,
180 additional_headers);
181 }
182 }
183
184 DLOG_IF(ERROR, FAILED(hr)) << __FUNCTION__;
185 return hr;
186}
187
188HRESULT BSCBImpl::OnResponse(DWORD response_code, LPCWSTR response_headers,
189 LPCWSTR request_headers,
190 LPWSTR* additional_headers) {
[email protected]2b9a9f162010-10-19 20:30:45191 DVLOG(1) << __FUNCTION__ << me()
192 << base::StringPrintf(" tid=%i", PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10193
194 HRESULT hr = S_OK;
195 if (delegate_) {
196 ScopedComPtr<IHttpNegotiate> http_negotiate;
197 http_negotiate.QueryFrom(delegate_);
198 if (http_negotiate) {
199 hr = http_negotiate->OnResponse(response_code, response_headers,
200 request_headers, additional_headers);
201 }
202 }
203 return hr;
204}
205
206HRESULT BSCBImpl::GetRootSecurityId(BYTE* security_id, DWORD* security_id_size,
207 DWORD_PTR reserved) {
208 HRESULT hr = S_OK;
209 if (delegate_) {
210 ScopedComPtr<IHttpNegotiate2> http_negotiate;
211 http_negotiate.QueryFrom(delegate_);
212 if (http_negotiate) {
213 hr = http_negotiate->GetRootSecurityId(security_id, security_id_size,
214 reserved);
215 }
216 }
217 return hr;
218}
219
220HRESULT BSCBImpl::GetSerializedClientCertContext(BYTE** cert,
221 DWORD* cert_size) {
222 HRESULT hr = S_OK;
223 if (delegate_) {
224 ScopedComPtr<IHttpNegotiate3> http_negotiate;
225 http_negotiate.QueryFrom(delegate_);
226 if (http_negotiate) {
227 return http_negotiate->GetSerializedClientCertContext(cert, cert_size);
228 }
229 }
230 return hr;
231}
232