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 PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ | |
6 #define PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "ppapi/thunk/ppb_url_request_info_api.h" | |
13 #include "ppapi/shared_impl/resource.h" | |
14 | |
15 namespace ppapi { | |
16 | |
17 namespace thunk { | |
18 class PPB_FileRef_API; | |
19 } | |
20 | |
21 struct PPB_URLRequestInfo_Data { | |
22 struct BodyItem { | |
23 BodyItem(); | |
24 explicit BodyItem(const std::string& data); | |
25 BodyItem(Resource* file_ref, | |
26 int64_t start_offset, | |
27 int64_t number_of_bytes, | |
28 PP_Time expected_last_modified_time); | |
29 | |
30 // Set if the input is a file, false means the |data| is valid. | |
31 bool is_file; | |
32 | |
33 std::string data; | |
34 | |
35 // Is is_file is set, these variables are set. Note that the resoruce | |
bbudge
2011/08/23 20:35:59
sp. resource
| |
36 // may still be NULL in some cases, such as deserialization errors. | |
37 // | |
38 // This is a bit tricky. In the plugin side of the proxy, both the file | |
39 // ref and the file_ref_host_resource will be set and valid: the scoped_ptr | |
40 // ensures that the resource is alive for as long as the BodyItem is, and | |
41 // the host resource is for the serialization system to send it over the | |
42 // wire. | |
bbudge
2011/08/23 20:35:59
I'm having a hard time understanding this comment.
brettw
2011/08/24 23:41:09
I simplified this a bit.
| |
43 // | |
44 // When we deserialize this in the renderer, the file_refs won't be valid | |
45 // until the host resources are converted to Resource pointers in the | |
46 // PPB_URLRequestInfo_Impl. | |
47 scoped_refptr<Resource> file_ref; | |
48 HostResource file_ref_host_resource; | |
49 | |
50 int64_t start_offset; | |
51 int64_t number_of_bytes; | |
52 PP_Time expected_last_modified_time; | |
53 | |
54 // If you add more stuff here, be sure to modify the serialization rules in | |
55 // ppapi_messages.h | |
56 }; | |
57 | |
58 PPB_URLRequestInfo_Data(); | |
59 ~PPB_URLRequestInfo_Data(); | |
60 | |
61 std::string url; | |
62 std::string method; | |
63 std::string headers; | |
64 | |
65 bool stream_to_file; | |
66 bool follow_redirects; | |
67 bool record_download_progress; | |
68 bool record_upload_progress; | |
69 | |
70 // |has_custom_referrer_url| is set to false if a custom referrer hasn't been | |
71 // set (or has been set to an Undefined Var) and the default referrer should | |
72 // be used. (Setting the custom referrer to an empty string indicates that no | |
73 // referrer header should be generated.) | |
74 bool has_custom_referrer_url; | |
75 std::string custom_referrer_url; | |
76 | |
77 bool allow_cross_origin_requests; | |
78 bool allow_credentials; | |
79 | |
80 // Similar to the custom referrer (above), but for custom content transfer | |
81 // encoding. | |
82 bool has_custom_content_transfer_encoding; | |
83 std::string custom_content_transfer_encoding; | |
84 | |
85 int32_t prefetch_buffer_upper_threshold; | |
86 int32_t prefetch_buffer_lower_threshold; | |
87 | |
88 std::vector<BodyItem> body; | |
89 | |
90 // If you add more stuff here, be sure to modify the serialization rules in | |
91 // ppapi_messages.h | |
92 }; | |
93 | |
94 class URLRequestInfoImpl : public ::ppapi::Resource, | |
95 public ::ppapi::thunk::PPB_URLRequestInfo_API { | |
96 public: | |
97 // This constructor initializes the object as a proxy object with the given | |
98 // host resource. | |
99 URLRequestInfoImpl(const HostResource& host_resource, | |
100 const PPB_URLRequestInfo_Data& data); | |
101 | |
102 ~URLRequestInfoImpl(); | |
103 | |
104 // Resource overrides. | |
105 virtual thunk::PPB_URLRequestInfo_API* AsPPB_URLRequestInfo_API() OVERRIDE; | |
106 | |
107 // PPB_URLRequestInfo_API implementation. | |
108 virtual PP_Bool SetProperty(PP_URLRequestProperty property, | |
109 PP_Var var) OVERRIDE; | |
110 virtual PP_Bool AppendDataToBody(const void* data, uint32_t len) OVERRIDE; | |
111 virtual PP_Bool AppendFileToBody( | |
112 PP_Resource file_ref, | |
113 int64_t start_offset, | |
114 int64_t number_of_bytes, | |
115 PP_Time expected_last_modified_time) OVERRIDE; | |
116 virtual const PPB_URLRequestInfo_Data& GetData() const OVERRIDE; | |
117 | |
118 protected: | |
119 // Constructor used by the webkit implementation. | |
120 URLRequestInfoImpl(PP_Instance instance, | |
121 const PPB_URLRequestInfo_Data& data); | |
122 | |
123 // Checks that the HTTP method is valid, returning the canonicalized version | |
124 // if so. Returns empty string if it's invalid. | |
125 static std::string ValidateMethod(const std::string& method); | |
126 | |
127 bool SetUndefinedProperty(PP_URLRequestProperty property); | |
128 bool SetBooleanProperty(PP_URLRequestProperty property, bool value); | |
129 bool SetIntegerProperty(PP_URLRequestProperty property, int32_t value); | |
130 bool SetStringProperty(PP_URLRequestProperty property, | |
131 const std::string& value); | |
132 | |
133 const PPB_URLRequestInfo_Data& data() const { return data_; } | |
134 PPB_URLRequestInfo_Data& data() { return data_; } | |
135 | |
136 private: | |
137 PPB_URLRequestInfo_Data data_; | |
138 | |
139 DISALLOW_IMPLICIT_CONSTRUCTORS(URLRequestInfoImpl); | |
140 }; | |
141 | |
142 } // namespace ppapi | |
143 | |
144 #endif // PPAPI_SHARED_IMPL_URL_REQUEST_INFO_IMPL_H_ | |
OLD | NEW |