blob: 9e535e5b34588252cf34d88dd86af43e05f96542 [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]ce072a72010-12-31 20:02:1610#include "base/threading/platform_thread.h"
[email protected]97965e12010-04-09 00:51:1011
12BSCBImpl::BSCBImpl() {
[email protected]2b9a9f162010-10-19 20:30:4513 DVLOG(1) << __FUNCTION__ << me();
[email protected]97965e12010-04-09 00:51:1014}
15
16BSCBImpl::~BSCBImpl() {
[email protected]2b9a9f162010-10-19 20:30:4517 DVLOG(1) << __FUNCTION__ << me();
[email protected]97965e12010-04-09 00:51:1018}
19
20std::string BSCBImpl::me() {
[email protected]d3451d832010-10-01 11:17:3721 return base::StringPrintf(" obj=0x%08X", static_cast<BSCBImpl*>(this));
[email protected]97965e12010-04-09 00:51:1022}
23
24HRESULT BSCBImpl::DelegateQI(void* obj, REFIID iid, void** ret, DWORD cookie) {
25 BSCBImpl* me = reinterpret_cast<BSCBImpl*>(obj);
26 HRESULT hr = E_NOINTERFACE;
27 if (me->delegate_)
28 hr = me->delegate_.QueryInterface(iid, ret);
29 return hr;
30}
31
32void BSCBImpl::Initialize(IBindStatusCallback* original) {
33 DCHECK(!delegate_);
34 delegate_ = original;
35}
36
37HRESULT BSCBImpl::AttachToBind(IBindCtx* bind_ctx) {
38 HRESULT hr = S_OK;
39 hr = ::RegisterBindStatusCallback(bind_ctx, this, delegate_.Receive(), 0);
40 if (SUCCEEDED(hr)) {
41 bind_ctx_ = bind_ctx;
42 }
43
44 return hr;
45}
46
47HRESULT BSCBImpl::ReleaseBind() {
[email protected]77d7aee2010-05-14 20:31:5548 // AddRef ourselves while we release these objects as we might
49 // perish during this operation.
50 AddRef();
51
[email protected]97965e12010-04-09 00:51:1052 HRESULT hr = S_OK;
[email protected]ffec6bf2010-04-09 23:53:2653 if (bind_ctx_) {
54 hr = ::RevokeBindStatusCallback(bind_ctx_, this);
[email protected]97965e12010-04-09 00:51:1055 }
[email protected]97965e12010-04-09 00:51:1056 delegate_.Release();
57 bind_ctx_.Release();
[email protected]77d7aee2010-05-14 20:31:5558
59 Release();
60
[email protected]97965e12010-04-09 00:51:1061 return hr;
62}
63
64// IServiceProvider
65HRESULT BSCBImpl::QueryService(REFGUID service, REFIID iid, void** object) {
66 HRESULT hr = E_NOINTERFACE;
67 if (delegate_) {
68 ScopedComPtr<IServiceProvider> svc;
69 svc.QueryFrom(delegate_);
70 if (svc) {
71 hr = svc->QueryService(service, iid, object);
72 }
73 }
74 return hr;
75}
76
77// IBindStatusCallback
78HRESULT BSCBImpl::OnStartBinding(DWORD reserved, IBinding* binding) {
[email protected]2b9a9f162010-10-19 20:30:4579 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:1680 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1081 HRESULT hr = S_OK;
82 if (delegate_)
83 hr = delegate_->OnStartBinding(reserved, binding);
84 return hr;
85}
86
87HRESULT BSCBImpl::GetPriority(LONG* priority) {
[email protected]2b9a9f162010-10-19 20:30:4588 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:1689 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1090 HRESULT hr = S_OK;
91 if (delegate_)
92 hr = delegate_->GetPriority(priority);
93 return hr;
94}
95
96HRESULT BSCBImpl::OnLowResource(DWORD reserved) {
[email protected]2b9a9f162010-10-19 20:30:4597 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:1698 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:1099 HRESULT hr = S_OK;
100 if (delegate_)
101 hr = delegate_->OnLowResource(reserved);
102 return hr;
103}
104
105HRESULT BSCBImpl::OnProgress(ULONG progress, ULONG progress_max,
106 ULONG status_code, LPCWSTR status_text) {
[email protected]2b9a9f162010-10-19 20:30:45107 DVLOG(1) << __FUNCTION__ << me()
108 << base::StringPrintf(" status=%i tid=%i %ls", status_code,
[email protected]ce072a72010-12-31 20:02:16109 base::PlatformThread::CurrentId(),
110 status_text);
[email protected]97965e12010-04-09 00:51:10111 HRESULT hr = S_OK;
112 if (delegate_)
113 delegate_->OnProgress(progress, progress_max, status_code, status_text);
114 return hr;
115}
116
117HRESULT BSCBImpl::OnStopBinding(HRESULT hresult, LPCWSTR error) {
[email protected]2b9a9f162010-10-19 20:30:45118 DVLOG(1) << __FUNCTION__ << me()
119 << base::StringPrintf(" hr=0x%08X '%ls' tid=%i", hresult, error,
[email protected]ce072a72010-12-31 20:02:16120 base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10121 HRESULT hr = S_OK;
122 if (delegate_)
123 delegate_->OnStopBinding(hresult, error);
124 return hr;
125}
126
127HRESULT BSCBImpl::GetBindInfo(DWORD* bindf, BINDINFO* bind_info) {
[email protected]2b9a9f162010-10-19 20:30:45128 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16129 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10130 HRESULT hr = S_OK;
131 if (delegate_)
132 delegate_->GetBindInfo(bindf, bind_info);
133 return hr;
134}
135
136HRESULT BSCBImpl::OnDataAvailable(DWORD bscf, DWORD size,
137 FORMATETC* format_etc, STGMEDIUM* stgmed) {
[email protected]2b9a9f162010-10-19 20:30:45138 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16139 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10140 HRESULT hr = S_OK;
141 if (delegate_)
142 hr = delegate_->OnDataAvailable(bscf, size, format_etc, stgmed);
143 return hr;
144}
145
146HRESULT BSCBImpl::OnObjectAvailable(REFIID iid, IUnknown* unk) {
[email protected]2b9a9f162010-10-19 20:30:45147 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16148 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10149 HRESULT hr = S_OK;
150 if (delegate_)
151 delegate_->OnObjectAvailable(iid, unk);
152 return hr;
153}
154
155// IBindStatusCallbackEx
156HRESULT BSCBImpl::GetBindInfoEx(DWORD* bindf, BINDINFO* bind_info,
157 DWORD* bindf2, DWORD* reserved) {
[email protected]2b9a9f162010-10-19 20:30:45158 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16159 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10160 HRESULT hr = S_OK;
161 if (delegate_) {
162 ScopedComPtr<IBindStatusCallbackEx> bscbex;
163 bscbex.QueryFrom(delegate_);
164 if (bscbex)
165 hr = bscbex->GetBindInfoEx(bindf, bind_info, bindf2, reserved);
166 }
167 return hr;
168}
169
170HRESULT BSCBImpl::BeginningTransaction(LPCWSTR url, LPCWSTR headers,
171 DWORD reserved,
172 LPWSTR* additional_headers) {
[email protected]2b9a9f162010-10-19 20:30:45173 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16174 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10175
176 HRESULT hr = S_OK;
177 if (delegate_) {
178 ScopedComPtr<IHttpNegotiate> http_negotiate;
179 http_negotiate.QueryFrom(delegate_);
180 if (http_negotiate) {
181 hr = http_negotiate->BeginningTransaction(url, headers, reserved,
182 additional_headers);
183 }
184 }
185
186 DLOG_IF(ERROR, FAILED(hr)) << __FUNCTION__;
187 return hr;
188}
189
190HRESULT BSCBImpl::OnResponse(DWORD response_code, LPCWSTR response_headers,
191 LPCWSTR request_headers,
192 LPWSTR* additional_headers) {
[email protected]2b9a9f162010-10-19 20:30:45193 DVLOG(1) << __FUNCTION__ << me()
[email protected]ce072a72010-12-31 20:02:16194 << base::StringPrintf(" tid=%i", base::PlatformThread::CurrentId());
[email protected]97965e12010-04-09 00:51:10195
196 HRESULT hr = S_OK;
197 if (delegate_) {
198 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);
203 }
204 }
205 return hr;
206}
207
208HRESULT BSCBImpl::GetRootSecurityId(BYTE* security_id, DWORD* security_id_size,
209 DWORD_PTR reserved) {
210 HRESULT hr = S_OK;
211 if (delegate_) {
212 ScopedComPtr<IHttpNegotiate2> http_negotiate;
213 http_negotiate.QueryFrom(delegate_);
214 if (http_negotiate) {
215 hr = http_negotiate->GetRootSecurityId(security_id, security_id_size,
216 reserved);
217 }
218 }
219 return hr;
220}
221
222HRESULT BSCBImpl::GetSerializedClientCertContext(BYTE** cert,
223 DWORD* cert_size) {
224 HRESULT hr = S_OK;
225 if (delegate_) {
226 ScopedComPtr<IHttpNegotiate3> http_negotiate;
227 http_negotiate.QueryFrom(delegate_);
228 if (http_negotiate) {
229 return http_negotiate->GetSerializedClientCertContext(cert, cert_size);
230 }
231 }
232 return hr;
233}