[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | #include "chrome_frame/urlmon_bind_status_callback.h" |
| 6 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 7 | #include <mshtml.h> |
[email protected] | fb716b30 | 2010-03-26 02:45:20 | [diff] [blame] | 8 | #include <shlguid.h> |
| 9 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 10 | #include "base/logging.h" |
| 11 | #include "base/string_util.h" |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 12 | #include "base/utf_string_conversions.h" |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 13 | |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 14 | #include "chrome_frame/bind_context_info.h" |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 15 | #include "chrome_frame/urlmon_moniker.h" |
| 16 | #include "chrome_tab.h" // NOLINT |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 17 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 18 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 19 | // A helper to given feed data to the specified |bscb| using |
| 20 | // CacheStream instance. |
| 21 | HRESULT CacheStream::BSCBFeedData(IBindStatusCallback* bscb, const char* data, |
| 22 | size_t size, CLIPFORMAT clip_format, |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 23 | size_t flags, bool eof) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 24 | if (!bscb) { |
| 25 | NOTREACHED() << "invalid IBindStatusCallback"; |
| 26 | return E_INVALIDARG; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 27 | } |
| 28 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 29 | // We can't use a CComObjectStackEx here since mshtml will hold |
| 30 | // onto the stream pointer. |
| 31 | CComObject<CacheStream>* cache_stream = NULL; |
| 32 | HRESULT hr = CComObject<CacheStream>::CreateInstance(&cache_stream); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 33 | if (FAILED(hr)) { |
| 34 | NOTREACHED(); |
| 35 | return hr; |
| 36 | } |
| 37 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 38 | cache_stream->AddRef(); |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 39 | cache_stream->Initialize(data, size, eof); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 40 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 41 | FORMATETC format_etc = { clip_format, NULL, DVASPECT_CONTENT, -1, |
| 42 | TYMED_ISTREAM }; |
| 43 | STGMEDIUM medium = {0}; |
| 44 | medium.tymed = TYMED_ISTREAM; |
| 45 | medium.pstm = cache_stream; |
| 46 | |
| 47 | hr = bscb->OnDataAvailable(flags, size, &format_etc, &medium); |
| 48 | |
| 49 | cache_stream->Release(); |
| 50 | return hr; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 53 | void CacheStream::Initialize(const char* cache, size_t size, bool eof) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 54 | cache_ = cache; |
| 55 | size_ = size; |
| 56 | position_ = 0; |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 57 | eof_ = eof; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 58 | } |
| 59 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 60 | // Read is the only call that we expect. Return E_PENDING if there |
| 61 | // is no more data to serve. Otherwise this will result in a |
| 62 | // read with 0 bytes indicating that no more data is available. |
| 63 | STDMETHODIMP CacheStream::Read(void* pv, ULONG cb, ULONG* read) { |
| 64 | if (!pv || !read) |
| 65 | return E_INVALIDARG; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 66 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 67 | // Default to E_PENDING to signal that this is a partial data. |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 68 | HRESULT hr = eof_ ? S_FALSE : E_PENDING; |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 69 | if (position_ < size_) { |
| 70 | *read = std::min(size_ - position_, size_t(cb)); |
| 71 | memcpy(pv, cache_ + position_, *read); |
| 72 | position_ += *read; |
| 73 | hr = S_OK; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 74 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 75 | |
| 76 | return hr; |
| 77 | } |
| 78 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 79 | |
| 80 | ///////////////////////////////////////////////////////////////////// |
| 81 | |
[email protected] | 040b800f | 2010-05-05 23:46:30 | [diff] [blame] | 82 | HRESULT SniffData::InitializeCache(const std::wstring& url) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 83 | url_ = url; |
| 84 | renderer_type_ = UNDETERMINED; |
| 85 | |
[email protected] | 040b800f | 2010-05-05 23:46:30 | [diff] [blame] | 86 | const int kInitialSize = 4 * 1024; // 4K |
| 87 | HGLOBAL mem = GlobalAlloc(0, kInitialSize); |
| 88 | DCHECK(mem) << "GlobalAlloc failed: " << GetLastError(); |
| 89 | |
| 90 | HRESULT hr = CreateStreamOnHGlobal(mem, TRUE, cache_.Receive()); |
[email protected] | b31b9ff | 2010-05-07 18:29:24 | [diff] [blame^] | 91 | if (SUCCEEDED(hr)) { |
| 92 | ULARGE_INTEGER size = {0}; |
| 93 | cache_->SetSize(size); |
| 94 | } else { |
| 95 | DLOG(ERROR) << "CreateStreamOnHGlobal failed: " << hr; |
| 96 | } |
| 97 | |
[email protected] | 040b800f | 2010-05-05 23:46:30 | [diff] [blame] | 98 | return hr; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 99 | } |
| 100 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 101 | HRESULT SniffData::ReadIntoCache(IStream* stream, bool force_determination) { |
| 102 | if (!stream) { |
| 103 | NOTREACHED(); |
| 104 | return E_INVALIDARG; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 105 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 106 | |
| 107 | HRESULT hr = S_OK; |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 108 | while (SUCCEEDED(hr)) { |
| 109 | const size_t kChunkSize = 4 * 1024; |
| 110 | char buffer[kChunkSize]; |
| 111 | DWORD read = 0; |
| 112 | hr = stream->Read(buffer, sizeof(buffer), &read); |
| 113 | if (read) { |
| 114 | DWORD written = 0; |
| 115 | cache_->Write(buffer, read, &written); |
| 116 | size_ += written; |
[email protected] | fb716b30 | 2010-03-26 02:45:20 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 119 | if ((S_FALSE == hr) || !read) |
| 120 | break; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | 37a3a4b | 2010-04-14 22:37:40 | [diff] [blame] | 123 | bool last_chance = force_determination || (size() >= kMaxSniffSize); |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 124 | eof_ = force_determination; |
[email protected] | 37a3a4b | 2010-04-14 22:37:40 | [diff] [blame] | 125 | DetermineRendererType(last_chance); |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 126 | return hr; |
| 127 | } |
| 128 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 129 | HRESULT SniffData::DrainCache(IBindStatusCallback* bscb, DWORD bscf, |
| 130 | CLIPFORMAT clip_format) { |
| 131 | if (!is_cache_valid()) { |
| 132 | return S_OK; |
| 133 | } |
| 134 | |
| 135 | // Ideally we could just use the cache_ IStream implementation but |
| 136 | // can't use it here since we have to return E_PENDING for the |
| 137 | // last call |
| 138 | HGLOBAL memory = NULL; |
| 139 | HRESULT hr = GetHGlobalFromStream(cache_, &memory); |
| 140 | if (SUCCEEDED(hr) && memory) { |
| 141 | char* buffer = reinterpret_cast<char*>(GlobalLock(memory)); |
[email protected] | de5bc35 | 2010-04-16 01:38:48 | [diff] [blame] | 142 | hr = CacheStream::BSCBFeedData(bscb, buffer, size_, clip_format, bscf, |
| 143 | eof_); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 144 | GlobalUnlock(memory); |
| 145 | } |
| 146 | |
| 147 | size_ = 0; |
| 148 | cache_.Release(); |
| 149 | return hr; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 152 | // Scan the buffer or OptIn URL list and decide if the renderer is |
[email protected] | 37a3a4b | 2010-04-14 22:37:40 | [diff] [blame] | 153 | // to be switched. Last chance means there's no more data. |
| 154 | void SniffData::DetermineRendererType(bool last_chance) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 155 | if (is_undetermined()) { |
[email protected] | 37a3a4b | 2010-04-14 22:37:40 | [diff] [blame] | 156 | if (last_chance) |
| 157 | renderer_type_ = OTHER; |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 158 | if (IsOptInUrl(url_.c_str())) { |
| 159 | renderer_type_ = CHROME; |
| 160 | } else { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 161 | if (is_cache_valid() && cache_) { |
| 162 | HGLOBAL memory = NULL; |
| 163 | GetHGlobalFromStream(cache_, &memory); |
| 164 | char* buffer = reinterpret_cast<char*>(GlobalLock(memory)); |
| 165 | |
| 166 | std::wstring html_contents; |
| 167 | // TODO(joshia): detect and handle different content encodings |
| 168 | if (buffer && size_) { |
| 169 | UTF8ToWide(buffer, size_, &html_contents); |
| 170 | GlobalUnlock(memory); |
| 171 | } |
| 172 | |
| 173 | // Note that document_contents_ may have NULL characters in it. While |
| 174 | // browsers may handle this properly, we don't and will stop scanning |
| 175 | // for the XUACompat content value if we encounter one. |
| 176 | std::wstring xua_compat_content; |
| 177 | UtilGetXUACompatContentValue(html_contents, &xua_compat_content); |
| 178 | if (StrStrI(xua_compat_content.c_str(), kChromeContentPrefix)) { |
| 179 | renderer_type_ = CHROME; |
| 180 | } |
| 181 | } |
| 182 | } |
[email protected] | ffec6bf | 2010-04-09 23:53:26 | [diff] [blame] | 183 | DLOG(INFO) << __FUNCTION__ << "Url: " << url_ << |
| 184 | StringPrintf("Renderer type: %s", |
| 185 | renderer_type_ == CHROME ? "CHROME" : "OTHER"); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 186 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 187 | } |
| 188 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 189 | ///////////////////////////////////////////////////////////////////// |
| 190 | |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 191 | HRESULT BSCBStorageBind::Initialize(IMoniker* moniker, IBindCtx* bind_ctx) { |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 192 | DLOG(INFO) << __FUNCTION__ << me() << StringPrintf(" tid=%i", |
| 193 | PlatformThread::CurrentId()); |
| 194 | |
[email protected] | 040b800f | 2010-05-05 23:46:30 | [diff] [blame] | 195 | std::wstring url = GetActualUrlFromMoniker(moniker, bind_ctx, |
| 196 | std::wstring()); |
| 197 | HRESULT hr = data_sniffer_.InitializeCache(url); |
| 198 | if (FAILED(hr)) |
| 199 | return hr; |
| 200 | |
| 201 | hr = AttachToBind(bind_ctx); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 202 | if (FAILED(hr)) { |
| 203 | NOTREACHED() << __FUNCTION__ << me() << "AttachToBind error: " << hr; |
| 204 | return hr; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 207 | if (!delegate()) { |
| 208 | NOTREACHED() << __FUNCTION__ << me() << "No existing callback: " << hr; |
| 209 | return E_FAIL; |
| 210 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 211 | |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 212 | return hr; |
| 213 | } |
| 214 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 215 | STDMETHODIMP BSCBStorageBind::OnProgress(ULONG progress, ULONG progress_max, |
| 216 | ULONG status_code, LPCWSTR status_text) { |
| 217 | DLOG(INFO) << __FUNCTION__ << me() << StringPrintf(" status=%i tid=%i %ls", |
| 218 | status_code, PlatformThread::CurrentId(), status_text); |
| 219 | |
| 220 | HRESULT hr = S_OK; |
[email protected] | b31b9ff | 2010-05-07 18:29:24 | [diff] [blame^] | 221 | |
| 222 | // Remember the last redirected URL in case we get switched into |
| 223 | // chrome frame |
| 224 | if (status_code == BINDSTATUS_REDIRECTING) { |
| 225 | scoped_refptr<BindContextInfo> info = |
| 226 | BindContextInfo::FromBindContext(bind_ctx_); |
| 227 | DCHECK(info); |
| 228 | if (info) |
| 229 | info->set_url(status_text); |
| 230 | } |
| 231 | |
| 232 | if (ShouldCacheProgress(status_code)) { |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 233 | Progress new_progress = { progress, progress_max, status_code, |
| 234 | status_text ? status_text : std::wstring() }; |
| 235 | saved_progress_.push_back(new_progress); |
| 236 | } else { |
| 237 | hr = CallbackImpl::OnProgress(progress, progress_max, status_code, |
| 238 | status_text); |
| 239 | } |
| 240 | |
| 241 | return hr; |
| 242 | } |
| 243 | |
| 244 | // Refer to urlmon_moniker.h for explanation of how things work. |
| 245 | STDMETHODIMP BSCBStorageBind::OnDataAvailable(DWORD flags, DWORD size, |
| 246 | FORMATETC* format_etc, |
| 247 | STGMEDIUM* stgmed) { |
| 248 | DLOG(INFO) << __FUNCTION__ << StringPrintf(" tid=%i", |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 249 | PlatformThread::CurrentId()); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 250 | |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 251 | // Do not touch anything other than text/html. |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 252 | bool is_interesting = (format_etc && stgmed && stgmed->pstm && |
[email protected] | 2b3102be | 2010-04-21 20:07:35 | [diff] [blame] | 253 | stgmed->tymed == TYMED_ISTREAM && |
| 254 | IsTextHtmlClipFormat(format_etc->cfFormat)); |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 255 | |
| 256 | if (!is_interesting) { |
| 257 | // Play back report progress so far. |
| 258 | MayPlayBack(flags); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 259 | return CallbackImpl::OnDataAvailable(flags, size, format_etc, stgmed); |
| 260 | } |
| 261 | |
| 262 | HRESULT hr = S_OK; |
| 263 | if (!clip_format_) |
| 264 | clip_format_ = format_etc->cfFormat; |
| 265 | |
| 266 | if (data_sniffer_.is_undetermined()) { |
| 267 | bool force_determination = !!(flags & |
| 268 | (BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE)); |
| 269 | hr = data_sniffer_.ReadIntoCache(stgmed->pstm, force_determination); |
| 270 | // If we don't have sufficient data to determine renderer type |
| 271 | // wait for the next data notification. |
| 272 | if (data_sniffer_.is_undetermined()) |
| 273 | return S_OK; |
| 274 | } |
| 275 | |
| 276 | DCHECK(!data_sniffer_.is_undetermined()); |
| 277 | |
| 278 | if (data_sniffer_.is_cache_valid()) { |
| 279 | hr = MayPlayBack(flags); |
| 280 | DCHECK(!data_sniffer_.is_cache_valid()); |
| 281 | } else { |
| 282 | hr = CallbackImpl::OnDataAvailable(flags, size, format_etc, stgmed); |
| 283 | } |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 284 | return hr; |
| 285 | } |
| 286 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 287 | STDMETHODIMP BSCBStorageBind::OnStopBinding(HRESULT hresult, LPCWSTR error) { |
| 288 | DLOG(INFO) << __FUNCTION__ << StringPrintf(" tid=%i", |
| 289 | PlatformThread::CurrentId()); |
| 290 | HRESULT hr = MayPlayBack(BSCF_LASTDATANOTIFICATION); |
[email protected] | ffec6bf | 2010-04-09 23:53:26 | [diff] [blame] | 291 | hr = CallbackImpl::OnStopBinding(hresult, error); |
| 292 | ReleaseBind(); |
| 293 | return hr; |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 294 | } |
| 295 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 296 | // Play back the cached data to the delegate. Normally this would happen |
| 297 | // when we have read enough data to determine the renderer. In this case |
| 298 | // we first play back the data from the cache and then go into a 'pass |
| 299 | // through' mode. In some cases we may end up getting OnStopBinding |
| 300 | // before we get a chance to determine. Also it's possible that the |
| 301 | // BindToStorage call will return before OnStopBinding is sent. Hence |
| 302 | // This is called from 3 places and it's important to maintain the |
| 303 | // exact sequence of calls. |
| 304 | // Once the data is played back, calling this again is a no op. |
| 305 | HRESULT BSCBStorageBind::MayPlayBack(DWORD flags) { |
| 306 | // Force renderer type determination if not already done since |
| 307 | // we want to play back data now. |
[email protected] | 37a3a4b | 2010-04-14 22:37:40 | [diff] [blame] | 308 | data_sniffer_.DetermineRendererType(true); |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 309 | DCHECK(!data_sniffer_.is_undetermined()); |
| 310 | |
| 311 | HRESULT hr = S_OK; |
| 312 | if (data_sniffer_.is_chrome()) { |
| 313 | // Remember clip format. If we are switching to chrome, then in order |
| 314 | // to make mshtml return INET_E_TERMINATED_BIND and reissue navigation |
| 315 | // with the same bind context, we have to return a mime type that is |
| 316 | // special cased by mshtml. |
| 317 | static const CLIPFORMAT kMagicClipFormat = |
| 318 | RegisterClipboardFormat(CFSTR_MIME_MPEG); |
| 319 | clip_format_ = kMagicClipFormat; |
| 320 | } else { |
| 321 | if (!saved_progress_.empty()) { |
| 322 | for (std::vector<Progress>::iterator i = saved_progress_.begin(); |
| 323 | i != saved_progress_.end(); i++) { |
| 324 | const wchar_t* status_text = i->status_text_.empty() ? |
| 325 | NULL : i->status_text_.c_str(); |
| 326 | CallbackImpl::OnProgress(i->progress_, i->progress_max_, |
| 327 | i->status_code_, status_text); |
| 328 | } |
| 329 | saved_progress_.clear(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if (data_sniffer_.is_cache_valid()) { |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 334 | if (data_sniffer_.is_chrome()) { |
[email protected] | 70277f6 | 2010-04-15 01:39:26 | [diff] [blame] | 335 | scoped_refptr<BindContextInfo> info = |
| 336 | BindContextInfo::FromBindContext(bind_ctx_); |
| 337 | DCHECK(info); |
| 338 | if (info) { |
| 339 | info->SetToSwitch(data_sniffer_.cache_); |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 340 | } |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 343 | hr = data_sniffer_.DrainCache(delegate(), |
| 344 | flags | BSCF_FIRSTDATANOTIFICATION, clip_format_); |
[email protected] | c8c547e | 2010-04-12 20:40:15 | [diff] [blame] | 345 | DLOG_IF(WARNING, INET_E_TERMINATED_BIND != hr) << __FUNCTION__ << |
| 346 | " mshtml OnDataAvailable returned: " << std::hex << hr; |
[email protected] | 97965e1 | 2010-04-09 00:51:10 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | return hr; |
[email protected] | 2b3102be | 2010-04-21 20:07:35 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | b31b9ff | 2010-05-07 18:29:24 | [diff] [blame^] | 352 | // We cache and suppress sending progress notifications till |
| 353 | // we get the first OnDataAvailable. This is to prevent |
| 354 | // mshtml from making up its mind about the mime type. |
| 355 | // However, this is the invasive part of the patch and |
| 356 | // could trip other software that's due to mistimed progress |
| 357 | // notifications. It is probably not a good idea to hide redirects |
| 358 | // and some cookie notifications. |
| 359 | // |
| 360 | // We only need to suppress data notifications like |
| 361 | // BINDSTATUS_MIMETYPEAVAILABLE, |
| 362 | // BINDSTATUS_CACHEFILENAMEAVAILABLE etc. |
| 363 | // |
| 364 | // This is an atempt to reduce the exposure by starting to |
| 365 | // cache only when we receive one of the interesting progress |
| 366 | // notification. |
| 367 | bool BSCBStorageBind::ShouldCacheProgress(unsigned long status_code) const { |
| 368 | // We need to cache progress notifications only if we haven't yet figured |
| 369 | // out which way the request is going. |
| 370 | if (data_sniffer_.is_undetermined()) { |
| 371 | // If we are already caching then continue. |
| 372 | if (!saved_progress_.empty()) |
| 373 | return true; |
| 374 | // Start caching only if we see one of the interesting progress |
| 375 | // notifications. |
| 376 | switch (status_code) { |
| 377 | case BINDSTATUS_BEGINDOWNLOADDATA: |
| 378 | case BINDSTATUS_DOWNLOADINGDATA: |
| 379 | case BINDSTATUS_USINGCACHEDCOPY: |
| 380 | case BINDSTATUS_MIMETYPEAVAILABLE: |
| 381 | case BINDSTATUS_CACHEFILENAMEAVAILABLE: |
| 382 | case BINDSTATUS_SERVER_MIMETYPEAVAILABLE: |
| 383 | return true; |
| 384 | default: |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | return false; |
| 390 | } |
| 391 | |