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 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 if (nexe_size_ > 0) { | 795 if (nexe_size_ > 0) { |
796 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f); | 796 float size_in_MB = static_cast<float>(nexe_size_) / (1024.f * 1024.f); |
797 HistogramTimeMedium(name, static_cast<int64_t>(dt)); | 797 HistogramTimeMedium(name, static_cast<int64_t>(dt)); |
798 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB)); | 798 HistogramTimeMedium(name + "PerMB", static_cast<int64_t>(dt / size_in_MB)); |
799 } | 799 } |
800 } | 800 } |
801 | 801 |
802 void Plugin::NexeFileDidOpen(int32_t pp_error) { | 802 void Plugin::NexeFileDidOpen(int32_t pp_error) { |
803 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%"NACL_PRId32")\n", | 803 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (pp_error=%"NACL_PRId32")\n", |
804 pp_error)); | 804 pp_error)); |
805 int32_t file_desc = nexe_downloader_.GetPOSIXFileDescriptor(); | 805 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); |
806 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%"NACL_PRId32")\n", | 806 PLUGIN_PRINTF(("Plugin::NexeFileDidOpen (file_desc=%"NACL_PRId32")\n", |
807 file_desc)); | 807 info.desc)); |
808 HistogramHTTPStatusCode( | 808 HistogramHTTPStatusCode( |
809 is_installed_ ? | 809 is_installed_ ? |
810 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : | 810 "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" : |
811 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", | 811 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp", |
812 nexe_downloader_.status_code()); | 812 nexe_downloader_.status_code()); |
813 ErrorInfo error_info; | 813 ErrorInfo error_info; |
814 if (pp_error != PP_OK || file_desc == NACL_NO_FILE_DESC) { | 814 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { |
815 if (pp_error == PP_ERROR_ABORTED) { | 815 if (pp_error == PP_ERROR_ABORTED) { |
816 ReportLoadAbort(); | 816 ReportLoadAbort(); |
817 } else if (pp_error == PP_ERROR_NOACCESS) { | 817 } else if (pp_error == PP_ERROR_NOACCESS) { |
818 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, | 818 error_info.SetReport(ERROR_NEXE_NOACCESS_URL, |
819 "access to nexe url was denied."); | 819 "access to nexe url was denied."); |
820 ReportLoadError(error_info); | 820 ReportLoadError(error_info); |
821 } else { | 821 } else { |
822 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); | 822 error_info.SetReport(ERROR_NEXE_LOAD_URL, "could not load nexe url."); |
823 ReportLoadError(error_info); | 823 ReportLoadError(error_info); |
824 } | 824 } |
825 return; | 825 return; |
826 } | 826 } |
827 int32_t file_desc_ok_to_close = DUP(file_desc); | 827 int32_t file_desc_ok_to_close = DUP(info.desc); |
828 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { | 828 if (file_desc_ok_to_close == NACL_NO_FILE_DESC) { |
829 error_info.SetReport(ERROR_NEXE_FH_DUP, | 829 error_info.SetReport(ERROR_NEXE_FH_DUP, |
830 "could not duplicate loaded file handle."); | 830 "could not duplicate loaded file handle."); |
831 ReportLoadError(error_info); | 831 ReportLoadError(error_info); |
832 return; | 832 return; |
833 } | 833 } |
834 struct stat stat_buf; | 834 struct stat stat_buf; |
835 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { | 835 if (0 != fstat(file_desc_ok_to_close, &stat_buf)) { |
836 CLOSE(file_desc_ok_to_close); | 836 CLOSE(file_desc_ok_to_close); |
837 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); | 837 error_info.SetReport(ERROR_NEXE_STAT, "could not stat nexe file."); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 nexe_downloader_.TimeSinceOpenMilliseconds()); | 1076 nexe_downloader_.TimeSinceOpenMilliseconds()); |
1077 HistogramHTTPStatusCode( | 1077 HistogramHTTPStatusCode( |
1078 is_installed_ ? | 1078 is_installed_ ? |
1079 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : | 1079 "NaCl.HttpStatusCodeClass.Manifest.InstalledApp" : |
1080 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", | 1080 "NaCl.HttpStatusCodeClass.Manifest.NotInstalledApp", |
1081 nexe_downloader_.status_code()); | 1081 nexe_downloader_.status_code()); |
1082 ErrorInfo error_info; | 1082 ErrorInfo error_info; |
1083 // The manifest file was successfully opened. Set the src property on the | 1083 // The manifest file was successfully opened. Set the src property on the |
1084 // plugin now, so that the full url is available to error handlers. | 1084 // plugin now, so that the full url is available to error handlers. |
1085 set_manifest_url(nexe_downloader_.url()); | 1085 set_manifest_url(nexe_downloader_.url()); |
1086 int32_t file_desc = nexe_downloader_.GetPOSIXFileDescriptor(); | 1086 struct NaClFileInfo info = nexe_downloader_.GetFileInfo(); |
1087 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" | 1087 PLUGIN_PRINTF(("Plugin::NaClManifestFileDidOpen (file_desc=%" |
1088 NACL_PRId32")\n", file_desc)); | 1088 NACL_PRId32")\n", info.desc)); |
1089 if (pp_error != PP_OK || file_desc == NACL_NO_FILE_DESC) { | 1089 if (pp_error != PP_OK || info.desc == NACL_NO_FILE_DESC) { |
1090 if (pp_error == PP_ERROR_ABORTED) { | 1090 if (pp_error == PP_ERROR_ABORTED) { |
1091 ReportLoadAbort(); | 1091 ReportLoadAbort(); |
1092 } else if (pp_error == PP_ERROR_NOACCESS) { | 1092 } else if (pp_error == PP_ERROR_NOACCESS) { |
1093 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, | 1093 error_info.SetReport(ERROR_MANIFEST_NOACCESS_URL, |
1094 "access to manifest url was denied."); | 1094 "access to manifest url was denied."); |
1095 ReportLoadError(error_info); | 1095 ReportLoadError(error_info); |
1096 } else { | 1096 } else { |
1097 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, | 1097 error_info.SetReport(ERROR_MANIFEST_LOAD_URL, |
1098 "could not load manifest url."); | 1098 "could not load manifest url."); |
1099 ReportLoadError(error_info); | 1099 ReportLoadError(error_info); |
1100 } | 1100 } |
1101 return; | 1101 return; |
1102 } | 1102 } |
1103 // SlurpFile closes the file descriptor after reading (or on error). | 1103 // SlurpFile closes the file descriptor after reading (or on error). |
1104 // Duplicate our file descriptor since it will be handled by the browser. | 1104 // Duplicate our file descriptor since it will be handled by the browser. |
1105 int dup_file_desc = DUP(file_desc); | 1105 int dup_file_desc = DUP(info.desc); |
1106 nacl::string json_buffer; | 1106 nacl::string json_buffer; |
1107 file_utils::StatusCode status = file_utils::SlurpFile( | 1107 file_utils::StatusCode status = file_utils::SlurpFile( |
1108 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes); | 1108 dup_file_desc, json_buffer, kNaClManifestMaxFileBytes); |
1109 | 1109 |
1110 if (status != file_utils::PLUGIN_FILE_SUCCESS) { | 1110 if (status != file_utils::PLUGIN_FILE_SUCCESS) { |
1111 switch (status) { | 1111 switch (status) { |
1112 case file_utils::PLUGIN_FILE_SUCCESS: | 1112 case file_utils::PLUGIN_FILE_SUCCESS: |
1113 CHECK(0); | 1113 CHECK(0); |
1114 break; | 1114 break; |
1115 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC: | 1115 case file_utils::PLUGIN_FILE_ERROR_MEM_ALLOC: |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 } | 1267 } |
1268 | 1268 |
1269 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, | 1269 void Plugin::UrlDidOpenForStreamAsFile(int32_t pp_error, |
1270 FileDownloader*& url_downloader, | 1270 FileDownloader*& url_downloader, |
1271 PP_CompletionCallback callback) { | 1271 PP_CompletionCallback callback) { |
1272 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%"NACL_PRId32 | 1272 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%"NACL_PRId32 |
1273 ", url_downloader=%p)\n", pp_error, | 1273 ", url_downloader=%p)\n", pp_error, |
1274 static_cast<void*>(url_downloader))); | 1274 static_cast<void*>(url_downloader))); |
1275 url_downloaders_.erase(url_downloader); | 1275 url_downloaders_.erase(url_downloader); |
1276 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); | 1276 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); |
1277 int32_t file_desc = scoped_url_downloader->GetPOSIXFileDescriptor(); | 1277 struct NaClFileInfo info = scoped_url_downloader->GetFileInfo(); |
1278 | 1278 |
1279 if (pp_error != PP_OK) { | 1279 if (pp_error != PP_OK) { |
1280 PP_RunCompletionCallback(&callback, pp_error); | 1280 PP_RunCompletionCallback(&callback, pp_error); |
1281 } else if (file_desc > NACL_NO_FILE_DESC) { | 1281 } else if (info.desc > NACL_NO_FILE_DESC) { |
1282 url_fd_map_[url_downloader->url_to_open()] = file_desc; | 1282 url_file_info_map_[url_downloader->url_to_open()] = info; |
1283 PP_RunCompletionCallback(&callback, PP_OK); | 1283 PP_RunCompletionCallback(&callback, PP_OK); |
1284 } else { | 1284 } else { |
1285 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); | 1285 PP_RunCompletionCallback(&callback, PP_ERROR_FAILED); |
1286 } | 1286 } |
1287 } | 1287 } |
1288 | 1288 |
1289 int32_t Plugin::GetPOSIXFileDesc(const nacl::string& url) { | 1289 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { |
1290 PLUGIN_PRINTF(("Plugin::GetFileDesc (url=%s)\n", url.c_str())); | 1290 struct NaClFileInfo info; |
1291 int32_t file_desc_ok_to_close = NACL_NO_FILE_DESC; | 1291 memset(&info, 0, sizeof(info)); |
1292 std::map<nacl::string, int32_t>::iterator it = url_fd_map_.find(url); | 1292 std::map<nacl::string, struct NaClFileInfo>::iterator it = |
1293 if (it != url_fd_map_.end()) | 1293 url_file_info_map_.find(url); |
1294 file_desc_ok_to_close = DUP(it->second); | 1294 if (it != url_file_info_map_.end()) { |
1295 return file_desc_ok_to_close; | 1295 info = it->second; |
| 1296 info.desc = DUP(info.desc); |
| 1297 } else { |
| 1298 info.desc = -1; |
| 1299 } |
| 1300 return info; |
1296 } | 1301 } |
1297 | 1302 |
1298 | |
1299 bool Plugin::StreamAsFile(const nacl::string& url, | 1303 bool Plugin::StreamAsFile(const nacl::string& url, |
1300 PP_CompletionCallback callback) { | 1304 PP_CompletionCallback callback) { |
1301 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); | 1305 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); |
1302 FileDownloader* downloader = new FileDownloader(); | 1306 FileDownloader* downloader = new FileDownloader(); |
1303 downloader->Initialize(this); | 1307 downloader->Initialize(this); |
1304 url_downloaders_.insert(downloader); | 1308 url_downloaders_.insert(downloader); |
1305 // Untrusted loads are always relative to the page's origin. | 1309 // Untrusted loads are always relative to the page's origin. |
1306 CHECK(url_util_ != NULL); | 1310 CHECK(url_util_ != NULL); |
1307 pp::Var resolved_url = | 1311 pp::Var resolved_url = |
1308 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); | 1312 url_util_->ResolveRelativeToURL(pp::Var(plugin_base_url()), url); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 // Fast path only works for installed file URLs. | 1571 // Fast path only works for installed file URLs. |
1568 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) | 1572 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) |
1569 return false; | 1573 return false; |
1570 // IMPORTANT: Make sure the document can request the given URL. If we don't | 1574 // IMPORTANT: Make sure the document can request the given URL. If we don't |
1571 // check, a malicious app could probe the extension system. This enforces a | 1575 // check, a malicious app could probe the extension system. This enforces a |
1572 // same-origin policy which prevents the app from requesting resources from | 1576 // same-origin policy which prevents the app from requesting resources from |
1573 // another app. | 1577 // another app. |
1574 if (!DocumentCanRequest(url)) | 1578 if (!DocumentCanRequest(url)) |
1575 return false; | 1579 return false; |
1576 | 1580 |
1577 PP_NaClExecutableMetadata file_metadata; | 1581 uint64_t file_token_lo = 0; |
| 1582 uint64_t file_token_hi = 0; |
1578 PP_FileHandle file_handle = | 1583 PP_FileHandle file_handle = |
1579 nacl_interface()->OpenNaClExecutable(pp_instance(), | 1584 nacl_interface()->OpenNaClExecutable(pp_instance(), |
1580 url.c_str(), | 1585 url.c_str(), |
1581 &file_metadata); | 1586 &file_token_lo, &file_token_hi); |
1582 // We shouldn't hit this if the file URL is in an installed app. | 1587 // We shouldn't hit this if the file URL is in an installed app. |
1583 if (file_handle == PP_kInvalidFileHandle) | 1588 if (file_handle == PP_kInvalidFileHandle) |
1584 return false; | 1589 return false; |
1585 | 1590 |
1586 // Release the PP_Var in the metadata struct. | |
1587 pp::Module* module = pp::Module::Get(); | |
1588 const PPB_Var* var_interface = | |
1589 static_cast<const PPB_Var*>( | |
1590 module->GetBrowserInterface(PPB_VAR_INTERFACE)); | |
1591 var_interface->Release(file_metadata.file_path); | |
1592 | |
1593 // FileDownloader takes ownership of the file handle. | 1591 // FileDownloader takes ownership of the file handle. |
1594 // TODO(bbudge) Consume metadata once we have the final format. | 1592 downloader->OpenFast(url, file_handle, file_token_lo, file_token_hi); |
1595 downloader->OpenFast(url, file_handle); | |
1596 return true; | 1593 return true; |
1597 } | 1594 } |
1598 | 1595 |
1599 UrlSchemeType Plugin::GetUrlScheme(const std::string& url) { | 1596 UrlSchemeType Plugin::GetUrlScheme(const std::string& url) { |
1600 CHECK(url_util_ != NULL); | 1597 CHECK(url_util_ != NULL); |
1601 PP_URLComponents_Dev comps; | 1598 PP_URLComponents_Dev comps; |
1602 pp::Var canonicalized = | 1599 pp::Var canonicalized = |
1603 url_util_->Canonicalize(pp::Var(url), &comps); | 1600 url_util_->Canonicalize(pp::Var(url), &comps); |
1604 | 1601 |
1605 if (canonicalized.is_null() || | 1602 if (canonicalized.is_null() || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 static_cast<uint32_t>(text.size())); | 1637 static_cast<uint32_t>(text.size())); |
1641 const PPB_Console* console_interface = | 1638 const PPB_Console* console_interface = |
1642 static_cast<const PPB_Console*>( | 1639 static_cast<const PPB_Console*>( |
1643 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1640 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
1644 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); | 1641 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); |
1645 var_interface->Release(prefix); | 1642 var_interface->Release(prefix); |
1646 var_interface->Release(str); | 1643 var_interface->Release(str); |
1647 } | 1644 } |
1648 | 1645 |
1649 } // namespace plugin | 1646 } // namespace plugin |
OLD | NEW |