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