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 "webkit/plugins/npapi/webplugin_impl.h" | 5 #include "webkit/plugins/npapi/webplugin_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 namespace webkit { | 79 namespace webkit { |
80 namespace npapi { | 80 namespace npapi { |
81 | 81 |
82 namespace { | 82 namespace { |
83 | 83 |
84 const char kFlashMimeType[] = "application/x-shockwave-flash"; | 84 const char kFlashMimeType[] = "application/x-shockwave-flash"; |
85 const char kOctetStreamMimeType[] = "application/octet-stream"; | 85 const char kOctetStreamMimeType[] = "application/octet-stream"; |
86 const char kHTMLMimeType[] = "text/html"; | 86 const char kHTMLMimeType[] = "text/html"; |
87 const char kPlainTextMimeType[] = "text/plain"; | 87 const char kPlainTextMimeType[] = "text/plain"; |
88 const char kPluginFlashMimeType[] = "Plugin.FlashMIMEType"; | 88 const char kPluginFlashMimeType[] = "Plugin.FlashMIMEType"; |
| 89 const char kPluginFlashVersion[] = "Plugin.FlashVersion"; |
89 | 90 |
90 enum { | 91 enum { |
91 MIME_TYPE_OK = 0, | 92 MIME_TYPE_OK = 0, |
92 MIME_TYPE_EMPTY, | 93 MIME_TYPE_EMPTY, |
93 MIME_TYPE_OCTETSTREAM, | 94 MIME_TYPE_OCTETSTREAM, |
94 MIME_TYPE_HTML, | 95 MIME_TYPE_HTML, |
95 MIME_TYPE_PLAINTEXT, | 96 MIME_TYPE_PLAINTEXT, |
96 MIME_TYPE_OTHER, | 97 MIME_TYPE_OTHER, |
97 MIME_TYPE_NUM_EVENTS | 98 MIME_TYPE_NUM_EVENTS |
98 }; | 99 }; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // WebKit::WebPlugin ---------------------------------------------------------- | 238 // WebKit::WebPlugin ---------------------------------------------------------- |
238 | 239 |
239 struct WebPluginImpl::ClientInfo { | 240 struct WebPluginImpl::ClientInfo { |
240 unsigned long id; | 241 unsigned long id; |
241 WebPluginResourceClient* client; | 242 WebPluginResourceClient* client; |
242 WebKit::WebURLRequest request; | 243 WebKit::WebURLRequest request; |
243 bool pending_failure_notification; | 244 bool pending_failure_notification; |
244 linked_ptr<WebKit::WebURLLoader> loader; | 245 linked_ptr<WebKit::WebURLLoader> loader; |
245 bool notify_redirects; | 246 bool notify_redirects; |
246 bool is_plugin_src_load; | 247 bool is_plugin_src_load; |
| 248 bool check_flash_version; |
247 }; | 249 }; |
248 | 250 |
249 bool WebPluginImpl::initialize(WebPluginContainer* container) { | 251 bool WebPluginImpl::initialize(WebPluginContainer* container) { |
250 if (!page_delegate_) { | 252 if (!page_delegate_) { |
251 LOG(ERROR) << "No page delegate"; | 253 LOG(ERROR) << "No page delegate"; |
252 return false; | 254 return false; |
253 } | 255 } |
254 | 256 |
255 WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( | 257 WebPluginDelegate* plugin_delegate = page_delegate_->CreatePluginDelegate( |
256 file_path_, mime_type_); | 258 file_path_, mime_type_); |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 ResponseInfo response_info; | 886 ResponseInfo response_info; |
885 GetResponseInfo(response, &response_info); | 887 GetResponseInfo(response, &response_info); |
886 | 888 |
887 ClientInfo* client_info = GetClientInfoFromLoader(loader); | 889 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
888 if (!client_info) | 890 if (!client_info) |
889 return; | 891 return; |
890 | 892 |
891 // Defend against content confusion by the Flash plug-in. | 893 // Defend against content confusion by the Flash plug-in. |
892 if (client_info->is_plugin_src_load && | 894 if (client_info->is_plugin_src_load && |
893 mime_type_ == kFlashMimeType) { | 895 mime_type_ == kFlashMimeType) { |
| 896 client_info->check_flash_version = true; |
894 std::string sniff = | 897 std::string sniff = |
895 response.httpHeaderField("X-Content-Type-Options").utf8(); | 898 response.httpHeaderField("X-Content-Type-Options").utf8(); |
896 std::string content_type = | 899 std::string content_type = |
897 response.httpHeaderField("Content-Type").utf8(); | 900 response.httpHeaderField("Content-Type").utf8(); |
898 StringToLowerASCII(&sniff); | 901 StringToLowerASCII(&sniff); |
899 StringToLowerASCII(&content_type); | 902 StringToLowerASCII(&content_type); |
| 903 // TODO(cevans): remove when we no longer need these. |
900 if (content_type.find(kFlashMimeType) != std::string::npos) { | 904 if (content_type.find(kFlashMimeType) != std::string::npos) { |
901 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, | 905 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, |
902 MIME_TYPE_OK, | 906 MIME_TYPE_OK, |
903 MIME_TYPE_NUM_EVENTS); | 907 MIME_TYPE_NUM_EVENTS); |
904 } else if (content_type.empty()) { | 908 } else if (content_type.empty()) { |
905 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, | 909 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, |
906 MIME_TYPE_EMPTY, | 910 MIME_TYPE_EMPTY, |
907 MIME_TYPE_NUM_EVENTS); | 911 MIME_TYPE_NUM_EVENTS); |
908 } else if (content_type.find(kOctetStreamMimeType) != std::string::npos) { | 912 } else if (content_type.find(kOctetStreamMimeType) != std::string::npos) { |
909 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, | 913 UMA_HISTOGRAM_ENUMERATION(kPluginFlashMimeType, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 } | 1010 } |
1007 | 1011 |
1008 void WebPluginImpl::didReceiveData(WebURLLoader* loader, | 1012 void WebPluginImpl::didReceiveData(WebURLLoader* loader, |
1009 const char *buffer, | 1013 const char *buffer, |
1010 int data_length, | 1014 int data_length, |
1011 int encoded_data_length) { | 1015 int encoded_data_length) { |
1012 WebPluginResourceClient* client = GetClientFromLoader(loader); | 1016 WebPluginResourceClient* client = GetClientFromLoader(loader); |
1013 if (!client) | 1017 if (!client) |
1014 return; | 1018 return; |
1015 | 1019 |
| 1020 ClientInfo* client_info = GetClientInfoFromLoader(loader); |
| 1021 if (client_info && client_info->check_flash_version) { |
| 1022 client_info->check_flash_version = false; |
| 1023 if (data_length >= 4 && |
| 1024 (buffer[0] == 'C' || buffer[1] == 'F') && |
| 1025 buffer[1] == 'W' && |
| 1026 buffer[2] == 'S') { |
| 1027 unsigned char version = static_cast<unsigned char>(buffer[3]); |
| 1028 // TODO(cevans): remove when we no longer need this. |
| 1029 UMA_HISTOGRAM_ENUMERATION(kPluginFlashVersion, |
| 1030 version, |
| 1031 256); |
| 1032 } |
| 1033 } |
| 1034 |
1016 MultiPartResponseHandlerMap::iterator index = | 1035 MultiPartResponseHandlerMap::iterator index = |
1017 multi_part_response_map_.find(client); | 1036 multi_part_response_map_.find(client); |
1018 if (index != multi_part_response_map_.end()) { | 1037 if (index != multi_part_response_map_.end()) { |
1019 MultipartResponseDelegate* multi_part_handler = (*index).second; | 1038 MultipartResponseDelegate* multi_part_handler = (*index).second; |
1020 DCHECK(multi_part_handler != NULL); | 1039 DCHECK(multi_part_handler != NULL); |
1021 multi_part_handler->OnReceivedData(buffer, | 1040 multi_part_handler->OnReceivedData(buffer, |
1022 data_length, | 1041 data_length, |
1023 encoded_data_length); | 1042 encoded_data_length); |
1024 } else { | 1043 } else { |
1025 loader->setDefersLoading(true); | 1044 loader->setDefersLoading(true); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 info.request.initialize(); | 1215 info.request.initialize(); |
1197 info.request.setURL(url); | 1216 info.request.setURL(url); |
1198 info.request.setFirstPartyForCookies( | 1217 info.request.setFirstPartyForCookies( |
1199 webframe_->document().firstPartyForCookies()); | 1218 webframe_->document().firstPartyForCookies()); |
1200 info.request.setRequestorProcessID(delegate_->GetProcessId()); | 1219 info.request.setRequestorProcessID(delegate_->GetProcessId()); |
1201 info.request.setTargetType(WebURLRequest::TargetIsObject); | 1220 info.request.setTargetType(WebURLRequest::TargetIsObject); |
1202 info.request.setHTTPMethod(WebString::fromUTF8(method)); | 1221 info.request.setHTTPMethod(WebString::fromUTF8(method)); |
1203 info.pending_failure_notification = false; | 1222 info.pending_failure_notification = false; |
1204 info.notify_redirects = notify_redirects; | 1223 info.notify_redirects = notify_redirects; |
1205 info.is_plugin_src_load = is_plugin_src_load; | 1224 info.is_plugin_src_load = is_plugin_src_load; |
| 1225 info.check_flash_version = false; |
1206 | 1226 |
1207 if (range_info) { | 1227 if (range_info) { |
1208 info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), | 1228 info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), |
1209 WebString::fromUTF8(range_info)); | 1229 WebString::fromUTF8(range_info)); |
1210 } | 1230 } |
1211 | 1231 |
1212 if (strcmp(method, "POST") == 0) { | 1232 if (strcmp(method, "POST") == 0) { |
1213 // Adds headers or form data to a request. This must be called before | 1233 // Adds headers or form data to a request. This must be called before |
1214 // we initiate the actual request. | 1234 // we initiate the actual request. |
1215 SetPostData(&info.request, buf, buf_len); | 1235 SetPostData(&info.request, buf, buf_len); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 webframe_->setReferrerForRequest(*request, plugin_url_); | 1422 webframe_->setReferrerForRequest(*request, plugin_url_); |
1403 break; | 1423 break; |
1404 | 1424 |
1405 default: | 1425 default: |
1406 break; | 1426 break; |
1407 } | 1427 } |
1408 } | 1428 } |
1409 | 1429 |
1410 } // namespace npapi | 1430 } // namespace npapi |
1411 } // namespace webkit | 1431 } // namespace webkit |
OLD | NEW |