Skip to content

Commit fd9fde6

Browse files
author
Shawn Gao
committed
Expose real path of Virtual Root (native file system)
Add a function, getRealPath(), to native_file_system object. Developer passes virtual root name to this function and get full path of this virtual root. BUG=XWALK-2455
1 parent ac16f43 commit fd9fde6

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

experimental/native_file_system/native_file_system_api.js

+9
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@ var getDirectoryList = function() {
4444
extension.internal.sendSyncMessage("get");
4545
}
4646

47+
var getRealPath = function(virtual_root) {
48+
var _msg = {
49+
cmd : "getRealPath",
50+
path : virtual_root
51+
}
52+
return extension.internal.sendSyncMessage(_msg);
53+
}
54+
4755
NativeFileSystem.prototype = new Object();
4856
NativeFileSystem.prototype.constructor = NativeFileSystem;
4957
NativeFileSystem.prototype.requestNativeFileSystem = requestNativeFileSystem;
5058
NativeFileSystem.prototype.getDirectoryList = getDirectoryList;
59+
NativeFileSystem.prototype.getRealPath = getRealPath;
5160

5261
exports = new NativeFileSystem();
5362

experimental/native_file_system/native_file_system_extension.cc

+30
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,36 @@ void NativeFileSystemInstance::HandleMessage(scoped_ptr<base::Value> msg) {
9292
checker->DoTask();
9393
}
9494

95+
void NativeFileSystemInstance::HandleSyncMessage(
96+
scoped_ptr<base::Value> msg) {
97+
base::DictionaryValue* dict;
98+
std::string command;
99+
100+
if (!msg->GetAsDictionary(&dict) || !dict->GetString("cmd", &command)) {
101+
LOG(ERROR) << "Fail to handle command sync message.";
102+
SendSyncReplyToJS(scoped_ptr<base::Value>(new base::StringValue("")));
103+
return;
104+
}
105+
106+
scoped_ptr<base::Value> result(new base::StringValue(""));
107+
std::string virtual_root_string = "";
108+
if ("getRealPath" == command &&
109+
dict->GetString("path", &virtual_root_string)) {
110+
std::transform(virtual_root_string.begin(),
111+
virtual_root_string.end(),
112+
virtual_root_string.begin(),
113+
::toupper);
114+
std::string real_path =
115+
VirtualRootProvider::GetInstance()->GetRealPath(
116+
virtual_root_string);
117+
result.reset(new base::StringValue(real_path));
118+
} else {
119+
LOG(ERROR) << command << " ASSERT NOT REACHED.";
120+
}
121+
122+
SendSyncReplyToJS(result.Pass());
123+
}
124+
95125
FileSystemChecker::FileSystemChecker(
96126
int process_id,
97127
const std::string& path,

experimental/native_file_system/native_file_system_extension.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class NativeFileSystemInstance : public XWalkExtensionInstance {
3838

3939
// XWalkExtensionInstance implementation.
4040
virtual void HandleMessage(scoped_ptr<base::Value> msg) OVERRIDE;
41+
virtual void HandleSyncMessage(scoped_ptr<base::Value> msg) OVERRIDE;
4142

4243
private:
4344
XWalkExtensionFunctionHandler handler_;

0 commit comments

Comments
 (0)