Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1186)

Unified Diff: chrome/renderer/pepper/ppb_nacl_private_impl.cc

Issue 14588009: PPAPI/NaCl: Move event dispatching from the plugin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/public/renderer/pepper_plugin_instance.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/pepper/ppb_nacl_private_impl.cc
diff --git a/chrome/renderer/pepper/ppb_nacl_private_impl.cc b/chrome/renderer/pepper/ppb_nacl_private_impl.cc
index 18193f323316c06b94a23b4e0ab212c5013b4b2c..45e8710bc61086c0db43f2a04b691afa73a845c7 100644
--- a/chrome/renderer/pepper/ppb_nacl_private_impl.cc
+++ b/chrome/renderer/pepper/ppb_nacl_private_impl.cc
@@ -29,11 +29,13 @@
#include "ppapi/shared_impl/ppapi_preferences.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/thunk/enter.h"
+#include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebPluginContainer.h"
#include "third_party/WebKit/public/web/WebView.h"
+#include "v8/include/v8.h"
namespace {
@@ -79,15 +81,15 @@ static int GetRoutingID(PP_Instance instance) {
// Launch NaCl's sel_ldr process.
PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
- const char* alleged_url,
- PP_Bool uses_irt,
- PP_Bool uses_ppapi,
- PP_Bool enable_ppapi_dev,
- PP_Bool enable_dyncode_syscalls,
- PP_Bool enable_exception_handling,
- PP_Bool enable_crash_throttling,
- void* imc_handle,
- struct PP_Var* error_message) {
+ const char* alleged_url,
+ PP_Bool uses_irt,
+ PP_Bool uses_ppapi,
+ PP_Bool enable_ppapi_dev,
+ PP_Bool enable_dyncode_syscalls,
+ PP_Bool enable_exception_handling,
+ PP_Bool enable_crash_throttling,
+ void* imc_handle,
+ struct PP_Var* error_message) {
nacl::FileDescriptor result_socket;
IPC::Sender* sender = content::RenderThread::Get();
DCHECK(sender);
@@ -336,6 +338,75 @@ PP_FileHandle OpenNaClExecutable(PP_Instance instance,
return handle;
}
+WebKit::WebString EventTypeToString(PP_NaClEventType event_type) {
+ switch (event_type) {
+ case PP_NACL_EVENT_LOADSTART:
+ return WebKit::WebString::fromUTF8("loadstart");
+ case PP_NACL_EVENT_PROGRESS:
+ return WebKit::WebString::fromUTF8("progress");
+ case PP_NACL_EVENT_ERROR:
+ return WebKit::WebString::fromUTF8("error");
+ case PP_NACL_EVENT_ABORT:
+ return WebKit::WebString::fromUTF8("abort");
+ case PP_NACL_EVENT_LOAD:
+ return WebKit::WebString::fromUTF8("load");
+ case PP_NACL_EVENT_LOADEND:
+ return WebKit::WebString::fromUTF8("loadend");
+ case PP_NACL_EVENT_CRASH:
+ return WebKit::WebString::fromUTF8("crash");
+ }
+ NOTIMPLEMENTED();
+ return WebKit::WebString();
+}
+
+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) {
+ content::PepperPluginInstance* plugin_instance =
+ content::PepperPluginInstance::Get(instance);
+ if (!plugin_instance) {
+ NOTREACHED();
+ return;
+ }
+ WebKit::WebPluginContainer* container = plugin_instance->GetContainer();
+ // It's possible that container() is NULL if the plugin has been removed from
+ // the DOM (but the PluginInstance is not destroyed yet).
+ if (!container)
+ return;
+ WebKit::WebFrame* frame = container->element().document().frame();
+ if (!frame)
+ return;
+ v8::HandleScope handle_scope(plugin_instance->GetIsolate());
+ v8::Local<v8::Context> context(
+ plugin_instance->GetIsolate()->GetCurrentContext());
+ if (context.IsEmpty()) {
+ // If there's no JavaScript on the stack, we have to make a new Context.
+ context = v8::Context::New(plugin_instance->GetIsolate());
+ }
+ v8::Context::Scope context_scope(context);
+
+ ppapi::StringVar* url_var = ppapi::StringVar::FromPPVar(resource_url);
+ if (url_var) {
+ WebKit::WebString url_string = WebKit::WebString::fromUTF8(
+ url_var->value().data(), url_var->value().size());
+ WebKit::WebDOMResourceProgressEvent event(EventTypeToString(event_type),
+ PP_ToBool(length_is_computable),
+ loaded_bytes,
+ total_bytes,
+ url_string);
+ container->element().dispatchEvent(event);
+ } else {
+ WebKit::WebDOMProgressEvent event(EventTypeToString(event_type),
+ PP_ToBool(length_is_computable),
+ loaded_bytes,
+ total_bytes);
+ container->element().dispatchEvent(event);
+ }
+}
+
const PPB_NaCl_Private nacl_interface = {
&LaunchSelLdr,
&StartPpapiProxy,
@@ -348,7 +419,8 @@ const PPB_NaCl_Private nacl_interface = {
&ReportTranslationFinished,
&IsOffTheRecord,
&ReportNaClError,
- &OpenNaClExecutable
+ &OpenNaClExecutable,
+ &DispatchEvent
};
} // namespace
« no previous file with comments | « no previous file | content/public/renderer/pepper_plugin_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698