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 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "native_client/src/trusted/plugin/plugin.h" | 10 #include "native_client/src/trusted/plugin/plugin.h" |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
799 if (nexe_size_ > 0) { | 799 if (nexe_size_ > 0) { |
800 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f); | 800 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f); |
801 HistogramTimeMedium(name, static_cast<int64_t>(dt)); | 801 HistogramTimeMedium(name, static_cast<int64_t>(dt)); |
802 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB)); | 802 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB)); |
803 } | 803 } |
804 } | 804 } |
805 | 805 |
806 void Plugin::NexeFileDidOpen(int32_t pp_error) { | 806 void Plugin::NexeFileDidOpen(int32_t pp_error) { |
807 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%"NACL_PRId32")\n", | 807 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%"NACL_PRId32")\n", |
808 pp_error)); | 808 pp_error)); |
809 int32_t file_desc = nexe_downloader_.GetPOSIXFileDescriptor(); | 809 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); |
810 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%"NACL_PRId32")\n", | 810 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%"NACL_PRId32")\n", |
811 file_desc)); | 811 info.desc)); |
812 HistogramHTTPStatusCode( | 812 HistogramHTTPStatusCode( |
813 is_installed_ ? | 813 is_installed_ ? |
814 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : | 814 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : |
815 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", | 815 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", |
816 nexe_downloader_.status_code()); | 816 nexe_downloader_.status_code()); |
817 ErrorInfo error_info; | 817 ErrorInfo error_info; |
818 if (pp_error != PP_OK || file_desc == NACL_NO_FILE_DESC) { | 818 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { |
819 if (pp_error == PP_ERROR_ABORTED) { | 819 if (pp_error == PP_ERROR_ABORTED) { |
820 ReportLoadAbort(); | 820 ReportLoadAbort(); |
821 } else if (pp_error == PP_ERROR_NOACCESS) { | 821 } else if (pp_error == PP_ERROR_NOACCESS) { |
822 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, | 822 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, |
823 "access to nexe url was denied."); | 823 "access to nexe url was denied."); |
824 ReportLoadError(error_info); | 824 ReportLoadError(error_info); |
825 } else { | 825 } else { |
826 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); | 826 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); |
827 ReportLoadError(error_info); | 827 ReportLoadError(error_info); |
828 } | 828 } |
829 return; | 829 return; |
830 } | 830 } |
831 int32_t file_desc_ok_to_close = DUP(file_desc); | 831 int32_t file_desc_ok_to_close = DUP(info.desc); |
832 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { | 832 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { |
833 error_info.SetReport(ERROR_NEXE_FH_DUP, | 833 error_info.SetReport(ERROR_NEXE_FH_DUP, |
834 "could not duplicate loaded file handle."); | 834 "could not duplicate loaded file handle."); |
835 ReportLoadError(error_info); | 835 ReportLoadError(error_info); |
836 return; | 836 return; |
837 } | 837 } |
838 struct stat stat_buf; | 838 struct stat stat_buf; |
839 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { | 839 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { |
840 CLOSE(file_desc_ok_to_close); | 840 CLOSE(file_desc_ok_to_close); |
841 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); | 841 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 nexe_downloader_.TimeSinceOpenMilliseconds()); | 1080 nexe_downloader_.TimeSinceOpenMilliseconds()); |
1081 HistogramHTTPStatusCode( | 1081 HistogramHTTPStatusCode( |
1082 is_installed_ ? | 1082 is_installed_ ? |
1083 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : | 1083 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : |
1084 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", | 1084 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", |
1085 nexe_downloader_.status_code()); | 1085 nexe_downloader_.status_code()); |
1086 ErrorInfo error_info; | 1086 ErrorInfo error_info; |
1087 // The manifest file was successfully opened. Set the src property on the | 1087 // The manifest file was successfully opened. Set the src property on the |
1088 // plugin now, so that the full url is available to error handlers. | 1088 // plugin now, so that the full url is available to error handlers. |
1089 set_manifest_url(nexe_downloader_.url()); | 1089 set_manifest_url(nexe_downloader_.url()); |
1090 int32_t file_desc = nexe_downloader_.GetPOSIXFileDescriptor(); | 1090 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); |
1091 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" | 1091 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" |
1092 NACL_PRId32")\n", file_desc)); | 1092 NACL_PRId32")\n", info.desc)); |
1093 if (pp_error != PP_OK || file_desc == NACL_NO_FILE_DESC) { | 1093 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { |
1094 if (pp_error == PP_ERROR_ABORTED) { | 1094 if (pp_error == PP_ERROR_ABORTED) { |
1095 ReportLoadAbort(); | 1095 ReportLoadAbort(); |
1096 } else if (pp_error == PP_ERROR_NOACCESS) { | 1096 } else if (pp_error == PP_ERROR_NOACCESS) { |
1097 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, | 1097 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, |
1098 "access to manifest url was denied."); | 1098 "access to manifest url was denied."); |
1099 ReportLoadError(error_info); | 1099 ReportLoadError(error_info); |
1100 } else { | 1100 } else { |
1101 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, | 1101 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, |
1102 "could not load manifest url."); | 1102 "could not load manifest url."); |
1103 ReportLoadError(error_info); | 1103 ReportLoadError(error_info); |
1104 } | 1104 } |
1105 return; | 1105 return; |
1106 } | 1106 } |
1107 // Duplicate the file descriptor in order to create a FILE stream with it | 1107 // Duplicate the file descriptor in order to create a FILE stream with it |
1108 // that can later be closed without closing the original descriptor. The | 1108 // that can later be closed without closing the original descriptor. The |
1109 // browser will take care of the original descriptor. | 1109 // browser will take care of the original descriptor. |
1110 int dup_file_desc = DUP(file_desc); | 1110 int dup_file_desc = DUP(info.desc); |
1111 struct stat stat_buf; | 1111 struct stat stat_buf; |
1112 if (0 != fstat(dup_file_desc, &stat_buf)) { | 1112 if (0 != fstat(dup_file_desc, &stat_buf)) { |
1113 CLOSE(dup_file_desc); | 1113 CLOSE(dup_file_desc); |
1114 error_info.SetReport(ERROR_MANIFEST_STAT, | 1114 error_info.SetReport(ERROR_MANIFEST_STAT, |
1115 "could not stat manifest file."); | 1115 "could not stat manifest file."); |
1116 ReportLoadError(error_info); | 1116 ReportLoadError(error_info); |
1117 return; | 1117 return; |
1118 } | 1118 } |
1119 size_t bytes_to_read = static_cast<size_t>(stat_buf.st_size); | 1119 size_t bytes_to_read = static_cast<size_t>(stat_buf.st_size); |
1120 if (bytes_to_read > kNaClManifestMaxFileBytes) { | 1120 if (bytes_to_read > kNaClManifestMaxFileBytes) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1302 } | 1302 } |
1303 | 1303 |
1304 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, | 1304 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, |
1305 FileDownloader*& url_downloader, | 1305 FileDownloader*& url_downloader, |
1306 PP_CompletionCallback callback) { | 1306 PP_CompletionCallback callback) { |
1307 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%"NACL_PRId32 | 1307 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%"NACL_PRId32 |
1308 ", url_downloader=%p)\n", pp_error, | 1308 ", url_downloader=%p)\n", pp_error, |
1309 static_cast<void*>(url_downloader))); | 1309 static_cast<void*>(url_downloader))); |
1310 url_downloaders_.erase(url_downloader); | 1310 url_downloaders_.erase(url_downloader); |
1311 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); | 1311 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); |
1312 int32_t file_desc = scoped_url_downloader->GetPOSIXFileDescriptor(); | 1312 struct NaClFileInfo info = scoped_url_downloader->GetFileInfo(); |
1313 | 1313 |
1314 if (pp_error != PP_OK) { | 1314 if (pp_error != PP_OK) { |
1315 PP_RunCompletionCallback(&callback, pp_error); | 1315 PP_RunCompletionCallback(&callback, pp_error); |
1316 } else if (file_desc > NACL_NO_FILE_DESC) { | 1316 } else if (info.desc > NACL_NO_FILE_DESC) { |
1317 url_fd_map_[url_downloader->url_to_open()] = file_desc; | 1317 url_file_info_map_[url_downloader->url_to_open()] = info; |
1318 PP_RunCompletionCallback(&callback, PP_OK); | 1318 PP_RunCompletionCallback(&callback, PP_OK); |
1319 } else { | 1319 } else { |
1320 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); | 1320 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); |
1321 } | 1321 } |
1322 } | 1322 } |
1323 | 1323 |
1324 int32_t Plugin::GetPOSIXFileDesc(const nacl::string& url) { | 1324 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { |
1325 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); | 1325 struct NaClFileInfo info; |
1326 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; | 1326 memset(&info, 0, sizeof(info)); |
1327 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); | 1327 std::map<nacl::string, struct NaClFileInfo>::iterator it = |
Mark Seaborn
2013/05/24 20:21:58
As an aside, having this URL -> FD mapping seems t
Nick Bray (chromium)
2013/05/24 21:35:24
I will certainly help you file an issue. This cha
| |
1328 if (it != url_fd_map_.end()) | 1328 url_file_info_map_.find(url); |
1329 file_desc_ok_to_close = DUP(it->second); | 1329 if (it != url_file_info_map_.end()) { |
1330 return file_desc_ok_to_close; | 1330 info = it->second; |
1331 info.desc = DUP(info.desc); | |
1332 } else { | |
1333 info.desc = -1; | |
1334 } | |
1335 return info; | |
1331 } | 1336 } |
1332 | 1337 |
1333 | |
1334 bool Plugin::StreamAsFile(const nacl::string& url, | 1338 bool Plugin::StreamAsFile(const nacl::string& url, |
1335 PP_CompletionCallback callback) { | 1339 PP_CompletionCallback callback) { |
1336 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); | 1340 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); |
1337 FileDownloader* downloader = new FileDownloader(); | 1341 FileDownloader* downloader = new FileDownloader(); |
1338 downloader->Initialize(this); | 1342 downloader->Initialize(this); |
1339 url_downloaders_.insert(downloader); | 1343 url_downloaders_.insert(downloader); |
1340 // Untrusted loads are always relative to the page's origin. | 1344 // Untrusted loads are always relative to the page's origin. |
1341 CHECK(url_util_ != NULL); | 1345 CHECK(url_util_ != NULL); |
1342 pp::Var resolved_url = | 1346 pp::Var resolved_url = |
1343 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); | 1347 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1602 // Fast path only works for installed file URLs. | 1606 // Fast path only works for installed file URLs. |
1603 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) | 1607 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) |
1604 return false; | 1608 return false; |
1605 // IMPORTANT: Make sure the document can request the given URL. If we don't | 1609 // IMPORTANT: Make sure the document can request the given URL. If we don't |
1606 // check, a malicious app could probe the extension system. This enforces a | 1610 // check, a malicious app could probe the extension system. This enforces a |
1607 // same-origin policy which prevents the app from requesting resources from | 1611 // same-origin policy which prevents the app from requesting resources from |
1608 // another app. | 1612 // another app. |
1609 if (!DocumentCanRequest(url)) | 1613 if (!DocumentCanRequest(url)) |
1610 return false; | 1614 return false; |
1611 | 1615 |
1612 PP_NaClExecutableMetadata file_metadata; | 1616 uint64_t file_token_lo = 0; |
1617 uint64_t file_token_hi = 0; | |
1613 PP_FileHandle file_handle = | 1618 PP_FileHandle file_handle = |
1614 nacl_interface()->OpenNaClExecutable(pp_instance(), | 1619 nacl_interface()->OpenNaClExecutable(pp_instance(), |
1615 url.c_str(), | 1620 url.c_str(), |
1616 &file_metadata); | 1621 &file_token_lo, &file_token_hi); |
1617 // We shouldn't hit this if the file URL is in an installed app. | 1622 // We shouldn't hit this if the file URL is in an installed app. |
1618 if (file_handle == PP_kInvalidFileHandle) | 1623 if (file_handle == PP_kInvalidFileHandle) |
1619 return false; | 1624 return false; |
1620 | 1625 |
1621 // Release the PP_Var in the metadata struct. | |
1622 pp::Module* module = pp::Module::Get(); | |
1623 const PPB_Var* var_interface = | |
1624 static_cast<const PPB_Var*>( | |
1625 module->GetBrowserInterface(PPB_VAR_INTERFACE)); | |
1626 var_interface->Release(file_metadata.file_path); | |
1627 | |
1628 // FileDownloader takes ownership of the file handle. | 1626 // FileDownloader takes ownership of the file handle. |
1629 // TODO(bbudge) Consume metadata once we have the final format. | 1627 downloader->OpenFast(url, file_handle, file_token_lo, file_token_hi); |
1630 downloader->OpenFast(url, file_handle); | |
1631 return true; | 1628 return true; |
1632 } | 1629 } |
1633 | 1630 |
1634 UrlSchemeType Plugin::GetUrlScheme(const std::string& url) { | 1631 UrlSchemeType Plugin::GetUrlScheme(const std::string& url) { |
1635 CHECK(url_util_ != NULL); | 1632 CHECK(url_util_ != NULL); |
1636 PP_URLComponents_Dev comps; | 1633 PP_URLComponents_Dev comps; |
1637 pp::Var canonicalized = | 1634 pp::Var canonicalized = |
1638 url_util_->Canonicalize(pp::Var(url), &comps); | 1635 url_util_->Canonicalize(pp::Var(url), &comps); |
1639 | 1636 |
1640 if (canonicalized.is_null() || | 1637 if (canonicalized.is_null() || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1675 static_cast<uint32_t>(text.size())); | 1672 static_cast<uint32_t>(text.size())); |
1676 const PPB_Console* console_interface = | 1673 const PPB_Console* console_interface = |
1677 static_cast<const PPB_Console*>( | 1674 static_cast<const PPB_Console*>( |
1678 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1675 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
1679 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); | 1676 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); |
1680 var_interface->Release(prefix); | 1677 var_interface->Release(prefix); |
1681 var_interface->Release(str); | 1678 var_interface->Release(str); |
1682 } | 1679 } |
1683 | 1680 |
1684 } // namespace plugin | 1681 } // namespace plugin |
OLD | NEW |