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

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: Use the right Context and Isolate. 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 344
343 if (out_fd == IPC::InvalidPlatformFileForTransit()) { 345 if (out_fd == IPC::InvalidPlatformFileForTransit()) {
344 return base::kInvalidPlatformFileValue; 346 return base::kInvalidPlatformFileValue;
345 } 347 }
346 348
347 base::PlatformFile handle = 349 base::PlatformFile handle =
348 IPC::PlatformFileForTransitToPlatformFile(out_fd); 350 IPC::PlatformFileForTransitToPlatformFile(out_fd);
349 return handle; 351 return handle;
350 } 352 }
351 353
354 WebKit::WebString EventTypeToString(PP_NaClEventType event_type) {
355 switch (event_type) {
356 case PP_NACL_EVENT_LOADSTART:
357 return WebKit::WebString::fromUTF8("loadstart");
358 case PP_NACL_EVENT_PROGRESS:
359 return WebKit::WebString::fromUTF8("progress");
360 case PP_NACL_EVENT_ERROR:
361 return WebKit::WebString::fromUTF8("error");
362 case PP_NACL_EVENT_ABORT:
363 return WebKit::WebString::fromUTF8("abort");
364 case PP_NACL_EVENT_LOAD:
365 return WebKit::WebString::fromUTF8("load");
366 case PP_NACL_EVENT_LOADEND:
367 return WebKit::WebString::fromUTF8("loadend");
368 case PP_NACL_EVENT_CRASH:
369 return WebKit::WebString::fromUTF8("crash");
370 }
371 NOTIMPLEMENTED();
372 return WebKit::WebString();
373 }
374
375 void DispatchEvent(PP_Instance instance,
376 PP_NaClEventType event_type,
377 struct PP_Var resource_url,
378 PP_Bool length_is_computable,
379 uint64_t loaded_bytes,
380 uint64_t total_bytes) {
381 content::PepperPluginInstance* plugin_instance =
382 content::PepperPluginInstance::Get(instance);
383 if (!plugin_instance) {
384 NOTREACHED();
385 return;
386 }
387 WebKit::WebPluginContainer* container = plugin_instance->GetContainer();
388 // It's possible that container() is NULL if the plugin has been removed from
389 // the DOM (but the PluginInstance is not destroyed yet).
390 if (!container)
391 return;
392 WebKit::WebFrame* frame = container->element().document().frame();
teravest1 2013/10/31 18:39:56 Why do you set frame here and check if it's non-NU
dmichael (off chromium) 2013/10/31 20:08:08 Ah, yes, I don't use it :-). This is probably a ba
393 if (!frame)
394 return;
395 v8::HandleScope handle_scope(plugin_instance->GetIsolate());
396 v8::Local<v8::Context> context(
397 plugin_instance->GetIsolate()->GetCurrentContext());
398 if (context.IsEmpty()) {
399 // If there's no JavaScript on the stack, we have to make a new Context.
400 context = v8::Context::New(plugin_instance->GetIsolate());
401 }
402 v8::Context::Scope context_scope(context);
403
404 ppapi::StringVar* url_var = ppapi::StringVar::FromPPVar(resource_url);
405 if (url_var) {
406 WebKit::WebString url_string = WebKit::WebString::fromUTF8(
407 url_var->value().data(), url_var->value().size());
408 WebKit::WebDOMResourceProgressEvent event(EventTypeToString(event_type),
409 PP_ToBool(length_is_computable),
410 loaded_bytes,
411 total_bytes,
412 url_string);
413 container->element().dispatchEvent(event);
414 } else {
415 WebKit::WebDOMProgressEvent event(EventTypeToString(event_type),
416 PP_ToBool(length_is_computable),
417 loaded_bytes,
418 total_bytes);
419 container->element().dispatchEvent(event);
420 }
421 }
422
352 const PPB_NaCl_Private nacl_interface = { 423 const PPB_NaCl_Private nacl_interface = {
353 &LaunchSelLdr, 424 &LaunchSelLdr,
354 &StartPpapiProxy, 425 &StartPpapiProxy,
355 &UrandomFD, 426 &UrandomFD,
356 &Are3DInterfacesDisabled, 427 &Are3DInterfacesDisabled,
357 &BrokerDuplicateHandle, 428 &BrokerDuplicateHandle,
358 &EnsurePnaclInstalled, 429 &EnsurePnaclInstalled,
359 &GetReadonlyPnaclFD, 430 &GetReadonlyPnaclFD,
360 &CreateTemporaryFile, 431 &CreateTemporaryFile,
361 &GetNexeFd, 432 &GetNexeFd,
362 &ReportTranslationFinished, 433 &ReportTranslationFinished,
363 &IsOffTheRecord, 434 &IsOffTheRecord,
364 &ReportNaClError, 435 &ReportNaClError,
365 &OpenNaClExecutable 436 &OpenNaClExecutable,
437 &DispatchEvent
366 }; 438 };
367 439
368 } // namespace 440 } // namespace
369 441
370 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() { 442 const PPB_NaCl_Private* PPB_NaCl_Private_Impl::GetInterface() {
371 return &nacl_interface; 443 return &nacl_interface;
372 } 444 }
373 445
374 #endif // DISABLE_NACL 446 #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