Implement lastModified in Linux native handler

This commit is contained in:
Kevin Sawicki
2012-08-22 15:56:08 -07:00
parent d665b39db7
commit 29b0b9c10c
2 changed files with 18 additions and 1 deletions

View File

@@ -58,7 +58,7 @@ NativeHandler::NativeHandler() :
"open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard",
"showDevTools", "newWindow", "saveDialog", "exit", "watchPath",
"unwatchPath", "makeDirectory", "move", "moveToTrash", "md5ForPath",
"getPlatform" };
"getPlatform", "lastModified" };
int arrayLength = sizeof(functionNames) / sizeof(const char *);
for (int i = 0; i < arrayLength; i++) {
const char *functionName = functionNames[i];
@@ -471,6 +471,17 @@ void NativeHandler::Digest(const CefString& name, CefRefPtr<CefV8Value> object,
retval = CefV8Value::CreateString(md5.str());
}
void NativeHandler::LastModified(const CefString& name,
CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval, CefString& exception) {
string path = arguments[0]->GetStringValue().ToString();
struct stat statInfo;
if (stat(path.c_str(), &statInfo) == 0) {
CefTime time(statInfo.st_mtime);
retval = CefV8Value::CreateDate(time);
}
}
bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exception) {
@@ -516,6 +527,8 @@ bool NativeHandler::Execute(const CefString& name, CefRefPtr<CefV8Value> object,
Digest(name, object, arguments, retval, exception);
else if (name == "getPlatform")
retval = CefV8Value::CreateString("linux");
else if (name == "lastModified")
LastModified(name, object, arguments, retval, exception);
else
cout << "Unhandled -> " + name.ToString() << " : "
<< arguments[0]->GetStringValue().ToString() << endl;

View File

@@ -121,6 +121,10 @@ private:
void Digest(const CefString& name, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exception);
void LastModified(const CefString& name, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
CefString& exception);
};
#endif