Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome_frame/protocol_sink_wrap.h

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/precompiled.cc ('k') | chrome_frame/protocol_sink_wrap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_FRAME_PROTOCOL_SINK_WRAP_H_
6 #define CHROME_FRAME_PROTOCOL_SINK_WRAP_H_
7
8 #include <exdisp.h>
9 #include <urlmon.h>
10 #include <atlbase.h>
11 #include <atlcom.h>
12 #include <map>
13 #include <string>
14
15 #include "base/basictypes.h"
16 #include "base/ref_counted.h"
17 #include "base/scoped_comptr_win.h"
18 #include "googleurl/src/gurl.h"
19 #include "chrome_frame/ie8_types.h"
20
21 // Typedefs for IInternetProtocol and related methods that we patch.
22 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Start_Fn)(
23 IInternetProtocol* this_object, LPCWSTR url,
24 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info,
25 DWORD flags, HANDLE_PTR reserved);
26 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_Read_Fn)(
27 IInternetProtocol* this_object, void* buffer, ULONG size,
28 ULONG* size_read);
29 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocol_StartEx_Fn)(
30 IInternetProtocolEx* this_object, IUri* uri,
31 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info,
32 DWORD flags, HANDLE_PTR reserved);
33 typedef HRESULT (STDMETHODCALLTYPE* InternetProtocolRoot_Continue_Fn)(
34 IInternetProtocolRoot* me, PROTOCOLDATA* data);
35
36 // A class to wrap protocol sink in IInternetProtocol::Start[Ex] for
37 // HTTP and HTTPS protocols.
38 //
39 // This is an alternative to a mime filter and we have to do this in order
40 // to inspect initial portion of HTML for 'chrome' meta tag and report
41 // a different mime type in that case.
42 //
43 // We implement several documented interfaces
44 // supported by the original sink provided by urlmon. There are a few
45 // undocumented interfaces that we have chosen not to implement
46 // but delegate simply the QI.
47 class ProtocolSinkWrap
48 : public CComObjectRootEx<CComMultiThreadModel>,
49 public IInternetProtocolSink,
50 public IInternetBindInfoEx,
51 public IServiceProvider,
52 public IAuthenticate,
53 public IInternetProtocolEx,
54 public IInternetPriority,
55 public IWrappedProtocol,
56 // public IPreBindingSupport, // undocumented
57 // public ITransProtocolSink, // Undocumented
58 // public ITransactionInternal, // undocumented
59 public IUriContainer {
60 public:
61
62 #define COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(x) \
63 COM_INTERFACE_ENTRY_FUNC(_ATL_IIDOF(x), \
64 offsetofclass(x, _ComMapClass), \
65 IfDelegateSupports)
66
67 BEGIN_COM_MAP(ProtocolSinkWrap)
68 COM_INTERFACE_ENTRY(IInternetProtocolSink)
69 COM_INTERFACE_ENTRY(IInternetBindInfo)
70 COM_INTERFACE_ENTRY(IInternetBindInfoEx)
71 COM_INTERFACE_ENTRY(IServiceProvider)
72 COM_INTERFACE_ENTRY(IAuthenticate)
73 COM_INTERFACE_ENTRY(IInternetProtocolRoot)
74 COM_INTERFACE_ENTRY(IInternetProtocol)
75 COM_INTERFACE_ENTRY(IInternetProtocolEx)
76 COM_INTERFACE_ENTRY(IInternetPriority)
77 COM_INTERFACE_ENTRY(IWrappedProtocol)
78 COM_INTERFACE_ENTRY_IF_DELEGATE_SUPPORTS(IUriContainer)
79 COM_INTERFACE_ENTRY_FUNC_BLIND(0, CheckOutgoingInterface)
80 END_COM_MAP()
81
82 ProtocolSinkWrap();
83 virtual ~ProtocolSinkWrap();
84
85 bool Initialize(IInternetProtocol* protocol,
86 IInternetProtocolSink* original_sink, const wchar_t* url);
87
88 static bool PatchProtocolHandler(const wchar_t* dll,
89 const CLSID& handler_clsid);
90
91 // IInternetProtocol/Ex patches.
92 static HRESULT STDMETHODCALLTYPE OnStart(InternetProtocol_Start_Fn orig_start,
93 IInternetProtocol* protocol, LPCWSTR url,
94 IInternetProtocolSink* prot_sink, IInternetBindInfo* bind_info,
95 DWORD flags, HANDLE_PTR reserved);
96
97 static HRESULT STDMETHODCALLTYPE OnStartEx(
98 InternetProtocol_StartEx_Fn orig_start_ex, IInternetProtocolEx* protocol,
99 IUri* uri, IInternetProtocolSink* prot_sink,
100 IInternetBindInfo* bind_info, DWORD flags, HANDLE_PTR reserved);
101
102 static HRESULT STDMETHODCALLTYPE OnRead(InternetProtocol_Read_Fn orig_read,
103 IInternetProtocol* protocol, void* buffer, ULONG size, ULONG* size_read);
104
105 // IInternetProtocolSink methods
106 STDMETHOD(Switch)(PROTOCOLDATA* protocol_data);
107 STDMETHOD(ReportProgress)(ULONG status_code, LPCWSTR status_text);
108 STDMETHOD(ReportData)(DWORD flags, ULONG progress, ULONG max_progress);
109 STDMETHOD(ReportResult)(HRESULT result, DWORD error, LPCWSTR result_text);
110
111 // IInternetBindInfoEx
112 STDMETHOD(GetBindInfo)(DWORD* flags, BINDINFO* bind_info);
113 STDMETHOD(GetBindString)(ULONG string_type, LPOLESTR* string_array,
114 ULONG array_size, ULONG* size_returned);
115 STDMETHOD(GetBindInfoEx)(DWORD *flags, BINDINFO* bind_info,
116 DWORD* bindf2, DWORD *reserved);
117
118 // IServiceProvider
119 STDMETHOD(QueryService)(REFGUID service_guid, REFIID riid, void** service);
120
121 // IAuthenticate
122 STDMETHOD(Authenticate)(HWND* window, LPWSTR* user_name, LPWSTR* password);
123
124 // IInternetProtocolEx
125 STDMETHOD(Start)(LPCWSTR url, IInternetProtocolSink *protocol_sink,
126 IInternetBindInfo* bind_info, DWORD flags, HANDLE_PTR reserved);
127 STDMETHOD(Continue)(PROTOCOLDATA* protocol_data);
128 STDMETHOD(Abort)(HRESULT reason, DWORD options);
129 STDMETHOD(Terminate)(DWORD options);
130 STDMETHOD(Suspend)();
131 STDMETHOD(Resume)();
132 STDMETHOD(Read)(void *buffer, ULONG size, ULONG* size_read);
133 STDMETHOD(Seek)(LARGE_INTEGER move, DWORD origin, ULARGE_INTEGER* new_pos);
134 STDMETHOD(LockRequest)(DWORD options);
135 STDMETHOD(UnlockRequest)();
136 STDMETHOD(StartEx)(IUri* uri, IInternetProtocolSink* protocol_sink,
137 IInternetBindInfo* bind_info, DWORD flags, HANDLE_PTR reserved);
138
139 // IInternetPriority
140 STDMETHOD(SetPriority)(LONG priority);
141 STDMETHOD(GetPriority)(LONG* priority);
142
143 // IWrappedProtocol
144 STDMETHOD(GetWrapperCode)(LONG *code, DWORD_PTR reserved);
145
146 // public IUriContainer
147 STDMETHOD(GetIUri)(IUri** uri);
148
149 // IPreBindingSupport, // undocumented
150 // ITransProtocolSink, // Undocumented
151 // ITransactionInternal, // undocumented
152
153 protected:
154 enum RendererType {
155 UNDETERMINED,
156 CHROME,
157 OTHER
158 };
159
160 typedef std::map<IInternetProtocol*, ProtocolSinkWrap*> ProtocolSinkMap;
161 static const int kMaxContentSniffLength = 1024;
162
163 static scoped_refptr<ProtocolSinkWrap> InstanceFromProtocol(
164 IInternetProtocol* protocol);
165 static HRESULT WebBrowserFromProtocolSink(IInternetProtocolSink* sink,
166 IWebBrowser2** web_browser);
167 static ScopedComPtr<IInternetProtocolSink> MaybeWrapSink(
168 IInternetProtocol* protocol, IInternetProtocolSink* prot_sink,
169 const wchar_t* url);
170 static HRESULT WINAPI CheckOutgoingInterface(void* obj, REFIID iid,
171 LPVOID* ret, DWORD cookie);
172 static HRESULT WINAPI IfDelegateSupports(void* obj, REFIID iid,
173 LPVOID* ret, DWORD cookie);
174
175 void DetermineRendererType();
176 HRESULT OnReadImpl(void* buffer, ULONG size, ULONG* size_read,
177 InternetProtocol_Read_Fn orig_read);
178
179 bool is_undetermined() const {
180 return (UNDETERMINED == renderer_type_);
181 }
182 RendererType renderer_type() const {
183 return renderer_type_;
184 }
185
186 // WARNING: Don't use GURL variables here. Please see
187 // http://b/issue?id=2102171 for details.
188
189 // Remember original sink
190 CComPtr<IInternetProtocolSink> delegate_;
191 // Cannot take a reference on the protocol.
192 IInternetProtocol* protocol_;
193 RendererType renderer_type_;
194
195 // Buffer for accumulated data including 1 extra for NULL-terminator
196 char buffer_[kMaxContentSniffLength + 1];
197 unsigned long buffer_size_;
198 unsigned long buffer_pos_;
199
200 // Accumulated result
201 bool is_saved_result_;
202 HRESULT result_code_;
203 DWORD result_error_;
204 std::wstring result_text_;
205 // For tracking re-entrency and preventing duplicate Read()s from
206 // distorting the outcome of ReportData.
207 int report_data_recursiveness_;
208
209 static ProtocolSinkMap sink_map_;
210 // TODO(joshia): Replace with Lock
211 static CComAutoCriticalSection sink_map_lock_;
212
213 std::wstring url_;
214
215 private:
216 DISALLOW_COPY_AND_ASSIGN(ProtocolSinkWrap);
217 };
218
219
220 #endif // CHROME_FRAME_PROTOCOL_SINK_WRAP_H_
221
OLDNEW
« no previous file with comments | « chrome_frame/precompiled.cc ('k') | chrome_frame/protocol_sink_wrap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698