OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_URLMON_BIND_STATUS_CALLBACK_H_ | 5 #ifndef CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
6 #define CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ | 6 #define CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chrome_frame/bind_status_callback_impl.h" | 12 #include "chrome_frame/bind_status_callback_impl.h" |
13 #include "chrome_frame/stream_impl.h" | 13 #include "chrome_frame/stream_impl.h" |
14 | 14 |
15 | 15 |
16 // A fake stream class to serve cached data to arbitrary | 16 // A fake stream class to serve cached data to arbitrary |
17 // IBindStatusCallback | 17 // IBindStatusCallback |
18 class CacheStream : public CComObjectRoot, public StreamImpl { | 18 class CacheStream : public CComObjectRoot, public StreamImpl { |
19 public: | 19 public: |
20 BEGIN_COM_MAP(CacheStream) | 20 BEGIN_COM_MAP(CacheStream) |
21 COM_INTERFACE_ENTRY(IStream) | 21 COM_INTERFACE_ENTRY(IStream) |
22 COM_INTERFACE_ENTRY(ISequentialStream) | 22 COM_INTERFACE_ENTRY(ISequentialStream) |
23 END_COM_MAP() | 23 END_COM_MAP() |
24 | 24 |
25 CacheStream() : cache_(NULL), size_(0), position_(0), eof_(false) { | 25 CacheStream() : size_(0), position_(0), eof_(false) { |
26 } | 26 } |
27 HRESULT Initialize(const char* cache, size_t size, bool eof); | 27 HRESULT Initialize(const char* cache, size_t size, bool eof); |
28 static HRESULT BSCBFeedData(IBindStatusCallback* bscb, const char* data, | 28 static HRESULT BSCBFeedData(IBindStatusCallback* bscb, const char* data, |
29 size_t size, CLIPFORMAT clip_format, | 29 size_t size, CLIPFORMAT clip_format, |
30 size_t flags, bool eof); | 30 size_t flags, bool eof); |
31 | 31 |
32 // IStream overrides | 32 // IStream overrides |
33 STDMETHOD(Read)(void* pv, ULONG cb, ULONG* read); | 33 STDMETHOD(Read)(void* pv, ULONG cb, ULONG* read); |
34 | 34 |
35 protected: | 35 protected: |
36 scoped_ptr<char> cache_; | 36 scoped_ptr<char[]> cache_; |
37 size_t size_; | 37 size_t size_; |
38 size_t position_; | 38 size_t position_; |
39 bool eof_; | 39 bool eof_; |
40 | 40 |
41 private: | 41 private: |
42 DISALLOW_COPY_AND_ASSIGN(CacheStream); | 42 DISALLOW_COPY_AND_ASSIGN(CacheStream); |
43 }; | 43 }; |
44 | 44 |
45 // Utility class for data sniffing | 45 // Utility class for data sniffing |
46 class SniffData { | 46 class SniffData { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 protected: | 119 protected: |
120 SniffData data_sniffer_; | 120 SniffData data_sniffer_; |
121 | 121 |
122 // A structure to cache the progress notifications. | 122 // A structure to cache the progress notifications. |
123 class Progress { | 123 class Progress { |
124 public: | 124 public: |
125 Progress(ULONG progress, ULONG progress_max, ULONG status_code, | 125 Progress(ULONG progress, ULONG progress_max, ULONG status_code, |
126 const wchar_t* status_text) | 126 const wchar_t* status_text) |
127 : progress_(progress), | 127 : progress_(progress), |
128 progress_max_(progress_max), | 128 progress_max_(progress_max), |
129 status_code_(status_code), | 129 status_code_(status_code) { |
130 status_text_(NULL) { | |
131 if (status_text) { | 130 if (status_text) { |
132 int len = lstrlenW(status_text) + 1; | 131 int len = lstrlenW(status_text) + 1; |
133 status_text_.reset(new wchar_t[len]); | 132 status_text_.reset(new wchar_t[len]); |
134 if (status_text_.get()) { | 133 if (status_text_.get()) { |
135 lstrcpynW(status_text_.get(), status_text, len); | 134 lstrcpynW(status_text_.get(), status_text, len); |
136 } else { | 135 } else { |
137 NOTREACHED(); | 136 NOTREACHED(); |
138 } | 137 } |
139 } | 138 } |
140 } | 139 } |
(...skipping 17 matching lines...) Expand all Loading... |
158 return status_text_.get(); | 157 return status_text_.get(); |
159 } | 158 } |
160 | 159 |
161 protected: | 160 protected: |
162 ULONG progress_; | 161 ULONG progress_; |
163 ULONG progress_max_; | 162 ULONG progress_max_; |
164 ULONG status_code_; | 163 ULONG status_code_; |
165 // We don't use std::wstring here since we want to be able to play | 164 // We don't use std::wstring here since we want to be able to play |
166 // progress notifications back exactly as we got them. NULL and L"" are | 165 // progress notifications back exactly as we got them. NULL and L"" are |
167 // not equal. | 166 // not equal. |
168 scoped_ptr<wchar_t> status_text_; | 167 scoped_ptr<wchar_t[]> status_text_; |
169 }; | 168 }; |
170 | 169 |
171 typedef std::vector<Progress*> ProgressVector; | 170 typedef std::vector<Progress*> ProgressVector; |
172 ProgressVector saved_progress_; | 171 ProgressVector saved_progress_; |
173 CLIPFORMAT clip_format_; | 172 CLIPFORMAT clip_format_; |
174 | 173 |
175 private: | 174 private: |
176 DISALLOW_COPY_AND_ASSIGN(BSCBStorageBind); | 175 DISALLOW_COPY_AND_ASSIGN(BSCBStorageBind); |
177 }; | 176 }; |
178 | 177 |
179 #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ | 178 #endif // CHROME_FRAME_URLMON_BIND_STATUS_CALLBACK_H_ |
OLD | NEW |