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

Side by Side Diff: chrome_frame/urlmon_url_request.cc

Issue 386008: ChromeFrame HTTP requests would randomly fail if we navigated to multiple HTT... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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/urlmon_url_request.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome_frame/urlmon_url_request.h" 5 #include "chrome_frame/urlmon_url_request.h"
6 6
7 #include <wininet.h> 7 #include <wininet.h>
8 8
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "chrome_frame/chrome_frame_activex_base.h" 13 #include "chrome_frame/chrome_frame_activex_base.h"
14 #include "chrome_frame/urlmon_upload_data_stream.h" 14 #include "chrome_frame/urlmon_upload_data_stream.h"
15 #include "chrome_frame/utils.h" 15 #include "chrome_frame/utils.h"
16 #include "net/http/http_util.h" 16 #include "net/http/http_util.h"
17 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
18 18
19 static const LARGE_INTEGER kZero = {0}; 19 static const LARGE_INTEGER kZero = {0};
20 static const ULARGE_INTEGER kUnsignedZero = {0}; 20 static const ULARGE_INTEGER kUnsignedZero = {0};
21 int UrlmonUrlRequest::instance_count_ = 0; 21 int UrlmonUrlRequest::instance_count_ = 0;
22 const char kXFrameOptionsHeader[] = "X-Frame-Options"; 22 const char kXFrameOptionsHeader[] = "X-Frame-Options";
23 23
24 UrlmonUrlRequest::UrlmonUrlRequest() 24 UrlmonUrlRequest::UrlmonUrlRequest()
25 : pending_read_size_(0), 25 : pending_read_size_(0),
26 status_(URLRequestStatus::FAILED, net::ERR_FAILED), 26 status_(URLRequestStatus::FAILED, net::ERR_FAILED),
27 thread_(PlatformThread::CurrentId()), 27 thread_(PlatformThread::CurrentId()),
28 redirect_status_(0), 28 redirect_status_(0),
29 parent_window_(NULL), 29 parent_window_(NULL),
30 worker_thread_(NULL), 30 worker_thread_(NULL) {
31 task_marshaller_(NULL) {
32 DLOG(INFO) << StringPrintf("Created request. Obj: %X", this) 31 DLOG(INFO) << StringPrintf("Created request. Obj: %X", this)
33 << " Count: " << ++instance_count_; 32 << " Count: " << ++instance_count_;
34 } 33 }
35 34
36 UrlmonUrlRequest::~UrlmonUrlRequest() { 35 UrlmonUrlRequest::~UrlmonUrlRequest() {
37 DLOG(INFO) << StringPrintf("Deleted request. Obj: %X", this) 36 DLOG(INFO) << StringPrintf("Deleted request. Obj: %X", this)
38 << " Count: " << --instance_count_; 37 << " Count: " << --instance_count_;
39 } 38 }
40 39
41 bool UrlmonUrlRequest::Start() { 40 bool UrlmonUrlRequest::Start() {
42 DCHECK_EQ(PlatformThread::CurrentId(), thread_); 41 DCHECK_EQ(PlatformThread::CurrentId(), thread_);
43 42
44 if (!worker_thread_) { 43 if (!worker_thread_) {
45 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; 44 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized";
46 return false; 45 return false;
47 } 46 }
48 47
48 Create(HWND_MESSAGE);
49 if (!IsWindow()) {
50 NOTREACHED() << "Failed to create urlmon message window: "
51 << GetLastError();
52 return false;
53 }
54
49 // Take a self reference to maintain COM lifetime. This will be released 55 // Take a self reference to maintain COM lifetime. This will be released
50 // in EndRequest 56 // in OnFinalMessage
51 AddRef(); 57 AddRef();
52 request_handler()->AddRequest(this); 58 request_handler()->AddRequest(this);
53 59
54 worker_thread_->message_loop()->PostTask( 60 worker_thread_->message_loop()->PostTask(
55 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StartAsync)); 61 FROM_HERE, NewRunnableMethod(this, &UrlmonUrlRequest::StartAsync));
56 62
57 return true; 63 return true;
58 } 64 }
59 65
60 void UrlmonUrlRequest::Stop() { 66 void UrlmonUrlRequest::Stop() {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 101
96 if (binding_) { 102 if (binding_) {
97 binding_->Abort(); 103 binding_->Abort();
98 } else { 104 } else {
99 status_.set_status(URLRequestStatus::CANCELED); 105 status_.set_status(URLRequestStatus::CANCELED);
100 status_.set_os_error(net::ERR_FAILED); 106 status_.set_os_error(net::ERR_FAILED);
101 EndRequest(); 107 EndRequest();
102 } 108 }
103 } 109 }
104 110
111 void UrlmonUrlRequest::OnFinalMessage(HWND window) {
112 m_hWnd = NULL;
113 // Release the outstanding reference in the context of the UI thread to
114 // ensure that our instance gets deleted in the same thread which created it.
115 Release();
116 }
117
105 bool UrlmonUrlRequest::Read(int bytes_to_read) { 118 bool UrlmonUrlRequest::Read(int bytes_to_read) {
106 DCHECK_EQ(PlatformThread::CurrentId(), thread_); 119 DCHECK_EQ(PlatformThread::CurrentId(), thread_);
107 120
108 DLOG(INFO) << StringPrintf("URL: %s Obj: %X", url().c_str(), this); 121 DLOG(INFO) << StringPrintf("URL: %s Obj: %X", url().c_str(), this);
109 122
110 if (!worker_thread_) { 123 if (!worker_thread_) {
111 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized"; 124 NOTREACHED() << __FUNCTION__ << " Urlmon request thread not initialized";
112 return false; 125 return false;
113 } 126 }
114 127
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (!status_.is_success() && status_.os_error() == net::ERR_ACCESS_DENIED) { 609 if (!status_.is_success() && status_.os_error() == net::ERR_ACCESS_DENIED) {
597 int status = GetHttpResponseStatus(); 610 int status = GetHttpResponseStatus();
598 if (status >= 300 && status < 400) { 611 if (status >= 300 && status < 400) {
599 redirect_status_ = status; // store the latest redirect status value. 612 redirect_status_ = status; // store the latest redirect status value.
600 status_.set_os_error(net::ERR_UNSAFE_REDIRECT); 613 status_.set_os_error(net::ERR_UNSAFE_REDIRECT);
601 } 614 }
602 } 615 }
603 616
604 OnResponseEnd(status_); 617 OnResponseEnd(status_);
605 618
606 DCHECK(task_marshaller_ != NULL);
607
608 // Remove the request mapping and release the outstanding reference to us in 619 // Remove the request mapping and release the outstanding reference to us in
609 // the context of the UI thread. 620 // the context of the UI thread.
610 task_marshaller_->PostTask( 621 PostTask(FROM_HERE,
611 FROM_HERE, NewRunnableMethod(this, 622 NewRunnableMethod(this, &UrlmonUrlRequest::EndRequestInternal));
612 &UrlmonUrlRequest::EndRequestInternal));
613 } 623 }
614 624
615 void UrlmonUrlRequest::EndRequestInternal() { 625 void UrlmonUrlRequest::EndRequestInternal() {
616 // The request object could have been removed from the map in the 626 // The request object could have been removed from the map in the
617 // OnRequestEnd callback which executes on receiving the 627 // OnRequestEnd callback which executes on receiving the
618 // AutomationMsg_RequestEnd IPC from Chrome. 628 // AutomationMsg_RequestEnd IPC from Chrome.
619 request_handler()->RemoveRequest(this); 629 request_handler()->RemoveRequest(this);
620 // Release the outstanding reference in the context of the UI thread to 630 // The current instance could get destroyed in the context of DestroyWindow.
621 // ensure that our instance gets deleted in the same thread which created it. 631 // We should not access the object after this.
622 Release(); 632 DestroyWindow();
623 } 633 }
624 634
625 int UrlmonUrlRequest::GetHttpResponseStatus() const { 635 int UrlmonUrlRequest::GetHttpResponseStatus() const {
626 if (binding_ == NULL) { 636 if (binding_ == NULL) {
627 DLOG(WARNING) << "GetHttpResponseStatus - no binding_"; 637 DLOG(WARNING) << "GetHttpResponseStatus - no binding_";
628 return 0; 638 return 0;
629 } 639 }
630 640
631 int http_status = 0; 641 int http_status = 0;
632 642
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 ret = net::ERR_ACCESS_DENIED; 820 ret = net::ERR_ACCESS_DENIED;
811 break; 821 break;
812 822
813 default: 823 default:
814 DLOG(WARNING) 824 DLOG(WARNING)
815 << StringPrintf("TODO: translate HRESULT 0x%08X to net::Error", hr); 825 << StringPrintf("TODO: translate HRESULT 0x%08X to net::Error", hr);
816 break; 826 break;
817 } 827 }
818 return ret; 828 return ret;
819 } 829 }
OLDNEW
« no previous file with comments | « chrome_frame/urlmon_url_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698