| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "Document.h" | 7 #include "Document.h" |
| 8 #include "DocumentLoader.h" | 8 #include "DocumentLoader.h" |
| 9 #include "Event.h" | 9 #include "Event.h" |
| 10 #include "EventNames.h" | 10 #include "EventNames.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 NOTREACHED(); | 112 NOTREACHED(); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 resource_response_ = response; | 116 resource_response_ = response; |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Receives individual part data from a multipart response. | 119 // Receives individual part data from a multipart response. |
| 120 virtual void didReceiveData( | 120 virtual void didReceiveData( |
| 121 WebURLLoader*, const char* data, int data_size, long long) { | 121 WebURLLoader*, const char* data, int data_size, long long) { |
| 122 // TODO(ananta) |
| 123 // We should defer further loads on multipart resources on the same lines |
| 124 // as regular resources requested by plugins to prevent reentrancy. |
| 122 resource_client_->DidReceiveData( | 125 resource_client_->DidReceiveData( |
| 123 data, data_size, byte_range_lower_bound_); | 126 data, data_size, byte_range_lower_bound_); |
| 124 } | 127 } |
| 125 | 128 |
| 126 virtual void didFinishLoading(WebURLLoader*) {} | 129 virtual void didFinishLoading(WebURLLoader*) {} |
| 127 virtual void didFail(WebURLLoader*, const WebURLError&) {} | 130 virtual void didFail(WebURLLoader*, const WebURLError&) {} |
| 128 | 131 |
| 129 void Clear() { | 132 void Clear() { |
| 130 resource_response_.reset(); | 133 resource_response_.reset(); |
| 131 byte_range_lower_bound_ = 0; | 134 byte_range_lower_bound_ = 0; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 delegate_->SendJavaScriptStream(url, wresult, succ, notify_needed, | 471 delegate_->SendJavaScriptStream(url, wresult, succ, notify_needed, |
| 469 notify_data); | 472 notify_data); |
| 470 | 473 |
| 471 return succ; | 474 return succ; |
| 472 } | 475 } |
| 473 | 476 |
| 474 void WebPluginImpl::CancelResource(int id) { | 477 void WebPluginImpl::CancelResource(int id) { |
| 475 for (size_t i = 0; i < clients_.size(); ++i) { | 478 for (size_t i = 0; i < clients_.size(); ++i) { |
| 476 if (clients_[i].id == id) { | 479 if (clients_[i].id == id) { |
| 477 if (clients_[i].loader.get()) { | 480 if (clients_[i].loader.get()) { |
| 481 clients_[i].loader->setDefersLoading(false); |
| 478 clients_[i].loader->cancel(); | 482 clients_[i].loader->cancel(); |
| 479 RemoveClient(i); | 483 RemoveClient(i); |
| 480 } | 484 } |
| 481 return; | 485 return; |
| 482 } | 486 } |
| 483 } | 487 } |
| 484 } | 488 } |
| 485 | 489 |
| 486 bool WebPluginImpl::SetPostData(WebURLRequest* request, | 490 bool WebPluginImpl::SetPostData(WebURLRequest* request, |
| 487 const char *buf, | 491 const char *buf, |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 if (!delegate_->HandleInputEvent(web_event, &cursor_info)) | 908 if (!delegate_->HandleInputEvent(web_event, &cursor_info)) |
| 905 event->setDefaultHandled(); | 909 event->setDefaultHandled(); |
| 906 } | 910 } |
| 907 | 911 |
| 908 NPObject* WebPluginImpl::GetPluginScriptableObject() { | 912 NPObject* WebPluginImpl::GetPluginScriptableObject() { |
| 909 return delegate_->GetPluginScriptableObject(); | 913 return delegate_->GetPluginScriptableObject(); |
| 910 } | 914 } |
| 911 | 915 |
| 912 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( | 916 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( |
| 913 WebURLLoader* loader) { | 917 WebURLLoader* loader) { |
| 918 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
| 919 if (client_info) |
| 920 return client_info->client; |
| 921 return NULL; |
| 922 } |
| 923 |
| 924 WebPluginImpl::ClientInfo* WebPluginImpl::GetClientInfoFromLoader( |
| 925 WebURLLoader* loader) { |
| 914 for (size_t i = 0; i < clients_.size(); ++i) { | 926 for (size_t i = 0; i < clients_.size(); ++i) { |
| 915 if (clients_[i].loader.get() == loader) | 927 if (clients_[i].loader.get() == loader) |
| 916 return clients_[i].client; | 928 return &clients_[i]; |
| 917 } | 929 } |
| 918 | 930 |
| 919 NOTREACHED(); | 931 NOTREACHED(); |
| 920 return 0; | 932 return 0; |
| 921 } | 933 } |
| 922 | 934 |
| 923 | |
| 924 void WebPluginImpl::willSendRequest(WebURLLoader* loader, | 935 void WebPluginImpl::willSendRequest(WebURLLoader* loader, |
| 925 WebURLRequest& request, | 936 WebURLRequest& request, |
| 926 const WebURLResponse&) { | 937 const WebURLResponse&) { |
| 927 WebPluginResourceClient* client = GetClientFromLoader(loader); | 938 WebPluginResourceClient* client = GetClientFromLoader(loader); |
| 928 if (client) | 939 if (client) |
| 929 client->WillSendRequest(request.url()); | 940 client->WillSendRequest(request.url()); |
| 930 } | 941 } |
| 931 | 942 |
| 932 void WebPluginImpl::didSendData(WebURLLoader* loader, | 943 void WebPluginImpl::didSendData(WebURLLoader* loader, |
| 933 unsigned long long bytes_sent, | 944 unsigned long long bytes_sent, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 clients_[i].client = resource_client; | 999 clients_[i].client = resource_client; |
| 989 client = resource_client; | 1000 client = resource_client; |
| 990 break; | 1001 break; |
| 991 } | 1002 } |
| 992 } | 1003 } |
| 993 | 1004 |
| 994 DCHECK(client != NULL); | 1005 DCHECK(client != NULL); |
| 995 } | 1006 } |
| 996 } | 1007 } |
| 997 | 1008 |
| 1009 // Calling into a plugin could result in reentrancy if the plugin yields |
| 1010 // control to the OS like entering a modal loop etc. Prevent this by |
| 1011 // stopping further loading until the plugin notifies us that it is ready to |
| 1012 // accept data |
| 1013 loader->setDefersLoading(true); |
| 1014 |
| 998 client->DidReceiveResponse( | 1015 client->DidReceiveResponse( |
| 999 base::SysWideToNativeMB(http_response_info.mime_type), | 1016 base::SysWideToNativeMB(http_response_info.mime_type), |
| 1000 base::SysWideToNativeMB(GetAllHeaders(resource_response)), | 1017 base::SysWideToNativeMB(GetAllHeaders(resource_response)), |
| 1001 http_response_info.expected_length, | 1018 http_response_info.expected_length, |
| 1002 http_response_info.last_modified, request_is_seekable, &cancel); | 1019 http_response_info.last_modified, request_is_seekable); |
| 1003 | |
| 1004 if (cancel) { | |
| 1005 loader->cancel(); | |
| 1006 RemoveClient(loader); | |
| 1007 return; | |
| 1008 } | |
| 1009 | 1020 |
| 1010 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP | 1021 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP |
| 1011 // error codes in the stream header and as a result, was unaware of the | 1022 // error codes in the stream header and as a result, was unaware of the |
| 1012 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF | 1023 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF |
| 1013 // destroy the stream and invoke the NPP_DestroyStream function on the | 1024 // destroy the stream and invoke the NPP_DestroyStream function on the |
| 1014 // plugin if the HTTP request fails. | 1025 // plugin if the HTTP request fails. |
| 1015 const GURL& url = response.url(); | 1026 const GURL& url = response.url(); |
| 1016 if (url.SchemeIs("http") || url.SchemeIs("https")) { | 1027 if (url.SchemeIs("http") || url.SchemeIs("https")) { |
| 1017 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { | 1028 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { |
| 1018 // The plugin instance could be in the process of deletion here. | 1029 // The plugin instance could be in the process of deletion here. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1034 WebPluginResourceClient* client = GetClientFromLoader(loader); | 1045 WebPluginResourceClient* client = GetClientFromLoader(loader); |
| 1035 if (!client) | 1046 if (!client) |
| 1036 return; | 1047 return; |
| 1037 MultiPartResponseHandlerMap::iterator index = | 1048 MultiPartResponseHandlerMap::iterator index = |
| 1038 multi_part_response_map_.find(client); | 1049 multi_part_response_map_.find(client); |
| 1039 if (index != multi_part_response_map_.end()) { | 1050 if (index != multi_part_response_map_.end()) { |
| 1040 MultipartResponseDelegate* multi_part_handler = (*index).second; | 1051 MultipartResponseDelegate* multi_part_handler = (*index).second; |
| 1041 DCHECK(multi_part_handler != NULL); | 1052 DCHECK(multi_part_handler != NULL); |
| 1042 multi_part_handler->OnReceivedData(buffer, length); | 1053 multi_part_handler->OnReceivedData(buffer, length); |
| 1043 } else { | 1054 } else { |
| 1055 loader->setDefersLoading(true); |
| 1044 client->DidReceiveData(buffer, length, 0); | 1056 client->DidReceiveData(buffer, length, 0); |
| 1045 } | 1057 } |
| 1046 } | 1058 } |
| 1047 | 1059 |
| 1048 void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { | 1060 void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { |
| 1049 WebPluginResourceClient* client = GetClientFromLoader(loader); | 1061 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
| 1050 if (client) { | 1062 if (client_info && client_info->client) { |
| 1051 MultiPartResponseHandlerMap::iterator index = | 1063 MultiPartResponseHandlerMap::iterator index = |
| 1052 multi_part_response_map_.find(client); | 1064 multi_part_response_map_.find(client_info->client); |
| 1053 if (index != multi_part_response_map_.end()) { | 1065 if (index != multi_part_response_map_.end()) { |
| 1054 delete (*index).second; | 1066 delete (*index).second; |
| 1055 multi_part_response_map_.erase(index); | 1067 multi_part_response_map_.erase(index); |
| 1056 | 1068 |
| 1057 WebView* web_view = webframe_->GetView(); | 1069 WebView* web_view = webframe_->GetView(); |
| 1058 web_view->GetDelegate()->DidStopLoading(web_view); | 1070 web_view->GetDelegate()->DidStopLoading(web_view); |
| 1059 } | 1071 } |
| 1060 client->DidFinishLoading(); | 1072 loader->setDefersLoading(true); |
| 1073 client_info->client->DidFinishLoading(); |
| 1074 // The WebPluginResourceClient pointer gets deleted soon after a call to |
| 1075 // DidFinishLoading. |
| 1076 client_info->client = NULL; |
| 1061 } | 1077 } |
| 1062 | |
| 1063 RemoveClient(loader); | |
| 1064 } | 1078 } |
| 1065 | 1079 |
| 1066 void WebPluginImpl::didFail(WebURLLoader* loader, | 1080 void WebPluginImpl::didFail(WebURLLoader* loader, |
| 1067 const WebURLError&) { | 1081 const WebURLError&) { |
| 1068 WebPluginResourceClient* client = GetClientFromLoader(loader); | 1082 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
| 1069 if (client) | 1083 if (client_info && client_info->client) { |
| 1070 client->DidFail(); | 1084 loader->setDefersLoading(true); |
| 1071 | 1085 client_info->client->DidFail(); |
| 1072 RemoveClient(loader); | 1086 // The WebPluginResourceClient pointer gets deleted soon after a call to |
| 1087 // DidFinishLoading. |
| 1088 client_info->client = NULL; |
| 1089 } |
| 1073 } | 1090 } |
| 1074 | 1091 |
| 1075 void WebPluginImpl::RemoveClient(size_t i) { | 1092 void WebPluginImpl::RemoveClient(size_t i) { |
| 1076 clients_.erase(clients_.begin() + i); | 1093 clients_.erase(clients_.begin() + i); |
| 1077 } | 1094 } |
| 1078 | 1095 |
| 1079 void WebPluginImpl::RemoveClient(WebURLLoader* loader) { | 1096 void WebPluginImpl::RemoveClient(WebURLLoader* loader) { |
| 1080 for (size_t i = 0; i < clients_.size(); ++i) { | 1097 for (size_t i = 0; i < clients_.size(); ++i) { |
| 1081 if (clients_[i].loader.get() == loader) { | 1098 if (clients_[i].loader.get() == loader) { |
| 1082 RemoveClient(i); | 1099 RemoveClient(i); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 CompleteURL(url, &complete_url_string); | 1296 CompleteURL(url, &complete_url_string); |
| 1280 | 1297 |
| 1281 WebPluginResourceClient* resource_client = | 1298 WebPluginResourceClient* resource_client = |
| 1282 delegate_->CreateResourceClient(resource_id, complete_url_string, | 1299 delegate_->CreateResourceClient(resource_id, complete_url_string, |
| 1283 notify_needed, notify_data, | 1300 notify_needed, notify_data, |
| 1284 existing_stream); | 1301 existing_stream); |
| 1285 InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0, | 1302 InitiateHTTPRequest(resource_id, resource_client, "GET", NULL, 0, |
| 1286 GURL(complete_url_string), range_info, true); | 1303 GURL(complete_url_string), range_info, true); |
| 1287 } | 1304 } |
| 1288 | 1305 |
| 1306 void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) { |
| 1307 std::vector<ClientInfo>::iterator client_index = clients_.begin(); |
| 1308 while (client_index != clients_.end()) { |
| 1309 ClientInfo& client_info = *client_index; |
| 1310 |
| 1311 if (client_info.id == resource_id) { |
| 1312 client_info.loader->setDefersLoading(defer); |
| 1313 break; |
| 1314 } |
| 1315 client_index++; |
| 1316 } |
| 1317 } |
| 1318 |
| 1289 void WebPluginImpl::HandleHttpMultipartResponse( | 1319 void WebPluginImpl::HandleHttpMultipartResponse( |
| 1290 const WebURLResponse& response, | 1320 const WebURLResponse& response, WebPluginResourceClient* client) { |
| 1291 WebPluginResourceClient* client) { | |
| 1292 std::string multipart_boundary; | 1321 std::string multipart_boundary; |
| 1293 if (!MultipartResponseDelegate::ReadMultipartBoundary( | 1322 if (!MultipartResponseDelegate::ReadMultipartBoundary( |
| 1294 response, &multipart_boundary)) { | 1323 response, &multipart_boundary)) { |
| 1295 NOTREACHED(); | 1324 NOTREACHED(); |
| 1296 return; | 1325 return; |
| 1297 } | 1326 } |
| 1298 | 1327 |
| 1299 WebView* web_view = webframe_->GetView(); | 1328 WebView* web_view = webframe_->GetView(); |
| 1300 web_view->GetDelegate()->DidStartLoading(web_view); | 1329 web_view->GetDelegate()->DidStartLoading(web_view); |
| 1301 | 1330 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1430 | 1459 |
| 1431 WebPluginGeometry move; | 1460 WebPluginGeometry move; |
| 1432 move.window = window_; | 1461 move.window = window_; |
| 1433 move.window_rect = gfx::Rect(); | 1462 move.window_rect = gfx::Rect(); |
| 1434 move.clip_rect = gfx::Rect(); | 1463 move.clip_rect = gfx::Rect(); |
| 1435 move.rects_valid = false; | 1464 move.rects_valid = false; |
| 1436 move.visible = widget_->isVisible(); | 1465 move.visible = widget_->isVisible(); |
| 1437 | 1466 |
| 1438 webview->delegate()->DidMovePlugin(move); | 1467 webview->delegate()->DidMovePlugin(move); |
| 1439 } | 1468 } |
| OLD | NEW |