Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is chrome.fileSystem usable inside google Native Client

Is it possible to use chrome.fileSystem inside NaCl?

Thanks

like image 855
KaBa Avatar asked Apr 23 '15 17:04

KaBa


1 Answers

The chrome.fileSystem API allows you to access the user's local filesystem via a Chrome App. This requires a user to pick a directory to expose to the App.

This filesystem can be passed to the NaCl module and then used with the standard NaCl pp::FileSystem API.

There is an example of this in the NaCl SDK at examples/tutorial/filesystem_passing. You can browse the code for it here.

Here are the important parts: JavaScript:

chrome.fileSystem.chooseEntry({type: 'openDirectory'}, function(entry) {
  if (!entry) {
    // The user cancelled the dialog.
    return;
  }

  // Send the filesystem and the directory path to the NaCl module.
  common.naclModule.postMessage({
    filesystem: entry.filesystem,
    fullPath: entry.fullPath
  });
});

C++:

// Got a message from JavaScript. We're assuming it is a dictionary with
// two elements:
//   {
//     filesystem: <A Filesystem var>,
//     fullPath: <A string>
//   }
pp::VarDictionary var_dict(var_message);
pp::Resource filesystem_resource = var_dict.Get("filesystem").AsResource();
pp::FileSystem filesystem(filesystem_resource);
std::string full_path = var_dict.Get("fullPath").AsString();
std::string save_path = full_path + "/hello_from_nacl.txt";
std::string contents = "Hello, from Native Client!\n";

It's important to note that all paths in this FileSystem must be prefixed with full_path. Any other accesses will fail.

like image 111
binji Avatar answered Nov 15 '22 04:11

binji