OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // 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 | 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 "ceee/ie/plugin/bho/http_negotiate.h" | 5 #include "ceee/ie/plugin/bho/http_negotiate.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlctl.h> | 8 #include <atlctl.h> |
9 #include <htiframe.h> | 9 #include <htiframe.h> |
10 #include <urlmon.h> | 10 #include <urlmon.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 | 16 #include "base/win/scoped_comptr.h" |
17 #include "ceee/ie/plugin/bho/cookie_accountant.h" | 17 #include "ceee/ie/plugin/bho/cookie_accountant.h" |
18 #include "chrome_frame/vtable_patch_manager.h" | 18 #include "chrome_frame/vtable_patch_manager.h" |
19 #include "chrome_frame/utils.h" | 19 #include "chrome_frame/utils.h" |
20 #include "base/scoped_comptr_win.h" | |
21 | 20 |
22 static const int kHttpNegotiateBeginningTransactionIndex = 3; | 21 static const int kHttpNegotiateBeginningTransactionIndex = 3; |
23 static const int kHttpNegotiateOnResponseIndex = 4; | 22 static const int kHttpNegotiateOnResponseIndex = 4; |
24 | 23 |
25 CComAutoCriticalSection HttpNegotiatePatch::bho_instance_count_crit_; | 24 CComAutoCriticalSection HttpNegotiatePatch::bho_instance_count_crit_; |
26 int HttpNegotiatePatch::bho_instance_count_ = 0; | 25 int HttpNegotiatePatch::bho_instance_count_ = 0; |
27 | 26 |
28 | 27 |
29 BEGIN_VTABLE_PATCHES(IHttpNegotiate) | 28 BEGIN_VTABLE_PATCHES(IHttpNegotiate) |
30 VTABLE_PATCH_ENTRY(kHttpNegotiateBeginningTransactionIndex, | 29 VTABLE_PATCH_ENTRY(kHttpNegotiateBeginningTransactionIndex, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 } | 94 } |
96 | 95 |
97 if (IS_PATCHED(IHttpNegotiate)) { | 96 if (IS_PATCHED(IHttpNegotiate)) { |
98 LOG(WARNING) << __FUNCTION__ << ": already patched."; | 97 LOG(WARNING) << __FUNCTION__ << ": already patched."; |
99 return true; | 98 return true; |
100 } | 99 } |
101 | 100 |
102 // Use our SimpleBindStatusCallback class as we need a temporary object that | 101 // Use our SimpleBindStatusCallback class as we need a temporary object that |
103 // implements IBindStatusCallback. | 102 // implements IBindStatusCallback. |
104 CComObjectStackEx<SimpleBindStatusCallback> request; | 103 CComObjectStackEx<SimpleBindStatusCallback> request; |
105 ScopedComPtr<IBindCtx> bind_ctx; | 104 base::win::ScopedComPtr<IBindCtx> bind_ctx; |
106 HRESULT hr = ::CreateAsyncBindCtx(0, &request, NULL, bind_ctx.Receive()); | 105 HRESULT hr = ::CreateAsyncBindCtx(0, &request, NULL, bind_ctx.Receive()); |
107 | 106 |
108 DCHECK(SUCCEEDED(hr)) << "CreateAsyncBindCtx"; | 107 DCHECK(SUCCEEDED(hr)) << "CreateAsyncBindCtx"; |
109 if (bind_ctx) { | 108 if (bind_ctx) { |
110 ScopedComPtr<IUnknown> bscb_holder; | 109 base::win::ScopedComPtr<IUnknown> bscb_holder; |
111 bind_ctx->GetObjectParam(L"_BSCB_Holder_", bscb_holder.Receive()); | 110 bind_ctx->GetObjectParam(L"_BSCB_Holder_", bscb_holder.Receive()); |
112 if (bscb_holder) { | 111 if (bscb_holder) { |
113 hr = PatchHttpNegotiate(bscb_holder); | 112 hr = PatchHttpNegotiate(bscb_holder); |
114 } else { | 113 } else { |
115 NOTREACHED() << "Failed to get _BSCB_Holder_"; | 114 NOTREACHED() << "Failed to get _BSCB_Holder_"; |
116 hr = E_UNEXPECTED; | 115 hr = E_UNEXPECTED; |
117 } | 116 } |
118 bind_ctx.Release(); | 117 bind_ctx.Release(); |
119 } | 118 } |
120 | 119 |
121 return SUCCEEDED(hr); | 120 return SUCCEEDED(hr); |
122 } | 121 } |
123 | 122 |
124 // static | 123 // static |
125 void HttpNegotiatePatch::Uninitialize() { | 124 void HttpNegotiatePatch::Uninitialize() { |
126 CComCritSecLock<CComAutoCriticalSection> lock(bho_instance_count_crit_); | 125 CComCritSecLock<CComAutoCriticalSection> lock(bho_instance_count_crit_); |
127 bho_instance_count_--; | 126 bho_instance_count_--; |
128 DCHECK_GE(bho_instance_count_, 0); | 127 DCHECK_GE(bho_instance_count_, 0); |
129 if (bho_instance_count_ == 0) { | 128 if (bho_instance_count_ == 0) { |
130 vtable_patch::UnpatchInterfaceMethods(IHttpNegotiate_PatchInfo); | 129 vtable_patch::UnpatchInterfaceMethods(IHttpNegotiate_PatchInfo); |
131 } | 130 } |
132 } | 131 } |
133 | 132 |
134 // static | 133 // static |
135 HRESULT HttpNegotiatePatch::PatchHttpNegotiate(IUnknown* to_patch) { | 134 HRESULT HttpNegotiatePatch::PatchHttpNegotiate(IUnknown* to_patch) { |
136 DCHECK(to_patch); | 135 DCHECK(to_patch); |
137 DCHECK_IS_NOT_PATCHED(IHttpNegotiate); | 136 DCHECK_IS_NOT_PATCHED(IHttpNegotiate); |
138 | 137 |
139 ScopedComPtr<IHttpNegotiate> http; | 138 base::win::ScopedComPtr<IHttpNegotiate> http; |
140 HRESULT hr = http.QueryFrom(to_patch); | 139 HRESULT hr = http.QueryFrom(to_patch); |
141 if (FAILED(hr)) { | 140 if (FAILED(hr)) { |
142 hr = DoQueryService(IID_IHttpNegotiate, to_patch, http.Receive()); | 141 hr = DoQueryService(IID_IHttpNegotiate, to_patch, http.Receive()); |
143 } | 142 } |
144 | 143 |
145 if (http) { | 144 if (http) { |
146 hr = vtable_patch::PatchInterfaceMethods(http, IHttpNegotiate_PatchInfo); | 145 hr = vtable_patch::PatchInterfaceMethods(http, IHttpNegotiate_PatchInfo); |
147 DLOG_IF(ERROR, FAILED(hr)) | 146 DLOG_IF(ERROR, FAILED(hr)) |
148 << StringPrintf("HttpNegotiate patch failed 0x%08X", hr); | 147 << StringPrintf("HttpNegotiate patch failed 0x%08X", hr); |
149 } else { | 148 } else { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 if (FAILED(hr)) { | 187 if (FAILED(hr)) { |
189 DLOG(WARNING) << __FUNCTION__ << " Delegate returned an error"; | 188 DLOG(WARNING) << __FUNCTION__ << " Delegate returned an error"; |
190 return hr; | 189 return hr; |
191 } | 190 } |
192 | 191 |
193 CookieAccountant::GetInstance()->RecordHttpResponseCookies( | 192 CookieAccountant::GetInstance()->RecordHttpResponseCookies( |
194 std::string(CW2A(response_headers)), current_time); | 193 std::string(CW2A(response_headers)), current_time); |
195 | 194 |
196 return hr; | 195 return hr; |
197 } | 196 } |
OLD | NEW |