OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_NET_URL_REQUEST_INTERCEPT_JOB_H_ | |
6 #define CHROME_COMMON_NET_URL_REQUEST_INTERCEPT_JOB_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/scoped_ptr.h" | |
12 #include "base/task.h" | |
13 #include "chrome/common/chrome_plugin_api.h" | |
14 #include "chrome/common/chrome_plugin_util.h" | |
15 #include "content/common/notification_registrar.h" | |
16 #include "net/url_request/url_request_job.h" | |
17 | |
18 namespace net { | |
19 class URLRequest; | |
20 } // namespace net | |
21 | |
22 class ChromePluginLib; | |
23 | |
24 // A request job that handles network requests intercepted by a Chrome plugin. | |
25 class URLRequestInterceptJob : public net::URLRequestJob, | |
26 public NotificationObserver { | |
27 public: | |
28 static URLRequestInterceptJob* FromCPRequest(CPRequest* request) { | |
29 return ScopableCPRequest::GetData<URLRequestInterceptJob*>(request); | |
30 } | |
31 | |
32 URLRequestInterceptJob(net::URLRequest* request, ChromePluginLib* plugin, | |
33 ScopableCPRequest* cprequest); | |
34 virtual ~URLRequestInterceptJob(); | |
35 | |
36 // Plugin callbacks. | |
37 void OnStartCompleted(int result); | |
38 void OnReadCompleted(int bytes_read); | |
39 | |
40 // net::URLRequestJob | |
41 virtual void Start(); | |
42 virtual void Kill(); | |
43 virtual bool GetMimeType(std::string* mime_type) const; | |
44 virtual bool GetCharset(std::string* charset); | |
45 virtual void GetResponseInfo(net::HttpResponseInfo* info); | |
46 virtual int GetResponseCode() const; | |
47 virtual bool GetContentEncodings( | |
48 std::vector<net::Filter::FilterType>* encoding_types); | |
49 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); | |
50 | |
51 // NotificationObserver | |
52 virtual void Observe(NotificationType type, | |
53 const NotificationSource& source, | |
54 const NotificationDetails& details); | |
55 | |
56 protected: | |
57 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); | |
58 | |
59 private: | |
60 void StartAsync(); | |
61 void DetachPlugin(); | |
62 | |
63 NotificationRegistrar registrar_; | |
64 scoped_ptr<ScopableCPRequest> cprequest_; | |
65 ChromePluginLib* plugin_; | |
66 net::IOBuffer* read_buffer_; | |
67 int read_buffer_size_; | |
68 ScopedRunnableMethodFactory<URLRequestInterceptJob> method_factory_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(URLRequestInterceptJob); | |
71 }; | |
72 | |
73 #endif // CHROME_COMMON_NET_URL_REQUEST_INTERCEPT_JOB_H_ | |
OLD | NEW |