| 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 #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/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 10 #include "base/time.h" |
| 10 #include "chrome/browser/automation/automation_resource_message_filter.h" | 11 #include "chrome/browser/automation/automation_resource_message_filter.h" |
| 11 #include "chrome/common/automation_messages.h" | 12 #include "chrome/common/automation_messages.h" |
| 12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 13 #include "content/browser/renderer_host/render_view_host.h" | 14 #include "content/browser/renderer_host/render_view_host.h" |
| 14 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 15 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 15 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 16 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| 16 #include "net/base/cookie_monster.h" | 17 #include "net/base/cookie_monster.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 AutomationResourceMessageFilter* filter, | 55 AutomationResourceMessageFilter* filter, |
| 55 bool is_pending) | 56 bool is_pending) |
| 56 : net::URLRequestJob(request), | 57 : net::URLRequestJob(request), |
| 57 id_(0), | 58 id_(0), |
| 58 tab_(tab), | 59 tab_(tab), |
| 59 message_filter_(filter), | 60 message_filter_(filter), |
| 60 pending_buf_size_(0), | 61 pending_buf_size_(0), |
| 61 redirect_status_(0), | 62 redirect_status_(0), |
| 62 request_id_(request_id), | 63 request_id_(request_id), |
| 63 is_pending_(is_pending), | 64 is_pending_(is_pending), |
| 64 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 65 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 65 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; | 66 DVLOG(1) << "URLRequestAutomationJob create. Count: " << ++instance_count_; |
| 66 DCHECK(message_filter_ != NULL); | 67 DCHECK(message_filter_ != NULL); |
| 67 | 68 |
| 68 if (message_filter_) { | 69 if (message_filter_) { |
| 69 id_ = message_filter_->NewAutomationRequestId(); | 70 id_ = message_filter_->NewAutomationRequestId(); |
| 70 DCHECK_NE(id_, 0); | 71 DCHECK_NE(id_, 0); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 URLRequestAutomationJob::~URLRequestAutomationJob() { | 75 URLRequestAutomationJob::~URLRequestAutomationJob() { |
| 75 DVLOG(1) << "URLRequestAutomationJob delete. Count: " << --instance_count_; | 76 DVLOG(1) << "URLRequestAutomationJob delete. Count: " << --instance_count_; |
| 76 Cleanup(); | 77 Cleanup(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool URLRequestAutomationJob::EnsureProtocolFactoryRegistered() { | 80 void URLRequestAutomationJob::EnsureProtocolFactoryRegistered() { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 81 | 82 |
| 82 if (!is_protocol_factory_registered_) { | 83 if (!is_protocol_factory_registered_) { |
| 83 old_http_factory_ = | 84 old_http_factory_ = |
| 84 net::URLRequest::Deprecated::RegisterProtocolFactory( | 85 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 85 "http", &URLRequestAutomationJob::Factory); | 86 "http", &URLRequestAutomationJob::Factory); |
| 86 old_https_factory_ = | 87 old_https_factory_ = |
| 87 net::URLRequest::Deprecated::RegisterProtocolFactory( | 88 net::URLRequest::Deprecated::RegisterProtocolFactory( |
| 88 "https", &URLRequestAutomationJob::Factory); | 89 "https", &URLRequestAutomationJob::Factory); |
| 89 is_protocol_factory_registered_ = true; | 90 is_protocol_factory_registered_ = true; |
| 90 } | 91 } |
| 91 | |
| 92 return true; | |
| 93 } | 92 } |
| 94 | 93 |
| 95 net::URLRequestJob* URLRequestAutomationJob::Factory( | 94 net::URLRequestJob* URLRequestAutomationJob::Factory( |
| 96 net::URLRequest* request, | 95 net::URLRequest* request, |
| 97 const std::string& scheme) { | 96 const std::string& scheme) { |
| 98 bool scheme_is_http = request->url().SchemeIs("http"); | 97 bool scheme_is_http = request->url().SchemeIs("http"); |
| 99 bool scheme_is_https = request->url().SchemeIs("https"); | 98 bool scheme_is_https = request->url().SchemeIs("https"); |
| 100 | 99 |
| 101 // Returning null here just means that the built-in handler will be used. | 100 // Returning null here just means that the built-in handler will be used. |
| 102 if (scheme_is_http || scheme_is_https) { | 101 if (scheme_is_http || scheme_is_https) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 123 return NULL; | 122 return NULL; |
| 124 } | 123 } |
| 125 | 124 |
| 126 // net::URLRequestJob Implementation. | 125 // net::URLRequestJob Implementation. |
| 127 void URLRequestAutomationJob::Start() { | 126 void URLRequestAutomationJob::Start() { |
| 128 if (!is_pending()) { | 127 if (!is_pending()) { |
| 129 // Start reading asynchronously so that all error reporting and data | 128 // Start reading asynchronously so that all error reporting and data |
| 130 // callbacks happen as they would for network requests. | 129 // callbacks happen as they would for network requests. |
| 131 MessageLoop::current()->PostTask( | 130 MessageLoop::current()->PostTask( |
| 132 FROM_HERE, | 131 FROM_HERE, |
| 133 method_factory_.NewRunnableMethod( | 132 base::Bind(&URLRequestAutomationJob::StartAsync, |
| 134 &URLRequestAutomationJob::StartAsync)); | 133 weak_factory_.GetWeakPtr())); |
| 135 } else { | 134 } else { |
| 136 // If this is a pending job, then register it immediately with the message | 135 // If this is a pending job, then register it immediately with the message |
| 137 // filter so it can be serviced later when we receive a request from the | 136 // filter so it can be serviced later when we receive a request from the |
| 138 // external host to connect to the corresponding external tab. | 137 // external host to connect to the corresponding external tab. |
| 139 message_filter_->RegisterRequest(this); | 138 message_filter_->RegisterRequest(this); |
| 140 } | 139 } |
| 141 } | 140 } |
| 142 | 141 |
| 143 void URLRequestAutomationJob::Kill() { | 142 void URLRequestAutomationJob::Kill() { |
| 144 if (message_filter_.get()) { | 143 if (message_filter_.get()) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 | 161 |
| 163 pending_buf_ = buf; | 162 pending_buf_ = buf; |
| 164 pending_buf_size_ = buf_size; | 163 pending_buf_size_ = buf_size; |
| 165 | 164 |
| 166 if (message_filter_) { | 165 if (message_filter_) { |
| 167 message_filter_->Send(new AutomationMsg_RequestRead(tab_, id_, buf_size)); | 166 message_filter_->Send(new AutomationMsg_RequestRead(tab_, id_, buf_size)); |
| 168 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); | 167 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
| 169 } else { | 168 } else { |
| 170 MessageLoop::current()->PostTask( | 169 MessageLoop::current()->PostTask( |
| 171 FROM_HERE, | 170 FROM_HERE, |
| 172 method_factory_.NewRunnableMethod( | 171 base::Bind(&URLRequestAutomationJob::NotifyJobCompletionTask, |
| 173 &URLRequestAutomationJob::NotifyJobCompletionTask)); | 172 weak_factory_.GetWeakPtr())); |
| 174 } | 173 } |
| 175 return false; | 174 return false; |
| 176 } | 175 } |
| 177 | 176 |
| 178 bool URLRequestAutomationJob::GetMimeType(std::string* mime_type) const { | 177 bool URLRequestAutomationJob::GetMimeType(std::string* mime_type) const { |
| 179 if (!mime_type_.empty()) { | 178 if (!mime_type_.empty()) { |
| 180 *mime_type = mime_type_; | 179 *mime_type = mime_type_; |
| 181 } else if (headers_) { | 180 } else if (headers_) { |
| 182 headers_->GetMimeType(mime_type); | 181 headers_->GetMimeType(mime_type); |
| 183 } | 182 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 if (!is_done()) { | 488 if (!is_done()) { |
| 490 NotifyDone(request_status_); | 489 NotifyDone(request_status_); |
| 491 } | 490 } |
| 492 // Reset any pending reads. | 491 // Reset any pending reads. |
| 493 if (pending_buf_) { | 492 if (pending_buf_) { |
| 494 pending_buf_ = NULL; | 493 pending_buf_ = NULL; |
| 495 pending_buf_size_ = 0; | 494 pending_buf_size_ = 0; |
| 496 NotifyReadComplete(0); | 495 NotifyReadComplete(0); |
| 497 } | 496 } |
| 498 } | 497 } |
| OLD | NEW |