Question

The Google Chrome Extension javascript API cannot retrieve the content of mime type handlers such as a custom PDF handler. It is necessary to write a NACL plugin to catch the incoming content.

This can be done!

Loading A Native Client Chrome Extension For A Particular MIME Type

I am stuck on the ReadResponseBody part. When loading a document of type application/mu I get this console output from the code below.

========================

Resource interpreted as Document but transferred with MIME type application/mu:
Instance_HandleDocumentLoad(instance(7c2333c9) url_loader(14)) 
load_callback.func(20620) user_data(7c2333c9) flags(0) 
ReadResponseBody returned -1 
load_callback_func(user_data(7c2333c9) result(-3))

========================

ReadResponseBody returning -1 is normal PP_OK_COMPLETIONPENDING because the loading will be reported to the ReadResponseBody callback function.

The ReadResponseBody callback function result -3 is explained in pepper_29/include/ppapi/c/pp_errors.h

========================

/**
* This value indicates failure due to an asynchronous operation being
* interrupted. The most common cause of this error code is destroying a
* resource that still has a callback pending. All callbacks are guaranteed
* to execute, so any callbacks pending on a destroyed resource will be
* issued with PP_ERROR_ABORTED.
*
* If you get an aborted notification that you aren't expecting, check to
* make sure that the resource you're using is still in scope. A common
* mistake is to create a resource on the stack, which will destroy the
* resource as soon as the function returns.
*/
PP_ERROR_ABORTED = -3,

========================

My buffer is not on the stack so I am at a loss as to what to try.

Here is the relevant code.

========================

static char load_document_buffer[8192];

static void load_callback_func(void* user_data, int32_t result)
{
  char msg[256];

  sprintf(msg, "load_callback_func(user_data(%lx) result(%ld))",
      (long)user_data,
      (long)result);
  LogMessage((PP_Instance)user_data, msg);
}

static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
                                          PP_Resource url_loader) {
  char msg[256];

  sprintf(msg, "Instance_HandleDocumentLoad(instance(%lx) url_loader(%ld))",
      (long)instance,
      (long)url_loader
      );
  LogMessage(instance, msg);

  struct PP_CompletionCallback load_callback;
  load_callback.func       = load_callback_func;
  load_callback.user_data  = (void *)instance;
  load_callback.flags      = PP_COMPLETIONCALLBACK_FLAG_NONE;

  sprintf(msg, "load_callback.func(%lx) user_data(%lx) flags(%d)",
      (long)(load_callback.func),
      (long)(load_callback.user_data),
      (long)(load_callback.flags));
  LogMessage(instance, msg);

  load_document_buffer[0] = '\0';
  int32_t rv = ppb_urlloader_interface->ReadResponseBody(
      url_loader,
      load_document_buffer,
      sizeof(load_document_buffer),
      load_callback);

  sprintf(msg, "ReadResponseBody returned %d", rv);
  LogMessage(instance, msg);

  return PP_TRUE;
}
Was it helpful?

Solution

You are using the PPAPI C interface, which requires manual ref-counting. It looks like the URLLoader resource is being destroyed while you are trying to read from it. I think you'll need to AddRef the url_loader resource before you call ReadResponseBody.

See PPB_Core.AddRefResource

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top