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_impl.h" | 5 #include "components/nacl/renderer/ppb_nacl_private_impl.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/containers/scoped_ptr_hash_map.h" | 14 #include "base/containers/scoped_ptr_hash_map.h" |
15 #include "base/cpu.h" | 15 #include "base/cpu.h" |
16 #include "base/files/file.h" | 16 #include "base/files/file.h" |
17 #include "base/json/json_reader.h" | 17 #include "base/json/json_reader.h" |
18 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 19 #include "base/location.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 22 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/string_split.h" | 23 #include "base/strings/string_split.h" |
22 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/thread_task_runner_handle.h" |
23 #include "components/nacl/common/nacl_host_messages.h" | 26 #include "components/nacl/common/nacl_host_messages.h" |
24 #include "components/nacl/common/nacl_messages.h" | 27 #include "components/nacl/common/nacl_messages.h" |
25 #include "components/nacl/common/nacl_nonsfi_util.h" | 28 #include "components/nacl/common/nacl_nonsfi_util.h" |
26 #include "components/nacl/common/nacl_switches.h" | 29 #include "components/nacl/common/nacl_switches.h" |
27 #include "components/nacl/common/nacl_types.h" | 30 #include "components/nacl/common/nacl_types.h" |
28 #include "components/nacl/renderer/file_downloader.h" | 31 #include "components/nacl/renderer/file_downloader.h" |
29 #include "components/nacl/renderer/histogram.h" | 32 #include "components/nacl/renderer/histogram.h" |
30 #include "components/nacl/renderer/json_manifest.h" | 33 #include "components/nacl/renderer/json_manifest.h" |
31 #include "components/nacl/renderer/manifest_downloader.h" | 34 #include "components/nacl/renderer/manifest_downloader.h" |
32 #include "components/nacl/renderer/manifest_service_channel.h" | 35 #include "components/nacl/renderer/manifest_service_channel.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 const ManifestServiceChannel::OpenResourceCallback& callback) override { | 251 const ManifestServiceChannel::OpenResourceCallback& callback) override { |
249 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 252 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
250 BelongsToCurrentThread()); | 253 BelongsToCurrentThread()); |
251 | 254 |
252 // For security hardening, disable open_resource() when it is isn't | 255 // For security hardening, disable open_resource() when it is isn't |
253 // needed. PNaCl pexes can't use open_resource(), but general nexes | 256 // needed. PNaCl pexes can't use open_resource(), but general nexes |
254 // and the PNaCl translator nexes may use it. | 257 // and the PNaCl translator nexes may use it. |
255 if (process_type_ != kNativeNaClProcessType && | 258 if (process_type_ != kNativeNaClProcessType && |
256 process_type_ != kPNaClTranslatorProcessType) { | 259 process_type_ != kPNaClTranslatorProcessType) { |
257 // Return an error. | 260 // Return an error. |
258 base::MessageLoop::current()->PostTask( | 261 base::ThreadTaskRunnerHandle::Get()->PostTask( |
259 FROM_HERE, | 262 FROM_HERE, base::Bind(callback, base::Passed(base::File()), 0, 0)); |
260 base::Bind(callback, base::Passed(base::File()), 0, 0)); | |
261 return; | 263 return; |
262 } | 264 } |
263 | 265 |
264 std::string url; | 266 std::string url; |
265 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't | 267 // TODO(teravest): Clean up pnacl_options logic in JsonManifest so we don't |
266 // have to initialize it like this here. | 268 // have to initialize it like this here. |
267 PP_PNaClOptions pnacl_options; | 269 PP_PNaClOptions pnacl_options; |
268 pnacl_options.translate = PP_FALSE; | 270 pnacl_options.translate = PP_FALSE; |
269 pnacl_options.is_debug = PP_FALSE; | 271 pnacl_options.is_debug = PP_FALSE; |
270 pnacl_options.use_subzero = PP_FALSE; | 272 pnacl_options.use_subzero = PP_FALSE; |
271 pnacl_options.opt_level = 2; | 273 pnacl_options.opt_level = 2; |
272 bool is_helper_process = process_type_ == kPNaClTranslatorProcessType; | 274 bool is_helper_process = process_type_ == kPNaClTranslatorProcessType; |
273 if (!ManifestResolveKey(pp_instance_, is_helper_process, key, &url, | 275 if (!ManifestResolveKey(pp_instance_, is_helper_process, key, &url, |
274 &pnacl_options)) { | 276 &pnacl_options)) { |
275 base::MessageLoop::current()->PostTask( | 277 base::ThreadTaskRunnerHandle::Get()->PostTask( |
276 FROM_HERE, | 278 FROM_HERE, base::Bind(callback, base::Passed(base::File()), 0, 0)); |
277 base::Bind(callback, base::Passed(base::File()), 0, 0)); | |
278 return; | 279 return; |
279 } | 280 } |
280 | 281 |
281 // We have to call DidDownloadFile, even if this object is destroyed, so | 282 // We have to call DidDownloadFile, even if this object is destroyed, so |
282 // that the handle inside PP_NaClFileInfo isn't leaked. This means that the | 283 // that the handle inside PP_NaClFileInfo isn't leaked. This means that the |
283 // callback passed to this function shouldn't have a weak pointer to an | 284 // callback passed to this function shouldn't have a weak pointer to an |
284 // object either. | 285 // object either. |
285 // | 286 // |
286 // TODO(teravest): Make a type like PP_NaClFileInfo to use for DownloadFile | 287 // TODO(teravest): Make a type like PP_NaClFileInfo to use for DownloadFile |
287 // that would close the file handle on destruction. | 288 // that would close the file handle on destruction. |
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 | 1394 |
1394 void DownloadFile(PP_Instance instance, | 1395 void DownloadFile(PP_Instance instance, |
1395 const std::string& url, | 1396 const std::string& url, |
1396 const DownloadFileCallback& callback) { | 1397 const DownloadFileCallback& callback) { |
1397 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> | 1398 DCHECK(ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()-> |
1398 BelongsToCurrentThread()); | 1399 BelongsToCurrentThread()); |
1399 | 1400 |
1400 NexeLoadManager* load_manager = GetNexeLoadManager(instance); | 1401 NexeLoadManager* load_manager = GetNexeLoadManager(instance); |
1401 DCHECK(load_manager); | 1402 DCHECK(load_manager); |
1402 if (!load_manager) { | 1403 if (!load_manager) { |
1403 base::MessageLoop::current()->PostTask( | 1404 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1404 FROM_HERE, | 1405 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1405 base::Bind(callback, | 1406 kInvalidNaClFileInfo)); |
1406 static_cast<int32_t>(PP_ERROR_FAILED), | |
1407 kInvalidNaClFileInfo)); | |
1408 return; | 1407 return; |
1409 } | 1408 } |
1410 | 1409 |
1411 // Handle special PNaCl support files which are installed on the user's | 1410 // Handle special PNaCl support files which are installed on the user's |
1412 // machine. | 1411 // machine. |
1413 if (url.find(kPNaClTranslatorBaseUrl, 0) == 0) { | 1412 if (url.find(kPNaClTranslatorBaseUrl, 0) == 0) { |
1414 PP_NaClFileInfo file_info = kInvalidNaClFileInfo; | 1413 PP_NaClFileInfo file_info = kInvalidNaClFileInfo; |
1415 PP_FileHandle handle = GetReadonlyPnaclFd(url.c_str(), | 1414 PP_FileHandle handle = GetReadonlyPnaclFd(url.c_str(), |
1416 false /* is_executable */, | 1415 false /* is_executable */, |
1417 &file_info.token_lo, | 1416 &file_info.token_lo, |
1418 &file_info.token_hi); | 1417 &file_info.token_hi); |
1419 if (handle == PP_kInvalidFileHandle) { | 1418 if (handle == PP_kInvalidFileHandle) { |
1420 base::MessageLoop::current()->PostTask( | 1419 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1421 FROM_HERE, | 1420 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1422 base::Bind(callback, | 1421 kInvalidNaClFileInfo)); |
1423 static_cast<int32_t>(PP_ERROR_FAILED), | |
1424 kInvalidNaClFileInfo)); | |
1425 return; | 1422 return; |
1426 } | 1423 } |
1427 file_info.handle = handle; | 1424 file_info.handle = handle; |
1428 base::MessageLoop::current()->PostTask( | 1425 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1429 FROM_HERE, | 1426 FROM_HERE, |
1430 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); | 1427 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); |
1431 return; | 1428 return; |
1432 } | 1429 } |
1433 | 1430 |
1434 // We have to ensure that this url resolves relative to the plugin base url | 1431 // We have to ensure that this url resolves relative to the plugin base url |
1435 // before downloading it. | 1432 // before downloading it. |
1436 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); | 1433 const GURL& test_gurl = load_manager->plugin_base_url().Resolve(url); |
1437 if (!test_gurl.is_valid()) { | 1434 if (!test_gurl.is_valid()) { |
1438 base::MessageLoop::current()->PostTask( | 1435 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1439 FROM_HERE, | 1436 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1440 base::Bind(callback, | 1437 kInvalidNaClFileInfo)); |
1441 static_cast<int32_t>(PP_ERROR_FAILED), | |
1442 kInvalidNaClFileInfo)); | |
1443 return; | 1438 return; |
1444 } | 1439 } |
1445 | 1440 |
1446 // Try the fast path for retrieving the file first. | 1441 // Try the fast path for retrieving the file first. |
1447 uint64_t file_token_lo = 0; | 1442 uint64_t file_token_lo = 0; |
1448 uint64_t file_token_hi = 0; | 1443 uint64_t file_token_hi = 0; |
1449 PP_FileHandle file_handle = OpenNaClExecutable(instance, | 1444 PP_FileHandle file_handle = OpenNaClExecutable(instance, |
1450 url.c_str(), | 1445 url.c_str(), |
1451 &file_token_lo, | 1446 &file_token_lo, |
1452 &file_token_hi); | 1447 &file_token_hi); |
1453 if (file_handle != PP_kInvalidFileHandle) { | 1448 if (file_handle != PP_kInvalidFileHandle) { |
1454 PP_NaClFileInfo file_info; | 1449 PP_NaClFileInfo file_info; |
1455 file_info.handle = file_handle; | 1450 file_info.handle = file_handle; |
1456 file_info.token_lo = file_token_lo; | 1451 file_info.token_lo = file_token_lo; |
1457 file_info.token_hi = file_token_hi; | 1452 file_info.token_hi = file_token_hi; |
1458 base::MessageLoop::current()->PostTask( | 1453 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1459 FROM_HERE, | 1454 FROM_HERE, |
1460 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); | 1455 base::Bind(callback, static_cast<int32_t>(PP_OK), file_info)); |
1461 return; | 1456 return; |
1462 } | 1457 } |
1463 | 1458 |
1464 // The fast path didn't work, we'll fetch the file using URLLoader and write | 1459 // The fast path didn't work, we'll fetch the file using URLLoader and write |
1465 // it to local storage. | 1460 // it to local storage. |
1466 base::File target_file(CreateTemporaryFile(instance)); | 1461 base::File target_file(CreateTemporaryFile(instance)); |
1467 GURL gurl(url); | 1462 GURL gurl(url); |
1468 | 1463 |
1469 content::PepperPluginInstance* plugin_instance = | 1464 content::PepperPluginInstance* plugin_instance = |
1470 content::PepperPluginInstance::Get(instance); | 1465 content::PepperPluginInstance::Get(instance); |
1471 if (!plugin_instance) { | 1466 if (!plugin_instance) { |
1472 base::MessageLoop::current()->PostTask( | 1467 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1473 FROM_HERE, | 1468 FROM_HERE, base::Bind(callback, static_cast<int32_t>(PP_ERROR_FAILED), |
1474 base::Bind(callback, | 1469 kInvalidNaClFileInfo)); |
1475 static_cast<int32_t>(PP_ERROR_FAILED), | |
1476 kInvalidNaClFileInfo)); | |
1477 } | 1470 } |
1478 const blink::WebDocument& document = | 1471 const blink::WebDocument& document = |
1479 plugin_instance->GetContainer()->element().document(); | 1472 plugin_instance->GetContainer()->element().document(); |
1480 scoped_ptr<blink::WebURLLoader> url_loader( | 1473 scoped_ptr<blink::WebURLLoader> url_loader( |
1481 CreateWebURLLoader(document, gurl)); | 1474 CreateWebURLLoader(document, gurl)); |
1482 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); | 1475 blink::WebURLRequest url_request = CreateWebURLRequest(document, gurl); |
1483 | 1476 |
1484 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); | 1477 ProgressEventRateLimiter* tracker = new ProgressEventRateLimiter(instance); |
1485 | 1478 |
1486 // FileDownloader deletes itself after invoking DownloadNexeCompletion. | 1479 // FileDownloader deletes itself after invoking DownloadNexeCompletion. |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 | 1647 |
1655 void StreamPexe(PP_Instance instance, | 1648 void StreamPexe(PP_Instance instance, |
1656 const char* pexe_url, | 1649 const char* pexe_url, |
1657 int32_t opt_level, | 1650 int32_t opt_level, |
1658 PP_Bool use_subzero, | 1651 PP_Bool use_subzero, |
1659 const PPP_PexeStreamHandler* handler, | 1652 const PPP_PexeStreamHandler* handler, |
1660 void* handler_user_data) { | 1653 void* handler_user_data) { |
1661 content::PepperPluginInstance* plugin_instance = | 1654 content::PepperPluginInstance* plugin_instance = |
1662 content::PepperPluginInstance::Get(instance); | 1655 content::PepperPluginInstance::Get(instance); |
1663 if (!plugin_instance) { | 1656 if (!plugin_instance) { |
1664 base::MessageLoop::current()->PostTask( | 1657 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1665 FROM_HERE, | 1658 FROM_HERE, base::Bind(handler->DidFinishStream, handler_user_data, |
1666 base::Bind(handler->DidFinishStream, | 1659 static_cast<int32_t>(PP_ERROR_FAILED))); |
1667 handler_user_data, | |
1668 static_cast<int32_t>(PP_ERROR_FAILED))); | |
1669 return; | 1660 return; |
1670 } | 1661 } |
1671 | 1662 |
1672 GURL gurl(pexe_url); | 1663 GURL gurl(pexe_url); |
1673 const blink::WebDocument& document = | 1664 const blink::WebDocument& document = |
1674 plugin_instance->GetContainer()->element().document(); | 1665 plugin_instance->GetContainer()->element().document(); |
1675 scoped_ptr<blink::WebURLLoader> url_loader( | 1666 scoped_ptr<blink::WebURLLoader> url_loader( |
1676 CreateWebURLLoader(document, gurl)); | 1667 CreateWebURLLoader(document, gurl)); |
1677 PexeDownloader* downloader = | 1668 PexeDownloader* downloader = |
1678 new PexeDownloader(instance, url_loader.Pass(), pexe_url, opt_level, | 1669 new PexeDownloader(instance, url_loader.Pass(), pexe_url, opt_level, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 &StreamPexe | 1707 &StreamPexe |
1717 }; | 1708 }; |
1718 | 1709 |
1719 } // namespace | 1710 } // namespace |
1720 | 1711 |
1721 const PPB_NaCl_Private* GetNaClPrivateInterface() { | 1712 const PPB_NaCl_Private* GetNaClPrivateInterface() { |
1722 return &nacl_interface; | 1713 return &nacl_interface; |
1723 } | 1714 } |
1724 | 1715 |
1725 } // namespace nacl | 1716 } // namespace nacl |
OLD | NEW |