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/location.h" | 10 #include "base/location.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 } | 354 } |
355 | 355 |
356 // Only UpdateGeometry if either the window or clip rects have changed. | 356 // Only UpdateGeometry if either the window or clip rects have changed. |
357 if (delegate_ && (first_geometry_update_ || | 357 if (delegate_ && (first_geometry_update_ || |
358 new_geometry.window_rect != geometry_.window_rect || | 358 new_geometry.window_rect != geometry_.window_rect || |
359 new_geometry.clip_rect != geometry_.clip_rect)) { | 359 new_geometry.clip_rect != geometry_.clip_rect)) { |
360 // Notify the plugin that its parameters have changed. | 360 // Notify the plugin that its parameters have changed. |
361 delegate_->UpdateGeometry(new_geometry.window_rect, new_geometry.clip_rect); | 361 delegate_->UpdateGeometry(new_geometry.window_rect, new_geometry.clip_rect); |
362 } | 362 } |
363 | 363 |
364 // Initiate a download on the plugin url. This should be done for the | |
365 // first update geometry sequence. We need to ensure that the plugin | |
366 // receives the geometry update before it starts receiving data. | |
367 if (first_geometry_update_) { | |
368 // An empty url corresponds to an EMBED tag with no src attribute. | |
369 if (!load_manually_ && plugin_url_.is_valid()) { | |
370 // The Flash plugin hangs for a while if it receives data before | |
371 // receiving valid plugin geometry. By valid geometry we mean the | |
372 // geometry received by a call to setFrameRect in the Webkit | |
373 // layout code path. To workaround this issue we download the | |
374 // plugin source url on a timer. | |
375 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
376 FROM_HERE, base::Bind(&WebPluginImpl::OnDownloadPluginSrcUrl, | |
377 weak_factory_.GetWeakPtr())); | |
dcheng
2015/11/19 03:41:40
Looks like you can delete weak_factory_ too.
Nate Chapin
2015/11/19 19:28:50
Done.
| |
378 } | |
379 } | |
380 | |
381 #if defined(OS_WIN) | 364 #if defined(OS_WIN) |
382 // Don't cache the geometry during the first geometry update. The first | 365 // Don't cache the geometry during the first geometry update. The first |
383 // geometry update sequence is received when Widget::setParent is called. | 366 // geometry update sequence is received when Widget::setParent is called. |
384 // For plugins like media player which have a bug where they only honor | 367 // For plugins like media player which have a bug where they only honor |
385 // the first geometry update, we have a quirk which ignores the first | 368 // the first geometry update, we have a quirk which ignores the first |
386 // geometry update. To ensure that these plugins work correctly in cases | 369 // geometry update. To ensure that these plugins work correctly in cases |
387 // where we receive only one geometry update from webkit, we also force | 370 // where we receive only one geometry update from webkit, we also force |
388 // a geometry update during paint which should go out correctly as the | 371 // a geometry update during paint which should go out correctly as the |
389 // initial geometry update was not cached. | 372 // initial geometry update was not cached. |
390 if (!first_geometry_update_) | 373 if (!first_geometry_update_) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 cursor_info.type = web_cursor_info.type; | 412 cursor_info.type = web_cursor_info.type; |
430 cursor_info.hotSpot = web_cursor_info.hotspot; | 413 cursor_info.hotSpot = web_cursor_info.hotspot; |
431 cursor_info.customImage = web_cursor_info.custom_image; | 414 cursor_info.customImage = web_cursor_info.custom_image; |
432 cursor_info.imageScaleFactor = web_cursor_info.image_scale_factor; | 415 cursor_info.imageScaleFactor = web_cursor_info.image_scale_factor; |
433 #if defined(OS_WIN) | 416 #if defined(OS_WIN) |
434 cursor_info.externalHandle = web_cursor_info.external_handle; | 417 cursor_info.externalHandle = web_cursor_info.external_handle; |
435 #endif | 418 #endif |
436 return ret; | 419 return ret; |
437 } | 420 } |
438 | 421 |
439 void WebPluginImpl::didReceiveResponse(const WebURLResponse& response) { | |
440 ignore_response_error_ = false; | |
441 | |
442 ResponseInfo response_info; | |
443 GetResponseInfo(response, &response_info); | |
444 | |
445 delegate_->DidReceiveManualResponse( | |
446 response_info.url, | |
447 response_info.mime_type, | |
448 GetAllHeaders(response), | |
449 response_info.expected_length, | |
450 response_info.last_modified); | |
451 } | |
452 | |
453 void WebPluginImpl::didReceiveData(const char* data, int data_length) { | |
454 delegate_->DidReceiveManualData(data, data_length); | |
455 } | |
456 | |
457 void WebPluginImpl::didFinishLoading() { | |
458 delegate_->DidFinishManualLoading(); | |
459 } | |
460 | |
461 void WebPluginImpl::didFailLoading(const WebURLError& error) { | |
462 if (!ignore_response_error_) | |
463 delegate_->DidManualLoadFail(); | |
464 } | |
465 | |
466 void WebPluginImpl::didFinishLoadingFrameRequest( | |
467 const WebURL& url, void* notify_data) { | |
468 if (delegate_) { | |
469 // We're converting a void* into an arbitrary int id. Though | |
470 // these types are the same size on all the platforms we support, | |
471 // the compiler may complain as though they are different, so to | |
472 // make the casting gods happy go through an intptr_t (the union | |
473 // of void* and int) rather than converting straight across. | |
474 delegate_->DidFinishLoadWithReason( | |
475 url, NPRES_DONE, reinterpret_cast<intptr_t>(notify_data)); | |
476 } | |
477 } | |
478 | |
479 void WebPluginImpl::didFailLoadingFrameRequest( | |
480 const WebURL& url, void* notify_data, const WebURLError& error) { | |
481 if (!delegate_) | |
482 return; | |
483 | |
484 NPReason reason = | |
485 error.reason == net::ERR_ABORTED ? NPRES_USER_BREAK : NPRES_NETWORK_ERR; | |
486 // See comment in didFinishLoadingFrameRequest about the cast here. | |
487 delegate_->DidFinishLoadWithReason( | |
488 url, reason, reinterpret_cast<intptr_t>(notify_data)); | |
489 } | |
490 | |
491 bool WebPluginImpl::isPlaceholder() { | 422 bool WebPluginImpl::isPlaceholder() { |
492 return false; | 423 return false; |
493 } | 424 } |
494 | 425 |
495 WebPluginImpl::LoaderClient::LoaderClient(WebPluginImpl* parent) | 426 WebPluginImpl::LoaderClient::LoaderClient(WebPluginImpl* parent) |
496 : parent_(parent) {} | 427 : parent_(parent) {} |
497 | 428 |
498 void WebPluginImpl::LoaderClient::willFollowRedirect( | 429 void WebPluginImpl::LoaderClient::willFollowRedirect( |
499 blink::WebURLLoader* loader, blink::WebURLRequest& new_request, | 430 blink::WebURLLoader* loader, blink::WebURLRequest& new_request, |
500 const blink::WebURLResponse& redirect_response) { | 431 const blink::WebURLResponse& redirect_response) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 } | 621 } |
691 | 622 |
692 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( | 623 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( |
693 const char* url, | 624 const char* url, |
694 bool is_javascript_url, | 625 bool is_javascript_url, |
695 bool popups_allowed, | 626 bool popups_allowed, |
696 const char* method, | 627 const char* method, |
697 const char* target, | 628 const char* target, |
698 const char* buf, | 629 const char* buf, |
699 unsigned int len, | 630 unsigned int len, |
700 int notify_id, | |
701 ReferrerValue referrer_flag) { | 631 ReferrerValue referrer_flag) { |
702 // If there is no target, there is nothing to do | 632 // If there is no target, there is nothing to do |
703 if (!target) | 633 if (!target) |
704 return NOT_ROUTED; | 634 return NOT_ROUTED; |
705 | 635 |
706 // This could happen if the WebPluginContainer was already deleted. | 636 // This could happen if the WebPluginContainer was already deleted. |
707 if (!webframe_) | 637 if (!webframe_) |
708 return NOT_ROUTED; | 638 return NOT_ROUTED; |
709 | 639 |
710 WebString target_str = WebString::fromUTF8(target); | 640 WebString target_str = WebString::fromUTF8(target); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 request.setSkipServiceWorker(true); | 684 request.setSkipServiceWorker(true); |
755 if (len > 0) { | 685 if (len > 0) { |
756 if (!SetPostData(&request, buf, len)) { | 686 if (!SetPostData(&request, buf, len)) { |
757 // Uhoh - we're in trouble. There isn't a good way | 687 // Uhoh - we're in trouble. There isn't a good way |
758 // to recover at this point. Break out. | 688 // to recover at this point. Break out. |
759 NOTREACHED(); | 689 NOTREACHED(); |
760 return ROUTED; | 690 return ROUTED; |
761 } | 691 } |
762 } | 692 } |
763 | 693 |
764 container_->loadFrameRequest( | 694 container_->loadFrameRequest(request, target_str); |
765 request, target_str, notify_id != 0, reinterpret_cast<void*>(notify_id)); | |
766 return ROUTED; | 695 return ROUTED; |
767 } | 696 } |
768 | 697 |
769 NPObject* WebPluginImpl::GetWindowScriptNPObject() { | 698 NPObject* WebPluginImpl::GetWindowScriptNPObject() { |
770 if (!webframe_) { | 699 if (!webframe_) { |
771 NOTREACHED(); | 700 NOTREACHED(); |
772 return NULL; | 701 return NULL; |
773 } | 702 } |
774 return webframe_->windowObject(); | 703 return webframe_->windowObject(); |
775 } | 704 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 void WebPluginImpl::Invalidate() { | 822 void WebPluginImpl::Invalidate() { |
894 if (container_) | 823 if (container_) |
895 container_->invalidate(); | 824 container_->invalidate(); |
896 } | 825 } |
897 | 826 |
898 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { | 827 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { |
899 if (container_) | 828 if (container_) |
900 container_->invalidateRect(rect); | 829 container_->invalidateRect(rect); |
901 } | 830 } |
902 | 831 |
903 void WebPluginImpl::OnDownloadPluginSrcUrl() { | |
904 HandleURLRequestInternal( | |
905 plugin_url_.spec().c_str(), "GET", NULL, NULL, 0, 0, false, DOCUMENT_URL, | |
906 false, true); | |
907 } | |
908 | |
909 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( | 832 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( |
910 WebURLLoader* loader) { | 833 WebURLLoader* loader) { |
911 ClientInfo* client_info = GetClientInfoFromLoader(loader); | 834 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
912 if (client_info) | 835 if (client_info) |
913 return client_info->client; | 836 return client_info->client; |
914 return NULL; | 837 return NULL; |
915 } | 838 } |
916 | 839 |
917 WebPluginImpl::ClientInfo* WebPluginImpl::GetClientInfoFromLoader( | 840 WebPluginImpl::ClientInfo* WebPluginImpl::GetClientInfoFromLoader( |
918 WebURLLoader* loader) { | 841 WebURLLoader* loader) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 | 894 |
972 void WebPluginImpl::didSendData(WebURLLoader* loader, | 895 void WebPluginImpl::didSendData(WebURLLoader* loader, |
973 unsigned long long bytes_sent, | 896 unsigned long long bytes_sent, |
974 unsigned long long total_bytes_to_be_sent) { | 897 unsigned long long total_bytes_to_be_sent) { |
975 } | 898 } |
976 | 899 |
977 void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, | 900 void WebPluginImpl::didReceiveResponse(WebURLLoader* loader, |
978 const WebURLResponse& response) { | 901 const WebURLResponse& response) { |
979 // TODO(jam): THIS LOGIC IS COPIED IN PluginURLFetcher::OnReceivedResponse | 902 // TODO(jam): THIS LOGIC IS COPIED IN PluginURLFetcher::OnReceivedResponse |
980 // until kDirectNPAPIRequests is the default and we can remove this old path. | 903 // until kDirectNPAPIRequests is the default and we can remove this old path. |
981 static const int kHttpPartialResponseStatusCode = 206; | |
982 static const int kHttpResponseSuccessStatusCode = 200; | |
983 | 904 |
984 WebPluginResourceClient* client = GetClientFromLoader(loader); | 905 WebPluginResourceClient* client = GetClientFromLoader(loader); |
985 if (!client) | 906 if (!client) |
986 return; | 907 return; |
987 | 908 |
988 ResponseInfo response_info; | 909 ResponseInfo response_info; |
989 GetResponseInfo(response, &response_info); | 910 GetResponseInfo(response, &response_info); |
990 ClientInfo* client_info = GetClientInfoFromLoader(loader); | 911 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
991 if (!client_info) | 912 if (!client_info) |
992 return; | 913 return; |
993 | 914 |
994 bool request_is_seekable = true; | |
995 if (client->IsMultiByteResponseExpected()) { | |
996 if (response.httpStatusCode() == kHttpPartialResponseStatusCode) { | |
997 ClientInfo* client_info = GetClientInfoFromLoader(loader); | |
998 if (!client_info) | |
999 return; | |
1000 if (HandleHttpMultipartResponse(response, client)) { | |
1001 // Multiple ranges requested, data will be delivered by | |
1002 // MultipartResponseDelegate. | |
1003 client_info->data_offset = 0; | |
1004 return; | |
1005 } | |
1006 int64 upper_bound = 0, instance_size = 0; | |
1007 // Single range requested - go through original processing for | |
1008 // non-multipart requests, but update data offset. | |
1009 MultipartResponseDelegate::ReadContentRanges(response, | |
1010 &client_info->data_offset, | |
1011 &upper_bound, | |
1012 &instance_size); | |
1013 } else if (response.httpStatusCode() == kHttpResponseSuccessStatusCode) { | |
1014 RenderThreadImpl::current()->RecordAction( | |
1015 base::UserMetricsAction("Plugin_200ForByteRange")); | |
1016 // If the client issued a byte range request and the server responds with | |
1017 // HTTP 200 OK, it indicates that the server does not support byte range | |
1018 // requests. | |
1019 // We need to emulate Firefox behavior by doing the following:- | |
1020 // 1. Destroy the plugin instance in the plugin process. Ensure that | |
1021 // existing resource requests initiated for the plugin instance | |
1022 // continue to remain valid. | |
1023 // 2. Create a new plugin instance and notify it about the response | |
1024 // received here. | |
1025 if (!ReinitializePluginForResponse(loader)) { | |
1026 NOTREACHED(); | |
1027 return; | |
1028 } | |
1029 | |
1030 // The server does not support byte range requests. No point in creating | |
1031 // seekable streams. | |
1032 request_is_seekable = false; | |
1033 | |
1034 delete client; | |
1035 client = NULL; | |
1036 | |
1037 // Create a new resource client for this request. | |
1038 for (size_t i = 0; i < clients_.size(); ++i) { | |
1039 if (clients_[i].loader.get() == loader) { | |
1040 WebPluginResourceClient* resource_client = | |
1041 delegate_->CreateResourceClient(clients_[i].id, plugin_url_, 0); | |
1042 clients_[i].client = resource_client; | |
1043 client = resource_client; | |
1044 break; | |
1045 } | |
1046 } | |
1047 | |
1048 DCHECK(client != NULL); | |
1049 } | |
1050 } | |
1051 | |
1052 // Calling into a plugin could result in reentrancy if the plugin yields | 915 // Calling into a plugin could result in reentrancy if the plugin yields |
1053 // control to the OS like entering a modal loop etc. Prevent this by | 916 // control to the OS like entering a modal loop etc. Prevent this by |
1054 // stopping further loading until the plugin notifies us that it is ready to | 917 // stopping further loading until the plugin notifies us that it is ready to |
1055 // accept data | 918 // accept data |
1056 loader->setDefersLoading(true); | 919 loader->setDefersLoading(true); |
1057 | 920 |
1058 client->DidReceiveResponse( | 921 client->DidReceiveResponse( |
1059 response_info.mime_type, | 922 response_info.mime_type, |
1060 GetAllHeaders(response), | 923 GetAllHeaders(response), |
1061 response_info.expected_length, | 924 response_info.expected_length, |
1062 response_info.last_modified, | 925 response_info.last_modified, |
1063 request_is_seekable); | 926 true); |
1064 | 927 |
1065 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP | 928 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP |
1066 // error codes in the stream header and as a result, was unaware of the | 929 // error codes in the stream header and as a result, was unaware of the |
1067 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF | 930 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF |
1068 // destroy the stream and invoke the NPP_DestroyStream function on the | 931 // destroy the stream and invoke the NPP_DestroyStream function on the |
1069 // plugin if the HTTP request fails. | 932 // plugin if the HTTP request fails. |
1070 const GURL& url = response.url(); | 933 const GURL& url = response.url(); |
1071 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)) { | 934 if (url.SchemeIs(url::kHttpScheme) || url.SchemeIs(url::kHttpsScheme)) { |
1072 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { | 935 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { |
1073 // The plugin instance could be in the process of deletion here. | 936 // The plugin instance could be in the process of deletion here. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1151 } | 1014 } |
1152 | 1015 |
1153 void WebPluginImpl::SetContainer(WebPluginContainer* container) { | 1016 void WebPluginImpl::SetContainer(WebPluginContainer* container) { |
1154 if (!container) | 1017 if (!container) |
1155 TearDownPluginInstance(NULL); | 1018 TearDownPluginInstance(NULL); |
1156 container_ = container; | 1019 container_ = container; |
1157 if (container_) | 1020 if (container_) |
1158 container_->allowScriptObjects(); | 1021 container_->allowScriptObjects(); |
1159 } | 1022 } |
1160 | 1023 |
1161 void WebPluginImpl::HandleURLRequest(const char* url, | |
1162 const char* method, | |
1163 const char* target, | |
1164 const char* buf, | |
1165 unsigned int len, | |
1166 int notify_id, | |
1167 bool popups_allowed, | |
1168 bool notify_redirects) { | |
1169 // GetURL/PostURL requests initiated explicitly by plugins should specify the | |
1170 // plugin SRC url as the referrer if it is available. | |
1171 HandleURLRequestInternal( | |
1172 url, method, target, buf, len, notify_id, popups_allowed, PLUGIN_SRC, | |
1173 notify_redirects, false); | |
1174 } | |
1175 | |
1176 void WebPluginImpl::HandleURLRequestInternal(const char* url, | |
1177 const char* method, | |
1178 const char* target, | |
1179 const char* buf, | |
1180 unsigned int len, | |
1181 int notify_id, | |
1182 bool popups_allowed, | |
1183 ReferrerValue referrer_flag, | |
1184 bool notify_redirects, | |
1185 bool is_plugin_src_load) { | |
1186 // For this request, we either route the output to a frame | |
1187 // because a target has been specified, or we handle the request | |
1188 // here, i.e. by executing the script if it is a javascript url | |
1189 // or by initiating a download on the URL, etc. There is one special | |
1190 // case in that the request is a javascript url and the target is "_self", | |
1191 // in which case we route the output to the plugin rather than routing it | |
1192 // to the plugin's frame. | |
1193 bool is_javascript_url = | |
1194 url::FindAndCompareScheme(url, strlen(url), url::kJavaScriptScheme, NULL); | |
1195 RoutingStatus routing_status = RouteToFrame( | |
1196 url, is_javascript_url, popups_allowed, method, target, buf, len, | |
1197 notify_id, referrer_flag); | |
1198 if (routing_status == ROUTED) | |
1199 return; | |
1200 | |
1201 if (is_javascript_url) { | |
1202 GURL gurl(url); | |
1203 WebString result = container_->executeScriptURL(gurl, popups_allowed); | |
1204 | |
1205 // delegate_ could be NULL because executeScript caused the container to | |
1206 // be deleted. | |
1207 if (delegate_) { | |
1208 delegate_->SendJavaScriptStream( | |
1209 gurl, result.utf8(), !result.isNull(), notify_id); | |
1210 } | |
1211 | |
1212 return; | |
1213 } | |
1214 | |
1215 unsigned long resource_id = GetNextResourceId(); | |
1216 if (!resource_id) | |
1217 return; | |
1218 | |
1219 GURL complete_url = CompleteURL(url); | |
1220 // Remove when flash bug is fixed. http://crbug.com/40016. | |
1221 if (!WebPluginImpl::IsValidUrl(complete_url, referrer_flag)) | |
1222 return; | |
1223 | |
1224 // If the RouteToFrame call returned a failure then inform the result | |
1225 // back to the plugin asynchronously. | |
1226 if ((routing_status == INVALID_URL) || | |
1227 (routing_status == GENERAL_FAILURE)) { | |
1228 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( | |
1229 resource_id, complete_url, notify_id); | |
1230 if (resource_client) | |
1231 resource_client->DidFail(resource_id); | |
1232 return; | |
1233 } | |
1234 | |
1235 // CreateResourceClient() sends a synchronous IPC message so it's possible | |
1236 // that TearDownPluginInstance() may have been called in the nested | |
1237 // message loop. If so, don't start the request. | |
1238 if (!delegate_) | |
1239 return; | |
1240 | |
1241 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1242 switches::kDisableDirectNPAPIRequests)) { | |
1243 // We got here either because the plugin called GetURL/PostURL, or because | |
1244 // we're fetching the data for an embed tag. If we're in multi-process mode, | |
1245 // we want to fetch the data in the plugin process as the renderer won't be | |
1246 // able to request any origin when site isolation is in place. So bounce | |
1247 // this request back to the plugin process which will use ResourceDispatcher | |
1248 // to fetch the url. | |
1249 | |
1250 // TODO(jam): any better way of getting this? Can't find a way to get | |
1251 // frame()->loader()->outgoingReferrer() which | |
1252 // WebFrameImpl::setReferrerForRequest does. | |
1253 WebURLRequest request(complete_url); | |
1254 SetReferrer(&request, referrer_flag); | |
1255 Referrer referrer( | |
1256 GURL(request.httpHeaderField(WebString::fromUTF8("Referer"))), | |
1257 request.referrerPolicy()); | |
1258 | |
1259 GURL first_party_for_cookies = webframe_->document().firstPartyForCookies(); | |
1260 delegate_->FetchURL(resource_id, notify_id, complete_url, | |
1261 first_party_for_cookies, method, buf, len, referrer, | |
1262 notify_redirects, is_plugin_src_load, 0, | |
1263 render_frame_->GetRoutingID(), | |
1264 render_view_->GetRoutingID()); | |
1265 } else { | |
1266 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( | |
1267 resource_id, complete_url, notify_id); | |
1268 if (!resource_client) | |
1269 return; | |
1270 InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, | |
1271 len, NULL, referrer_flag, notify_redirects, | |
1272 is_plugin_src_load); | |
1273 } | |
1274 } | |
1275 | |
1276 unsigned long WebPluginImpl::GetNextResourceId() { | 1024 unsigned long WebPluginImpl::GetNextResourceId() { |
1277 if (!webframe_) | 1025 if (!webframe_) |
1278 return 0; | 1026 return 0; |
1279 WebView* view = webframe_->view(); | 1027 WebView* view = webframe_->view(); |
1280 if (!view) | 1028 if (!view) |
1281 return 0; | 1029 return 0; |
1282 return view->createUniqueIdentifierForRequest(); | 1030 return view->createUniqueIdentifierForRequest(); |
1283 } | 1031 } |
1284 | 1032 |
1285 bool WebPluginImpl::InitiateHTTPRequest(unsigned long resource_id, | |
1286 WebPluginResourceClient* client, | |
1287 const GURL& url, | |
1288 const char* method, | |
1289 const char* buf, | |
1290 int buf_len, | |
1291 const char* range_info, | |
1292 ReferrerValue referrer_flag, | |
1293 bool notify_redirects, | |
1294 bool is_plugin_src_load) { | |
1295 if (!client) { | |
1296 NOTREACHED(); | |
1297 return false; | |
1298 } | |
1299 | |
1300 ClientInfo info; | |
1301 info.id = resource_id; | |
1302 info.client = client; | |
1303 info.request.initialize(); | |
1304 info.request.setURL(url); | |
1305 info.request.setFirstPartyForCookies( | |
1306 webframe_->document().firstPartyForCookies()); | |
1307 info.request.setRequestorProcessID(delegate_->GetProcessId()); | |
1308 // TODO(mkwst): Is this a request for a plugin object itself | |
1309 // (RequestContextObject), or a request that the plugin makes | |
1310 // (RequestContextPlugin)? | |
1311 info.request.setRequestContext(WebURLRequest::RequestContextPlugin); | |
1312 info.request.setHTTPMethod(WebString::fromUTF8(method)); | |
1313 // ServiceWorker is disabled for NPAPI. | |
1314 info.request.setSkipServiceWorker(true); | |
1315 info.pending_failure_notification = false; | |
1316 info.notify_redirects = notify_redirects; | |
1317 info.is_plugin_src_load = is_plugin_src_load; | |
1318 info.data_offset = 0; | |
1319 | |
1320 if (range_info) { | |
1321 info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), | |
1322 WebString::fromUTF8(range_info)); | |
1323 } | |
1324 | |
1325 if (strcmp(method, "POST") == 0) { | |
1326 // Adds headers or form data to a request. This must be called before | |
1327 // we initiate the actual request. | |
1328 SetPostData(&info.request, buf, buf_len); | |
1329 } | |
1330 | |
1331 SetReferrer(&info.request, referrer_flag); | |
1332 | |
1333 WebURLLoaderOptions options; | |
1334 options.allowCredentials = true; | |
1335 options.crossOriginRequestPolicy = | |
1336 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | |
1337 info.loader.reset(webframe_->createAssociatedURLLoader(options)); | |
1338 if (!info.loader.get()) | |
1339 return false; | |
1340 info.loader->loadAsynchronously(info.request, &loader_client_); | |
1341 | |
1342 clients_.push_back(info); | |
1343 return true; | |
1344 } | |
1345 | |
1346 void WebPluginImpl::CancelDocumentLoad() { | 1033 void WebPluginImpl::CancelDocumentLoad() { |
1347 if (webframe_) { | 1034 if (webframe_) { |
1348 ignore_response_error_ = true; | 1035 ignore_response_error_ = true; |
1349 webframe_->stopLoading(); | 1036 webframe_->stopLoading(); |
1350 } | 1037 } |
1351 } | 1038 } |
1352 | 1039 |
1353 void WebPluginImpl::InitiateHTTPRangeRequest( | |
1354 const char* url, const char* range_info, int range_request_id) { | |
1355 unsigned long resource_id = GetNextResourceId(); | |
1356 if (!resource_id) | |
1357 return; | |
1358 | |
1359 GURL complete_url = CompleteURL(url); | |
1360 // Remove when flash bug is fixed. http://crbug.com/40016. | |
1361 if (!WebPluginImpl::IsValidUrl(complete_url, | |
1362 load_manually_ ? NO_REFERRER : PLUGIN_SRC)) | |
1363 return; | |
1364 | |
1365 WebPluginResourceClient* resource_client = | |
1366 delegate_->CreateSeekableResourceClient(resource_id, range_request_id); | |
1367 InitiateHTTPRequest( | |
1368 resource_id, resource_client, complete_url, "GET", NULL, 0, range_info, | |
1369 load_manually_ ? NO_REFERRER : PLUGIN_SRC, false, false); | |
1370 } | |
1371 | |
1372 void WebPluginImpl::DidStartLoading() { | 1040 void WebPluginImpl::DidStartLoading() { |
1373 if (render_view_.get()) { | 1041 if (render_view_.get()) { |
1374 // TODO(darin): Make is_loading_ be a counter! | 1042 // TODO(darin): Make is_loading_ be a counter! |
1375 render_view_->DidStartLoading(); | 1043 render_view_->DidStartLoading(); |
1376 } | 1044 } |
1377 } | 1045 } |
1378 | 1046 |
1379 void WebPluginImpl::DidStopLoading() { | 1047 void WebPluginImpl::DidStopLoading() { |
1380 if (render_view_.get()) { | 1048 if (render_view_.get()) { |
1381 // TODO(darin): Make is_loading_ be a counter! | 1049 // TODO(darin): Make is_loading_ be a counter! |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1549 case PLUGIN_SRC: | 1217 case PLUGIN_SRC: |
1550 webframe_->setReferrerForRequest(*request, plugin_url_); | 1218 webframe_->setReferrerForRequest(*request, plugin_url_); |
1551 break; | 1219 break; |
1552 | 1220 |
1553 default: | 1221 default: |
1554 break; | 1222 break; |
1555 } | 1223 } |
1556 } | 1224 } |
1557 | 1225 |
1558 } // namespace content | 1226 } // namespace content |
OLD | NEW |