KaB*_*aBa 5 google-chrome google-chrome-extension google-nativeclient google-chrome-app
可以在chrome.fileSystem里面使用NaCl吗?
谢谢
小智 6
chrome.fileSystem API允许您通过Chrome应用程序访问用户的本地文件系统.这需要用户选择要向App公开的目录.
该文件系统可以传递给NaCl模块,然后与标准的NaCl pp :: FileSystem API一起使用.
在NaCl SDK中有一个例子examples/tutorial/filesystem_passing.您可以在此处浏览代码.
以下是重要部分: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
});
});
Run Code Online (Sandbox Code Playgroud)
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";
Run Code Online (Sandbox Code Playgroud)
请务必注意,此FileSystem中的所有路径都必须以full_path为前缀.任何其他访问都将失败.
| 归档时间: |
|
| 查看次数: |
189 次 |
| 最近记录: |