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/browser/automation/url_request_automation_job.h" | 5 #include "chrome/browser/automation/url_request_automation_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 int URLRequestAutomationJob::instance_count_ = 0; | 45 int URLRequestAutomationJob::instance_count_ = 0; |
46 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; | 46 bool URLRequestAutomationJob::is_protocol_factory_registered_ = false; |
47 | 47 |
48 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ | 48 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_http_factory_ |
49 = NULL; | 49 = NULL; |
50 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ | 50 net::URLRequest::ProtocolFactory* URLRequestAutomationJob::old_https_factory_ |
51 = NULL; | 51 = NULL; |
52 | 52 |
53 URLRequestAutomationJob::URLRequestAutomationJob( | 53 URLRequestAutomationJob::URLRequestAutomationJob( |
54 net::URLRequest* request, | 54 net::URLRequest* request, |
| 55 net::NetworkDelegate* network_delegate, |
55 int tab, | 56 int tab, |
56 int request_id, | 57 int request_id, |
57 AutomationResourceMessageFilter* filter, | 58 AutomationResourceMessageFilter* filter, |
58 bool is_pending) | 59 bool is_pending) |
59 : net::URLRequestJob(request, request->context()->network_delegate()), | 60 : net::URLRequestJob(request, network_delegate), |
60 id_(0), | 61 id_(0), |
61 tab_(tab), | 62 tab_(tab), |
62 message_filter_(filter), | 63 message_filter_(filter), |
63 pending_buf_size_(0), | 64 pending_buf_size_(0), |
64 redirect_status_(0), | 65 redirect_status_(0), |
65 request_id_(request_id), | 66 request_id_(request_id), |
66 is_pending_(is_pending), | 67 is_pending_(is_pending), |
67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 68 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
68 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 69 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
69 DCHECK(message_filter_ != NULL); | 70 DCHECK(message_filter_ != NULL); |
(...skipping 18 matching lines...) Expand all Loading... |
88 "http", &URLRequestAutomationJob::Factory); | 89 "http", &URLRequestAutomationJob::Factory); |
89 old_https_factory_ = | 90 old_https_factory_ = |
90 net::URLRequest::Deprecated::RegisterProtocolFactory( | 91 net::URLRequest::Deprecated::RegisterProtocolFactory( |
91 "https", &URLRequestAutomationJob::Factory); | 92 "https", &URLRequestAutomationJob::Factory); |
92 is_protocol_factory_registered_ = true; | 93 is_protocol_factory_registered_ = true; |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
96 net::URLRequestJob* URLRequestAutomationJob::Factory( | 97 net::URLRequestJob* URLRequestAutomationJob::Factory( |
97 net::URLRequest* request, | 98 net::URLRequest* request, |
| 99 net::NetworkDelegate* network_delegate, |
98 const std::string& scheme) { | 100 const std::string& scheme) { |
99 bool scheme_is_http = request->url().SchemeIs("http"); | 101 bool scheme_is_http = request->url().SchemeIs("http"); |
100 bool scheme_is_https = request->url().SchemeIs("https"); | 102 bool scheme_is_https = request->url().SchemeIs("https"); |
101 | 103 |
102 // Returning null here just means that the built-in handler will be used. | 104 // Returning null here just means that the built-in handler will be used. |
103 if (scheme_is_http || scheme_is_https) { | 105 if (scheme_is_http || scheme_is_https) { |
104 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 106 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
105 if (info) { | 107 if (info) { |
106 int child_id = info->GetChildID(); | 108 int child_id = info->GetChildID(); |
107 int route_id = info->GetRouteID(); | 109 int route_id = info->GetRouteID(); |
108 AutomationResourceMessageFilter::AutomationDetails details; | 110 AutomationResourceMessageFilter::AutomationDetails details; |
109 if (AutomationResourceMessageFilter::LookupRegisteredRenderView( | 111 if (AutomationResourceMessageFilter::LookupRegisteredRenderView( |
110 child_id, route_id, &details)) { | 112 child_id, route_id, &details)) { |
111 URLRequestAutomationJob* job = new URLRequestAutomationJob(request, | 113 URLRequestAutomationJob* job = new URLRequestAutomationJob( |
| 114 request, network_delegate, |
112 details.tab_handle, info->GetRequestID(), details.filter, | 115 details.tab_handle, info->GetRequestID(), details.filter, |
113 details.is_pending_render_view); | 116 details.is_pending_render_view); |
114 return job; | 117 return job; |
115 } | 118 } |
116 } | 119 } |
117 | 120 |
118 if (scheme_is_http && old_http_factory_) | 121 if (scheme_is_http && old_http_factory_) |
119 return old_http_factory_(request, scheme); | 122 return old_http_factory_(request, network_delegate, scheme); |
120 else if (scheme_is_https && old_https_factory_) | 123 else if (scheme_is_https && old_https_factory_) |
121 return old_https_factory_(request, scheme); | 124 return old_https_factory_(request, network_delegate, scheme); |
122 } | 125 } |
123 return NULL; | 126 return NULL; |
124 } | 127 } |
125 | 128 |
126 // net::URLRequestJob Implementation. | 129 // net::URLRequestJob Implementation. |
127 void URLRequestAutomationJob::Start() { | 130 void URLRequestAutomationJob::Start() { |
128 if (!is_pending()) { | 131 if (!is_pending()) { |
129 // Start reading asynchronously so that all error reporting and data | 132 // Start reading asynchronously so that all error reporting and data |
130 // callbacks happen as they would for network requests. | 133 // callbacks happen as they would for network requests. |
131 MessageLoop::current()->PostTask( | 134 MessageLoop::current()->PostTask( |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (!is_done()) { | 488 if (!is_done()) { |
486 NotifyDone(request_status_); | 489 NotifyDone(request_status_); |
487 } | 490 } |
488 // Reset any pending reads. | 491 // Reset any pending reads. |
489 if (pending_buf_) { | 492 if (pending_buf_) { |
490 pending_buf_ = NULL; | 493 pending_buf_ = NULL; |
491 pending_buf_size_ = 0; | 494 pending_buf_size_ = 0; |
492 NotifyReadComplete(0); | 495 NotifyReadComplete(0); |
493 } | 496 } |
494 } | 497 } |
OLD | NEW |