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 #include <map> | 13 #include <map> |
13 #include <string> | 14 #include <string> |
14 | 15 |
15 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
16 #include "base/ref_counted.h" | 17 #include "base/ref_counted.h" |
17 #include "base/scoped_comptr_win.h" | 18 #include "base/scoped_comptr_win.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "chrome_frame/ie8_types.h" | 20 #include "chrome_frame/ie8_types.h" |
| 21 #include "chrome_frame/utils.h" |
20 #include "chrome_frame/vtable_patch_manager.h" | 22 #include "chrome_frame/vtable_patch_manager.h" |
21 | 23 |
22 // Typedefs for IInternetProtocol and related methods that we patch. | 24 // Typedefs for IInternetProtocol and related methods that we patch. |
23 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Start_Fn)( | 25 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Start_Fn)( |
24 IInternetProtocol* this_object, LPCWSTR url, | 26 IInternetProtocol* this_object, LPCWSTR url, |
25 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, | 27 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, |
26 DWORD flags, HANDLE_PTR reserved); | 28 DWORD flags, HANDLE_PTR reserved); |
27 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Read_Fn)( | 29 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Read_Fn)( |
28 IInternetProtocol* this_object, void* buffer, ULONG size, | 30 IInternetProtocol* this_object, void* buffer, ULONG size, |
29 ULONG* size_read); | 31 ULONG* size_read); |
(...skipping 23 matching lines...) Expand all Loading... |
53 public IAuthenticate, | 55 public IAuthenticate, |
54 public IInternetProtocolEx, | 56 public IInternetProtocolEx, |
55 public IInternetPriority, | 57 public IInternetPriority, |
56 public IWrappedProtocol, | 58 public IWrappedProtocol, |
57 // public IPreBindingSupport, // undocumented | 59 // public IPreBindingSupport, // undocumented |
58 // public ITransProtocolSink, // Undocumented | 60 // public ITransProtocolSink, // Undocumented |
59 // public ITransactionInternal, // undocumented | 61 // public ITransactionInternal, // undocumented |
60 public IUriContainer { | 62 public IUriContainer { |
61 public: | 63 public: |
62 | 64 |
63 #define COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(x) \ | |
64 COM_INTERFACE_ENTRY_FUNC(_ATL_IIDOF(x), \ | |
65 offsetofclass(x, _ComMapClass), \ | |
66 IfDelegateSupports) | |
67 | |
68 BEGIN_COM_MAP(ProtocolSinkWrap) | 65 BEGIN_COM_MAP(ProtocolSinkWrap) |
69 COM_INTERFACE_ENTRY(IInternetProtocolSink) | 66 COM_INTERFACE_ENTRY(IInternetProtocolSink) |
70 COM_INTERFACE_ENTRY(IInternetBindInfo) | 67 COM_INTERFACE_ENTRY(IInternetBindInfo) |
71 COM_INTERFACE_ENTRY(IInternetBindInfoEx) | 68 COM_INTERFACE_ENTRY(IInternetBindInfoEx) |
72 COM_INTERFACE_ENTRY(IServiceProvider) | 69 COM_INTERFACE_ENTRY(IServiceProvider) |
73 COM_INTERFACE_ENTRY(IAuthenticate) | 70 COM_INTERFACE_ENTRY(IAuthenticate) |
74 COM_INTERFACE_ENTRY(IInternetProtocolRoot) | 71 COM_INTERFACE_ENTRY(IInternetProtocolRoot) |
75 COM_INTERFACE_ENTRY(IInternetProtocol) | 72 COM_INTERFACE_ENTRY(IInternetProtocol) |
76 COM_INTERFACE_ENTRY(IInternetProtocolEx) | 73 COM_INTERFACE_ENTRY(IInternetProtocolEx) |
77 COM_INTERFACE_ENTRY(IInternetPriority) | 74 COM_INTERFACE_ENTRY(IInternetPriority) |
78 COM_INTERFACE_ENTRY(IWrappedProtocol) | 75 COM_INTERFACE_ENTRY(IWrappedProtocol) |
79 COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IUriContainer) | 76 COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IUriContainer) |
80 COM_INTERFACE_ENTRY_FUNC_BLIND(0, CheckOutgoingInterface) | 77 COM_INTERFACE_BLIND_DELEGATE() |
81 END_COM_MAP() | 78 END_COM_MAP() |
82 | 79 |
83 ProtocolSinkWrap(); | 80 ProtocolSinkWrap(); |
84 virtual ~ProtocolSinkWrap(); | 81 virtual ~ProtocolSinkWrap(); |
85 | 82 |
86 bool Initialize(IInternetProtocol* protocol, | 83 bool Initialize(IInternetProtocol* protocol, |
87 IInternetProtocolSink* original_sink, const wchar_t* url); | 84 IInternetProtocolSink* original_sink, const wchar_t* url); |
88 | 85 |
89 // VTable patches the IInternetProtocol and IIntenetProtocolEx interface. | 86 // VTable patches the IInternetProtocol and IIntenetProtocolEx interface. |
90 // Returns true on success. | 87 // Returns true on success. |
91 static bool PatchProtocolHandlers(); | 88 static bool PatchProtocolHandlers(); |
92 | 89 |
93 // Unpatches the IInternetProtocol and IInternetProtocolEx interfaces. | 90 // Unpatches the IInternetProtocol and IInternetProtocolEx interfaces. |
94 static void UnpatchProtocolHandlers(); | 91 static void UnpatchProtocolHandlers(); |
95 | 92 |
96 // IInternetProtocol/Ex patches. | 93 // IInternetProtocol/Ex patches. |
97 static HRESULT STDMETHODCALLTYPE OnStart(InternetProtocol_Start_Fn orig_start, | 94 static STDMETHODIMP OnStart(InternetProtocol_Start_Fn orig_start, |
98 IInternetProtocol* protocol, LPCWSTR url, | 95 IInternetProtocol* protocol, LPCWSTR url, |
99 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, | 96 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info, |
100 DWORD flags, HANDLE_PTR reserved); | 97 DWORD flags, HANDLE_PTR reserved); |
101 | 98 |
102 static HRESULT STDMETHODCALLTYPE OnStartEx( | 99 static STDMETHODIMP OnStartEx( |
103 InternetProtocol_StartEx_Fn orig_start_ex, IInternetProtocolEx* protocol, | 100 InternetProtocol_StartEx_Fn orig_start_ex, IInternetProtocolEx* protocol, |
104 IUri* uri, IInternetProtocolSink* prot_sink, | 101 IUri* uri, IInternetProtocolSink* prot_sink, |
105 IInternetBindInfo* bind_info, DWORD flags, HANDLE_PTR reserved); | 102 IInternetBindInfo* bind_info, DWORD flags, HANDLE_PTR reserved); |
106 | 103 |
107 static HRESULT STDMETHODCALLTYPE OnRead(InternetProtocol_Read_Fn orig_read, | 104 static STDMETHODIMP OnRead(InternetProtocol_Read_Fn orig_read, |
108 IInternetProtocol* protocol, void* buffer, ULONG size, ULONG* size_read); | 105 IInternetProtocol* protocol, void* buffer, ULONG size, ULONG* size_read); |
109 | 106 |
110 // IInternetProtocolSink methods | 107 // IInternetProtocolSink methods |
111 STDMETHOD(Switch)(PROTOCOLDATA* protocol_data); | 108 STDMETHOD(Switch)(PROTOCOLDATA* protocol_data); |
112 STDMETHOD(ReportProgress)(ULONG status_code, LPCWSTR status_text); | 109 STDMETHOD(ReportProgress)(ULONG status_code, LPCWSTR status_text); |
113 STDMETHOD(ReportData)(DWORD flags, ULONG progress, ULONG max_progress); | 110 STDMETHOD(ReportData)(DWORD flags, ULONG progress, ULONG max_progress); |
114 STDMETHOD(ReportResult)(HRESULT result, DWORD error, LPCWSTR result_text); | 111 STDMETHOD(ReportResult)(HRESULT result, DWORD error, LPCWSTR result_text); |
115 | 112 |
116 // IInternetBindInfoEx | 113 // IInternetBindInfoEx |
117 STDMETHOD(GetBindInfo)(DWORD* flags, BINDINFO* bind_info); | 114 STDMETHOD(GetBindInfo)(DWORD* flags, BINDINFO* bind_info); |
(...skipping 30 matching lines...) Expand all Loading... |
148 // IWrappedProtocol | 145 // IWrappedProtocol |
149 STDMETHOD(GetWrapperCode)(LONG *code, DWORD_PTR reserved); | 146 STDMETHOD(GetWrapperCode)(LONG *code, DWORD_PTR reserved); |
150 | 147 |
151 // public IUriContainer | 148 // public IUriContainer |
152 STDMETHOD(GetIUri)(IUri** uri); | 149 STDMETHOD(GetIUri)(IUri** uri); |
153 | 150 |
154 // IPreBindingSupport, // undocumented | 151 // IPreBindingSupport, // undocumented |
155 // ITransProtocolSink, // Undocumented | 152 // ITransProtocolSink, // Undocumented |
156 // ITransactionInternal, // undocumented | 153 // ITransactionInternal, // undocumented |
157 | 154 |
| 155 IInternetProtocolSink* delegate() const { |
| 156 return delegate_; |
| 157 } |
| 158 |
158 protected: | 159 protected: |
159 enum RendererType { | 160 enum RendererType { |
160 UNDETERMINED, | 161 UNDETERMINED, |
161 CHROME, | 162 CHROME, |
162 OTHER | 163 OTHER |
163 }; | 164 }; |
164 | 165 |
165 typedef std::map<IInternetProtocol*, ProtocolSinkWrap*> ProtocolSinkMap; | 166 typedef std::map<IInternetProtocol*, ProtocolSinkWrap*> ProtocolSinkMap; |
166 static const int kMaxContentSniffLength = 1024; | 167 static const int kMaxContentSniffLength = 1024; |
167 | 168 |
168 static scoped_refptr<ProtocolSinkWrap> InstanceFromProtocol( | 169 static scoped_refptr<ProtocolSinkWrap> InstanceFromProtocol( |
169 IInternetProtocol* protocol); | 170 IInternetProtocol* protocol); |
170 static HRESULT WebBrowserFromProtocolSink(IInternetProtocolSink* sink, | 171 static HRESULT WebBrowserFromProtocolSink(IInternetProtocolSink* sink, |
171 IWebBrowser2** web_browser); | 172 IWebBrowser2** web_browser); |
172 static ScopedComPtr<IInternetProtocolSink> MaybeWrapSink( | 173 static ScopedComPtr<IInternetProtocolSink> MaybeWrapSink( |
173 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, | 174 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink, |
174 const wchar_t* url); | 175 const wchar_t* url); |
175 static HRESULT WINAPI CheckOutgoingInterface(void* obj, REFIID iid, | |
176 LPVOID* ret, DWORD cookie); | |
177 static HRESULT WINAPI IfDelegateSupports(void* obj, REFIID iid, | |
178 LPVOID* ret, DWORD cookie); | |
179 | 176 |
180 void DetermineRendererType(); | 177 void DetermineRendererType(); |
181 HRESULT OnReadImpl(void* buffer, ULONG size, ULONG* size_read, | 178 HRESULT OnReadImpl(void* buffer, ULONG size, ULONG* size_read, |
182 InternetProtocol_Read_Fn orig_read); | 179 InternetProtocol_Read_Fn orig_read); |
183 | 180 |
184 bool is_undetermined() const { | 181 bool is_undetermined() const { |
185 return (UNDETERMINED == renderer_type_); | 182 return (UNDETERMINED == renderer_type_); |
186 } | 183 } |
187 RendererType renderer_type() const { | 184 RendererType renderer_type() const { |
188 return renderer_type_; | 185 return renderer_type_; |
(...skipping 11 matching lines...) Expand all Loading... |
200 // Returns S_OK on success. | 197 // Returns S_OK on success. |
201 static HRESULT PatchProtocolMethods( | 198 static HRESULT PatchProtocolMethods( |
202 const CLSID& protocol_clsid, | 199 const CLSID& protocol_clsid, |
203 vtable_patch::MethodPatchInfo* protocol_patch_info, | 200 vtable_patch::MethodPatchInfo* protocol_patch_info, |
204 vtable_patch::MethodPatchInfo* protocol_ex_patch_info); | 201 vtable_patch::MethodPatchInfo* protocol_ex_patch_info); |
205 | 202 |
206 // WARNING: Don't use GURL variables here. Please see | 203 // WARNING: Don't use GURL variables here. Please see |
207 // http://b/issue?id=2102171 for details. | 204 // http://b/issue?id=2102171 for details. |
208 | 205 |
209 // Remember original sink | 206 // Remember original sink |
210 CComPtr<IInternetProtocolSink> delegate_; | 207 ScopedComPtr<IInternetProtocolSink> delegate_; |
| 208 |
211 // Cannot take a reference on the protocol. | 209 // Cannot take a reference on the protocol. |
212 IInternetProtocol* protocol_; | 210 IInternetProtocol* protocol_; |
213 RendererType renderer_type_; | 211 RendererType renderer_type_; |
214 | 212 |
215 // Buffer for accumulated data including 1 extra for NULL-terminator | 213 // Buffer for accumulated data including 1 extra for NULL-terminator |
216 char buffer_[kMaxContentSniffLength + 1]; | 214 char buffer_[kMaxContentSniffLength + 1]; |
217 unsigned long buffer_size_; | 215 unsigned long buffer_size_; // NOLINT |
218 unsigned long buffer_pos_; | 216 unsigned long buffer_pos_; // NOLINT |
219 | 217 |
220 // Accumulated result | 218 // Accumulated result |
221 bool is_saved_result_; | 219 bool is_saved_result_; |
222 HRESULT result_code_; | 220 HRESULT result_code_; |
223 DWORD result_error_; | 221 DWORD result_error_; |
224 std::wstring result_text_; | 222 std::wstring result_text_; |
225 // For tracking re-entrency and preventing duplicate Read()s from | 223 // For tracking re-entrency and preventing duplicate Read()s from |
226 // distorting the outcome of ReportData. | 224 // distorting the outcome of ReportData. |
227 int report_data_recursiveness_; | 225 int report_data_recursiveness_; |
228 | 226 |
229 static ProtocolSinkMap sink_map_; | 227 static ProtocolSinkMap sink_map_; |
230 // TODO(joshia): Replace with Lock | 228 // TODO(joshia): Replace with Lock |
231 static CComAutoCriticalSection sink_map_lock_; | 229 static CComAutoCriticalSection sink_map_lock_; |
232 | 230 |
233 std::wstring url_; | 231 std::wstring url_; |
234 | 232 |
235 private: | 233 private: |
236 DISALLOW_COPY_AND_ASSIGN(ProtocolSinkWrap); | 234 DISALLOW_COPY_AND_ASSIGN(ProtocolSinkWrap); |
237 }; | 235 }; |
238 | 236 |
239 | |
240 #endif // CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ | 237 #endif // CHROME_FRAME_PROTOCOL_SINK_WRAP_H_ |
241 | |
OLD | NEW |