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 | 4 |
5 #include "webkit/glue/plugins/pepper_url_request_info.h" | 5 #include "webkit/glue/plugins/pepper_url_request_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "googleurl/src/gurl.h" |
8 #include "third_party/ppapi/c/pp_var.h" | 9 #include "third_party/ppapi/c/pp_var.h" |
| 10 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 11 #include "webkit/glue/plugins/pepper_file_ref.h" |
9 #include "webkit/glue/plugins/pepper_plugin_module.h" | 12 #include "webkit/glue/plugins/pepper_plugin_module.h" |
10 #include "webkit/glue/plugins/pepper_string.h" | 13 #include "webkit/glue/plugins/pepper_string.h" |
11 #include "webkit/glue/plugins/pepper_var.h" | 14 #include "webkit/glue/plugins/pepper_var.h" |
12 | 15 |
| 16 using WebKit::WebString; |
| 17 |
13 namespace pepper { | 18 namespace pepper { |
14 | 19 |
15 namespace { | 20 namespace { |
16 | 21 |
17 PP_Resource Create(PP_Module module_id) { | 22 PP_Resource Create(PP_Module module_id) { |
18 PluginModule* module = PluginModule::FromPPModule(module_id); | 23 PluginModule* module = PluginModule::FromPPModule(module_id); |
19 if (!module) | 24 if (!module) |
20 return 0; | 25 return 0; |
21 | 26 |
22 URLRequestInfo* request = new URLRequestInfo(module); | 27 URLRequestInfo* request = new URLRequestInfo(module); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return false; | 62 return false; |
58 | 63 |
59 return request->AppendDataToBody(data->value()); | 64 return request->AppendDataToBody(data->value()); |
60 } | 65 } |
61 | 66 |
62 bool AppendFileToBody(PP_Resource request_id, | 67 bool AppendFileToBody(PP_Resource request_id, |
63 PP_Resource file_ref_id, | 68 PP_Resource file_ref_id, |
64 int64_t start_offset, | 69 int64_t start_offset, |
65 int64_t number_of_bytes, | 70 int64_t number_of_bytes, |
66 PP_Time expected_last_modified_time) { | 71 PP_Time expected_last_modified_time) { |
67 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 72 scoped_refptr<URLRequestInfo> request( |
68 return false; | 73 Resource::GetAs<URLRequestInfo>(request_id)); |
| 74 if (!request.get()) |
| 75 return false; |
| 76 |
| 77 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); |
| 78 if (!file_ref.get()) |
| 79 return false; |
| 80 |
| 81 return request->AppendFileToBody(file_ref, |
| 82 start_offset, |
| 83 number_of_bytes, |
| 84 expected_last_modified_time); |
69 } | 85 } |
70 | 86 |
71 const PPB_URLRequestInfo ppb_urlrequestinfo = { | 87 const PPB_URLRequestInfo ppb_urlrequestinfo = { |
72 &Create, | 88 &Create, |
73 &IsURLRequestInfo, | 89 &IsURLRequestInfo, |
74 &SetProperty, | 90 &SetProperty, |
75 &AppendDataToBody, | 91 &AppendDataToBody, |
76 &AppendFileToBody | 92 &AppendFileToBody |
77 }; | 93 }; |
78 | 94 |
79 } // namespace | 95 } // namespace |
80 | 96 |
81 URLRequestInfo::URLRequestInfo(PluginModule* module) | 97 URLRequestInfo::URLRequestInfo(PluginModule* module) |
82 : Resource(module) { | 98 : Resource(module) { |
| 99 web_request_.initialize(); |
83 } | 100 } |
84 | 101 |
85 URLRequestInfo::~URLRequestInfo() { | 102 URLRequestInfo::~URLRequestInfo() { |
86 } | 103 } |
87 | 104 |
88 // static | 105 // static |
89 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { | 106 const PPB_URLRequestInfo* URLRequestInfo::GetInterface() { |
90 return &ppb_urlrequestinfo; | 107 return &ppb_urlrequestinfo; |
91 } | 108 } |
92 | 109 |
93 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, | 110 bool URLRequestInfo::SetBooleanProperty(PP_URLRequestProperty property, |
94 bool value) { | 111 bool value) { |
95 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 112 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
96 return false; | 113 return false; |
97 } | 114 } |
98 | 115 |
99 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, | 116 bool URLRequestInfo::SetStringProperty(PP_URLRequestProperty property, |
100 const std::string& value) { | 117 const std::string& value) { |
101 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 118 // TODO(darin): Validate input. Perhaps at a different layer? |
| 119 switch (property) { |
| 120 case PP_URLRequestProperty_URL: |
| 121 web_request_.setURL(GURL(value)); |
| 122 return true; |
| 123 case PP_URLRequestProperty_Method: |
| 124 web_request_.setHTTPMethod(WebString::fromUTF8(value)); |
| 125 return true; |
| 126 case PP_URLRequestProperty_Headers: |
| 127 // TODO(darin): Support extra request headers |
| 128 NOTIMPLEMENTED(); |
| 129 return false; |
| 130 } |
102 return false; | 131 return false; |
103 } | 132 } |
104 | 133 |
105 bool URLRequestInfo::AppendDataToBody(const std::string& data) { | 134 bool URLRequestInfo::AppendDataToBody(const std::string& data) { |
106 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 135 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
107 return false; | 136 return false; |
108 } | 137 } |
109 | 138 |
| 139 bool URLRequestInfo::AppendFileToBody(FileRef* file_ref, |
| 140 int64_t start_offset, |
| 141 int64_t number_of_bytes, |
| 142 PP_Time expected_last_modified_time) { |
| 143 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
| 144 return false; |
| 145 } |
| 146 |
110 } // namespace pepper | 147 } // namespace pepper |
OLD | NEW |