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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 callback.Run(base::File(file_info.handle), | 322 callback.Run(base::File(file_info.handle), |
322 file_info.token_lo, | 323 file_info.token_lo, |
323 file_info.token_hi); | 324 file_info.token_hi); |
324 } | 325 } |
325 | 326 |
326 PP_Instance pp_instance_; | 327 PP_Instance pp_instance_; |
327 NaClAppProcessType process_type_; | 328 NaClAppProcessType process_type_; |
328 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); | 329 DISALLOW_COPY_AND_ASSIGN(ManifestServiceProxy); |
329 }; | 330 }; |
330 | 331 |
331 blink::WebURLLoader* CreateWebURLLoader(const blink::WebDocument& document, | 332 blink::WebAssociatedURLLoader* CreateAssociatedURLLoader( |
332 const GURL& gurl) { | 333 const blink::WebDocument& document, |
333 blink::WebURLLoaderOptions options; | 334 const GURL& gurl) { |
| 335 blink::WebAssociatedURLLoaderOptions options; |
334 options.untrustedHTTP = true; | 336 options.untrustedHTTP = true; |
335 | 337 |
336 // Options settings here follow the original behavior in the trusted | 338 // Options settings here follow the original behavior in the trusted |
337 // plugin and PepperURLLoaderHost. | 339 // plugin and PepperURLLoaderHost. |
338 if (document.getSecurityOrigin().canRequest(gurl)) { | 340 if (document.getSecurityOrigin().canRequest(gurl)) { |
339 options.allowCredentials = true; | 341 options.allowCredentials = true; |
340 } else { | 342 } else { |
341 // Allow CORS. | 343 // Allow CORS. |
342 options.crossOriginRequestPolicy = | 344 options.crossOriginRequestPolicy = blink::WebAssociatedURLLoaderOptions:: |
343 blink::WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; | 345 CrossOriginRequestPolicyUseAccessControl; |
344 } | 346 } |
345 return document.frame()->createAssociatedURLLoader(options); | 347 return document.frame()->createAssociatedURLLoader(options); |
346 } | 348 } |
347 | 349 |
348 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, | 350 blink::WebURLRequest CreateWebURLRequest(const blink::WebDocument& document, |
349 const GURL& gurl) { | 351 const GURL& gurl) { |
350 blink::WebURLRequest request; | 352 blink::WebURLRequest request; |
351 request.setURL(gurl); | 353 request.setURL(gurl); |
352 request.setFirstPartyForCookies(document.firstPartyForCookies()); | 354 request.setFirstPartyForCookies(document.firstPartyForCookies()); |
353 return request; | 355 return request; |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 if (!load_manager || !plugin_instance) { | 1020 if (!load_manager || !plugin_instance) { |
1019 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1021 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1020 FROM_HERE, | 1022 FROM_HERE, |
1021 base::Bind(callback.func, callback.user_data, | 1023 base::Bind(callback.func, callback.user_data, |
1022 static_cast<int32_t>(PP_ERROR_FAILED))); | 1024 static_cast<int32_t>(PP_ERROR_FAILED))); |
1023 } | 1025 } |
1024 const blink::WebDocument& document = | 1026 const blink::WebDocument& document = |
1025 plugin_instance->GetContainer()->document(); | 1027 plugin_instance->GetContainer()->document(); |
1026 | 1028 |
1027 const GURL& gurl = load_manager->manifest_base_url(); | 1029 const GURL& gurl = load_manager->manifest_base_url(); |
1028 std::unique_ptr<blink::WebURLLoader> url_loader( | 1030 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1029 CreateWebURLLoader(document, gurl)); | 1031 CreateAssociatedURLLoader(document, gurl)); |
1030 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); | 1032 blink::WebURLRequest request = CreateWebURLRequest(document, gurl); |
1031 | 1033 |
1032 // ManifestDownloader deletes itself after invoking the callback. | 1034 // ManifestDownloader deletes itself after invoking the callback. |
1033 ManifestDownloader* manifest_downloader = new ManifestDownloader( | 1035 ManifestDownloader* manifest_downloader = new ManifestDownloader( |
1034 std::move(url_loader), load_manager->is_installed(), | 1036 std::move(url_loader), load_manager->is_installed(), |
1035 base::Bind(DownloadManifestToBufferCompletion, instance, callback, | 1037 base::Bind(DownloadManifestToBufferCompletion, instance, callback, |
1036 base::Time::Now())); | 1038 base::Time::Now())); |
1037 manifest_downloader->Load(request); | 1039 manifest_downloader->Load(request); |
1038 } | 1040 } |
1039 | 1041 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1371 content::PepperPluginInstance* plugin_instance = | 1373 content::PepperPluginInstance* plugin_instance = |
1372 content::PepperPluginInstance::Get(instance); | 1374 content::PepperPluginInstance::Get(instance); |
1373 if (!plugin_instance) { | 1375 if (!plugin_instance) { |
1374 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( | 1376 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
1375 FROM_HERE, | 1377 FROM_HERE, |
1376 base::Bind(callback.func, callback.user_data, | 1378 base::Bind(callback.func, callback.user_data, |
1377 static_cast<int32_t>(PP_ERROR_FAILED))); | 1379 static_cast<int32_t>(PP_ERROR_FAILED))); |
1378 } | 1380 } |
1379 const blink::WebDocument& document = | 1381 const blink::WebDocument& document = |
1380 plugin_instance->GetContainer()->document(); | 1382 plugin_instance->GetContainer()->document(); |
1381 std::unique_ptr<blink::WebURLLoader> url_loader( | 1383 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1382 CreateWebURLLoader(document, gurl)); | 1384 CreateAssociatedURLLoader(document, gurl)); |
1383 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1385 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1384 | 1386 |
1385 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1387 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1386 | 1388 |
1387 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1389 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1388 FileDownloader* file_downloader = new FileDownloader( | 1390 FileDownloader* file_downloader = new FileDownloader( |
1389 std::move(url_loader), std::move(target_file), | 1391 std::move(url_loader), std::move(target_file), |
1390 base::Bind(&DownloadNexeCompletion, request, out_file_info), | 1392 base::Bind(&DownloadNexeCompletion, request, out_file_info), |
1391 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1393 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1392 base::Owned(tracker), std::string(url))); | 1394 base::Owned(tracker), std::string(url))); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 | 1525 |
1524 content::PepperPluginInstance* plugin_instance = | 1526 content::PepperPluginInstance* plugin_instance = |
1525 content::PepperPluginInstance::Get(instance); | 1527 content::PepperPluginInstance::Get(instance); |
1526 if (!plugin_instance) { | 1528 if (!plugin_instance) { |
1527 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1529 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1528 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), | 1530 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1529 kInvalidNaClFileInfo)); | 1531 kInvalidNaClFileInfo)); |
1530 } | 1532 } |
1531 const blink::WebDocument& document = | 1533 const blink::WebDocument& document = |
1532 plugin_instance->GetContainer()->document(); | 1534 plugin_instance->GetContainer()->document(); |
1533 std::unique_ptr<blink::WebURLLoader> url_loader( | 1535 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1534 CreateWebURLLoader(document, gurl)); | 1536 CreateAssociatedURLLoader(document, gurl)); |
1535 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1537 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1536 | 1538 |
1537 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1539 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1538 | 1540 |
1539 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1541 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
1540 FileDownloader* file_downloader = | 1542 FileDownloader* file_downloader = |
1541 new FileDownloader(std::move(url_loader), std::move(target_file), | 1543 new FileDownloader(std::move(url_loader), std::move(target_file), |
1542 base::Bind(&DownloadFileCompletion, callback), | 1544 base::Bind(&DownloadFileCompletion, callback), |
1543 base::Bind(&ProgressEventRateLimiter::ReportProgress, | 1545 base::Bind(&ProgressEventRateLimiter::ReportProgress, |
1544 base::Owned(tracker), std::string(url))); | 1546 base::Owned(tracker), std::string(url))); |
(...skipping 30 matching lines...) Expand all Loading... |
1575 void PPBNaClPrivate::SetPNaClStartTime(PP_Instance instance) { | 1577 void PPBNaClPrivate::SetPNaClStartTime(PP_Instance instance) { |
1576 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1578 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1577 if (load_manager) | 1579 if (load_manager) |
1578 load_manager->set_pnacl_start_time(base::Time::Now()); | 1580 load_manager->set_pnacl_start_time(base::Time::Now()); |
1579 } | 1581 } |
1580 | 1582 |
1581 namespace { | 1583 namespace { |
1582 | 1584 |
1583 // PexeDownloader is responsible for deleting itself when the download | 1585 // PexeDownloader is responsible for deleting itself when the download |
1584 // finishes. | 1586 // finishes. |
1585 class PexeDownloader : public blink::WebURLLoaderClient { | 1587 class PexeDownloader : public blink::WebAssociatedURLLoaderClient { |
1586 public: | 1588 public: |
1587 PexeDownloader(PP_Instance instance, | 1589 PexeDownloader(PP_Instance instance, |
1588 std::unique_ptr<blink::WebURLLoader> url_loader, | 1590 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader, |
1589 const std::string& pexe_url, | 1591 const std::string& pexe_url, |
1590 int32_t pexe_opt_level, | 1592 int32_t pexe_opt_level, |
1591 bool use_subzero, | 1593 bool use_subzero, |
1592 const PPP_PexeStreamHandler* stream_handler, | 1594 const PPP_PexeStreamHandler* stream_handler, |
1593 void* stream_handler_user_data) | 1595 void* stream_handler_user_data) |
1594 : instance_(instance), | 1596 : instance_(instance), |
1595 url_loader_(std::move(url_loader)), | 1597 url_loader_(std::move(url_loader)), |
1596 pexe_url_(pexe_url), | 1598 pexe_url_(pexe_url), |
1597 pexe_opt_level_(pexe_opt_level), | 1599 pexe_opt_level_(pexe_opt_level), |
1598 use_subzero_(use_subzero), | 1600 use_subzero_(use_subzero), |
1599 stream_handler_(stream_handler), | 1601 stream_handler_(stream_handler), |
1600 stream_handler_user_data_(stream_handler_user_data), | 1602 stream_handler_user_data_(stream_handler_user_data), |
1601 success_(false), | 1603 success_(false), |
1602 expected_content_length_(-1), | 1604 expected_content_length_(-1), |
1603 weak_factory_(this) {} | 1605 weak_factory_(this) {} |
1604 | 1606 |
1605 void Load(const blink::WebURLRequest& request) { | 1607 void Load(const blink::WebURLRequest& request) { |
1606 url_loader_->loadAsynchronously(request, this); | 1608 url_loader_->loadAsynchronously(request, this); |
1607 } | 1609 } |
1608 | 1610 |
1609 private: | 1611 private: |
1610 void didReceiveResponse(blink::WebURLLoader* loader, | 1612 void didReceiveResponse(const blink::WebURLResponse& response) override { |
1611 const blink::WebURLResponse& response) override { | |
1612 success_ = (response.httpStatusCode() == 200); | 1613 success_ = (response.httpStatusCode() == 200); |
1613 if (!success_) | 1614 if (!success_) |
1614 return; | 1615 return; |
1615 | 1616 |
1616 expected_content_length_ = response.expectedContentLength(); | 1617 expected_content_length_ = response.expectedContentLength(); |
1617 | 1618 |
1618 // Defer loading after receiving headers. This is because we may already | 1619 // Defer loading after receiving headers. This is because we may already |
1619 // have a cached translated nexe, so check for that now. | 1620 // have a cached translated nexe, so check for that now. |
1620 url_loader_->setDefersLoading(true); | 1621 url_loader_->setDefersLoading(true); |
1621 | 1622 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1663 } | 1664 } |
1664 stream_handler_->DidCacheMiss(stream_handler_user_data_, | 1665 stream_handler_->DidCacheMiss(stream_handler_user_data_, |
1665 expected_content_length_, | 1666 expected_content_length_, |
1666 file_handle); | 1667 file_handle); |
1667 | 1668 |
1668 // No translated nexe was found in the cache, so we should download the | 1669 // No translated nexe was found in the cache, so we should download the |
1669 // file to start streaming it. | 1670 // file to start streaming it. |
1670 url_loader_->setDefersLoading(false); | 1671 url_loader_->setDefersLoading(false); |
1671 } | 1672 } |
1672 | 1673 |
1673 void didReceiveData(blink::WebURLLoader* loader, | 1674 void didReceiveData(const char* data, int data_length) override { |
1674 const char* data, | |
1675 int data_length, | |
1676 int encoded_data_length, | |
1677 int encoded_body_length) override { | |
1678 if (content::PepperPluginInstance::Get(instance_)) { | 1675 if (content::PepperPluginInstance::Get(instance_)) { |
1679 // Stream the data we received to the stream callback. | 1676 // Stream the data we received to the stream callback. |
1680 stream_handler_->DidStreamData(stream_handler_user_data_, | 1677 stream_handler_->DidStreamData(stream_handler_user_data_, |
1681 data, | 1678 data, |
1682 data_length); | 1679 data_length); |
1683 } | 1680 } |
1684 } | 1681 } |
1685 | 1682 |
1686 void didFinishLoading(blink::WebURLLoader* loader, | 1683 void didFinishLoading(double finish_time) override { |
1687 double finish_time, | |
1688 int64_t total_encoded_data_length) override { | |
1689 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; | 1684 int32_t result = success_ ? PP_OK : PP_ERROR_FAILED; |
1690 | 1685 |
1691 if (content::PepperPluginInstance::Get(instance_)) | 1686 if (content::PepperPluginInstance::Get(instance_)) |
1692 stream_handler_->DidFinishStream(stream_handler_user_data_, result); | 1687 stream_handler_->DidFinishStream(stream_handler_user_data_, result); |
1693 delete this; | 1688 delete this; |
1694 } | 1689 } |
1695 | 1690 |
1696 void didFail(blink::WebURLLoader* loader, | 1691 void didFail(const blink::WebURLError& error) override { |
1697 const blink::WebURLError& error) override { | |
1698 if (content::PepperPluginInstance::Get(instance_)) | 1692 if (content::PepperPluginInstance::Get(instance_)) |
1699 stream_handler_->DidFinishStream(stream_handler_user_data_, | 1693 stream_handler_->DidFinishStream(stream_handler_user_data_, |
1700 PP_ERROR_FAILED); | 1694 PP_ERROR_FAILED); |
1701 delete this; | 1695 delete this; |
1702 } | 1696 } |
1703 | 1697 |
1704 PP_Instance instance_; | 1698 PP_Instance instance_; |
1705 std::unique_ptr<blink::WebURLLoader> url_loader_; | 1699 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader_; |
1706 std::string pexe_url_; | 1700 std::string pexe_url_; |
1707 int32_t pexe_opt_level_; | 1701 int32_t pexe_opt_level_; |
1708 bool use_subzero_; | 1702 bool use_subzero_; |
1709 const PPP_PexeStreamHandler* stream_handler_; | 1703 const PPP_PexeStreamHandler* stream_handler_; |
1710 void* stream_handler_user_data_; | 1704 void* stream_handler_user_data_; |
1711 bool success_; | 1705 bool success_; |
1712 int64_t expected_content_length_; | 1706 int64_t expected_content_length_; |
1713 base::WeakPtrFactory<PexeDownloader> weak_factory_; | 1707 base::WeakPtrFactory<PexeDownloader> weak_factory_; |
1714 }; | 1708 }; |
1715 | 1709 |
(...skipping 11 matching lines...) Expand all Loading... |
1727 if (!plugin_instance) { | 1721 if (!plugin_instance) { |
1728 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1722 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1729 FROM_HERE, base::Bind(handler->DidFinishStream, handler_user_data, | 1723 FROM_HERE, base::Bind(handler->DidFinishStream, handler_user_data, |
1730 static_cast<int32_t>(PP_ERROR_FAILED))); | 1724 static_cast<int32_t>(PP_ERROR_FAILED))); |
1731 return; | 1725 return; |
1732 } | 1726 } |
1733 | 1727 |
1734 GURL gurl(pexe_url); | 1728 GURL gurl(pexe_url); |
1735 const blink::WebDocument& document = | 1729 const blink::WebDocument& document = |
1736 plugin_instance->GetContainer()->document(); | 1730 plugin_instance->GetContainer()->document(); |
1737 std::unique_ptr<blink::WebURLLoader> url_loader( | 1731 std::unique_ptr<blink::WebAssociatedURLLoader> url_loader( |
1738 CreateWebURLLoader(document, gurl)); | 1732 CreateAssociatedURLLoader(document, gurl)); |
1739 PexeDownloader* downloader = | 1733 PexeDownloader* downloader = |
1740 new PexeDownloader(instance, std::move(url_loader), pexe_url, opt_level, | 1734 new PexeDownloader(instance, std::move(url_loader), pexe_url, opt_level, |
1741 PP_ToBool(use_subzero), handler, handler_user_data); | 1735 PP_ToBool(use_subzero), handler, handler_user_data); |
1742 | 1736 |
1743 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1737 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1744 // Mark the request as requesting a PNaCl bitcode file, | 1738 // Mark the request as requesting a PNaCl bitcode file, |
1745 // so that component updater can detect this user action. | 1739 // so that component updater can detect this user action. |
1746 url_request.addHTTPHeaderField( | 1740 url_request.addHTTPHeaderField( |
1747 blink::WebString::fromUTF8("Accept"), | 1741 blink::WebString::fromUTF8("Accept"), |
1748 blink::WebString::fromUTF8("application/x-pnacl, */*")); | 1742 blink::WebString::fromUTF8("application/x-pnacl, */*")); |
1749 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); | 1743 url_request.setRequestContext(blink::WebURLRequest::RequestContextObject); |
1750 downloader->Load(url_request); | 1744 downloader->Load(url_request); |
1751 } | 1745 } |
1752 | 1746 |
1753 } // namespace nacl | 1747 } // namespace nacl |
OLD | NEW |