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

Side by Side Diff: content/renderer/npapi/webplugin_impl.cc

Issue 23830007: Support byte range requests when routing resource requests directly through the browser process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/npapi/webplugin_impl.h" 5 #include "content/renderer/npapi/webplugin_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/crash_logging.h" 9 #include "base/debug/crash_logging.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 namespace { 89 namespace {
90 90
91 // This class handles individual multipart responses. It is instantiated when 91 // This class handles individual multipart responses. It is instantiated when
92 // we receive HTTP status code 206 in the HTTP response. This indicates 92 // we receive HTTP status code 206 in the HTTP response. This indicates
93 // that the response could have multiple parts each separated by a boundary 93 // that the response could have multiple parts each separated by a boundary
94 // specified in the response header. 94 // specified in the response header.
95 class MultiPartResponseClient : public WebURLLoaderClient { 95 class MultiPartResponseClient : public WebURLLoaderClient {
96 public: 96 public:
97 explicit MultiPartResponseClient(WebPluginResourceClient* resource_client) 97 explicit MultiPartResponseClient(WebPluginResourceClient* resource_client)
98 : resource_client_(resource_client) { 98 : byte_range_lower_bound_(0), resource_client_(resource_client) {}
99 Clear();
100 }
101 99
102 virtual void willSendRequest( 100 virtual void willSendRequest(
103 WebURLLoader*, WebURLRequest&, const WebURLResponse&) {} 101 WebURLLoader*, WebURLRequest&, const WebURLResponse&) {}
104 virtual void didSendData( 102 virtual void didSendData(
105 WebURLLoader*, unsigned long long, unsigned long long) {} 103 WebURLLoader*, unsigned long long, unsigned long long) {}
106 104
107 // Called when the multipart parser encounters an embedded multipart 105 // Called when the multipart parser encounters an embedded multipart
108 // response. 106 // response.
109 virtual void didReceiveResponse( 107 virtual void didReceiveResponse(
110 WebURLLoader*, const WebURLResponse& response) { 108 WebURLLoader*, const WebURLResponse& response) {
111 int64 instance_size; 109 int64 byte_range_upper_bound, instance_size;
112 if (!MultipartResponseDelegate::ReadContentRanges( 110 if (!MultipartResponseDelegate::ReadContentRanges(
113 response, 111 response,
114 &byte_range_lower_bound_, 112 &byte_range_lower_bound_,
115 &byte_range_upper_bound_, 113 &byte_range_upper_bound,
116 &instance_size)) { 114 &instance_size)) {
117 NOTREACHED(); 115 NOTREACHED();
118 return;
119 } 116 }
120
121 resource_response_ = response;
122 } 117 }
123 118
124 // Receives individual part data from a multipart response. 119 // Receives individual part data from a multipart response.
125 virtual void didReceiveData(WebURLLoader*, 120 virtual void didReceiveData(WebURLLoader*,
126 const char* data, 121 const char* data,
127 int data_length, 122 int data_length,
128 int encoded_data_length) { 123 int encoded_data_length) {
129 // TODO(ananta) 124 // TODO(ananta)
130 // We should defer further loads on multipart resources on the same lines 125 // We should defer further loads on multipart resources on the same lines
131 // as regular resources requested by plugins to prevent reentrancy. 126 // as regular resources requested by plugins to prevent reentrancy.
132 resource_client_->DidReceiveData( 127 resource_client_->DidReceiveData(
133 data, data_length, byte_range_lower_bound_); 128 data, data_length, byte_range_lower_bound_);
134 byte_range_lower_bound_ += data_length; 129 byte_range_lower_bound_ += data_length;
135 } 130 }
136 131
137 virtual void didFinishLoading(WebURLLoader*, double finishTime) {} 132 virtual void didFinishLoading(WebURLLoader*, double finishTime) {}
138 virtual void didFail(WebURLLoader*, const WebURLError&) {} 133 virtual void didFail(WebURLLoader*, const WebURLError&) {}
139 134
140 void Clear() {
141 resource_response_.reset();
142 byte_range_lower_bound_ = 0;
143 byte_range_upper_bound_ = 0;
144 }
145
146 private: 135 private:
147 WebURLResponse resource_response_;
148 // The lower bound of the byte range. 136 // The lower bound of the byte range.
149 int64 byte_range_lower_bound_; 137 int64 byte_range_lower_bound_;
150 // The upper bound of the byte range.
151 int64 byte_range_upper_bound_;
152 // The handler for the data. 138 // The handler for the data.
153 WebPluginResourceClient* resource_client_; 139 WebPluginResourceClient* resource_client_;
154 }; 140 };
155 141
156 class HeaderFlattener : public WebHTTPHeaderVisitor { 142 class HeaderFlattener : public WebHTTPHeaderVisitor {
157 public: 143 public:
158 explicit HeaderFlattener(std::string* buf) : buf_(buf) { 144 explicit HeaderFlattener(std::string* buf) : buf_(buf) {
159 } 145 }
160 146
161 virtual void visitHeader(const WebString& name, const WebString& value) { 147 virtual void visitHeader(const WebString& name, const WebString& value) {
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } 925 }
940 } 926 }
941 927
942 void WebPluginImpl::didSendData(WebURLLoader* loader, 928 void WebPluginImpl::didSendData(WebURLLoader* loader,
943 unsigned long long bytes_sent, 929 unsigned long long bytes_sent,
944 unsigned long long total_bytes_to_be_sent) { 930 unsigned long long total_bytes_to_be_sent) {
945 } 931 }
946 932
947 void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, 933 void WebPluginImpl::didReceiveResponse(WebURLLoader* loader,
948 const WebURLResponse& response) { 934 const WebURLResponse& response) {
935 // TODO(jam): THIS LOGIC IS COPIED IN PluginURLFetcher::OnReceivedResponse
936 // until kDirectNPAPIRequests is the default and we can remove this old path.
949 static const int kHttpPartialResponseStatusCode = 206; 937 static const int kHttpPartialResponseStatusCode = 206;
950 static const int kHttpResponseSuccessStatusCode = 200; 938 static const int kHttpResponseSuccessStatusCode = 200;
951 939
952 WebPluginResourceClient* client = GetClientFromLoader(loader); 940 WebPluginResourceClient* client = GetClientFromLoader(loader);
953 if (!client) 941 if (!client)
954 return; 942 return;
955 943
956 ResponseInfo response_info; 944 ResponseInfo response_info;
957 GetResponseInfo(response, &response_info); 945 GetResponseInfo(response, &response_info);
958 ClientInfo* client_info = GetClientInfoFromLoader(loader); 946 ClientInfo* client_info = GetClientInfoFromLoader(loader);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 } 1060 }
1073 1061
1074 void WebPluginImpl::didFinishLoading(WebURLLoader* loader, double finishTime) { 1062 void WebPluginImpl::didFinishLoading(WebURLLoader* loader, double finishTime) {
1075 ClientInfo* client_info = GetClientInfoFromLoader(loader); 1063 ClientInfo* client_info = GetClientInfoFromLoader(loader);
1076 if (client_info && client_info->client) { 1064 if (client_info && client_info->client) {
1077 MultiPartResponseHandlerMap::iterator index = 1065 MultiPartResponseHandlerMap::iterator index =
1078 multi_part_response_map_.find(client_info->client); 1066 multi_part_response_map_.find(client_info->client);
1079 if (index != multi_part_response_map_.end()) { 1067 if (index != multi_part_response_map_.end()) {
1080 delete (*index).second; 1068 delete (*index).second;
1081 multi_part_response_map_.erase(index); 1069 multi_part_response_map_.erase(index);
1082 if (render_view_.get()) { 1070 DidStopLoading();
1083 // TODO(darin): Make is_loading_ be a counter!
1084 render_view_->didStopLoading();
1085 }
1086 } 1071 }
1087 loader->setDefersLoading(true); 1072 loader->setDefersLoading(true);
1088 WebPluginResourceClient* resource_client = client_info->client; 1073 WebPluginResourceClient* resource_client = client_info->client;
1089 // The ClientInfo can get deleted in the call to DidFinishLoading below. 1074 // The ClientInfo can get deleted in the call to DidFinishLoading below.
1090 // It is not safe to access this structure after that. 1075 // It is not safe to access this structure after that.
1091 client_info->client = NULL; 1076 client_info->client = NULL;
1092 resource_client->DidFinishLoading(client_info->id); 1077 resource_client->DidFinishLoading(client_info->id);
1093 } 1078 }
1094 } 1079 }
1095 1080
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 // TODO(jam): any better way of getting this? Can't find a way to get 1204 // TODO(jam): any better way of getting this? Can't find a way to get
1220 // frame()->loader()->outgoingReferrer() which 1205 // frame()->loader()->outgoingReferrer() which
1221 // WebFrameImpl::setReferrerForRequest does. 1206 // WebFrameImpl::setReferrerForRequest does.
1222 WebURLRequest request(complete_url); 1207 WebURLRequest request(complete_url);
1223 SetReferrer(&request, referrer_flag); 1208 SetReferrer(&request, referrer_flag);
1224 GURL referrer( 1209 GURL referrer(
1225 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); 1210 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8());
1226 1211
1227 GURL first_party_for_cookies = webframe_->document().firstPartyForCookies(); 1212 GURL first_party_for_cookies = webframe_->document().firstPartyForCookies();
1228 delegate_->FetchURL(resource_id, notify_id, complete_url, 1213 delegate_->FetchURL(resource_id, notify_id, complete_url,
1229 first_party_for_cookies, method, std::string(buf, len), 1214 first_party_for_cookies, method, buf, len, referrer,
1230 referrer, notify_redirects, is_plugin_src_load, 0, 1215 notify_redirects, is_plugin_src_load, 0,
1231 render_view_->routing_id()); 1216 render_view_->routing_id());
1232 } else { 1217 } else {
1233 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( 1218 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient(
1234 resource_id, complete_url, notify_id); 1219 resource_id, complete_url, notify_id);
1235 if (!resource_client) 1220 if (!resource_client)
1236 return; 1221 return;
1237 InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, 1222 InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf,
1238 len, NULL, referrer_flag, notify_redirects, 1223 len, NULL, referrer_flag, notify_redirects,
1239 is_plugin_src_load); 1224 is_plugin_src_load);
1240 } 1225 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 load_manually_ ? NO_REFERRER : PLUGIN_SRC)) 1309 load_manually_ ? NO_REFERRER : PLUGIN_SRC))
1325 return; 1310 return;
1326 1311
1327 WebPluginResourceClient* resource_client = 1312 WebPluginResourceClient* resource_client =
1328 delegate_->CreateSeekableResourceClient(resource_id, range_request_id); 1313 delegate_->CreateSeekableResourceClient(resource_id, range_request_id);
1329 InitiateHTTPRequest( 1314 InitiateHTTPRequest(
1330 resource_id, resource_client, complete_url, "GET", NULL, 0, range_info, 1315 resource_id, resource_client, complete_url, "GET", NULL, 0, range_info,
1331 load_manually_ ? NO_REFERRER : PLUGIN_SRC, false, false); 1316 load_manually_ ? NO_REFERRER : PLUGIN_SRC, false, false);
1332 } 1317 }
1333 1318
1319 void WebPluginImpl::DidStartLoading() {
1320 if (render_view_.get()) {
1321 // TODO(darin): Make is_loading_ be a counter!
1322 render_view_->didStartLoading();
1323 }
1324 }
1325
1326 void WebPluginImpl::DidStopLoading() {
1327 if (render_view_.get()) {
1328 // TODO(darin): Make is_loading_ be a counter!
1329 render_view_->didStopLoading();
1330 }
1331 }
1332
1334 void WebPluginImpl::SetDeferResourceLoading(unsigned long resource_id, 1333 void WebPluginImpl::SetDeferResourceLoading(unsigned long resource_id,
1335 bool defer) { 1334 bool defer) {
1336 std::vector<ClientInfo>::iterator client_index = clients_.begin(); 1335 std::vector<ClientInfo>::iterator client_index = clients_.begin();
1337 while (client_index != clients_.end()) { 1336 while (client_index != clients_.end()) {
1338 ClientInfo& client_info = *client_index; 1337 ClientInfo& client_info = *client_index;
1339 1338
1340 if (client_info.id == resource_id) { 1339 if (client_info.id == resource_id) {
1341 client_info.loader->setDefersLoading(defer); 1340 client_info.loader->setDefersLoading(defer);
1342 1341
1343 // If we determined that the request had failed via the HTTP headers 1342 // If we determined that the request had failed via the HTTP headers
(...skipping 15 matching lines...) Expand all
1359 } 1358 }
1360 } 1359 }
1361 1360
1362 bool WebPluginImpl::IsOffTheRecord() { 1361 bool WebPluginImpl::IsOffTheRecord() {
1363 return false; 1362 return false;
1364 } 1363 }
1365 1364
1366 bool WebPluginImpl::HandleHttpMultipartResponse( 1365 bool WebPluginImpl::HandleHttpMultipartResponse(
1367 const WebURLResponse& response, WebPluginResourceClient* client) { 1366 const WebURLResponse& response, WebPluginResourceClient* client) {
1368 std::string multipart_boundary; 1367 std::string multipart_boundary;
1368 std::string content_type =
ananta 2013/09/16 18:35:41 Remove?
jam 2013/09/16 19:31:34 Done, thanks. that was left over code from another
1369 response.httpHeaderField(WebString::fromUTF8("Content-Type")).utf8();
1369 if (!MultipartResponseDelegate::ReadMultipartBoundary( 1370 if (!MultipartResponseDelegate::ReadMultipartBoundary(
1370 response, &multipart_boundary)) { 1371 response, &multipart_boundary)) {
1371 return false; 1372 return false;
1372 } 1373 }
1373 1374
1374 if (render_view_.get()) { 1375 DidStartLoading();
1375 // TODO(darin): Make is_loading_ be a counter!
1376 render_view_->didStartLoading();
1377 }
1378 1376
1379 MultiPartResponseClient* multi_part_response_client = 1377 MultiPartResponseClient* multi_part_response_client =
1380 new MultiPartResponseClient(client); 1378 new MultiPartResponseClient(client);
1381 1379
1382 MultipartResponseDelegate* multi_part_response_handler = 1380 MultipartResponseDelegate* multi_part_response_handler =
1383 new MultipartResponseDelegate(multi_part_response_client, NULL, 1381 new MultipartResponseDelegate(multi_part_response_client, NULL,
1384 response, 1382 response,
1385 multipart_boundary); 1383 multipart_boundary);
1386 multi_part_response_map_[client] = multi_part_response_handler; 1384 multi_part_response_map_[client] = multi_part_response_handler;
1387 return true; 1385 return true;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 case PLUGIN_SRC: 1497 case PLUGIN_SRC:
1500 webframe_->setReferrerForRequest(*request, plugin_url_); 1498 webframe_->setReferrerForRequest(*request, plugin_url_);
1501 break; 1499 break;
1502 1500
1503 default: 1501 default:
1504 break; 1502 break;
1505 } 1503 }
1506 } 1504 }
1507 1505
1508 } // namespace content 1506 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698