NACL:无法在HandleDocumentLoad中使用ReadResponseBody

时间:2013-10-21 20:08:29

标签: google-chrome google-chrome-extension google-nativeclient

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

这可以做到!

Loading A Native Client Chrome Extension For A Particular MIME Type

我被困在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;
}

1 个答案:

答案 0 :(得分:1)

您正在使用PPAPI C接口,该接口需要手动重新计数。当您尝试从中读取时,看起来URLLoader资源正在被销毁。在您致电AddRef之前,我认为您需要ReadResponseBody url_loader资源。

请参阅PPB_Core.AddRefResource