| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ | 5 #ifndef CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ |
| 6 #define CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ | 6 #define CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ |
| 7 | 7 |
| 8 #include <exdisp.h> | 8 #include <exdisp.h> |
| 9 #include <urlmon.h> | 9 #include <urlmon.h> |
| 10 #include <atlbase.h> | 10 #include <atlbase.h> |
| 11 #include <atlcom.h> | 11 #include <atlcom.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/ref_counted.h" | 17 #include "base/ref_counted.h" |
| 18 #include "base/scoped_comptr_win.h" | 18 #include "base/scoped_comptr_win.h" |
| 19 #include "base/scoped_bstr_win.h" | 19 #include "base/scoped_bstr_win.h" |
| 20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 21 #include "chrome_frame/chrome_frame_delegate.h" | 21 #include "chrome_frame/chrome_frame_delegate.h" |
| 22 #include "chrome_frame/http_negotiate.h" |
| 22 #include "chrome_frame/ie8_types.h" | 23 #include "chrome_frame/ie8_types.h" |
| 23 #include "chrome_frame/utils.h" | 24 #include "chrome_frame/utils.h" |
| 24 #include "chrome_frame/vtable_patch_manager.h" | 25 #include "chrome_frame/vtable_patch_manager.h" |
| 25 | 26 |
| 26 // Typedefs for IInternetProtocol and related methods that we patch. | 27 // Typedefs for IInternetProtocol and related methods that we patch. |
| 27 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Start_Fn)( | 28 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Start_Fn)( |
| 28 IInternetProtocol* this_object, LPCWSTR url, | 29 IInternetProtocol* this_object, LPCWSTR url, |
| 29 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, | 30 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, |
| 30 DWORD flags, HANDLE_PTR reserved); | 31 DWORD flags, HANDLE_PTR reserved); |
| 31 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Read_Fn)( | 32 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Read_Fn)( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 53 // This is an alternative to a mime filter and we have to do this in order | 54 // This is an alternative to a mime filter and we have to do this in order |
| 54 // to inspect initial portion of HTML for 'chrome' meta tag and report | 55 // to inspect initial portion of HTML for 'chrome' meta tag and report |
| 55 // a different mime type in that case. | 56 // a different mime type in that case. |
| 56 // | 57 // |
| 57 // We implement several documented interfaces | 58 // We implement several documented interfaces |
| 58 // supported by the original sink provided by urlmon. There are a few | 59 // supported by the original sink provided by urlmon. There are a few |
| 59 // undocumented interfaces that we have chosen not to implement | 60 // undocumented interfaces that we have chosen not to implement |
| 60 // but delegate simply the QI. | 61 // but delegate simply the QI. |
| 61 class ProtocolSinkWrap | 62 class ProtocolSinkWrap |
| 62 : public CComObjectRootEx<CComMultiThreadModel>, | 63 : public CComObjectRootEx<CComMultiThreadModel>, |
| 64 public IServiceProvider, |
| 65 public UserAgentAddOn, // implements IHttpNegotiate |
| 63 public IInternetProtocolSink { | 66 public IInternetProtocolSink { |
| 64 public: | 67 public: |
| 65 | 68 |
| 66 BEGIN_COM_MAP(ProtocolSinkWrap) | 69 BEGIN_COM_MAP(ProtocolSinkWrap) |
| 70 COM_INTERFACE_ENTRY(IServiceProvider) |
| 67 COM_INTERFACE_ENTRY(IInternetProtocolSink) | 71 COM_INTERFACE_ENTRY(IInternetProtocolSink) |
| 68 COM_INTERFACE_BLIND_DELEGATE() | 72 COM_INTERFACE_BLIND_DELEGATE() |
| 69 END_COM_MAP() | 73 END_COM_MAP() |
| 70 | 74 |
| 71 static ScopedComPtr<IInternetProtocolSink> CreateNewSink( | 75 static ScopedComPtr<IInternetProtocolSink> CreateNewSink( |
| 72 IInternetProtocolSink* sink, ProtData* prot_data); | 76 IInternetProtocolSink* sink, ProtData* prot_data); |
| 73 | 77 |
| 74 // Apparently this has to be public, to satisfy COM_INTERFACE_BLIND_DELEGATE | 78 // Apparently this has to be public, to satisfy COM_INTERFACE_BLIND_DELEGATE |
| 75 IInternetProtocolSink* delegate() { | 79 IInternetProtocolSink* delegate() { |
| 76 return delegate_; | 80 return delegate_; |
| 77 } | 81 } |
| 78 | 82 |
| 79 protected: | 83 protected: |
| 80 ProtocolSinkWrap(); | 84 ProtocolSinkWrap(); |
| 81 ~ProtocolSinkWrap(); | 85 ~ProtocolSinkWrap(); |
| 82 | 86 |
| 83 private: | 87 private: |
| 84 // IInternetProtocolSink methods | 88 // IInternetProtocolSink methods |
| 85 STDMETHOD(Switch)(PROTOCOLDATA* protocol_data); | 89 STDMETHOD(Switch)(PROTOCOLDATA* protocol_data); |
| 86 STDMETHOD(ReportProgress)(ULONG status_code, LPCWSTR status_text); | 90 STDMETHOD(ReportProgress)(ULONG status_code, LPCWSTR status_text); |
| 87 STDMETHOD(ReportData)(DWORD flags, ULONG progress, ULONG max_progress); | 91 STDMETHOD(ReportData)(DWORD flags, ULONG progress, ULONG max_progress); |
| 88 STDMETHOD(ReportResult)(HRESULT result, DWORD error, LPCWSTR result_text); | 92 STDMETHOD(ReportResult)(HRESULT result, DWORD error, LPCWSTR result_text); |
| 89 | 93 |
| 94 // IServiceProvider - return our HttpNegotiate or forward to delegate |
| 95 STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void** ppvObject); |
| 96 |
| 97 // Helpers. |
| 98 HRESULT ObtainHttpNegotiate(); |
| 99 HRESULT ObtainServiceProvider(); |
| 100 |
| 90 // Remember original sink | 101 // Remember original sink |
| 91 ScopedComPtr<IInternetProtocolSink> delegate_; | 102 ScopedComPtr<IInternetProtocolSink> delegate_; |
| 103 ScopedComPtr<IServiceProvider> delegate_service_provider_; |
| 92 scoped_refptr<ProtData> prot_data_; | 104 scoped_refptr<ProtData> prot_data_; |
| 93 DISALLOW_COPY_AND_ASSIGN(ProtocolSinkWrap); | 105 DISALLOW_COPY_AND_ASSIGN(ProtocolSinkWrap); |
| 94 }; | 106 }; |
| 95 | 107 |
| 96 class ProtData : public base::RefCounted<ProtData> { | 108 class ProtData : public base::RefCounted<ProtData> { |
| 97 public: | 109 public: |
| 98 ProtData(IInternetProtocol* protocol, InternetProtocol_Read_Fn read_fun, | 110 ProtData(IInternetProtocol* protocol, InternetProtocol_Read_Fn read_fun, |
| 99 const wchar_t* url); | 111 const wchar_t* url); |
| 100 ~ProtData(); | 112 ~ProtData(); |
| 101 HRESULT Read(void* buffer, ULONG size, ULONG* size_read); | 113 HRESULT Read(void* buffer, ULONG size, ULONG* size_read); |
| 102 HRESULT ReportProgress(IInternetProtocolSink* delegate, | 114 HRESULT ReportProgress(IInternetProtocolSink* delegate, |
| 103 ULONG status_code, | 115 ULONG status_code, |
| 104 LPCWSTR status_text); | 116 LPCWSTR status_text); |
| 105 HRESULT ReportData(IInternetProtocolSink* delegate, | 117 HRESULT ReportData(IInternetProtocolSink* delegate, |
| 106 DWORD flags, ULONG progress, ULONG max_progress); | 118 DWORD flags, ULONG progress, ULONG max_progress); |
| 107 HRESULT ReportResult(IInternetProtocolSink* delegate, HRESULT result, | 119 HRESULT ReportResult(IInternetProtocolSink* delegate, HRESULT result, |
| 108 DWORD error, LPCWSTR result_text); | 120 DWORD error, LPCWSTR result_text); |
| 109 void UpdateUrl(const wchar_t* url); | 121 void UpdateUrl(const wchar_t* url); |
| 110 static scoped_refptr<ProtData> DataFromProtocol(IInternetProtocol* protocol); | 122 static scoped_refptr<ProtData> DataFromProtocol(IInternetProtocol* protocol); |
| 111 | 123 |
| 112 RendererType renderer_type() { | 124 RendererType renderer_type() { |
| 113 return renderer_type_; | 125 return renderer_type_; |
| 114 } | 126 } |
| 115 | 127 |
| 128 // Valid only if renderer_type_ is CHROME. |
| 129 const std::string& referrer() const { |
| 130 return referrer_; |
| 131 } |
| 132 |
| 116 private: | 133 private: |
| 117 typedef std::map<IInternetProtocol*, ProtData*> ProtocolDataMap; | 134 typedef std::map<IInternetProtocol*, ProtData*> ProtocolDataMap; |
| 118 static ProtocolDataMap datamap_; | 135 static ProtocolDataMap datamap_; |
| 119 static Lock datamap_lock_; | 136 static Lock datamap_lock_; |
| 120 | 137 |
| 121 // Url we are retrieving. Used for IsOptInUrl() only. | 138 // Url we are retrieving. Used for IsOptInUrl() only. |
| 122 std::wstring url_; | 139 std::wstring url_; |
| 140 // HTTP "Referrer" header if we detect are going to switch. |
| 141 // We have to save and pass it to Chrome, so scripts can read it via DOM. |
| 142 std::string referrer_; |
| 143 |
| 123 // Our gate to IInternetProtocol::Read() | 144 // Our gate to IInternetProtocol::Read() |
| 124 IInternetProtocol* protocol_; | 145 IInternetProtocol* protocol_; |
| 125 InternetProtocol_Read_Fn read_fun_; | 146 InternetProtocol_Read_Fn read_fun_; |
| 126 | 147 |
| 127 // What BINDSTATUS_MIMETYPEAVAILABLE and Co. tells us. | 148 // What BINDSTATUS_MIMETYPEAVAILABLE and Co. tells us. |
| 128 ScopedBstr suggested_mime_type_; | 149 ScopedBstr suggested_mime_type_; |
| 129 // At least one of the following has been received: | 150 // At least one of the following has been received: |
| 130 // BINDSTATUS_MIMETYPEAVAILABLE, | 151 // BINDSTATUS_MIMETYPEAVAILABLE, |
| 131 // MIMESTATUS_VERIFIEDMIMETYPEAVAILABLE | 152 // MIMESTATUS_VERIFIEDMIMETYPEAVAILABLE |
| 132 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE | 153 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE |
| 133 bool has_suggested_mime_type_; | 154 bool has_suggested_mime_type_; |
| 134 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE received, so we shall fire one. | 155 // BINDSTATUS_SERVER_MIMETYPEAVAILABLE received, so we shall fire one. |
| 135 bool has_server_mime_type_; | 156 bool has_server_mime_type_; |
| 136 | 157 |
| 137 RendererType renderer_type_; | 158 RendererType renderer_type_; |
| 138 | 159 |
| 139 // Buffer for accumulated data including 1 extra for NULL-terminator | 160 // Buffer for accumulated data including 1 extra for NULL-terminator |
| 140 static const size_t kMaxContentSniffLength = 2 * 1024; | 161 static const size_t kMaxContentSniffLength = 2 * 1024; |
| 141 char buffer_[kMaxContentSniffLength + 1]; | 162 char buffer_[kMaxContentSniffLength + 1]; |
| 142 unsigned long buffer_size_; // NOLINT | 163 unsigned long buffer_size_; // NOLINT |
| 143 unsigned long buffer_pos_; // NOLINT | 164 unsigned long buffer_pos_; // NOLINT |
| 144 | 165 |
| 145 HRESULT FillBuffer(); | 166 HRESULT FillBuffer(); |
| 146 void SaveSuggestedMimeType(LPCWSTR status_text); | 167 void SaveSuggestedMimeType(LPCWSTR status_text); |
| 147 void FireSugestedMimeType(IInternetProtocolSink* delegate); | 168 void FireSugestedMimeType(IInternetProtocolSink* delegate); |
| 169 void SaveReferrer(IInternetProtocolSink* delegate); |
| 148 }; | 170 }; |
| 149 | 171 |
| 150 struct TransactionHooks { | 172 struct TransactionHooks { |
| 151 void InstallHooks(); | 173 void InstallHooks(); |
| 152 void RevertHooks(); | 174 void RevertHooks(); |
| 153 }; | 175 }; |
| 154 | 176 |
| 155 DECLSPEC_SELECTANY struct TransactionHooks g_trans_hooks; | 177 DECLSPEC_SELECTANY struct TransactionHooks g_trans_hooks; |
| 156 | 178 |
| 157 #endif // CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ | 179 #endif // CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ |
| 158 | 180 |
| OLD | NEW |