OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome_frame/urlmon_url_request.h" | 5 #include "chrome_frame/urlmon_url_request.h" |
6 | 6 |
7 #include <urlmon.h> | 7 #include <urlmon.h> |
8 #include <wininet.h> | 8 #include <wininet.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return S_OK; | 239 return S_OK; |
240 | 240 |
241 if (!delegate_) { | 241 if (!delegate_) { |
242 DVLOG(1) << "Invalid delegate"; | 242 DVLOG(1) << "Invalid delegate"; |
243 return S_OK; | 243 return S_OK; |
244 } | 244 } |
245 | 245 |
246 switch (status_code) { | 246 switch (status_code) { |
247 case BINDSTATUS_CONNECTING: { | 247 case BINDSTATUS_CONNECTING: { |
248 if (status_text) { | 248 if (status_text) { |
249 socket_address_.set_host(WideToUTF8(status_text)); | 249 socket_address_.set_host(base::WideToUTF8(status_text)); |
250 } | 250 } |
251 break; | 251 break; |
252 } | 252 } |
253 | 253 |
254 case BINDSTATUS_REDIRECTING: { | 254 case BINDSTATUS_REDIRECTING: { |
255 // If we receive a redirect for the initial pending request initiated | 255 // If we receive a redirect for the initial pending request initiated |
256 // when our document loads we should stash it away and inform Chrome | 256 // when our document loads we should stash it away and inform Chrome |
257 // accordingly when it requests data for the original URL. | 257 // accordingly when it requests data for the original URL. |
258 base::win::ScopedComPtr<BindContextInfo> info; | 258 base::win::ScopedComPtr<BindContextInfo> info; |
259 BindContextInfo::FromBindContext(bind_context_, info.Receive()); | 259 BindContextInfo::FromBindContext(bind_context_, info.Receive()); |
260 DCHECK(info); | 260 DCHECK(info); |
261 GURL previously_redirected(info ? info->GetUrl() : std::wstring()); | 261 GURL previously_redirected(info ? info->GetUrl() : std::wstring()); |
262 if (GURL(status_text) != previously_redirected) { | 262 if (GURL(status_text) != previously_redirected) { |
263 DVLOG(1) << __FUNCTION__ << me() << "redirect from " << url() | 263 DVLOG(1) << __FUNCTION__ << me() << "redirect from " << url() |
264 << " to " << status_text; | 264 << " to " << status_text; |
265 // Fetch the redirect status as they aren't all equal (307 in particular | 265 // Fetch the redirect status as they aren't all equal (307 in particular |
266 // retains the HTTP request verb). | 266 // retains the HTTP request verb). |
267 int http_code = GetHttpResponseStatusFromBinding(binding_); | 267 int http_code = GetHttpResponseStatusFromBinding(binding_); |
268 status_.SetRedirected(http_code, WideToUTF8(status_text)); | 268 status_.SetRedirected(http_code, base::WideToUTF8(status_text)); |
269 // Abort. We will inform Chrome in OnStopBinding callback. | 269 // Abort. We will inform Chrome in OnStopBinding callback. |
270 binding_->Abort(); | 270 binding_->Abort(); |
271 return E_ABORT; | 271 return E_ABORT; |
272 } | 272 } |
273 break; | 273 break; |
274 } | 274 } |
275 | 275 |
276 case BINDSTATUS_COOKIE_SENT: | 276 case BINDSTATUS_COOKIE_SENT: |
277 delegate_->AddPrivacyDataForUrl(url(), "", COOKIEACTION_READ); | 277 delegate_->AddPrivacyDataForUrl(url(), "", COOKIEACTION_READ); |
278 break; | 278 break; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 // For certain requests like empty POST requests the server can return | 342 // For certain requests like empty POST requests the server can return |
343 // back a HTTP success code in the range 200 to 299. We need to flag | 343 // back a HTTP success code in the range 200 to 299. We need to flag |
344 // these requests as succeeded. | 344 // these requests as succeeded. |
345 if (IS_HTTP_SUCCESS_CODE(http_code)) { | 345 if (IS_HTTP_SUCCESS_CODE(http_code)) { |
346 // If this DCHECK fires it means that the server returned a HTTP | 346 // If this DCHECK fires it means that the server returned a HTTP |
347 // success code outside the standard range 200-206. We need to confirm | 347 // success code outside the standard range 200-206. We need to confirm |
348 // if the following code path is correct. | 348 // if the following code path is correct. |
349 DCHECK_LE(http_code, 206); | 349 DCHECK_LE(http_code, 206); |
350 status_.set_result(S_OK); | 350 status_.set_result(S_OK); |
351 std::string headers = GetHttpHeadersFromBinding(binding_); | 351 std::string headers = GetHttpHeadersFromBinding(binding_); |
352 OnResponse(0, UTF8ToWide(headers).c_str(), NULL, NULL); | 352 OnResponse(0, base::UTF8ToWide(headers).c_str(), NULL, NULL); |
353 } else if (net::HttpResponseHeaders::IsRedirectResponseCode(http_code) && | 353 } else if (net::HttpResponseHeaders::IsRedirectResponseCode(http_code) && |
354 result == E_ACCESSDENIED) { | 354 result == E_ACCESSDENIED) { |
355 // Special case. If the last request was a redirect and the current OS | 355 // Special case. If the last request was a redirect and the current OS |
356 // error value is E_ACCESSDENIED, that means an unsafe redirect was | 356 // error value is E_ACCESSDENIED, that means an unsafe redirect was |
357 // attempted. In that case, correct the OS error value to be the more | 357 // attempted. In that case, correct the OS error value to be the more |
358 // specific ERR_UNSAFE_REDIRECT error value. | 358 // specific ERR_UNSAFE_REDIRECT error value. |
359 status_.set_result(net::URLRequestStatus::FAILED, | 359 status_.set_result(net::URLRequestStatus::FAILED, |
360 net::ERR_UNSAFE_REDIRECT); | 360 net::ERR_UNSAFE_REDIRECT); |
361 } | 361 } |
362 } | 362 } |
(...skipping 23 matching lines...) Expand all Loading... |
386 NotifyDelegateAndDie(); | 386 NotifyDelegateAndDie(); |
387 return S_OK; | 387 return S_OK; |
388 } | 388 } |
389 | 389 |
390 // Status::ABORTING | 390 // Status::ABORTING |
391 if (status_.was_redirected()) { | 391 if (status_.was_redirected()) { |
392 // Just release bindings here. Chrome will issue EndRequest(request_id) | 392 // Just release bindings here. Chrome will issue EndRequest(request_id) |
393 // after processing headers we had provided. | 393 // after processing headers we had provided. |
394 if (!pending_) { | 394 if (!pending_) { |
395 std::string headers = GetHttpHeadersFromBinding(binding_); | 395 std::string headers = GetHttpHeadersFromBinding(binding_); |
396 OnResponse(0, UTF8ToWide(headers).c_str(), NULL, NULL); | 396 OnResponse(0, base::UTF8ToWide(headers).c_str(), NULL, NULL); |
397 } | 397 } |
398 ReleaseBindings(); | 398 ReleaseBindings(); |
399 return S_OK; | 399 return S_OK; |
400 } | 400 } |
401 | 401 |
402 // Stop invoked. | 402 // Stop invoked. |
403 NotifyDelegateAndDie(); | 403 NotifyDelegateAndDie(); |
404 return S_OK; | 404 return S_OK; |
405 } | 405 } |
406 | 406 |
(...skipping 16 matching lines...) Expand all Loading... |
423 if (load_flags_ & net::LOAD_BYPASS_CACHE) | 423 if (load_flags_ & net::LOAD_BYPASS_CACHE) |
424 *bind_flags |= BINDF_GETNEWESTVERSION; | 424 *bind_flags |= BINDF_GETNEWESTVERSION; |
425 | 425 |
426 if (LowerCaseEqualsASCII(method(), "get")) { | 426 if (LowerCaseEqualsASCII(method(), "get")) { |
427 bind_info->dwBindVerb = BINDVERB_GET; | 427 bind_info->dwBindVerb = BINDVERB_GET; |
428 } else if (LowerCaseEqualsASCII(method(), "post")) { | 428 } else if (LowerCaseEqualsASCII(method(), "post")) { |
429 bind_info->dwBindVerb = BINDVERB_POST; | 429 bind_info->dwBindVerb = BINDVERB_POST; |
430 } else if (LowerCaseEqualsASCII(method(), "put")) { | 430 } else if (LowerCaseEqualsASCII(method(), "put")) { |
431 bind_info->dwBindVerb = BINDVERB_PUT; | 431 bind_info->dwBindVerb = BINDVERB_PUT; |
432 } else { | 432 } else { |
433 std::wstring verb(ASCIIToWide(StringToUpperASCII(method()))); | 433 std::wstring verb(base::ASCIIToWide(StringToUpperASCII(method()))); |
434 bind_info->dwBindVerb = BINDVERB_CUSTOM; | 434 bind_info->dwBindVerb = BINDVERB_CUSTOM; |
435 bind_info->szCustomVerb = reinterpret_cast<wchar_t*>( | 435 bind_info->szCustomVerb = reinterpret_cast<wchar_t*>( |
436 ::CoTaskMemAlloc((verb.length() + 1) * sizeof(wchar_t))); | 436 ::CoTaskMemAlloc((verb.length() + 1) * sizeof(wchar_t))); |
437 lstrcpyW(bind_info->szCustomVerb, verb.c_str()); | 437 lstrcpyW(bind_info->szCustomVerb, verb.c_str()); |
438 } | 438 } |
439 | 439 |
440 if (bind_info->dwBindVerb == BINDVERB_POST || | 440 if (bind_info->dwBindVerb == BINDVERB_POST || |
441 bind_info->dwBindVerb == BINDVERB_PUT || | 441 bind_info->dwBindVerb == BINDVERB_PUT || |
442 post_data_len() > 0) { | 442 post_data_len() > 0) { |
443 // Bypass caching proxies on upload requests and avoid writing responses to | 443 // Bypass caching proxies on upload requests and avoid writing responses to |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 new_headers += ReplaceOrAddUserAgent(current_headers, user_agent); | 582 new_headers += ReplaceOrAddUserAgent(current_headers, user_agent); |
583 | 583 |
584 if (!new_headers.empty()) { | 584 if (!new_headers.empty()) { |
585 *additional_headers = reinterpret_cast<wchar_t*>( | 585 *additional_headers = reinterpret_cast<wchar_t*>( |
586 CoTaskMemAlloc((new_headers.size() + 1) * sizeof(wchar_t))); | 586 CoTaskMemAlloc((new_headers.size() + 1) * sizeof(wchar_t))); |
587 | 587 |
588 if (*additional_headers == NULL) { | 588 if (*additional_headers == NULL) { |
589 NOTREACHED(); | 589 NOTREACHED(); |
590 hr = E_OUTOFMEMORY; | 590 hr = E_OUTOFMEMORY; |
591 } else { | 591 } else { |
592 lstrcpynW(*additional_headers, ASCIIToWide(new_headers).c_str(), | 592 lstrcpynW(*additional_headers, base::ASCIIToWide(new_headers).c_str(), |
593 new_headers.size()); | 593 new_headers.size()); |
594 } | 594 } |
595 } | 595 } |
596 request_headers_ = new_headers; | 596 request_headers_ = new_headers; |
597 return hr; | 597 return hr; |
598 } | 598 } |
599 | 599 |
600 STDMETHODIMP UrlmonUrlRequest::OnResponse(DWORD dwResponseCode, | 600 STDMETHODIMP UrlmonUrlRequest::OnResponse(DWORD dwResponseCode, |
601 const wchar_t* response_headers, const wchar_t* request_headers, | 601 const wchar_t* response_headers, const wchar_t* request_headers, |
602 wchar_t** additional_headers) { | 602 wchar_t** additional_headers) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 } | 701 } |
702 return hr; | 702 return hr; |
703 } | 703 } |
704 | 704 |
705 HRESULT UrlmonUrlRequest::StartAsyncDownload() { | 705 HRESULT UrlmonUrlRequest::StartAsyncDownload() { |
706 DVLOG(1) << __FUNCTION__ << me() << url(); | 706 DVLOG(1) << __FUNCTION__ << me() << url(); |
707 HRESULT hr = E_FAIL; | 707 HRESULT hr = E_FAIL; |
708 DCHECK((moniker_ && bind_context_) || (!moniker_ && !bind_context_)); | 708 DCHECK((moniker_ && bind_context_) || (!moniker_ && !bind_context_)); |
709 | 709 |
710 if (!moniker_.get()) { | 710 if (!moniker_.get()) { |
711 std::wstring wide_url = UTF8ToWide(url()); | 711 std::wstring wide_url = base::UTF8ToWide(url()); |
712 hr = CreateURLMonikerEx(NULL, wide_url.c_str(), moniker_.Receive(), | 712 hr = CreateURLMonikerEx(NULL, wide_url.c_str(), moniker_.Receive(), |
713 URL_MK_UNIFORM); | 713 URL_MK_UNIFORM); |
714 if (FAILED(hr)) { | 714 if (FAILED(hr)) { |
715 NOTREACHED() << "CreateURLMonikerEx failed. Error: " << hr; | 715 NOTREACHED() << "CreateURLMonikerEx failed. Error: " << hr; |
716 return hr; | 716 return hr; |
717 } | 717 } |
718 } | 718 } |
719 | 719 |
720 if (bind_context_.get() == NULL) { | 720 if (bind_context_.get() == NULL) { |
721 hr = ::CreateAsyncBindCtxEx(NULL, 0, this, NULL, | 721 hr = ::CreateAsyncBindCtxEx(NULL, 0, this, NULL, |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 940 |
941 if (!privacy_info_.privacy_impacted) { | 941 if (!privacy_info_.privacy_impacted) { |
942 if (flags & (COOKIEACTION_ACCEPT | COOKIEACTION_REJECT | | 942 if (flags & (COOKIEACTION_ACCEPT | COOKIEACTION_REJECT | |
943 COOKIEACTION_DOWNGRADE)) { | 943 COOKIEACTION_DOWNGRADE)) { |
944 privacy_info_.privacy_impacted = true; | 944 privacy_info_.privacy_impacted = true; |
945 fire_privacy_event = true; | 945 fire_privacy_event = true; |
946 } | 946 } |
947 } | 947 } |
948 | 948 |
949 PrivacyInfo::PrivacyEntry& privacy_entry = | 949 PrivacyInfo::PrivacyEntry& privacy_entry = |
950 privacy_info_.privacy_records[UTF8ToWide(url)]; | 950 privacy_info_.privacy_records[base::UTF8ToWide(url)]; |
951 | 951 |
952 privacy_entry.flags |= flags; | 952 privacy_entry.flags |= flags; |
953 privacy_entry.policy_ref = UTF8ToWide(policy_ref); | 953 privacy_entry.policy_ref = base::UTF8ToWide(policy_ref); |
954 | 954 |
955 if (fire_privacy_event && IsWindow(notification_window_)) { | 955 if (fire_privacy_event && IsWindow(notification_window_)) { |
956 PostMessage(notification_window_, WM_FIRE_PRIVACY_CHANGE_NOTIFICATION, 1, | 956 PostMessage(notification_window_, WM_FIRE_PRIVACY_CHANGE_NOTIFICATION, 1, |
957 0); | 957 0); |
958 } | 958 } |
959 } | 959 } |
OLD | NEW |