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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/public/renderer/pepper_plugin_instance.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/renderer/pepper/ppb_nacl_private_impl.h" 5 #include "chrome/renderer/pepper/ppb_nacl_private_impl.h"
6 6
7 #ifndef DISABLE_NACL 7 #ifndef DISABLE_NACL
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/renderer/renderer_ppapi_host.h" 22 #include "content/public/renderer/renderer_ppapi_host.h"
23 #include "content/public/renderer/render_thread.h" 23 #include "content/public/renderer/render_thread.h"
24 #include "content/public/renderer/render_view.h" 24 #include "content/public/renderer/render_view.h"
25 #include "ppapi/c/pp_bool.h" 25 #include "ppapi/c/pp_bool.h"
26 #include "ppapi/c/private/pp_file_handle.h" 26 #include "ppapi/c/private/pp_file_handle.h"
27 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" 27 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
28 #include "ppapi/shared_impl/ppapi_permissions.h" 28 #include "ppapi/shared_impl/ppapi_permissions.h"
29 #include "ppapi/shared_impl/ppapi_preferences.h" 29 #include "ppapi/shared_impl/ppapi_preferences.h"
30 #include "ppapi/shared_impl/var.h" 30 #include "ppapi/shared_impl/var.h"
31 #include "ppapi/thunk/enter.h" 31 #include "ppapi/thunk/enter.h"
32 #include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h"
32 #include "third_party/WebKit/public/web/WebDocument.h" 33 #include "third_party/WebKit/public/web/WebDocument.h"
33 #include "third_party/WebKit/public/web/WebElement.h" 34 #include "third_party/WebKit/public/web/WebElement.h"
34 #include "third_party/WebKit/public/web/WebFrame.h" 35 #include "third_party/WebKit/public/web/WebFrame.h"
35 #include "third_party/WebKit/public/web/WebPluginContainer.h" 36 #include "third_party/WebKit/public/web/WebPluginContainer.h"
36 #include "third_party/WebKit/public/web/WebView.h" 37 #include "third_party/WebKit/public/web/WebView.h"
38 #include "v8/include/v8.h"
37 39
38 namespace { 40 namespace {
39 41
40 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> > 42 base::LazyInstance<scoped_refptr<PnaclTranslationResourceHost> >
41 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER; 43 g_pnacl_resource_host = LAZY_INSTANCE_INITIALIZER;
42 44
43 static bool InitializePnaclResourceHost() { 45 static bool InitializePnaclResourceHost() {
44 // Must run on the main thread. 46 // Must run on the main thread.
45 content::RenderThread* render_thread = content::RenderThread::Get(); 47 content::RenderThread* render_thread = content::RenderThread::Get();
46 if (!render_thread) 48 if (!render_thread)
(...skipping 25 matching lines...) Expand all
72 DCHECK(content::RenderThread::Get()); 74 DCHECK(content::RenderThread::Get());
73 content::RendererPpapiHost *host = 75 content::RendererPpapiHost *host =
74 content::RendererPpapiHost::GetForPPInstance(instance); 76 content::RendererPpapiHost::GetForPPInstance(instance);
75 if (!host) 77 if (!host)
76 return 0; 78 return 0;
77 return host->GetRoutingIDForWidget(instance); 79 return host->GetRoutingIDForWidget(instance);
78 } 80 }
79 81
80 // Launch NaCl's sel_ldr process. 82 // Launch NaCl's sel_ldr process.
81 PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance, 83 PP_ExternalPluginResult LaunchSelLdr(PP_Instance instance,
82 const char* alleged_url, 84 const char* alleged_url,
83 PP_Bool uses_irt, 85 PP_Bool uses_irt,
84 PP_Bool uses_ppapi, 86 PP_Bool uses_ppapi,
85 PP_Bool enable_ppapi_dev, 87 PP_Bool enable_ppapi_dev,
86 PP_Bool enable_dyncode_syscalls, 88 PP_Bool enable_dyncode_syscalls,
87 PP_Bool enable_exception_handling, 89 PP_Bool enable_exception_handling,
88 PP_Bool enable_crash_throttling, 90 PP_Bool enable_crash_throttling,
89 void* imc_handle, 91 void* imc_handle,
90 struct PP_Var* error_message) { 92 struct PP_Var* error_message) {
91 nacl::FileDescriptor result_socket; 93 nacl::FileDescriptor result_socket;
92 IPC::Sender* sender = content::RenderThread::Get(); 94 IPC::Sender* sender = content::RenderThread::Get();
93 DCHECK(sender); 95 DCHECK(sender);
94 *error_message = PP_MakeUndefined(); 96 *error_message = PP_MakeUndefined();
95 int routing_id = 0; 97 int routing_id = 0;
96 // If the nexe uses ppapi APIs, we need a routing ID. 98 // If the nexe uses ppapi APIs, we need a routing ID.
97 // To get the routing ID, we must be on the main thread. 99 // To get the routing ID, we must be on the main thread.
98 // Some nexes do not use ppapi and launch from the background thread, 100 // Some nexes do not use ppapi and launch from the background thread,
99 // so those nexes can skip finding a routing_id. 101 // so those nexes can skip finding a routing_id.
100 if (uses_ppapi) { 102 if (uses_ppapi) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 331
330 if (out_fd == IPC::InvalidPlatformFileForTransit()) { 332 if (out_fd == IPC::InvalidPlatformFileForTransit()) {
331 return base::kInvalidPlatformFileValue; 333 return base::kInvalidPlatformFileValue;
332 } 334 }
333 335
334 base::PlatformFile handle = 336 base::PlatformFile handle =
335 IPC::PlatformFileForTransitToPlatformFile(out_fd); 337 IPC::PlatformFileForTransitToPlatformFile(out_fd);
336 return handle; 338 return handle;
337 } 339 }
338 340
341 WebKit::WebString EventTypeToString(PP_NaClEventType event_type) {
342 switch (event_type) {
343 case PP_NACL_EVENT_LOADSTART:
344 return WebKit::WebString::fromUTF8("loadstart");
345 case PP_NACL_EVENT_PROGRESS:
346 return WebKit::WebString::fromUTF8("progress");
347 case PP_NACL_EVENT_ERROR:
348 return WebKit::WebString::fromUTF8("error");
349 case PP_NACL_EVENT_ABORT:
350 return WebKit::WebString::fromUTF8("abort");
351 case PP_NACL_EVENT_LOAD:
352 return WebKit::WebString::fromUTF8("load");
353 case PP_NACL_EVENT_LOADEND:
354 return WebKit::WebString::fromUTF8("loadend");
355 case PP_NACL_EVENT_CRASH:
356 return WebKit::WebString::fromUTF8("crash");
357 }
358 NOTIMPLEMENTED();
359 return WebKit::WebString();
360 }
361
362 void DispatchEvent(PP_Instance instance,
363 PP_NaClEventType event_type,
364 struct PP_Var resource_url,
365 PP_Bool length_is_computable,
366 uint64_t loaded_bytes,
367 uint64_t total_bytes) {
368 content::PepperPluginInstance* plugin_instance =
369 content::PepperPluginInstance::Get(instance);
370 if (!plugin_instance) {
371 NOTREACHED();
372 return;
373 }
374 WebKit::WebPluginContainer* container = plugin_instance->GetContainer();
375 // It's possible that container() is NULL if the plugin has been removed from
376 // the DOM (but the PluginInstance is not destroyed yet).
377 if (!container)
378 return;
379 WebKit::WebFrame* frame = container->element().document().frame();
380 if (!frame)
381 return;
382 v8::HandleScope handle_scope(plugin_instance->GetIsolate());
383 v8::Local<v8::Context> context(
384 plugin_instance->GetIsolate()->GetCurrentContext());
385 if (context.IsEmpty()) {
386 // If there's no JavaScript on the stack, we have to make a new Context.
387 context = v8::Context::New(plugin_instance->GetIsolate());
388 }
389 v8::Context::Scope context_scope(context);
390
391 ppapi::StringVar* url_var = ppapi::StringVar::FromPPVar(resource_url);
392 if (url_var) {
393 WebKit::WebString url_string = WebKit::WebString::fromUTF8(
394 url_var->value().data(), url_var->value().size());
395 WebKit::WebDOMResourceProgressEvent event(EventTypeToString(event_type),
396 PP_ToBool(length_is_computable),
397 loaded_bytes,
398 total_bytes,
399 url_string);
400 container->element().dispatchEvent(event);
401 } else {
402 WebKit::WebDOMProgressEvent event(EventTypeToString(event_type),
403 PP_ToBool(length_is_computable),
404 loaded_bytes,
405 total_bytes);
406 container->element().dispatchEvent(event);
407 }
408 }
409
339 const PPB_NaCl_Private nacl_interface = { 410 const PPB_NaCl_Private nacl_interface = {
340 &LaunchSelLdr, 411 &LaunchSelLdr,
341 &StartPpapiProxy, 412 &StartPpapiProxy,
342 &UrandomFD, 413 &UrandomFD,
343 &Are3DInterfacesDisabled, 414 &Are3DInterfacesDisabled,
344 &BrokerDuplicateHandle, 415 &BrokerDuplicateHandle,
345 &GetReadonlyPnaclFD, 416 &GetReadonlyPnaclFD,
346 &CreateTemporaryFile, 417 &CreateTemporaryFile,
347 &GetNexeFd, 418 &GetNexeFd,
348 &ReportTranslationFinished, 419 &ReportTranslationFinished,
349 &IsOffTheRecord, 420 &IsOffTheRecord,
350 &ReportNaClError, 421 &ReportNaClError,
351 &OpenNaClExecutable 422 &OpenNaClExecutable,
423 &DispatchEvent
352 }; 424 };
353 425
354 } // namespace 426 } // namespace
355 427
356 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { 428 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() {
357 return &nacl_interface; 429 return &nacl_interface;
358 } 430 }
359 431
360 #endif // DISABLE_NACL 432 #endif // DISABLE_NACL
OLDNEW
« 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