OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/renderer/ppb_nacl_private.h" | 5 #include "components/nacl/renderer/ppb_nacl_private.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "net/http/http_util.h" | 56 #include "net/http/http_util.h" |
57 #include "ppapi/c/pp_bool.h" | 57 #include "ppapi/c/pp_bool.h" |
58 #include "ppapi/c/private/pp_file_handle.h" | 58 #include "ppapi/c/private/pp_file_handle.h" |
59 #include "ppapi/shared_impl/ppapi_globals.h" | 59 #include "ppapi/shared_impl/ppapi_globals.h" |
60 #include "ppapi/shared_impl/ppapi_permissions.h" | 60 #include "ppapi/shared_impl/ppapi_permissions.h" |
61 #include "ppapi/shared_impl/ppapi_preferences.h" | 61 #include "ppapi/shared_impl/ppapi_preferences.h" |
62 #include "ppapi/shared_impl/var.h" | 62 #include "ppapi/shared_impl/var.h" |
63 #include "ppapi/shared_impl/var_tracker.h" | 63 #include "ppapi/shared_impl/var_tracker.h" |
64 #include "ppapi/thunk/enter.h" | 64 #include "ppapi/thunk/enter.h" |
65 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 65 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
66 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 66 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
67 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 67 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 68 #include "third_party/WebKit/public/web/WebAssociatedURLLoader.h" |
| 69 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" |
68 #include "third_party/WebKit/public/web/WebDocument.h" | 70 #include "third_party/WebKit/public/web/WebDocument.h" |
69 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 71 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
70 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 72 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
71 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | |
72 | 73 |
73 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
74 #include "base/win/scoped_handle.h" | 75 #include "base/win/scoped_handle.h" |
75 #endif | 76 #endif |
76 | 77 |
77 namespace nacl { | 78 namespace nacl { |
78 namespace { | 79 namespace { |
79 | 80 |
80 // The pseudo-architecture used to indicate portable native client. | 81 // The pseudo-architecture used to indicate portable native client. |
81 const char* const kPortableArch = "portable"; | 82 const char* const kPortableArch = "portable"; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 callback.Run(base::File(file_info.handle), | 310 callback.Run(base::File(file_info.handle), |
310 file_info.token_lo, | 311 file_info.token_lo, |
311 file_info.token_hi); | 312 file_info.token_hi); |
312 } | 313 } |
313 | 314 |
314 PP_Instance pp_instance_; | 315 PP_Instance pp_instance_; |
315 NaClAppProcessType process_type_; | 316 NaClAppProcessType process_type_; |
316 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); | 317 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); |
317 }; | 318 }; |
318 | 319 |
319 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, | 320 blink::WebAssociatedURLLoader* CreateAssociatedURLLoader( |
320 const GURL& gurl) { | 321 const blink::WebDocument& document, |
321 blink::WebURLLoaderOptions options; | 322 const GURL& gurl) { |
| 323 blink::WebAssociatedURLLoaderOptions options; |
322 options.untrustedHTTP = true; | 324 options.untrustedHTTP = true; |
323 | 325 |
324 // Options settings here follow the original behavior in the trusted | 326 // Options settings here follow the original behavior in the trusted |
325 // plugin and PepperURLLoaderHost. | 327 // plugin and PepperURLLoaderHost. |
326 if (document.getSecurityOrigin().canRequest(gurl)) { | 328 if (document.getSecurityOrigin().canRequest(gurl)) { |
327 options.allowCredentials = true; | 329 options.allowCredentials = true; |
328 } else { | 330 } else { |
329 // Allow CORS. | 331 // Allow CORS. |
330 options.crossOriginRequestPolicy = | 332 options.crossOriginRequestPolicy = blink::WebAssociatedURLLoaderOptions:: |
331 blink::WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; | 333 CrossOriginRequestPolicyUseAccessControl; |
332 } | 334 } |
333 return document.frame()->createAssociatedURLLoader(options); | 335 return document.frame()->createAssociatedURLLoader(options); |
334 } | 336 } |
335 | 337 |
336 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, | 338 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, |
337 const GURL& gurl) { | 339 const GURL& gurl) { |
338 blink::WebURLRequest request; | 340 blink::WebURLRequest request; |
339 request.setURL(gurl); | 341 request.setURL(gurl); |
340 request.setFirstPartyForCookies(document.firstPartyForCookies()); | 342 request.setFirstPartyForCookies(document.firstPartyForCookies()); |
341 return request; | 343 return request; |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 if (!load_manager || !plugin_instance) { | 1008 if (!load_manager || !plugin_instance) { |
1007 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1009 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1008 FROM_HERE, | 1010 FROM_HERE, |
1009 base::Bind(callback.func, callback.user_data, | 1011 base::Bind(callback.func, callback.user_data, |
1010 static_cast<int32_t>(PP_ERROR_FAILED))); | 1012 static_cast<int32_t>(PP_ERROR_FAILED))); |
1011 } | 1013 } |
1012 const blink::WebDocument& document = | 1014 const blink::WebDocument& document = |
1013 plugin_instance->GetContainer()->document(); | 1015 plugin_instance->GetContainer()->document(); |
1014 | 1016 |
1015 const GURL& gurl = load_manager->manifest_base_url(); | 1017 const GURL& gurl = load_manager->manifest_base_url(); |
1016 std::unique_ptr<blink::WebURLLoader> url_loader( | 1018 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1017 CreateWebURLLoader(document, gurl)); | 1019 CreateAssociatedURLLoader(document, gurl)); |
1018 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); | 1020 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); |
1019 | 1021 |
1020 // ManifestDownloader deletes itself after invoking the callback. | 1022 // ManifestDownloader deletes itself after invoking the callback. |
1021 ManifestDownloader* manifest_downloader = new ManifestDownloader( | 1023 ManifestDownloader* manifest_downloader = new ManifestDownloader( |
1022 std::move(url_loader), load_manager->is_installed(), | 1024 std::move(url_loader), load_manager->is_installed(), |
1023 base::Bind(DownloadManifestToBufferCompletion, instance, callback, | 1025 base::Bind(DownloadManifestToBufferCompletion, instance, callback, |
1024 base::Time::Now())); | 1026 base::Time::Now())); |
1025 manifest_downloader->Load(request); | 1027 manifest_downloader->Load(request); |
1026 } | 1028 } |
1027 | 1029 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 content::PepperPluginInstance* plugin_instance = | 1361 content::PepperPluginInstance* plugin_instance = |
1360 content::PepperPluginInstance::Get(instance); | 1362 content::PepperPluginInstance::Get(instance); |
1361 if (!plugin_instance) { | 1363 if (!plugin_instance) { |
1362 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1364 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1363 FROM_HERE, | 1365 FROM_HERE, |
1364 base::Bind(callback.func, callback.user_data, | 1366 base::Bind(callback.func, callback.user_data, |
1365 static_cast<int32_t>(PP_ERROR_FAILED))); | 1367 static_cast<int32_t>(PP_ERROR_FAILED))); |
1366 } | 1368 } |
1367 const blink::WebDocument& document = | 1369 const blink::WebDocument& document = |
1368 plugin_instance->GetContainer()->document(); | 1370 plugin_instance->GetContainer()->document(); |
1369 std::unique_ptr<blink::WebURLLoader> url_loader( | 1371 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1370 CreateWebURLLoader(document, gurl)); | 1372 CreateAssociatedURLLoader(document, gurl)); |
1371 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1373 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1372 | 1374 |
1373 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1375 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1374 | 1376 |
1375 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1377 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1376 FileDownloader* file_downloader = new FileDownloader( | 1378 FileDownloader* file_downloader = new FileDownloader( |
1377 std::move(url_loader), std::move(target_file), | 1379 std::move(url_loader), std::move(target_file), |
1378 base::Bind(&DownloadNexeCompletion, request, out_file_info), | 1380 base::Bind(&DownloadNexeCompletion, request, out_file_info), |
1379 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1381 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1380 base::Owned(tracker), std::string(url))); | 1382 base::Owned(tracker), std::string(url))); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 | 1513 |
1512 content::PepperPluginInstance* plugin_instance = | 1514 content::PepperPluginInstance* plugin_instance = |
1513 content::PepperPluginInstance::Get(instance); | 1515 content::PepperPluginInstance::Get(instance); |
1514 if (!plugin_instance) { | 1516 if (!plugin_instance) { |
1515 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1517 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1516 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), | 1518 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1517 kInvalidNaClFileInfo)); | 1519 kInvalidNaClFileInfo)); |
1518 } | 1520 } |
1519 const blink::WebDocument& document = | 1521 const blink::WebDocument& document = |
1520 plugin_instance->GetContainer()->document(); | 1522 plugin_instance->GetContainer()->document(); |
1521 std::unique_ptr<blink::WebURLLoader> url_loader( | 1523 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1522 CreateWebURLLoader(document, gurl)); | 1524 CreateAssociatedURLLoader(document, gurl)); |
1523 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1525 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1524 | 1526 |
1525 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1527 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1526 | 1528 |
1527 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1529 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1528 FileDownloader* file_downloader = | 1530 FileDownloader* file_downloader = |
1529 new FileDownloader(std::move(url_loader), std::move(target_file), | 1531 new FileDownloader(std::move(url_loader), std::move(target_file), |
1530 base::Bind(&DownloadFileCompletion, callback), | 1532 base::Bind(&DownloadFileCompletion, callback), |
1531 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1533 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1532 base::Owned(tracker), std::string(url))); | 1534 base::Owned(tracker), std::string(url))); |
(...skipping 30 matching lines...) Expand all Loading... |
1563 void PPBNaClPrivate::SetPNaClStartTime(PP_Instance instance) { | 1565 void PPBNaClPrivate::SetPNaClStartTime(PP_Instance instance) { |
1564 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1566 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1565 if (load_manager) | 1567 if (load_manager) |
1566 load_manager->set_pnacl_start_time(base::Time::Now()); | 1568 load_manager->set_pnacl_start_time(base::Time::Now()); |
1567 } | 1569 } |
1568 | 1570 |
1569 namespace { | 1571 namespace { |
1570 | 1572 |
1571 // PexeDownloader is responsible for deleting itself when the download | 1573 // PexeDownloader is responsible for deleting itself when the download |
1572 // finishes. | 1574 // finishes. |
1573 class PexeDownloader : public blink::WebURLLoaderClient { | 1575 class PexeDownloader : public blink::WebAssociatedURLLoaderClient { |
1574 public: | 1576 public: |
1575 PexeDownloader(PP_Instance instance, | 1577 PexeDownloader(PP_Instance instance, |
1576 std::unique_ptr<blink::WebURLLoader> url_loader, | 1578 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader, |
1577 const std::string& pexe_url, | 1579 const std::string& pexe_url, |
1578 int32_t pexe_opt_level, | 1580 int32_t pexe_opt_level, |
1579 bool use_subzero, | 1581 bool use_subzero, |
1580 const PPP_PexeStreamHandler* stream_handler, | 1582 const PPP_PexeStreamHandler* stream_handler, |
1581 void* stream_handler_user_data) | 1583 void* stream_handler_user_data) |
1582 : instance_(instance), | 1584 : instance_(instance), |
1583 url_loader_(std::move(url_loader)), | 1585 url_loader_(std::move(url_loader)), |
1584 pexe_url_(pexe_url), | 1586 pexe_url_(pexe_url), |
1585 pexe_opt_level_(pexe_opt_level), | 1587 pexe_opt_level_(pexe_opt_level), |
1586 use_subzero_(use_subzero), | 1588 use_subzero_(use_subzero), |
1587 stream_handler_(stream_handler), | 1589 stream_handler_(stream_handler), |
1588 stream_handler_user_data_(stream_handler_user_data), | 1590 stream_handler_user_data_(stream_handler_user_data), |
1589 success_(false), | 1591 success_(false), |
1590 expected_content_length_(-1), | 1592 expected_content_length_(-1), |
1591 weak_factory_(this) {} | 1593 weak_factory_(this) {} |
1592 | 1594 |
1593 void Load(const blink::WebURLRequest& request) { | 1595 void Load(const blink::WebURLRequest& request) { |
1594 url_loader_->loadAsynchronously(request, this); | 1596 url_loader_->loadAsynchronously(request, this); |
1595 } | 1597 } |
1596 | 1598 |
1597 private: | 1599 private: |
1598 void didReceiveResponse(blink::WebURLLoader* loader, | 1600 void didReceiveResponse(const blink::WebURLResponse& response) override { |
1599 const blink::WebURLResponse& response) override { | |
1600 success_ = (response.httpStatusCode() == 200); | 1601 success_ = (response.httpStatusCode() == 200); |
1601 if (!success_) | 1602 if (!success_) |
1602 return; | 1603 return; |
1603 | 1604 |
1604 expected_content_length_ = response.expectedContentLength(); | 1605 expected_content_length_ = response.expectedContentLength(); |
1605 | 1606 |
1606 // Defer loading after receiving headers. This is because we may already | 1607 // Defer loading after receiving headers. This is because we may already |
1607 // have a cached translated nexe, so check for that now. | 1608 // have a cached translated nexe, so check for that now. |
1608 url_loader_->setDefersLoading(true); | 1609 url_loader_->setDefersLoading(true); |
1609 | 1610 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 } | 1652 } |
1652 stream_handler_->DidCacheMiss(stream_handler_user_data_, | 1653 stream_handler_->DidCacheMiss(stream_handler_user_data_, |
1653 expected_content_length_, | 1654 expected_content_length_, |
1654 file_handle); | 1655 file_handle); |
1655 | 1656 |
1656 // No translated nexe was found in the cache, so we should download the | 1657 // No translated nexe was found in the cache, so we should download the |
1657 // file to start streaming it. | 1658 // file to start streaming it. |
1658 url_loader_->setDefersLoading(false); | 1659 url_loader_->setDefersLoading(false); |
1659 } | 1660 } |
1660 | 1661 |
1661 void didReceiveData(blink::WebURLLoader* loader, | 1662 void didReceiveData(const char* data, int data_length) override { |
1662 const char* data, | |
1663 int data_length, | |
1664 int encoded_data_length, | |
1665 int encoded_body_length) override { | |
1666 if (content::PepperPluginInstance::Get(instance_)) { | 1663 if (content::PepperPluginInstance::Get(instance_)) { |
1667 // Stream the data we received to the stream callback. | 1664 // Stream the data we received to the stream callback. |
1668 stream_handler_->DidStreamData(stream_handler_user_data_, | 1665 stream_handler_->DidStreamData(stream_handler_user_data_, |
1669 data, | 1666 data, |
1670 data_length); | 1667 data_length); |
1671 } | 1668 } |
1672 } | 1669 } |
1673 | 1670 |
1674 void didFinishLoading(blink::WebURLLoader* loader, | 1671 void didFinishLoading(double finish_time) override { |
1675 double finish_time, | |
1676 int64_t total_encoded_data_length) override { | |
1677 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; | 1672 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; |
1678 | 1673 |
1679 if (content::PepperPluginInstance::Get(instance_)) | 1674 if (content::PepperPluginInstance::Get(instance_)) |
1680 stream_handler_->DidFinishStream(stream_handler_user_data_, result); | 1675 stream_handler_->DidFinishStream(stream_handler_user_data_, result); |
1681 delete this; | 1676 delete this; |
1682 } | 1677 } |
1683 | 1678 |
1684 void didFail(blink::WebURLLoader* loader, | 1679 void didFail(const blink::WebURLError& error) override { |
1685 const blink::WebURLError& error) override { | |
1686 if (content::PepperPluginInstance::Get(instance_)) | 1680 if (content::PepperPluginInstance::Get(instance_)) |
1687 stream_handler_->DidFinishStream(stream_handler_user_data_, | 1681 stream_handler_->DidFinishStream(stream_handler_user_data_, |
1688 PP_ERROR_FAILED); | 1682 PP_ERROR_FAILED); |
1689 delete this; | 1683 delete this; |
1690 } | 1684 } |
1691 | 1685 |
1692 PP_Instance instance_; | 1686 PP_Instance instance_; |
1693 std::unique_ptr<blink::WebURLLoader> url_loader_; | 1687 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader_; |
1694 std::string pexe_url_; | 1688 std::string pexe_url_; |
1695 int32_t pexe_opt_level_; | 1689 int32_t pexe_opt_level_; |
1696 bool use_subzero_; | 1690 bool use_subzero_; |
1697 const PPP_PexeStreamHandler* stream_handler_; | 1691 const PPP_PexeStreamHandler* stream_handler_; |
1698 void* stream_handler_user_data_; | 1692 void* stream_handler_user_data_; |
1699 bool success_; | 1693 bool success_; |
1700 int64_t expected_content_length_; | 1694 int64_t expected_content_length_; |
1701 base::WeakPtrFactory<PexeDownloader> weak_factory_; | 1695 base::WeakPtrFactory<PexeDownloader> weak_factory_; |
1702 }; | 1696 }; |
1703 | 1697 |
(...skipping 11 matching lines...) Expand all Loading... |
1715 if (!plugin_instance) { | 1709 if (!plugin_instance) { |
1716 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1710 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1717 FROM_HERE, base::Bind(handler->DidFinishStream, handler_user_data, | 1711 FROM_HERE, base::Bind(handler->DidFinishStream, handler_user_data, |
1718 static_cast<int32_t>(PP_ERROR_FAILED))); | 1712 static_cast<int32_t>(PP_ERROR_FAILED))); |
1719 return; | 1713 return; |
1720 } | 1714 } |
1721 | 1715 |
1722 GURL gurl(pexe_url); | 1716 GURL gurl(pexe_url); |
1723 const blink::WebDocument& document = | 1717 const blink::WebDocument& document = |
1724 plugin_instance->GetContainer()->document(); | 1718 plugin_instance->GetContainer()->document(); |
1725 std::unique_ptr<blink::WebURLLoader> url_loader( | 1719 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1726 CreateWebURLLoader(document, gurl)); | 1720 CreateAssociatedURLLoader(document, gurl)); |
1727 PexeDownloader* downloader = | 1721 PexeDownloader* downloader = |
1728 new PexeDownloader(instance, std::move(url_loader), pexe_url, opt_level, | 1722 new PexeDownloader(instance, std::move(url_loader), pexe_url, opt_level, |
1729 PP_ToBool(use_subzero), handler, handler_user_data); | 1723 PP_ToBool(use_subzero), handler, handler_user_data); |
1730 | 1724 |
1731 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1725 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1732 // Mark the request as requesting a PNaCl bitcode file, | 1726 // Mark the request as requesting a PNaCl bitcode file, |
1733 // so that component updater can detect this user action. | 1727 // so that component updater can detect this user action. |
1734 url_request.addHTTPHeaderField( | 1728 url_request.addHTTPHeaderField( |
1735 blink::WebString::fromUTF8("Accept"), | 1729 blink::WebString::fromUTF8("Accept"), |
1736 blink::WebString::fromUTF8("application/x-pnacl, */*")); | 1730 blink::WebString::fromUTF8("application/x-pnacl, */*")); |
1737 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 1731 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
1738 downloader->Load(url_request); | 1732 downloader->Load(url_request); |
1739 } | 1733 } |
1740 | 1734 |
1741 } // namespace nacl | 1735 } // namespace nacl |
OLD | NEW |