0

Google Chrome 扩展 javascript API 无法检索 mime 类型处理程序的内容,例如自定义 PDF 处理程序。有必要编写一个 NACL 插件来捕获传入的内容。

这是可以做到的!

为特定的 MIME 类型加载本机客户端 Chrome 扩展

我被困在 ReadResponseBody 部分。加载 application/mu 类型的文档时,我从下面的代码中获取此控制台输出。

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

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 返回 -1 是正常的 PP_OK_COMPLETIONPENDING 因为加载将报告给 ReadResponseBody 回调函数。

Pepper_29/include/ppapi/c/pp_errors.h中解释了ReadResponseBody回调函数结果-3

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

/**
* 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,

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

我的缓冲区不在堆栈上,所以我不知道该尝试什么。

这是相关的代码。

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

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;
}
4

1 回答 1

1

您正在使用需要手动引用计数的 PPAPI C 接口。URLLoader当您尝试从中读取资源时,该资源似乎正在被破坏。我认为您AddRef在调用之前需要 url_loader 资源ReadResponseBody

请参阅PPB_Core.AddRefResource

于 2013-10-21T23:32:59.687 回答