[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
| 6 | #define CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
| 7 | |
| 8 | #include <atlbase.h> |
| 9 | #include <atlcom.h> |
| 10 | |
| 11 | #include "chrome_frame/urlmon_moniker.h" |
| 12 | |
| 13 | // Our implementation of IBindStatusCallback that allows us to sit on the |
| 14 | // sidelines and cache all the data that passes by (using the RequestData |
| 15 | // class). That cache can then be used by other monikers for the same URL |
| 16 | // that immediately follow. |
| 17 | class CFUrlmonBindStatusCallback |
| 18 | : public CComObjectRootEx<CComMultiThreadModel>, |
| 19 | public IBindStatusCallbackEx, |
| 20 | public IHttpNegotiate3, |
| 21 | public IServiceProvider { |
| 22 | public: |
| 23 | CFUrlmonBindStatusCallback(); |
| 24 | ~CFUrlmonBindStatusCallback(); |
| 25 | |
| 26 | // used for logging. |
| 27 | std::string me(); |
| 28 | |
| 29 | BEGIN_COM_MAP(CFUrlmonBindStatusCallback) |
| 30 | COM_INTERFACE_ENTRY(IBindStatusCallback) |
| 31 | COM_INTERFACE_ENTRY(IHttpNegotiate) |
| 32 | COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IBindStatusCallbackEx) |
| 33 | COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IHttpNegotiate2) |
| 34 | COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IHttpNegotiate3) |
| 35 | COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IServiceProvider) |
| 36 | COM_INTERFACE_ENTRY_FUNC_BLIND(0, DelegateQI) |
| 37 | END_COM_MAP() |
| 38 | |
| 39 | static STDMETHODIMP DelegateQI(void* obj, REFIID iid, void** ret, |
| 40 | DWORD cookie); |
| 41 | |
| 42 | HRESULT Initialize(IBindCtx* bind_ctx, RequestHeaders* headers); |
| 43 | |
| 44 | // For the COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS macro. |
| 45 | IBindStatusCallback* delegate() const { |
| 46 | return delegate_; |
| 47 | } |
| 48 | |
| 49 | RequestData* request_data() { |
| 50 | return data_; |
| 51 | } |
| 52 | |
| 53 | // IServiceProvider |
| 54 | STDMETHOD(QueryService)(REFGUID service, REFIID iid, void** object); |
| 55 | |
| 56 | // IBindStatusCallback |
| 57 | STDMETHOD(OnStartBinding)(DWORD reserved, IBinding* binding); |
| 58 | STDMETHOD(GetPriority)(LONG* priority); |
| 59 | STDMETHOD(OnLowResource)(DWORD reserved); |
| 60 | STDMETHOD(OnProgress)(ULONG progress, ULONG progress_max, ULONG status_code, |
| 61 | LPCWSTR status_text); |
| 62 | STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR error); |
| 63 | STDMETHOD(GetBindInfo)(DWORD* bindf, BINDINFO* bind_info); |
| 64 | STDMETHOD(OnDataAvailable)(DWORD bscf, DWORD size, FORMATETC* format_etc, |
| 65 | STGMEDIUM* stgmed); |
| 66 | STDMETHOD(OnObjectAvailable)(REFIID iid, IUnknown* unk); |
| 67 | |
| 68 | // IBindStatusCallbackEx |
| 69 | STDMETHOD(GetBindInfoEx)(DWORD* bindf, BINDINFO* bind_info, DWORD* bindf2, |
| 70 | DWORD* reserved); |
| 71 | |
| 72 | // IHttpNegotiate |
| 73 | STDMETHOD(BeginningTransaction)(LPCWSTR url, LPCWSTR headers, DWORD reserved, |
| 74 | LPWSTR* additional_headers); |
| 75 | STDMETHOD(OnResponse)(DWORD response_code, LPCWSTR response_headers, |
| 76 | LPCWSTR request_headers, LPWSTR* additional_headers); |
| 77 | |
| 78 | // IHttpNegotiate2 |
| 79 | STDMETHOD(GetRootSecurityId)(BYTE* security_id, DWORD* security_id_size, |
| 80 | DWORD_PTR reserved); |
| 81 | |
| 82 | // IHttpNegotiate3 |
| 83 | STDMETHOD(GetSerializedClientCertContext)(BYTE** cert, DWORD* cert_size); |
| 84 | |
| 85 | protected: |
| 86 | ScopedComPtr<IBindStatusCallback> delegate_; |
| 87 | ScopedComPtr<IBindCtx> bind_ctx_; |
| 88 | ScopedComPtr<SimpleBindingImpl, &GUID_NULL> binding_delegate_; |
| 89 | bool only_buffer_; |
| 90 | scoped_refptr<RequestData> data_; |
| 91 | std::wstring redirected_url_; |
| 92 | |
| 93 | private: |
| 94 | DISALLOW_COPY_AND_ASSIGN(CFUrlmonBindStatusCallback); |
| 95 | }; |
| 96 | |
| 97 | #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
| 98 | |