diff options
author | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:51:10 +0000 |
---|---|---|
committer | amit@chromium.org <amit@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:51:10 +0000 |
commit | 97965e190cb9f5009f6c97195bef9225c6034931 (patch) | |
tree | 96f2320c853a50d06664a1b2134a0dcb97c42bac /chrome_frame/urlmon_bind_status_callback.h | |
parent | 4a626f876a6dcd77e4d2cfc5d2496acdd44d7fe1 (diff) | |
download | chromium_src-97965e190cb9f5009f6c97195bef9225c6034931.zip chromium_src-97965e190cb9f5009f6c97195bef9225c6034931.tar.gz chromium_src-97965e190cb9f5009f6c97195bef9225c6034931.tar.bz2 |
Switch renderer in Moniker patch
Step one of the changes. Inspect data and cause a switch
in the moniker patch.
Review URL: http://codereview.chromium.org/1589013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/urlmon_bind_status_callback.h')
-rw-r--r-- | chrome_frame/urlmon_bind_status_callback.h | 161 |
1 files changed, 96 insertions, 65 deletions
diff --git a/chrome_frame/urlmon_bind_status_callback.h b/chrome_frame/urlmon_bind_status_callback.h index d8ede6d..f1b1473 100644 --- a/chrome_frame/urlmon_bind_status_callback.h +++ b/chrome_frame/urlmon_bind_status_callback.h @@ -8,91 +8,122 @@ #include <atlbase.h> #include <atlcom.h> -#include "chrome_frame/urlmon_moniker.h" - -// Our implementation of IBindStatusCallback that allows us to sit on the -// sidelines and cache all the data that passes by (using the RequestData -// class). That cache can then be used by other monikers for the same URL -// that immediately follow. -class CFUrlmonBindStatusCallback - : public CComObjectRootEx<CComMultiThreadModel>, - public IBindStatusCallbackEx, - public IHttpNegotiate3, - public IServiceProvider { +#include "chrome_frame/bind_status_callback_impl.h" +#include "chrome_frame/stream_impl.h" + + +// A fake stream class to serve cached data to arbitrary +// IBindStatusCallback +class CacheStream : public CComObjectRoot, public StreamImpl { public: - CFUrlmonBindStatusCallback(); - ~CFUrlmonBindStatusCallback(); + BEGIN_COM_MAP(CacheStream) + COM_INTERFACE_ENTRY(IStream) + COM_INTERFACE_ENTRY(ISequentialStream) + END_COM_MAP() - // used for logging. - std::string me(); + CacheStream() : cache_(NULL), size_(0), position_(0) { + } + void Initialize(const char* cache, size_t size); + static HRESULT BSCBFeedData(IBindStatusCallback* bscb, const char* data, + size_t size, CLIPFORMAT clip_format, + size_t flags); -BEGIN_COM_MAP(CFUrlmonBindStatusCallback) - COM_INTERFACE_ENTRY(IBindStatusCallback) - COM_INTERFACE_ENTRY(IHttpNegotiate) - COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IBindStatusCallbackEx) - COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IHttpNegotiate2) - COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IHttpNegotiate3) - COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IServiceProvider) - COM_INTERFACE_ENTRY_FUNC_BLIND(0, DelegateQI) -END_COM_MAP() + // IStream overrides + STDMETHOD(Read)(void* pv, ULONG cb, ULONG* read); + + protected: + const char* cache_; + size_t size_; + size_t position_; + + private: + DISALLOW_COPY_AND_ASSIGN(CacheStream); +}; - static STDMETHODIMP DelegateQI(void* obj, REFIID iid, void** ret, - DWORD cookie); +// Utility class for data sniffing +class SniffData { + public: + SniffData() : renderer_type_(OTHER), size_(0) {} + + enum RendererType { + UNDETERMINED, + CHROME, + OTHER + }; + + bool InitializeCache(const std::wstring& url); + HRESULT ReadIntoCache(IStream* stream, bool force_determination); + HRESULT DrainCache(IBindStatusCallback* bscb, DWORD bscf, + CLIPFORMAT clip_format); + void DetermineRendererType(); + + bool is_undetermined() const { + return (UNDETERMINED == renderer_type_); + } + bool is_chrome() const { + return (CHROME == renderer_type_); + } - HRESULT Initialize(IBindCtx* bind_ctx, RequestHeaders* headers); + RendererType renderer_type() const { + return renderer_type_; + } - // For the COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS macro. - IBindStatusCallback* delegate() const { - return delegate_; + size_t size() const { + return size_; } - RequestData* request_data() { - return data_; + bool is_cache_valid() { + return (size_ != 0); } - // IServiceProvider - STDMETHOD(QueryService)(REFGUID service, REFIID iid, void** object); + ScopedComPtr<IStream> cache_; + std::wstring url_; + RendererType renderer_type_; + size_t size_; + + static const size_t kMaxSniffSize = 2 * 1024; + + private: + DISALLOW_COPY_AND_ASSIGN(SniffData); +}; + +// A wrapper for bind status callback in IMoniker::BindToStorage +class BSCBStorageBind : public BSCBImpl { + public: + typedef BSCBImpl CallbackImpl; + BSCBStorageBind() : clip_format_(CF_NULL) {} + +BEGIN_COM_MAP(BSCBStorageBind) + COM_INTERFACE_ENTRY(IBindStatusCallback) + COM_INTERFACE_ENTRY_CHAIN(CallbackImpl) +END_COM_MAP() + + HRESULT Initialize(IMoniker* moniker, IBindCtx* bind_ctx); + HRESULT MayPlayBack(DWORD flags); // IBindStatusCallback - STDMETHOD(OnStartBinding)(DWORD reserved, IBinding* binding); - STDMETHOD(GetPriority)(LONG* priority); - STDMETHOD(OnLowResource)(DWORD reserved); STDMETHOD(OnProgress)(ULONG progress, ULONG progress_max, ULONG status_code, LPCWSTR status_text); - STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR error); - STDMETHOD(GetBindInfo)(DWORD* bindf, BINDINFO* bind_info); - STDMETHOD(OnDataAvailable)(DWORD bscf, DWORD size, FORMATETC* format_etc, + STDMETHOD(OnDataAvailable)(DWORD flags, DWORD size, FORMATETC* format_etc, STGMEDIUM* stgmed); - STDMETHOD(OnObjectAvailable)(REFIID iid, IUnknown* unk); - - // IBindStatusCallbackEx - STDMETHOD(GetBindInfoEx)(DWORD* bindf, BINDINFO* bind_info, DWORD* bindf2, - DWORD* reserved); - - // IHttpNegotiate - STDMETHOD(BeginningTransaction)(LPCWSTR url, LPCWSTR headers, DWORD reserved, - LPWSTR* additional_headers); - STDMETHOD(OnResponse)(DWORD response_code, LPCWSTR response_headers, - LPCWSTR request_headers, LPWSTR* additional_headers); + STDMETHOD(OnStopBinding)(HRESULT hresult, LPCWSTR error); - // IHttpNegotiate2 - STDMETHOD(GetRootSecurityId)(BYTE* security_id, DWORD* security_id_size, - DWORD_PTR reserved); + protected: + SniffData data_sniffer_; - // IHttpNegotiate3 - STDMETHOD(GetSerializedClientCertContext)(BYTE** cert, DWORD* cert_size); + // A structure to cache the progress notifications + struct Progress { + ULONG progress_; + ULONG progress_max_; + ULONG status_code_; + std::wstring status_text_; + }; - protected: - ScopedComPtr<IBindStatusCallback> delegate_; - ScopedComPtr<IBindCtx> bind_ctx_; - ScopedComPtr<SimpleBindingImpl, &GUID_NULL> binding_delegate_; - bool only_buffer_; - scoped_refptr<RequestData> data_; - std::wstring redirected_url_; + std::vector<Progress> saved_progress_; + CLIPFORMAT clip_format_; private: - DISALLOW_COPY_AND_ASSIGN(CFUrlmonBindStatusCallback); + DISALLOW_COPY_AND_ASSIGN(BSCBStorageBind); }; #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ - |