| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 // This class simulates what wininet does when a dns lookup fails. | 4 // This class simulates what wininet does when a dns lookup fails. |
| 5 | 5 |
| 6 #ifndef CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ | 6 #ifndef CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ |
| 7 #define CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ | 7 #define CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ |
| 8 #pragma once | 8 #pragma once |
| 9 | 9 |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "chrome/common/ref_counted_util.h" | 11 #include "chrome/common/ref_counted_util.h" |
| 12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
| 13 #include "net/url_request/url_request_job.h" | 13 #include "net/url_request/url_request_job.h" |
| 14 | 14 |
| 15 class AutomationResourceMessageFilter; | 15 class AutomationResourceMessageFilter; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class HttpResponseHeaders; | 18 class HttpResponseHeaders; |
| 19 class HttpResponseInfo; | 19 class HttpResponseInfo; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace IPC { | 22 namespace IPC { |
| 23 class Message; | 23 class Message; |
| 24 struct AutomationURLResponse; | 24 struct AutomationURLResponse; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // URLRequestJob implementation that loads the resources using | 27 // net::URLRequestJob implementation that loads the resources using |
| 28 // automation. | 28 // automation. |
| 29 class URLRequestAutomationJob : public net::URLRequestJob { | 29 class URLRequestAutomationJob : public net::URLRequestJob { |
| 30 public: | 30 public: |
| 31 URLRequestAutomationJob(net::URLRequest* request, int tab, int request_id, | 31 URLRequestAutomationJob(net::URLRequest* request, int tab, int request_id, |
| 32 AutomationResourceMessageFilter* filter, | 32 AutomationResourceMessageFilter* filter, |
| 33 bool is_pending); | 33 bool is_pending); |
| 34 | 34 |
| 35 // Register our factory for HTTP/HTTPs requests. | 35 // Register our factory for HTTP/HTTPs requests. |
| 36 static bool EnsureProtocolFactoryRegistered(); | 36 static bool EnsureProtocolFactoryRegistered(); |
| 37 | 37 |
| 38 static net::URLRequest::ProtocolFactory Factory; | 38 static net::URLRequest::ProtocolFactory Factory; |
| 39 | 39 |
| 40 // URLRequestJob methods. | 40 // net::URLRequestJob methods. |
| 41 virtual void Start(); | 41 virtual void Start(); |
| 42 virtual void Kill(); | 42 virtual void Kill(); |
| 43 virtual bool GetMimeType(std::string* mime_type) const; | 43 virtual bool GetMimeType(std::string* mime_type) const; |
| 44 virtual bool GetCharset(std::string* charset); | 44 virtual bool GetCharset(std::string* charset); |
| 45 virtual void GetResponseInfo(net::HttpResponseInfo* info); | 45 virtual void GetResponseInfo(net::HttpResponseInfo* info); |
| 46 virtual int GetResponseCode() const; | 46 virtual int GetResponseCode() const; |
| 47 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); | 47 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); |
| 48 | 48 |
| 49 // Peek and process automation messages for URL requests. | 49 // Peek and process automation messages for URL requests. |
| 50 static bool MayFilterMessage(const IPC::Message& message, int* request_id); | 50 static bool MayFilterMessage(const IPC::Message& message, int* request_id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 return message_filter_; | 66 return message_filter_; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Resumes a job, which was waiting for the external host to connect to the | 69 // Resumes a job, which was waiting for the external host to connect to the |
| 70 // automation channel. This is to ensure that this request gets routed to the | 70 // automation channel. This is to ensure that this request gets routed to the |
| 71 // external host. | 71 // external host. |
| 72 void StartPendingJob(int new_tab_handle, | 72 void StartPendingJob(int new_tab_handle, |
| 73 AutomationResourceMessageFilter* new_filter); | 73 AutomationResourceMessageFilter* new_filter); |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 // Protected URLRequestJob override. | 76 // Protected net::URLRequestJob override. |
| 77 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); | 77 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); |
| 78 | 78 |
| 79 void StartAsync(); | 79 void StartAsync(); |
| 80 void Cleanup(); | 80 void Cleanup(); |
| 81 void DisconnectFromMessageFilter(); | 81 void DisconnectFromMessageFilter(); |
| 82 | 82 |
| 83 // IPC message handlers. | 83 // IPC message handlers. |
| 84 void OnRequestStarted(int tab, int id, | 84 void OnRequestStarted(int tab, int id, |
| 85 const IPC::AutomationURLResponse& response); | 85 const IPC::AutomationURLResponse& response); |
| 86 void OnDataAvailable(int tab, int id, const std::string& bytes); | 86 void OnDataAvailable(int tab, int id, const std::string& bytes); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Contains the request status code, which is eventually passed to the http | 122 // Contains the request status code, which is eventually passed to the http |
| 123 // stack when we receive a Read request for a completed job. | 123 // stack when we receive a Read request for a completed job. |
| 124 URLRequestStatus request_status_; | 124 URLRequestStatus request_status_; |
| 125 | 125 |
| 126 ScopedRunnableMethodFactory<URLRequestAutomationJob> method_factory_; | 126 ScopedRunnableMethodFactory<URLRequestAutomationJob> method_factory_; |
| 127 | 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(URLRequestAutomationJob); | 128 DISALLOW_COPY_AND_ASSIGN(URLRequestAutomationJob); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 #endif // CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ | 131 #endif // CHROME_BROWSER_AUTOMATION_URL_REQUEST_AUTOMATION_JOB_H_ |
| OLD | NEW |