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

Side by Side Diff: content/browser/loader/stream_resource_handler.h

Issue 12645004: Add Resource Handler for creating Streams to forward to extensions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Disable Stream Resource Throttle Created 7 years, 9 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #ifndef CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_
7 7
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/loader/resource_handler.h" 10 #include "content/browser/loader/resource_handler.h"
11 #include "content/browser/streams/stream_write_observer.h"
16 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
17 #include "net/base/mime_util.h"
18 13
19 namespace net { 14 namespace net {
20 class IOBuffer;
21 class URLRequest; 15 class URLRequest;
22 class URLRequestStatus;
23 } // namespace net 16 } // namespace net
24 17
25 namespace content { 18 namespace content {
26 19
27 // This class handles certificate mime types such as: 20 class StreamRegistry;
28 // - "application/x-x509-user-cert" 21
29 // - "application/x-x509-ca-cert" 22 // Redirect this resource to a stream.
30 // - "application/x-pkcs12" 23 class StreamResourceHandler : public StreamWriteObserver,
31 // 24 public ResourceHandler {
32 class CertificateResourceHandler : public ResourceHandler {
33 public: 25 public:
34 CertificateResourceHandler(net::URLRequest* request, 26 StreamResourceHandler(net::URLRequest* request,
35 int render_process_host_id, 27 StreamRegistry* registry,
36 int render_view_id); 28 const GURL& security_origin);
37 virtual ~CertificateResourceHandler(); 29 virtual ~StreamResourceHandler();
38 30
39 virtual bool OnUploadProgress(int request_id, 31 virtual bool OnUploadProgress(int request_id,
40 uint64 position, 32 uint64 position,
41 uint64 size) OVERRIDE; 33 uint64 size) OVERRIDE;
42 34
43 // Not needed, as this event handler ought to be the final resource. 35 // Not needed, as this event handler ought to be the final resource.
44 virtual bool OnRequestRedirected(int request_id, 36 virtual bool OnRequestRedirected(int request_id,
45 const GURL& url, 37 const GURL& url,
46 ResourceResponse* resp, 38 ResourceResponse* resp,
47 bool* defer) OVERRIDE; 39 bool* defer) OVERRIDE;
48 40
49 // Check if this indeed an X509 cert.
50 virtual bool OnResponseStarted(int request_id, 41 virtual bool OnResponseStarted(int request_id,
51 ResourceResponse* resp, 42 ResourceResponse* resp,
52 bool* defer) OVERRIDE; 43 bool* defer) OVERRIDE;
53 44
54 // Pass-through implementation.
55 virtual bool OnWillStart(int request_id, 45 virtual bool OnWillStart(int request_id,
56 const GURL& url, 46 const GURL& url,
57 bool* defer) OVERRIDE; 47 bool* defer) OVERRIDE;
58 48
59 // Create a new buffer to store received data. 49 // Create a new buffer to store received data.
60 virtual bool OnWillRead(int request_id, 50 virtual bool OnWillRead(int request_id,
61 net::IOBuffer** buf, 51 net::IOBuffer** buf,
62 int* buf_size, 52 int* buf_size,
63 int min_size) OVERRIDE; 53 int min_size) OVERRIDE;
64 54
65 // A read was completed, maybe allocate a new buffer for further data. 55 // A read was completed, forward the data to the Stream.
66 virtual bool OnReadCompleted(int request_id, 56 virtual bool OnReadCompleted(int request_id,
67 int bytes_read, 57 int bytes_read,
68 bool* defer) OVERRIDE; 58 bool* defer) OVERRIDE;
69 59
70 // Done downloading the certificate.
71 virtual bool OnResponseCompleted(int request_id, 60 virtual bool OnResponseCompleted(int request_id,
72 const net::URLRequestStatus& urs, 61 const net::URLRequestStatus& status,
73 const std::string& sec_info) OVERRIDE; 62 const std::string& sec_info) OVERRIDE;
74 63
75 // N/A to cert downloading.
76 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; 64 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE;
77 65
66 Stream* stream() { return stream_; }
67
78 private: 68 private:
79 typedef std::vector<std::pair<scoped_refptr<net::IOBuffer>, 69 virtual void OnSpaceAvailable(Stream* stream) OVERRIDE;
80 size_t> > ContentVector; 70 virtual void OnClose(Stream* stream) OVERRIDE;
81 71
82 void AssembleResource();
83
84 GURL url_;
85 net::URLRequest* request_; 72 net::URLRequest* request_;
86 size_t content_length_; 73 scoped_refptr<Stream> stream_;
87 ContentVector buffer_;
88 scoped_refptr<net::IOBuffer> read_buffer_; 74 scoped_refptr<net::IOBuffer> read_buffer_;
89 scoped_refptr<net::IOBuffer> resource_buffer_; // Downloaded certificate. 75 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler);
90 // The id of the |RenderProcessHost| which started the download.
91 int render_process_host_id_;
92 // The id of the |RenderView| which started the download.
93 int render_view_id_;
94 net::CertificateMimeType cert_type_;
95 DISALLOW_COPY_AND_ASSIGN(CertificateResourceHandler);
96 }; 76 };
97 77
98 } // namespace content 78 } // namespace content
99 79
100 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ 80 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_
81
OLDNEW
« no previous file with comments | « content/browser/loader/resource_request_info_impl.cc ('k') | content/browser/loader/stream_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698