summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 21:02:05 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 21:02:05 +0000
commit7c5cb04e63557803aeb2426ad0833e33952f9889 (patch)
treebd05929567bd5c7a5356a7a8d32c3939fc3acefe /ppapi
parentcf83d9e7171688232e30353229f5d53404612fb8 (diff)
downloadchromium_src-7c5cb04e63557803aeb2426ad0833e33952f9889.zip
chromium_src-7c5cb04e63557803aeb2426ad0833e33952f9889.tar.gz
chromium_src-7c5cb04e63557803aeb2426ad0833e33952f9889.tar.bz2
PPAPI/NaCl: Move event dispatching from the plugin
Added chrome/renderer/nacl and OWNERS Requires the following blink change: https://codereview.chromium.org/14773025/ BUG=239656 R=jam@chromium.org, marja@chromium.org, teravest@chromium.org Review URL: https://codereview.chromium.org/14588009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233356 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/api/private/ppb_nacl_private.idl22
-rw-r--r--ppapi/c/private/ppb_nacl_private.h22
-rw-r--r--ppapi/native_client/src/trusted/plugin/plugin.cc106
-rw-r--r--ppapi/native_client/src/trusted/plugin/plugin.h13
-rw-r--r--ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc6
-rw-r--r--ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c8
6 files changed, 80 insertions, 97 deletions
diff --git a/ppapi/api/private/ppb_nacl_private.idl b/ppapi/api/private/ppb_nacl_private.idl
index 7a52372..8e354d4 100644
--- a/ppapi/api/private/ppb_nacl_private.idl
+++ b/ppapi/api/private/ppb_nacl_private.idl
@@ -24,6 +24,17 @@ enum PP_NaClError {
PP_NACL_MANIFEST_MISSING_ARCH = 0
};
+/** Event types that NaCl may use when reporting load progress or errors. */
+enum PP_NaClEventType {
+ PP_NACL_EVENT_LOADSTART,
+ PP_NACL_EVENT_PROGRESS,
+ PP_NACL_EVENT_ERROR,
+ PP_NACL_EVENT_ABORT,
+ PP_NACL_EVENT_LOAD,
+ PP_NACL_EVENT_LOADEND,
+ PP_NACL_EVENT_CRASH
+};
+
/* PPB_NaCl_Private */
interface PPB_NaCl_Private {
/* Launches NaCl's sel_ldr process. Returns PP_EXTERNAL_PLUGIN_OK on success
@@ -151,4 +162,15 @@ interface PPB_NaCl_Private {
[in] str_t file_url,
[out] uint64_t file_token_lo,
[out] uint64_t file_token_hi);
+
+
+ /* Dispatch a progress event on the DOM element where the given instance is
+ * embedded.
+ */
+ void DispatchEvent([in] PP_Instance instance,
+ [in] PP_NaClEventType event_type,
+ [in] PP_Var resource_url,
+ [in] PP_Bool length_is_computable,
+ [in] uint64_t loaded_bytes,
+ [in] uint64_t total_bytes);
};
diff --git a/ppapi/c/private/ppb_nacl_private.h b/ppapi/c/private/ppb_nacl_private.h
index 3b67740..0cca65c 100644
--- a/ppapi/c/private/ppb_nacl_private.h
+++ b/ppapi/c/private/ppb_nacl_private.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From private/ppb_nacl_private.idl modified Thu Oct 31 15:10:06 2013. */
+/* From private/ppb_nacl_private.idl modified Tue Nov 5 15:33:53 2013. */
#ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
#define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
@@ -40,6 +40,17 @@ typedef enum {
*/
PP_NACL_MANIFEST_MISSING_ARCH = 0
} PP_NaClError;
+
+/** Event types that NaCl may use when reporting load progress or errors. */
+typedef enum {
+ PP_NACL_EVENT_LOADSTART,
+ PP_NACL_EVENT_PROGRESS,
+ PP_NACL_EVENT_ERROR,
+ PP_NACL_EVENT_ABORT,
+ PP_NACL_EVENT_LOAD,
+ PP_NACL_EVENT_LOADEND,
+ PP_NACL_EVENT_CRASH
+} PP_NaClEventType;
/**
* @}
*/
@@ -163,6 +174,15 @@ struct PPB_NaCl_Private_1_0 {
const char* file_url,
uint64_t* file_token_lo,
uint64_t* file_token_hi);
+ /* Dispatch a progress event on the DOM element where the given instance is
+ * embedded.
+ */
+ void (*DispatchEvent)(PP_Instance instance,
+ PP_NaClEventType event_type,
+ struct PP_Var resource_url,
+ PP_Bool length_is_computable,
+ uint64_t loaded_bytes,
+ uint64_t total_bytes);
};
typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private;
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc
index 5a783af..a146ff3 100644
--- a/ppapi/native_client/src/trusted/plugin/plugin.cc
+++ b/ppapi/native_client/src/trusted/plugin/plugin.cc
@@ -559,20 +559,9 @@ char* Plugin::LookupArgument(const char* key) {
return NULL;
}
-// Suggested names for progress event types, per
-// http://www.w3.org/TR/progress-events/
-const char* const Plugin::kProgressEventLoadStart = "loadstart";
-const char* const Plugin::kProgressEventProgress = "progress";
-const char* const Plugin::kProgressEventError = "error";
-const char* const Plugin::kProgressEventAbort = "abort";
-const char* const Plugin::kProgressEventLoad = "load";
-const char* const Plugin::kProgressEventLoadEnd = "loadend";
-// Define a NaCl specific event type for .nexe crashes.
-const char* const Plugin::kProgressEventCrash = "crash";
-
class ProgressEvent {
public:
- ProgressEvent(const char* event_type,
+ ProgressEvent(PP_NaClEventType event_type,
const nacl::string& url,
Plugin::LengthComputable length_computable,
uint64_t loaded_bytes,
@@ -582,7 +571,7 @@ class ProgressEvent {
length_computable_(length_computable),
loaded_bytes_(loaded_bytes),
total_bytes_(total_bytes) { }
- const char* event_type() const { return event_type_; }
+ PP_NaClEventType event_type() const { return event_type_; }
const char* url() const { return url_.c_str(); }
Plugin::LengthComputable length_computable() const {
return length_computable_;
@@ -591,10 +580,7 @@ class ProgressEvent {
uint64_t total_bytes() const { return total_bytes_; }
private:
- // event_type_ is always passed from a string literal, so ownership is
- // not taken. Hence it does not need to be deleted when ProgressEvent is
- // destroyed.
- const char* event_type_;
+ PP_NaClEventType event_type_;
nacl::string url_;
Plugin::LengthComputable length_computable_;
uint64_t loaded_bytes_;
@@ -869,7 +855,7 @@ void Plugin::NexeFileDidOpen(int32_t pp_error) {
static_cast<float>(nexe_downloader_.TimeSinceOpenMilliseconds()));
// Inform JavaScript that we successfully downloaded the nacl module.
- EnqueueProgressEvent(kProgressEventProgress,
+ EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS,
nexe_downloader_.url_to_open(),
LENGTH_IS_COMPUTABLE,
nexe_bytes_read,
@@ -1046,7 +1032,7 @@ void Plugin::ReportDeadNexe() {
set_last_error_string(message);
AddToConsole(message);
- EnqueueProgressEvent(kProgressEventCrash);
+ EnqueueProgressEvent(PP_NACL_EVENT_CRASH);
set_nexe_error_reported(true);
}
// else ReportLoadError() and ReportAbortError() will be used by loading code
@@ -1180,7 +1166,7 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
is_installed_ = GetUrlScheme(program_url) == SCHEME_CHROME_EXTENSION;
nacl_ready_state_ = LOADING;
// Inform JavaScript that we found a nexe URL to load.
- EnqueueProgressEvent(kProgressEventProgress);
+ EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS);
if (pnacl_options.translate()) {
pp::CompletionCallback translate_callback =
callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
@@ -1238,7 +1224,7 @@ void Plugin::RequestNaClManifest(const nacl::string& url) {
set_manifest_url(url);
// Inform JavaScript that a load is starting.
nacl_ready_state_ = OPENED;
- EnqueueProgressEvent(kProgressEventLoadStart);
+ EnqueueProgressEvent(PP_NACL_EVENT_LOADSTART);
bool is_data_uri = GetUrlScheme(nmf_resolved_url.AsString()) == SCHEME_DATA;
HistogramEnumerateManifestIsDataURI(static_cast<int>(is_data_uri));
if (is_data_uri) {
@@ -1360,9 +1346,9 @@ void Plugin::ReportLoadSuccess(LengthComputable length_computable,
// Inform JavaScript that loading was successful and is complete.
const nacl::string& url = nexe_downloader_.url_to_open();
EnqueueProgressEvent(
- kProgressEventLoad, url, length_computable, loaded_bytes, total_bytes);
+ PP_NACL_EVENT_LOAD, url, length_computable, loaded_bytes, total_bytes);
EnqueueProgressEvent(
- kProgressEventLoadEnd, url, length_computable, loaded_bytes, total_bytes);
+ PP_NACL_EVENT_LOADEND, url, length_computable, loaded_bytes, total_bytes);
// UMA
HistogramEnumerateLoadStatus(ERROR_LOAD_SUCCESS, is_installed_);
@@ -1392,8 +1378,8 @@ void Plugin::ReportLoadError(const ErrorInfo& error_info) {
AddToConsole(nacl::string("NaCl module load failed: ") +
error_info.console_message());
// Inform JavaScript that loading encountered an error and is complete.
- EnqueueProgressEvent(kProgressEventError);
- EnqueueProgressEvent(kProgressEventLoadEnd);
+ EnqueueProgressEvent(PP_NACL_EVENT_ERROR);
+ EnqueueProgressEvent(PP_NACL_EVENT_LOADEND);
// UMA
HistogramEnumerateLoadStatus(error_info.error_code(), is_installed_);
@@ -1410,8 +1396,8 @@ void Plugin::ReportLoadAbort() {
set_last_error_string(error_string);
AddToConsole(error_string);
// Inform JavaScript that loading was aborted and is complete.
- EnqueueProgressEvent(kProgressEventAbort);
- EnqueueProgressEvent(kProgressEventLoadEnd);
+ EnqueueProgressEvent(PP_NACL_EVENT_ABORT);
+ EnqueueProgressEvent(PP_NACL_EVENT_LOADEND);
// UMA
HistogramEnumerateLoadStatus(ERROR_LOAD_ABORTED, is_installed_);
@@ -1444,7 +1430,7 @@ void Plugin::UpdateDownloadProgress(
LengthComputable length_computable = (total_bytes_to_be_received >= 0) ?
LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE;
- plugin->EnqueueProgressEvent(kProgressEventProgress,
+ plugin->EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS,
url,
length_computable,
bytes_received,
@@ -1471,7 +1457,7 @@ const FileDownloader* Plugin::FindFileDownloader(
return file_downloader;
}
-void Plugin::EnqueueProgressEvent(const char* event_type) {
+void Plugin::EnqueueProgressEvent(PP_NaClEventType event_type) {
EnqueueProgressEvent(event_type,
NACL_NO_URL,
Plugin::LENGTH_IS_NOT_COMPUTABLE,
@@ -1479,7 +1465,7 @@ void Plugin::EnqueueProgressEvent(const char* event_type) {
Plugin::kUnknownBytes);
}
-void Plugin::EnqueueProgressEvent(const char* event_type,
+void Plugin::EnqueueProgressEvent(PP_NaClEventType event_type,
const nacl::string& url,
LengthComputable length_computable,
uint64_t loaded_bytes,
@@ -1525,63 +1511,21 @@ void Plugin::DispatchProgressEvent(int32_t result) {
nacl::scoped_ptr<ProgressEvent> event(progress_events_.front());
progress_events_.pop();
PLUGIN_PRINTF(("Plugin::DispatchProgressEvent ("
- "event_type='%s', url='%s', length_computable=%d, "
+ "event_type='%d', url='%s', length_computable=%d, "
"loaded=%" NACL_PRIu64 ", total=%" NACL_PRIu64 ")\n",
- event->event_type(),
+ static_cast<int>(event->event_type()),
event->url(),
static_cast<int>(event->length_computable()),
event->loaded_bytes(),
event->total_bytes()));
- static const char* kEventClosureJS =
- "(function(target, type, url,"
- " lengthComputable, loadedBytes, totalBytes) {"
- " var progress_event = new ProgressEvent(type, {"
- " bubbles: false,"
- " cancelable: true,"
- " lengthComputable: lengthComputable,"
- " loaded: loadedBytes,"
- " total: totalBytes"
- " });"
- " progress_event.url = url;"
- " target.dispatchEvent(progress_event);"
- "})";
-
- // Create a function object by evaluating the JavaScript text.
- // TODO(sehr, polina): We should probably cache the created function object to
- // avoid JavaScript reparsing.
- pp::VarPrivate exception;
- pp::VarPrivate function_object = ExecuteScript(kEventClosureJS, &exception);
- if (!exception.is_undefined() || !function_object.is_object()) {
- PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:"
- " Function object creation failed.\n"));
- return;
- }
- // Get the target of the event to be dispatched.
- pp::Var owner_element_object = GetOwnerElementObject();
- if (!owner_element_object.is_object()) {
- PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:"
- " Couldn't get owner element object.\n"));
- NACL_NOTREACHED();
- return;
- }
-
- pp::Var argv[6];
- static const uint32_t argc = NACL_ARRAY_SIZE(argv);
- argv[0] = owner_element_object;
- argv[1] = pp::Var(event->event_type());
- argv[2] = pp::Var(event->url());
- argv[3] = pp::Var(event->length_computable() == LENGTH_IS_COMPUTABLE);
- argv[4] = pp::Var(static_cast<double>(event->loaded_bytes()));
- argv[5] = pp::Var(static_cast<double>(event->total_bytes()));
-
- // Dispatch the event.
- const pp::Var default_method;
- function_object.Call(default_method, argc, argv, &exception);
- if (!exception.is_undefined()) {
- PLUGIN_PRINTF(("Plugin::DispatchProgressEvent:"
- " event dispatch failed.\n"));
- }
+ nacl_interface_->DispatchEvent(
+ pp_instance(),
+ event->event_type(),
+ pp::Var(event->url()).pp_var(),
+ event->length_computable() == LENGTH_IS_COMPUTABLE ? PP_TRUE : PP_FALSE,
+ event->loaded_bytes(),
+ event->total_bytes());
}
bool Plugin::OpenURLFast(const nacl::string& url,
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h
index c1a93880..401978d 100644
--- a/ppapi/native_client/src/trusted/plugin/plugin.h
+++ b/ppapi/native_client/src/trusted/plugin/plugin.h
@@ -146,22 +146,13 @@ class Plugin : public pp::InstancePrivate {
// event (loadstart, progress, error, abort, load, loadend). Events are
// enqueued on the JavaScript event loop, which then calls back through
// DispatchProgressEvent.
- void EnqueueProgressEvent(const char* event_type);
- void EnqueueProgressEvent(const char* event_type,
+ void EnqueueProgressEvent(PP_NaClEventType event_type);
+ void EnqueueProgressEvent(PP_NaClEventType event_type,
const nacl::string& url,
LengthComputable length_computable,
uint64_t loaded_bytes,
uint64_t total_bytes);
- // Progress event types.
- static const char* const kProgressEventLoadStart;
- static const char* const kProgressEventProgress;
- static const char* const kProgressEventError;
- static const char* const kProgressEventAbort;
- static const char* const kProgressEventLoad;
- static const char* const kProgressEventLoadEnd;
- static const char* const kProgressEventCrash;
-
// Report the error code that sel_ldr produces when starting a nexe.
void ReportSelLdrLoadStatus(int status);
diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc
index 9d7fa0d..d67b991 100644
--- a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc
+++ b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc
@@ -344,7 +344,7 @@ void PnaclCoordinator::TranslateFinished(int32_t pp_error) {
// that were delayed (see the delay inserted in BitcodeGotCompiled).
if (ExpectedProgressKnown()) {
pexe_bytes_compiled_ = expected_pexe_size_;
- plugin_->EnqueueProgressEvent(plugin::Plugin::kProgressEventProgress,
+ plugin_->EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS,
pexe_url_,
plugin::Plugin::LENGTH_IS_COMPUTABLE,
pexe_bytes_compiled_,
@@ -634,14 +634,14 @@ void PnaclCoordinator::BitcodeGotCompiled(int32_t pp_error,
// that bytes were sent to the compiler.
if (ExpectedProgressKnown()) {
if (!ShouldDelayProgressEvent()) {
- plugin_->EnqueueProgressEvent(plugin::Plugin::kProgressEventProgress,
+ plugin_->EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS,
pexe_url_,
plugin::Plugin::LENGTH_IS_COMPUTABLE,
pexe_bytes_compiled_,
expected_pexe_size_);
}
} else {
- plugin_->EnqueueProgressEvent(plugin::Plugin::kProgressEventProgress,
+ plugin_->EnqueueProgressEvent(PP_NACL_EVENT_PROGRESS,
pexe_url_,
plugin::Plugin::LENGTH_IS_NOT_COMPUTABLE,
pexe_bytes_compiled_,
diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
index 1365a3e..51c5aff 100644
--- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
+++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c
@@ -3098,6 +3098,11 @@ static PP_FileHandle Pnacl_M25_PPB_NaCl_Private_OpenNaClExecutable(PP_Instance i
return iface->OpenNaClExecutable(instance, file_url, file_token_lo, file_token_hi);
}
+static void Pnacl_M25_PPB_NaCl_Private_DispatchEvent(PP_Instance instance, PP_NaClEventType event_type, struct PP_Var* resource_url, PP_Bool length_is_computable, uint64_t loaded_bytes, uint64_t total_bytes) {
+ const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface;
+ iface->DispatchEvent(instance, event_type, *resource_url, length_is_computable, loaded_bytes, total_bytes);
+}
+
/* End wrapper methods for PPB_NaCl_Private_1_0 */
/* Begin wrapper methods for PPB_NetAddress_Private_0_1 */
@@ -4945,7 +4950,8 @@ struct PPB_NaCl_Private_1_0 Pnacl_Wrappers_PPB_NaCl_Private_1_0 = {
.ReportTranslationFinished = (void (*)(PP_Instance instance, PP_Bool success))&Pnacl_M25_PPB_NaCl_Private_ReportTranslationFinished,
.IsOffTheRecord = (PP_Bool (*)(void))&Pnacl_M25_PPB_NaCl_Private_IsOffTheRecord,
.ReportNaClError = (PP_ExternalPluginResult (*)(PP_Instance instance, PP_NaClError message_id))&Pnacl_M25_PPB_NaCl_Private_ReportNaClError,
- .OpenNaClExecutable = (PP_FileHandle (*)(PP_Instance instance, const char* file_url, uint64_t* file_token_lo, uint64_t* file_token_hi))&Pnacl_M25_PPB_NaCl_Private_OpenNaClExecutable
+ .OpenNaClExecutable = (PP_FileHandle (*)(PP_Instance instance, const char* file_url, uint64_t* file_token_lo, uint64_t* file_token_hi))&Pnacl_M25_PPB_NaCl_Private_OpenNaClExecutable,
+ .DispatchEvent = (void (*)(PP_Instance instance, PP_NaClEventType event_type, struct PP_Var resource_url, PP_Bool length_is_computable, uint64_t loaded_bytes, uint64_t total_bytes))&Pnacl_M25_PPB_NaCl_Private_DispatchEvent
};
struct PPB_NetAddress_Private_0_1 Pnacl_Wrappers_PPB_NetAddress_Private_0_1 = {