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/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "cc/layers/io_surface_layer.h" | 16 #include "cc/layers/io_surface_layer.h" |
16 #include "content/child/appcache/web_application_cache_host_impl.h" | 17 #include "content/child/appcache/web_application_cache_host_impl.h" |
17 #include "content/child/npapi/plugin_host.h" | 18 #include "content/child/npapi/plugin_host.h" |
18 #include "content/child/npapi/plugin_instance.h" | 19 #include "content/child/npapi/plugin_instance.h" |
19 #include "content/child/npapi/webplugin_delegate_impl.h" | 20 #include "content/child/npapi/webplugin_delegate_impl.h" |
20 #include "content/child/npapi/webplugin_resource_client.h" | 21 #include "content/child/npapi/webplugin_resource_client.h" |
21 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
22 #include "content/public/common/content_constants.h" | 23 #include "content/public/common/content_constants.h" |
| 24 #include "content/public/common/content_switches.h" |
23 #include "content/public/renderer/content_renderer_client.h" | 25 #include "content/public/renderer/content_renderer_client.h" |
24 #include "content/renderer/npapi/webplugin_delegate_proxy.h" | 26 #include "content/renderer/npapi/webplugin_delegate_proxy.h" |
25 #include "content/renderer/render_process.h" | 27 #include "content/renderer/render_process.h" |
26 #include "content/renderer/render_view_impl.h" | 28 #include "content/renderer/render_view_impl.h" |
27 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
28 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
29 #include "net/http/http_response_headers.h" | 31 #include "net/http/http_response_headers.h" |
30 #include "skia/ext/platform_canvas.h" | 32 #include "skia/ext/platform_canvas.h" |
31 #include "third_party/WebKit/public/platform/WebCString.h" | 33 #include "third_party/WebKit/public/platform/WebCString.h" |
32 #include "third_party/WebKit/public/platform/WebCookieJar.h" | 34 #include "third_party/WebKit/public/platform/WebCookieJar.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // Store the plugin's unique identifier, used by the container to track its | 251 // Store the plugin's unique identifier, used by the container to track its |
250 // script objects. | 252 // script objects. |
251 npp_ = plugin_delegate->GetPluginNPP(); | 253 npp_ = plugin_delegate->GetPluginNPP(); |
252 | 254 |
253 // Set the container before Initialize because the plugin may | 255 // Set the container before Initialize because the plugin may |
254 // synchronously call NPN_GetValue to get its container, or make calls | 256 // synchronously call NPN_GetValue to get its container, or make calls |
255 // passing script objects that need to be tracked, during initialization. | 257 // passing script objects that need to be tracked, during initialization. |
256 SetContainer(container); | 258 SetContainer(container); |
257 | 259 |
258 bool ok = plugin_delegate->Initialize( | 260 bool ok = plugin_delegate->Initialize( |
259 plugin_url_, arg_names_, arg_values_, this, load_manually_); | 261 plugin_url_, arg_names_, arg_values_, load_manually_); |
260 if (!ok) { | 262 if (!ok) { |
261 LOG(ERROR) << "Couldn't initialize plug-in"; | 263 LOG(ERROR) << "Couldn't initialize plug-in"; |
262 plugin_delegate->PluginDestroyed(); | 264 plugin_delegate->PluginDestroyed(); |
263 | 265 |
264 WebKit::WebPlugin* replacement_plugin = | 266 WebKit::WebPlugin* replacement_plugin = |
265 GetContentClient()->renderer()->CreatePluginReplacement( | 267 GetContentClient()->renderer()->CreatePluginReplacement( |
266 render_view_.get(), file_path_); | 268 render_view_.get(), file_path_); |
267 if (!replacement_plugin) | 269 if (!replacement_plugin) |
268 return false; | 270 return false; |
269 | 271 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 WebHTTPBody http_body; | 620 WebHTTPBody http_body; |
619 if (body.size()) { | 621 if (body.size()) { |
620 http_body.initialize(); | 622 http_body.initialize(); |
621 http_body.appendData(WebData(&body[0], body.size())); | 623 http_body.appendData(WebData(&body[0], body.size())); |
622 } | 624 } |
623 request->setHTTPBody(http_body); | 625 request->setHTTPBody(http_body); |
624 | 626 |
625 return rv; | 627 return rv; |
626 } | 628 } |
627 | 629 |
628 WebPluginDelegate* WebPluginImpl::delegate() { | |
629 return delegate_; | |
630 } | |
631 | |
632 bool WebPluginImpl::IsValidUrl(const GURL& url, Referrer referrer_flag) { | 630 bool WebPluginImpl::IsValidUrl(const GURL& url, Referrer referrer_flag) { |
633 if (referrer_flag == PLUGIN_SRC && | 631 if (referrer_flag == PLUGIN_SRC && |
634 mime_type_ == kFlashPluginSwfMimeType && | 632 mime_type_ == kFlashPluginSwfMimeType && |
635 url.GetOrigin() != plugin_url_.GetOrigin()) { | 633 url.GetOrigin() != plugin_url_.GetOrigin()) { |
636 // Do url check to make sure that there are no @, ;, \ chars in between url | 634 // Do url check to make sure that there are no @, ;, \ chars in between url |
637 // scheme and url path. | 635 // scheme and url path. |
638 const char* url_to_check(url.spec().data()); | 636 const char* url_to_check(url.spec().data()); |
639 url_parse::Parsed parsed; | 637 url_parse::Parsed parsed; |
640 url_parse::ParseStandardURL(url_to_check, strlen(url_to_check), &parsed); | 638 url_parse::ParseStandardURL(url_to_check, strlen(url_to_check), &parsed); |
641 if (parsed.path.begin <= parsed.scheme.end()) | 639 if (parsed.path.begin <= parsed.scheme.end()) |
642 return true; | 640 return true; |
643 std::string string_to_search; | 641 std::string string_to_search; |
644 string_to_search.assign(url_to_check + parsed.scheme.end(), | 642 string_to_search.assign(url_to_check + parsed.scheme.end(), |
645 parsed.path.begin - parsed.scheme.end()); | 643 parsed.path.begin - parsed.scheme.end()); |
646 if (string_to_search.find("@") != std::string::npos || | 644 if (string_to_search.find("@") != std::string::npos || |
647 string_to_search.find(";") != std::string::npos || | 645 string_to_search.find(";") != std::string::npos || |
648 string_to_search.find("\\") != std::string::npos) | 646 string_to_search.find("\\") != std::string::npos) |
649 return false; | 647 return false; |
650 } | 648 } |
651 | 649 |
652 return true; | 650 return true; |
653 } | 651 } |
654 | 652 |
655 WebPluginDelegate* WebPluginImpl::CreatePluginDelegate() { | 653 WebPluginDelegate* WebPluginImpl::CreatePluginDelegate() { |
656 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); | 654 bool in_process_plugin = RenderProcess::current()->UseInProcessPlugins(); |
657 if (in_process_plugin) { | 655 if (in_process_plugin) { |
658 #if defined(OS_WIN) && !defined(USE_AURA) | 656 #if defined(OS_WIN) && !defined(USE_AURA) |
659 return WebPluginDelegateImpl::Create(file_path_, mime_type_); | 657 return WebPluginDelegateImpl::Create(this, file_path_, mime_type_); |
660 #else | 658 #else |
661 // In-proc plugins aren't supported on non-Windows. | 659 // In-proc plugins aren't supported on non-Windows. |
662 NOTIMPLEMENTED(); | 660 NOTIMPLEMENTED(); |
663 return NULL; | 661 return NULL; |
664 #endif | 662 #endif |
665 } | 663 } |
666 | 664 |
667 return new WebPluginDelegateProxy(mime_type_, render_view_); | 665 return new WebPluginDelegateProxy(this, mime_type_, render_view_); |
668 } | 666 } |
669 | 667 |
670 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( | 668 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( |
671 const char* url, | 669 const char* url, |
672 bool is_javascript_url, | 670 bool is_javascript_url, |
673 bool popups_allowed, | 671 bool popups_allowed, |
674 const char* method, | 672 const char* method, |
675 const char* target, | 673 const char* target, |
676 const char* buf, | 674 const char* buf, |
677 unsigned int len, | 675 unsigned int len, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 return &clients_[i]; | 886 return &clients_[i]; |
889 } | 887 } |
890 | 888 |
891 NOTREACHED(); | 889 NOTREACHED(); |
892 return 0; | 890 return 0; |
893 } | 891 } |
894 | 892 |
895 void WebPluginImpl::willSendRequest(WebURLLoader* loader, | 893 void WebPluginImpl::willSendRequest(WebURLLoader* loader, |
896 WebURLRequest& request, | 894 WebURLRequest& request, |
897 const WebURLResponse& response) { | 895 const WebURLResponse& response) { |
| 896 // TODO(jam): THIS LOGIC IS COPIED IN PluginURLFetcher::OnReceivedRedirect |
| 897 // until kDirectNPAPIRequests is the default and we can remove this old path. |
898 WebPluginImpl::ClientInfo* client_info = GetClientInfoFromLoader(loader); | 898 WebPluginImpl::ClientInfo* client_info = GetClientInfoFromLoader(loader); |
899 if (client_info) { | 899 if (client_info) { |
900 // Currently this check is just to catch an https -> http redirect when | 900 // Currently this check is just to catch an https -> http redirect when |
901 // loading the main plugin src URL. Longer term, we could investigate | 901 // loading the main plugin src URL. Longer term, we could investigate |
902 // firing mixed diplay or scripting issues for subresource loads | 902 // firing mixed diplay or scripting issues for subresource loads |
903 // initiated by plug-ins. | 903 // initiated by plug-ins. |
904 if (client_info->is_plugin_src_load && | 904 if (client_info->is_plugin_src_load && |
905 webframe_ && | 905 webframe_ && |
906 !webframe_->checkIfRunInsecureContent(request.url())) { | 906 !webframe_->checkIfRunInsecureContent(request.url())) { |
907 loader->cancel(); | 907 loader->cancel(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 | 1177 |
1178 unsigned long resource_id = GetNextResourceId(); | 1178 unsigned long resource_id = GetNextResourceId(); |
1179 if (!resource_id) | 1179 if (!resource_id) |
1180 return; | 1180 return; |
1181 | 1181 |
1182 GURL complete_url = CompleteURL(url); | 1182 GURL complete_url = CompleteURL(url); |
1183 // Remove when flash bug is fixed. http://crbug.com/40016. | 1183 // Remove when flash bug is fixed. http://crbug.com/40016. |
1184 if (!WebPluginImpl::IsValidUrl(complete_url, referrer_flag)) | 1184 if (!WebPluginImpl::IsValidUrl(complete_url, referrer_flag)) |
1185 return; | 1185 return; |
1186 | 1186 |
1187 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( | |
1188 resource_id, complete_url, notify_id); | |
1189 if (!resource_client) | |
1190 return; | |
1191 | |
1192 // If the RouteToFrame call returned a failure then inform the result | 1187 // If the RouteToFrame call returned a failure then inform the result |
1193 // back to the plugin asynchronously. | 1188 // back to the plugin asynchronously. |
1194 if ((routing_status == INVALID_URL) || | 1189 if ((routing_status == INVALID_URL) || |
1195 (routing_status == GENERAL_FAILURE)) { | 1190 (routing_status == GENERAL_FAILURE)) { |
1196 resource_client->DidFail(resource_id); | 1191 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( |
| 1192 resource_id, complete_url, notify_id); |
| 1193 if (resource_client) |
| 1194 resource_client->DidFail(resource_id); |
1197 return; | 1195 return; |
1198 } | 1196 } |
1199 | 1197 |
1200 // CreateResourceClient() sends a synchronous IPC message so it's possible | 1198 // CreateResourceClient() sends a synchronous IPC message so it's possible |
1201 // that TearDownPluginInstance() may have been called in the nested | 1199 // that TearDownPluginInstance() may have been called in the nested |
1202 // message loop. If so, don't start the request. | 1200 // message loop. If so, don't start the request. |
1203 if (!delegate_) | 1201 if (!delegate_) |
1204 return; | 1202 return; |
1205 | 1203 |
1206 InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, | 1204 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1207 len, NULL, referrer_flag, notify_redirects, | 1205 switches::kDirectNPAPIRequests)) { |
1208 is_plugin_src_load); | 1206 // TODO(jam): any better way of getting this? Can't find a way to get |
| 1207 // frame()->loader()->outgoingReferrer() which |
| 1208 // WebFrameImpl::setReferrerForRequest does. |
| 1209 WebURLRequest request(complete_url); |
| 1210 SetReferrer(&request, referrer_flag); |
| 1211 GURL referrer( |
| 1212 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); |
| 1213 |
| 1214 GURL first_party_for_cookies = webframe_->document().firstPartyForCookies(); |
| 1215 delegate_->FetchURL(resource_id, notify_id, complete_url, |
| 1216 first_party_for_cookies, method, std::string(buf, len), |
| 1217 referrer, notify_redirects, is_plugin_src_load); |
| 1218 } else { |
| 1219 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( |
| 1220 resource_id, complete_url, notify_id); |
| 1221 if (!resource_client) |
| 1222 return; |
| 1223 InitiateHTTPRequest(resource_id, resource_client, complete_url, method, buf, |
| 1224 len, NULL, referrer_flag, notify_redirects, |
| 1225 is_plugin_src_load); |
| 1226 } |
1209 } | 1227 } |
1210 | 1228 |
1211 unsigned long WebPluginImpl::GetNextResourceId() { | 1229 unsigned long WebPluginImpl::GetNextResourceId() { |
1212 if (!webframe_) | 1230 if (!webframe_) |
1213 return 0; | 1231 return 0; |
1214 WebView* view = webframe_->view(); | 1232 WebView* view = webframe_->view(); |
1215 if (!view) | 1233 if (!view) |
1216 return 0; | 1234 return 0; |
1217 return view->createUniqueIdentifierForRequest(); | 1235 return view->createUniqueIdentifierForRequest(); |
1218 } | 1236 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 | 1393 |
1376 WebPluginDelegate* plugin_delegate = CreatePluginDelegate(); | 1394 WebPluginDelegate* plugin_delegate = CreatePluginDelegate(); |
1377 | 1395 |
1378 // Store the plugin's unique identifier, used by the container to track its | 1396 // Store the plugin's unique identifier, used by the container to track its |
1379 // script objects, and enable script objects (since Initialize may use them | 1397 // script objects, and enable script objects (since Initialize may use them |
1380 // even if it fails). | 1398 // even if it fails). |
1381 npp_ = plugin_delegate->GetPluginNPP(); | 1399 npp_ = plugin_delegate->GetPluginNPP(); |
1382 container_->allowScriptObjects(); | 1400 container_->allowScriptObjects(); |
1383 | 1401 |
1384 bool ok = plugin_delegate && plugin_delegate->Initialize( | 1402 bool ok = plugin_delegate && plugin_delegate->Initialize( |
1385 plugin_url_, arg_names_, arg_values_, this, load_manually_); | 1403 plugin_url_, arg_names_, arg_values_, load_manually_); |
1386 | 1404 |
1387 if (!ok) { | 1405 if (!ok) { |
1388 container_->clearScriptObjects(); | 1406 container_->clearScriptObjects(); |
1389 container_ = NULL; | 1407 container_ = NULL; |
1390 // TODO(iyengar) Should we delete the current plugin instance here? | 1408 // TODO(iyengar) Should we delete the current plugin instance here? |
1391 return false; | 1409 return false; |
1392 } | 1410 } |
1393 | 1411 |
1394 delegate_ = plugin_delegate; | 1412 delegate_ = plugin_delegate; |
1395 | 1413 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 case PLUGIN_SRC: | 1485 case PLUGIN_SRC: |
1468 webframe_->setReferrerForRequest(*request, plugin_url_); | 1486 webframe_->setReferrerForRequest(*request, plugin_url_); |
1469 break; | 1487 break; |
1470 | 1488 |
1471 default: | 1489 default: |
1472 break; | 1490 break; |
1473 } | 1491 } |
1474 } | 1492 } |
1475 | 1493 |
1476 } // namespace content | 1494 } // namespace content |
OLD | NEW |