Add directory_entry.cc to libppapi_cpp

I believe FileRef::ReadDirectoryEntries is the one depends on it.

BUG=
R=binji@chromium.org, sbc@chromium.org

Review URL: https://codereview.chromium.org/15969018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203995 0039d316-1c4b-4281-b951-d872f2087c98
parent a38a7b7c
......@@ -658,6 +658,7 @@ src/ppapi_cpp/array_output.cc
src/ppapi_cpp/audio.cc
src/ppapi_cpp/audio_config.cc
src/ppapi_cpp/core.cc
src/ppapi_cpp/directory_entry.cc
src/ppapi_cpp/file_io.cc
src/ppapi_cpp/file_ref.cc
src/ppapi_cpp/file_system.cc
......
......@@ -19,6 +19,7 @@ function attachListeners() {
document.getElementById('saveButton').addEventListener('click', saveFile);
document.getElementById('loadButton').addEventListener('click', loadFile);
document.getElementById('deleteButton').addEventListener('click', deleteFile);
document.getElementById('listButton').addEventListener('click', listDir);
}
function loadFile() {
......@@ -55,6 +56,17 @@ function deleteFile() {
}
}
function listDir() {
if (common.naclModule) {
var dirName = document.getElementById('dirName').value;
// Package a message using a simple protocol containing:
// instruction file_name_length file_name
var msg = "ls " + dirName.length + " " + dirName;
common.naclModule.postMessage(msg);
}
}
// Called by the common.js module.
function handleMessage(message_event) {
var messageParts = message_event.data.split("|", 3);
......
......@@ -11,6 +11,7 @@
#include "ppapi/c/pp_stdint.h"
#include "ppapi/c/ppb_file_io.h"
#include "ppapi/cpp/directory_entry.h"
#include "ppapi/cpp/file_io.h"
#include "ppapi/cpp/file_ref.h"
#include "ppapi/cpp/file_system.h"
......@@ -39,6 +40,7 @@ namespace {
const char* const kLoadPrefix = "ld";
const char* const kSavePrefix = "sv";
const char* const kDeletePrefix = "de";
const char* const kListPrefix = "ls";
}
/// The Instance class. One of these exists for each instance of your NaCl
......@@ -133,6 +135,13 @@ class FileIoInstance : public pp::Instance {
callback_factory_.NewCallback(&FileIoInstance::Delete, file_name));
return;
}
if (instruction.compare(kListPrefix) == 0) {
const std::string& dir_name = file_name;
file_thread_.message_loop().PostWork(
callback_factory_.NewCallback(&FileIoInstance::List, dir_name));
return;
}
}
void OpenFileSystem(int32_t /* result */) {
......@@ -267,6 +276,35 @@ class FileIoInstance : public pp::Instance {
ShowStatusMessage("File deleted");
}
void List(int32_t /* result */, const std::string& dir_name) {
if (!file_system_ready_) {
ShowErrorMessage("File system is not open", PP_ERROR_FAILED);
return;
}
pp::FileRef ref(file_system_, dir_name.c_str());
// Pass ref along to keep it alive.
ref.ReadDirectoryEntries(callback_factory_.NewCallbackWithOutput(
&FileIoInstance::ListCallback, ref));
}
void ListCallback(int32_t result,
const std::vector<pp::DirectoryEntry>& entries,
pp::FileRef /* unused_ref */) {
if (result != PP_OK) {
ShowErrorMessage("List failed", result);
return;
}
std::string buffer = "File list:";
for (size_t i = 0; i < entries.size(); ++i) {
pp::Var name = entries[i].file_ref().GetName();
if (name.is_string())
buffer += " " + name.AsString();
}
ShowStatusMessage(buffer);
}
/// Encapsulates our simple javascript communication protocol
void ShowErrorMessage(const std::string& message, int32_t result) {
std::stringstream ss;
......
......@@ -29,6 +29,10 @@
<button id="loadButton" action="">Load</button>
<button id="deleteButton" action="">Delete</button>
<br>Directory Name
<input type="text" id="dirName" action="" value="/">
<button id="listButton" action="">List</button>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
See common.js.-->
<div id="listener"></div>
......
......@@ -18,6 +18,7 @@
'audio.cc',
'audio_config.cc',
'core.cc',
'directory_entry.cc',
'file_io.cc',
'file_ref.cc',
'file_system.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment