diff options
author | victorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-04 17:33:21 +0000 |
---|---|---|
committer | victorhsieh@chromium.org <victorhsieh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-04 17:33:21 +0000 |
commit | 8bea43f3f9b607adf6b25f92e69e7dbcba6e6992 (patch) | |
tree | 34085b769975e924484c2b658b7cd02523dfaddf /native_client_sdk | |
parent | a38a7b7c1c436c737124be4b6ebc018b6446d7ea (diff) | |
download | chromium_src-8bea43f3f9b607adf6b25f92e69e7dbcba6e6992.zip chromium_src-8bea43f3f9b607adf6b25f92e69e7dbcba6e6992.tar.gz chromium_src-8bea43f3f9b607adf6b25f92e69e7dbcba6e6992.tar.bz2 |
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
Diffstat (limited to 'native_client_sdk')
5 files changed, 56 insertions, 0 deletions
diff --git a/native_client_sdk/src/build_tools/sdk_files.list b/native_client_sdk/src/build_tools/sdk_files.list index f1b01c3..f42e499 100644 --- a/native_client_sdk/src/build_tools/sdk_files.list +++ b/native_client_sdk/src/build_tools/sdk_files.list @@ -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 diff --git a/native_client_sdk/src/examples/api/file_io/example.js b/native_client_sdk/src/examples/api/file_io/example.js index e73f4b9..1183c9c 100644 --- a/native_client_sdk/src/examples/api/file_io/example.js +++ b/native_client_sdk/src/examples/api/file_io/example.js @@ -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); diff --git a/native_client_sdk/src/examples/api/file_io/file_io.cc b/native_client_sdk/src/examples/api/file_io/file_io.cc index 9de72f8..d8e27af 100644 --- a/native_client_sdk/src/examples/api/file_io/file_io.cc +++ b/native_client_sdk/src/examples/api/file_io/file_io.cc @@ -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; diff --git a/native_client_sdk/src/examples/api/file_io/index.html b/native_client_sdk/src/examples/api/file_io/index.html index 7625bd6..7c62ebd 100644 --- a/native_client_sdk/src/examples/api/file_io/index.html +++ b/native_client_sdk/src/examples/api/file_io/index.html @@ -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> diff --git a/native_client_sdk/src/libraries/ppapi_cpp/library.dsc b/native_client_sdk/src/libraries/ppapi_cpp/library.dsc index 2914c92..e6ffb6c 100644 --- a/native_client_sdk/src/libraries/ppapi_cpp/library.dsc +++ b/native_client_sdk/src/libraries/ppapi_cpp/library.dsc @@ -18,6 +18,7 @@ 'audio.cc', 'audio_config.cc', 'core.cc', + 'directory_entry.cc', 'file_io.cc', 'file_ref.cc', 'file_system.cc', |