| 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 "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 char* Plugin::LookupArgument(const char* key) { | 552 char* Plugin::LookupArgument(const char* key) { |
| 553 char** keys = argn_; | 553 char** keys = argn_; |
| 554 for (int ii = 0, len = argc_; ii < len; ++ii) { | 554 for (int ii = 0, len = argc_; ii < len; ++ii) { |
| 555 if (!strcmp(keys[ii], key)) { | 555 if (!strcmp(keys[ii], key)) { |
| 556 return argv_[ii]; | 556 return argv_[ii]; |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 return NULL; | 559 return NULL; |
| 560 } | 560 } |
| 561 | 561 |
| 562 // Suggested names for progress event types, per | |
| 563 // http://www.w3.org/TR/progress-events/ | |
| 564 const char* const Plugin::kProgressEventLoadStart = "loadstart"; | |
| 565 const char* const Plugin::kProgressEventProgress = "progress"; | |
| 566 const char* const Plugin::kProgressEventError = "error"; | |
| 567 const char* const Plugin::kProgressEventAbort = "abort"; | |
| 568 const char* const Plugin::kProgressEventLoad = "load"; | |
| 569 const char* const Plugin::kProgressEventLoadEnd = "loadend"; | |
| 570 // Define a NaCl specific event type for .nexe crashes. | |
| 571 const char* const Plugin::kProgressEventCrash = "crash"; | |
| 572 | |
| 573 class ProgressEvent { | 562 class ProgressEvent { |
| 574 public: | 563 public: |
| 575 ProgressEvent(const char* event_type, | 564 ProgressEvent(PP_NaClEventType event_type, |
| 576 const nacl::string& url, | 565 const nacl::string& url, |
| 577 Plugin::LengthComputable length_computable, | 566 Plugin::LengthComputable length_computable, |
| 578 uint64_t loaded_bytes, | 567 uint64_t loaded_bytes, |
| 579 uint64_t total_bytes) : | 568 uint64_t total_bytes) : |
| 580 event_type_(event_type), | 569 event_type_(event_type), |
| 581 url_(url), | 570 url_(url), |
| 582 length_computable_(length_computable), | 571 length_computable_(length_computable), |
| 583 loaded_bytes_(loaded_bytes), | 572 loaded_bytes_(loaded_bytes), |
| 584 total_bytes_(total_bytes) { } | 573 total_bytes_(total_bytes) { } |
| 585 const char* event_type() const { return event_type_; } | 574 PP_NaClEventType event_type() const { return event_type_; } |
| 586 const char* url() const { return url_.c_str(); } | 575 const char* url() const { return url_.c_str(); } |
| 587 Plugin::LengthComputable length_computable() const { | 576 Plugin::LengthComputable length_computable() const { |
| 588 return length_computable_; | 577 return length_computable_; |
| 589 } | 578 } |
| 590 uint64_t loaded_bytes() const { return loaded_bytes_; } | 579 uint64_t loaded_bytes() const { return loaded_bytes_; } |
| 591 uint64_t total_bytes() const { return total_bytes_; } | 580 uint64_t total_bytes() const { return total_bytes_; } |
| 592 | 581 |
| 593 private: | 582 private: |
| 594 // event_type_ is always passed from a string literal, so ownership is | 583 PP_NaClEventType event_type_; |
| 595 // not taken. Hence it does not need to be deleted when ProgressEvent is | |
| 596 // destroyed. | |
| 597 const char* event_type_; | |
| 598 nacl::string url_; | 584 nacl::string url_; |
| 599 Plugin::LengthComputable length_computable_; | 585 Plugin::LengthComputable length_computable_; |
| 600 uint64_t loaded_bytes_; | 586 uint64_t loaded_bytes_; |
| 601 uint64_t total_bytes_; | 587 uint64_t total_bytes_; |
| 602 }; | 588 }; |
| 603 | 589 |
| 604 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; | 590 const char* const Plugin::kNaClMIMEType = "application/x-nacl"; |
| 605 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl"; | 591 const char* const Plugin::kPnaclMIMEType = "application/x-pnacl"; |
| 606 | 592 |
| 607 bool Plugin::NexeIsContentHandler() const { | 593 bool Plugin::NexeIsContentHandler() const { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 size_t nexe_bytes_read = static_cast<size_t>(stat_buf.st_size); | 848 size_t nexe_bytes_read = static_cast<size_t>(stat_buf.st_size); |
| 863 | 849 |
| 864 nexe_size_ = nexe_bytes_read; | 850 nexe_size_ = nexe_bytes_read; |
| 865 HistogramSizeKB("NaCl.Perf.Size.Nexe", | 851 HistogramSizeKB("NaCl.Perf.Size.Nexe", |
| 866 static_cast<int32_t>(nexe_size_ / 1024)); | 852 static_cast<int32_t>(nexe_size_ / 1024)); |
| 867 HistogramStartupTimeMedium( | 853 HistogramStartupTimeMedium( |
| 868 "NaCl.Perf.StartupTime.NexeDownload", | 854 "NaCl.Perf.StartupTime.NexeDownload", |
| 869 static_cast<float>(nexe_downloader_.TimeSinceOpenMilliseconds())); | 855 static_cast<float>(nexe_downloader_.TimeSinceOpenMilliseconds())); |
| 870 | 856 |
| 871 // Inform JavaScript that we successfully downloaded the nacl module. | 857 // Inform JavaScript that we successfully downloaded the nacl module. |
| 872 EnqueueProgressEvent(kProgressEventProgress, | 858 EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS, |
| 873 nexe_downloader_.url_to_open(), | 859 nexe_downloader_.url_to_open(), |
| 874 LENGTH_IS_COMPUTABLE, | 860 LENGTH_IS_COMPUTABLE, |
| 875 nexe_bytes_read, | 861 nexe_bytes_read, |
| 876 nexe_bytes_read); | 862 nexe_bytes_read); |
| 877 | 863 |
| 878 load_start_ = NaClGetTimeOfDayMicroseconds(); | 864 load_start_ = NaClGetTimeOfDayMicroseconds(); |
| 879 nacl::scoped_ptr<nacl::DescWrapper> | 865 nacl::scoped_ptr<nacl::DescWrapper> |
| 880 wrapper(wrapper_factory()->MakeFileDesc(file_desc_ok_to_close, O_RDONLY)); | 866 wrapper(wrapper_factory()->MakeFileDesc(file_desc_ok_to_close, O_RDONLY)); |
| 881 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); | 867 NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); |
| 882 bool was_successful = LoadNaClModule( | 868 bool was_successful = LoadNaClModule( |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 // Crashes will be more likely near startup, so use a medium histogram | 1025 // Crashes will be more likely near startup, so use a medium histogram |
| 1040 // instead of a large one. | 1026 // instead of a large one. |
| 1041 HistogramTimeMedium( | 1027 HistogramTimeMedium( |
| 1042 "NaCl.ModuleUptime.Crash", | 1028 "NaCl.ModuleUptime.Crash", |
| 1043 (crash_time - ready_time_) / NACL_MICROS_PER_MILLI); | 1029 (crash_time - ready_time_) / NACL_MICROS_PER_MILLI); |
| 1044 | 1030 |
| 1045 nacl::string message = nacl::string("NaCl module crashed"); | 1031 nacl::string message = nacl::string("NaCl module crashed"); |
| 1046 set_last_error_string(message); | 1032 set_last_error_string(message); |
| 1047 AddToConsole(message); | 1033 AddToConsole(message); |
| 1048 | 1034 |
| 1049 EnqueueProgressEvent(kProgressEventCrash); | 1035 EnqueueProgressEvent(PP_NACL_EVENT_CRASH); |
| 1050 set_nexe_error_reported(true); | 1036 set_nexe_error_reported(true); |
| 1051 } | 1037 } |
| 1052 // else ReportLoadError() and ReportAbortError() will be used by loading code | 1038 // else ReportLoadError() and ReportAbortError() will be used by loading code |
| 1053 // to provide error handling. | 1039 // to provide error handling. |
| 1054 // | 1040 // |
| 1055 // NOTE: not all crashes during load will make it here. | 1041 // NOTE: not all crashes during load will make it here. |
| 1056 // Those in BrowserPpp::InitializeModule and creation of PPP interfaces | 1042 // Those in BrowserPpp::InitializeModule and creation of PPP interfaces |
| 1057 // will just get reported back as PP_ERROR_FAILED. | 1043 // will just get reported back as PP_ERROR_FAILED. |
| 1058 } | 1044 } |
| 1059 | 1045 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 ErrorInfo error_info; | 1159 ErrorInfo error_info; |
| 1174 if (!SetManifestObject(manifest_json, &error_info)) { | 1160 if (!SetManifestObject(manifest_json, &error_info)) { |
| 1175 ReportLoadError(error_info); | 1161 ReportLoadError(error_info); |
| 1176 return; | 1162 return; |
| 1177 } | 1163 } |
| 1178 | 1164 |
| 1179 if (manifest_->GetProgramURL(&program_url, &pnacl_options, &error_info)) { | 1165 if (manifest_->GetProgramURL(&program_url, &pnacl_options, &error_info)) { |
| 1180 is_installed_ = GetUrlScheme(program_url) == SCHEME_CHROME_EXTENSION; | 1166 is_installed_ = GetUrlScheme(program_url) == SCHEME_CHROME_EXTENSION; |
| 1181 nacl_ready_state_ = LOADING; | 1167 nacl_ready_state_ = LOADING; |
| 1182 // Inform JavaScript that we found a nexe URL to load. | 1168 // Inform JavaScript that we found a nexe URL to load. |
| 1183 EnqueueProgressEvent(kProgressEventProgress); | 1169 EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS); |
| 1184 if (pnacl_options.translate()) { | 1170 if (pnacl_options.translate()) { |
| 1185 pp::CompletionCallback translate_callback = | 1171 pp::CompletionCallback translate_callback = |
| 1186 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); | 1172 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); |
| 1187 // Will always call the callback on success or failure. | 1173 // Will always call the callback on success or failure. |
| 1188 pnacl_coordinator_.reset( | 1174 pnacl_coordinator_.reset( |
| 1189 PnaclCoordinator::BitcodeToNative(this, | 1175 PnaclCoordinator::BitcodeToNative(this, |
| 1190 program_url, | 1176 program_url, |
| 1191 pnacl_options, | 1177 pnacl_options, |
| 1192 translate_callback)); | 1178 translate_callback)); |
| 1193 return; | 1179 return; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 return; | 1217 return; |
| 1232 } | 1218 } |
| 1233 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (resolved url='%s')\n", | 1219 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (resolved url='%s')\n", |
| 1234 nmf_resolved_url.AsString().c_str())); | 1220 nmf_resolved_url.AsString().c_str())); |
| 1235 is_installed_ = GetUrlScheme(nmf_resolved_url.AsString()) == | 1221 is_installed_ = GetUrlScheme(nmf_resolved_url.AsString()) == |
| 1236 SCHEME_CHROME_EXTENSION; | 1222 SCHEME_CHROME_EXTENSION; |
| 1237 set_manifest_base_url(nmf_resolved_url.AsString()); | 1223 set_manifest_base_url(nmf_resolved_url.AsString()); |
| 1238 set_manifest_url(url); | 1224 set_manifest_url(url); |
| 1239 // Inform JavaScript that a load is starting. | 1225 // Inform JavaScript that a load is starting. |
| 1240 nacl_ready_state_ = OPENED; | 1226 nacl_ready_state_ = OPENED; |
| 1241 EnqueueProgressEvent(kProgressEventLoadStart); | 1227 EnqueueProgressEvent(PP_NACL_EVENT_LOADSTART); |
| 1242 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; | 1228 bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA; |
| 1243 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); | 1229 HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri)); |
| 1244 if (is_data_uri) { | 1230 if (is_data_uri) { |
| 1245 pp::CompletionCallback open_callback = | 1231 pp::CompletionCallback open_callback = |
| 1246 callback_factory_.NewCallback(&Plugin::NaClManifestBufferReady); | 1232 callback_factory_.NewCallback(&Plugin::NaClManifestBufferReady); |
| 1247 // Will always call the callback on success or failure. | 1233 // Will always call the callback on success or failure. |
| 1248 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), | 1234 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), |
| 1249 DOWNLOAD_TO_BUFFER, | 1235 DOWNLOAD_TO_BUFFER, |
| 1250 open_callback, | 1236 open_callback, |
| 1251 false, | 1237 false, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 | 1339 |
| 1354 | 1340 |
| 1355 void Plugin::ReportLoadSuccess(LengthComputable length_computable, | 1341 void Plugin::ReportLoadSuccess(LengthComputable length_computable, |
| 1356 uint64_t loaded_bytes, | 1342 uint64_t loaded_bytes, |
| 1357 uint64_t total_bytes) { | 1343 uint64_t total_bytes) { |
| 1358 // Set the readyState attribute to indicate loaded. | 1344 // Set the readyState attribute to indicate loaded. |
| 1359 nacl_ready_state_ = DONE; | 1345 nacl_ready_state_ = DONE; |
| 1360 // Inform JavaScript that loading was successful and is complete. | 1346 // Inform JavaScript that loading was successful and is complete. |
| 1361 const nacl::string& url = nexe_downloader_.url_to_open(); | 1347 const nacl::string& url = nexe_downloader_.url_to_open(); |
| 1362 EnqueueProgressEvent( | 1348 EnqueueProgressEvent( |
| 1363 kProgressEventLoad, url, length_computable, loaded_bytes, total_bytes); | 1349 PP_NACL_EVENT_LOAD, url, length_computable, loaded_bytes, total_bytes); |
| 1364 EnqueueProgressEvent( | 1350 EnqueueProgressEvent( |
| 1365 kProgressEventLoadEnd, url, length_computable, loaded_bytes, total_bytes); | 1351 PP_NACL_EVENT_LOADEND, url, length_computable, loaded_bytes, total_bytes); |
| 1366 | 1352 |
| 1367 // UMA | 1353 // UMA |
| 1368 HistogramEnumerateLoadStatus(ERROR_LOAD_SUCCESS, is_installed_); | 1354 HistogramEnumerateLoadStatus(ERROR_LOAD_SUCCESS, is_installed_); |
| 1369 } | 1355 } |
| 1370 | 1356 |
| 1371 | 1357 |
| 1372 // TODO(ncbray): report UMA stats | 1358 // TODO(ncbray): report UMA stats |
| 1373 void Plugin::ReportLoadError(const ErrorInfo& error_info) { | 1359 void Plugin::ReportLoadError(const ErrorInfo& error_info) { |
| 1374 PLUGIN_PRINTF(("Plugin::ReportLoadError (error='%s')\n", | 1360 PLUGIN_PRINTF(("Plugin::ReportLoadError (error='%s')\n", |
| 1375 error_info.message().c_str())); | 1361 error_info.message().c_str())); |
| 1376 // For errors the user (and not just the developer) should know about, | 1362 // For errors the user (and not just the developer) should know about, |
| 1377 // report them to the renderer so the browser can display a message. | 1363 // report them to the renderer so the browser can display a message. |
| 1378 if (error_info.error_code() == ERROR_MANIFEST_PROGRAM_MISSING_ARCH) { | 1364 if (error_info.error_code() == ERROR_MANIFEST_PROGRAM_MISSING_ARCH) { |
| 1379 // A special case: the manifest may otherwise be valid but is missing | 1365 // A special case: the manifest may otherwise be valid but is missing |
| 1380 // a program/file compatible with the user's sandbox. | 1366 // a program/file compatible with the user's sandbox. |
| 1381 nacl_interface()->ReportNaClError(pp_instance(), | 1367 nacl_interface()->ReportNaClError(pp_instance(), |
| 1382 PP_NACL_MANIFEST_MISSING_ARCH); | 1368 PP_NACL_MANIFEST_MISSING_ARCH); |
| 1383 } | 1369 } |
| 1384 | 1370 |
| 1385 // Set the readyState attribute to indicate we need to start over. | 1371 // Set the readyState attribute to indicate we need to start over. |
| 1386 nacl_ready_state_ = DONE; | 1372 nacl_ready_state_ = DONE; |
| 1387 set_nexe_error_reported(true); | 1373 set_nexe_error_reported(true); |
| 1388 // Report an error in lastError and on the JavaScript console. | 1374 // Report an error in lastError and on the JavaScript console. |
| 1389 nacl::string message = nacl::string("NaCl module load failed: ") + | 1375 nacl::string message = nacl::string("NaCl module load failed: ") + |
| 1390 error_info.message(); | 1376 error_info.message(); |
| 1391 set_last_error_string(message); | 1377 set_last_error_string(message); |
| 1392 AddToConsole(nacl::string("NaCl module load failed: ") + | 1378 AddToConsole(nacl::string("NaCl module load failed: ") + |
| 1393 error_info.console_message()); | 1379 error_info.console_message()); |
| 1394 // Inform JavaScript that loading encountered an error and is complete. | 1380 // Inform JavaScript that loading encountered an error and is complete. |
| 1395 EnqueueProgressEvent(kProgressEventError); | 1381 EnqueueProgressEvent(PP_NACL_EVENT_ERROR); |
| 1396 EnqueueProgressEvent(kProgressEventLoadEnd); | 1382 EnqueueProgressEvent(PP_NACL_EVENT_LOADEND); |
| 1397 | 1383 |
| 1398 // UMA | 1384 // UMA |
| 1399 HistogramEnumerateLoadStatus(error_info.error_code(), is_installed_); | 1385 HistogramEnumerateLoadStatus(error_info.error_code(), is_installed_); |
| 1400 } | 1386 } |
| 1401 | 1387 |
| 1402 | 1388 |
| 1403 void Plugin::ReportLoadAbort() { | 1389 void Plugin::ReportLoadAbort() { |
| 1404 PLUGIN_PRINTF(("Plugin::ReportLoadAbort\n")); | 1390 PLUGIN_PRINTF(("Plugin::ReportLoadAbort\n")); |
| 1405 // Set the readyState attribute to indicate we need to start over. | 1391 // Set the readyState attribute to indicate we need to start over. |
| 1406 nacl_ready_state_ = DONE; | 1392 nacl_ready_state_ = DONE; |
| 1407 set_nexe_error_reported(true); | 1393 set_nexe_error_reported(true); |
| 1408 // Report an error in lastError and on the JavaScript console. | 1394 // Report an error in lastError and on the JavaScript console. |
| 1409 nacl::string error_string("NaCl module load failed: user aborted"); | 1395 nacl::string error_string("NaCl module load failed: user aborted"); |
| 1410 set_last_error_string(error_string); | 1396 set_last_error_string(error_string); |
| 1411 AddToConsole(error_string); | 1397 AddToConsole(error_string); |
| 1412 // Inform JavaScript that loading was aborted and is complete. | 1398 // Inform JavaScript that loading was aborted and is complete. |
| 1413 EnqueueProgressEvent(kProgressEventAbort); | 1399 EnqueueProgressEvent(PP_NACL_EVENT_ABORT); |
| 1414 EnqueueProgressEvent(kProgressEventLoadEnd); | 1400 EnqueueProgressEvent(PP_NACL_EVENT_LOADEND); |
| 1415 | 1401 |
| 1416 // UMA | 1402 // UMA |
| 1417 HistogramEnumerateLoadStatus(ERROR_LOAD_ABORTED, is_installed_); | 1403 HistogramEnumerateLoadStatus(ERROR_LOAD_ABORTED, is_installed_); |
| 1418 } | 1404 } |
| 1419 | 1405 |
| 1420 void Plugin::UpdateDownloadProgress( | 1406 void Plugin::UpdateDownloadProgress( |
| 1421 PP_Instance pp_instance, | 1407 PP_Instance pp_instance, |
| 1422 PP_Resource pp_resource, | 1408 PP_Resource pp_resource, |
| 1423 int64_t /*bytes_sent*/, | 1409 int64_t /*bytes_sent*/, |
| 1424 int64_t /*total_bytes_to_be_sent*/, | 1410 int64_t /*total_bytes_to_be_sent*/, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1437 // Find the URL loader that sent this notification. | 1423 // Find the URL loader that sent this notification. |
| 1438 const FileDownloader* file_downloader = | 1424 const FileDownloader* file_downloader = |
| 1439 plugin->FindFileDownloader(pp_resource); | 1425 plugin->FindFileDownloader(pp_resource); |
| 1440 // If not a streamed file, it must be the .nexe loader. | 1426 // If not a streamed file, it must be the .nexe loader. |
| 1441 if (file_downloader == NULL) | 1427 if (file_downloader == NULL) |
| 1442 file_downloader = &plugin->nexe_downloader_; | 1428 file_downloader = &plugin->nexe_downloader_; |
| 1443 nacl::string url = file_downloader->url_to_open(); | 1429 nacl::string url = file_downloader->url_to_open(); |
| 1444 LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? | 1430 LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? |
| 1445 LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; | 1431 LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; |
| 1446 | 1432 |
| 1447 plugin->EnqueueProgressEvent(kProgressEventProgress, | 1433 plugin->EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS, |
| 1448 url, | 1434 url, |
| 1449 length_computable, | 1435 length_computable, |
| 1450 bytes_received, | 1436 bytes_received, |
| 1451 total_bytes_to_be_received); | 1437 total_bytes_to_be_received); |
| 1452 } | 1438 } |
| 1453 } | 1439 } |
| 1454 } | 1440 } |
| 1455 | 1441 |
| 1456 const FileDownloader* Plugin::FindFileDownloader( | 1442 const FileDownloader* Plugin::FindFileDownloader( |
| 1457 PP_Resource url_loader) const { | 1443 PP_Resource url_loader) const { |
| 1458 const FileDownloader* file_downloader = NULL; | 1444 const FileDownloader* file_downloader = NULL; |
| 1459 if (url_loader == nexe_downloader_.url_loader()) { | 1445 if (url_loader == nexe_downloader_.url_loader()) { |
| 1460 file_downloader = &nexe_downloader_; | 1446 file_downloader = &nexe_downloader_; |
| 1461 } else { | 1447 } else { |
| 1462 std::set<FileDownloader*>::const_iterator it = url_downloaders_.begin(); | 1448 std::set<FileDownloader*>::const_iterator it = url_downloaders_.begin(); |
| 1463 while (it != url_downloaders_.end()) { | 1449 while (it != url_downloaders_.end()) { |
| 1464 if (url_loader == (*it)->url_loader()) { | 1450 if (url_loader == (*it)->url_loader()) { |
| 1465 file_downloader = (*it); | 1451 file_downloader = (*it); |
| 1466 break; | 1452 break; |
| 1467 } | 1453 } |
| 1468 ++it; | 1454 ++it; |
| 1469 } | 1455 } |
| 1470 } | 1456 } |
| 1471 return file_downloader; | 1457 return file_downloader; |
| 1472 } | 1458 } |
| 1473 | 1459 |
| 1474 void Plugin::EnqueueProgressEvent(const char* event_type) { | 1460 void Plugin::EnqueueProgressEvent(PP_NaClEventType event_type) { |
| 1475 EnqueueProgressEvent(event_type, | 1461 EnqueueProgressEvent(event_type, |
| 1476 NACL_NO_URL, | 1462 NACL_NO_URL, |
| 1477 Plugin::LENGTH_IS_NOT_COMPUTABLE, | 1463 Plugin::LENGTH_IS_NOT_COMPUTABLE, |
| 1478 Plugin::kUnknownBytes, | 1464 Plugin::kUnknownBytes, |
| 1479 Plugin::kUnknownBytes); | 1465 Plugin::kUnknownBytes); |
| 1480 } | 1466 } |
| 1481 | 1467 |
| 1482 void Plugin::EnqueueProgressEvent(const char* event_type, | 1468 void Plugin::EnqueueProgressEvent(PP_NaClEventType event_type, |
| 1483 const nacl::string& url, | 1469 const nacl::string& url, |
| 1484 LengthComputable length_computable, | 1470 LengthComputable length_computable, |
| 1485 uint64_t loaded_bytes, | 1471 uint64_t loaded_bytes, |
| 1486 uint64_t total_bytes) { | 1472 uint64_t total_bytes) { |
| 1487 PLUGIN_PRINTF(("Plugin::EnqueueProgressEvent (" | 1473 PLUGIN_PRINTF(("Plugin::EnqueueProgressEvent (" |
| 1488 "event_type='%s', url='%s', length_computable=%d, " | 1474 "event_type='%s', url='%s', length_computable=%d, " |
| 1489 "loaded=%" NACL_PRIu64 ", total=%" NACL_PRIu64 ")\n", | 1475 "loaded=%" NACL_PRIu64 ", total=%" NACL_PRIu64 ")\n", |
| 1490 event_type, | 1476 event_type, |
| 1491 url.c_str(), | 1477 url.c_str(), |
| 1492 static_cast<int>(length_computable), | 1478 static_cast<int>(length_computable), |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1518 if (result < 0) { | 1504 if (result < 0) { |
| 1519 return; | 1505 return; |
| 1520 } | 1506 } |
| 1521 if (progress_events_.empty()) { | 1507 if (progress_events_.empty()) { |
| 1522 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent: no pending events\n")); | 1508 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent: no pending events\n")); |
| 1523 return; | 1509 return; |
| 1524 } | 1510 } |
| 1525 nacl::scoped_ptr<ProgressEvent> event(progress_events_.front()); | 1511 nacl::scoped_ptr<ProgressEvent> event(progress_events_.front()); |
| 1526 progress_events_.pop(); | 1512 progress_events_.pop(); |
| 1527 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent (" | 1513 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent (" |
| 1528 "event_type='%s', url='%s', length_computable=%d, " | 1514 "event_type='%d', url='%s', length_computable=%d, " |
| 1529 "loaded=%" NACL_PRIu64 ", total=%" NACL_PRIu64 ")\n", | 1515 "loaded=%" NACL_PRIu64 ", total=%" NACL_PRIu64 ")\n", |
| 1530 event->event_type(), | 1516 static_cast<int>(event->event_type()), |
| 1531 event->url(), | 1517 event->url(), |
| 1532 static_cast<int>(event->length_computable()), | 1518 static_cast<int>(event->length_computable()), |
| 1533 event->loaded_bytes(), | 1519 event->loaded_bytes(), |
| 1534 event->total_bytes())); | 1520 event->total_bytes())); |
| 1535 | 1521 |
| 1536 static const char* kEventClosureJS = | 1522 nacl_interface_->DispatchEvent( |
| 1537 "(function(target, type, url," | 1523 pp_instance(), |
| 1538 " lengthComputable, loadedBytes, totalBytes) {" | 1524 event->event_type(), |
| 1539 " var progress_event = new ProgressEvent(type, {" | 1525 pp::Var(event->url()).pp_var(), |
| 1540 " bubbles: false," | 1526 event->length_computable() == LENGTH_IS_COMPUTABLE ? PP_TRUE : PP_FALSE, |
| 1541 " cancelable: true," | 1527 event->loaded_bytes(), |
| 1542 " lengthComputable: lengthComputable," | 1528 event->total_bytes()); |
| 1543 " loaded: loadedBytes," | |
| 1544 " total: totalBytes" | |
| 1545 " });" | |
| 1546 " progress_event.url = url;" | |
| 1547 " target.dispatchEvent(progress_event);" | |
| 1548 "})"; | |
| 1549 | |
| 1550 // Create a function object by evaluating the JavaScript text. | |
| 1551 // TODO(sehr, polina): We should probably cache the created function object to | |
| 1552 // avoid JavaScript reparsing. | |
| 1553 pp::VarPrivate exception; | |
| 1554 pp::VarPrivate function_object = ExecuteScript(kEventClosureJS, &exception); | |
| 1555 if (!exception.is_undefined() || !function_object.is_object()) { | |
| 1556 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:" | |
| 1557 " Function object creation failed.\n")); | |
| 1558 return; | |
| 1559 } | |
| 1560 // Get the target of the event to be dispatched. | |
| 1561 pp::Var owner_element_object = GetOwnerElementObject(); | |
| 1562 if (!owner_element_object.is_object()) { | |
| 1563 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:" | |
| 1564 " Couldn't get owner element object.\n")); | |
| 1565 NACL_NOTREACHED(); | |
| 1566 return; | |
| 1567 } | |
| 1568 | |
| 1569 pp::Var argv[6]; | |
| 1570 static const uint32_t argc = NACL_ARRAY_SIZE(argv); | |
| 1571 argv[0] = owner_element_object; | |
| 1572 argv[1] = pp::Var(event->event_type()); | |
| 1573 argv[2] = pp::Var(event->url()); | |
| 1574 argv[3] = pp::Var(event->length_computable() == LENGTH_IS_COMPUTABLE); | |
| 1575 argv[4] = pp::Var(static_cast<double>(event->loaded_bytes())); | |
| 1576 argv[5] = pp::Var(static_cast<double>(event->total_bytes())); | |
| 1577 | |
| 1578 // Dispatch the event. | |
| 1579 const pp::Var default_method; | |
| 1580 function_object.Call(default_method, argc, argv, &exception); | |
| 1581 if (!exception.is_undefined()) { | |
| 1582 PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:" | |
| 1583 " event dispatch failed.\n")); | |
| 1584 } | |
| 1585 } | 1529 } |
| 1586 | 1530 |
| 1587 bool Plugin::OpenURLFast(const nacl::string& url, | 1531 bool Plugin::OpenURLFast(const nacl::string& url, |
| 1588 FileDownloader* downloader) { | 1532 FileDownloader* downloader) { |
| 1589 // Fast path only works for installed file URLs. | 1533 // Fast path only works for installed file URLs. |
| 1590 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) | 1534 if (GetUrlScheme(url) != SCHEME_CHROME_EXTENSION) |
| 1591 return false; | 1535 return false; |
| 1592 // IMPORTANT: Make sure the document can request the given URL. If we don't | 1536 // IMPORTANT: Make sure the document can request the given URL. If we don't |
| 1593 // check, a malicious app could probe the extension system. This enforces a | 1537 // check, a malicious app could probe the extension system. This enforces a |
| 1594 // same-origin policy which prevents the app from requesting resources from | 1538 // same-origin policy which prevents the app from requesting resources from |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 static_cast<uint32_t>(text.size())); | 1599 static_cast<uint32_t>(text.size())); |
| 1656 const PPB_Console* console_interface = | 1600 const PPB_Console* console_interface = |
| 1657 static_cast<const PPB_Console*>( | 1601 static_cast<const PPB_Console*>( |
| 1658 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); | 1602 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); |
| 1659 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); | 1603 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); |
| 1660 var_interface->Release(prefix); | 1604 var_interface->Release(prefix); |
| 1661 var_interface->Release(str); | 1605 var_interface->Release(str); |
| 1662 } | 1606 } |
| 1663 | 1607 |
| 1664 } // namespace plugin | 1608 } // namespace plugin |
| OLD | NEW |