var types_ = validator_.Types;
var native_ = new xwalk.utils.NativeManager(extension);
+/*
+ * Create new array-like object of numbers: UTF-16 char codes from string.
+ * As type pass Array, Uint8Array, etc.
+ * Useful for passing data through crosswalk.
+ */
+function StringToArray(str, type) {
+ var len = str.length;
+ var output = new type(len);
+ for (var i = 0; i < len; i++) {
+ output[i] = str.charCodeAt(i);
+ }
+ return output;
+}
+
+/*
+ * Pass array-like object of numbers (Array, Uint8Array, etc.), returns string.
+ * Each char has codepoint equal to value from array cropped with & 0xFF
+ * Useful for passing data through crosswalk.
+ */
+function ArrayToString(data) {
+ var output = '';
+ var len = data.length;
+ for (var i = 0; i < len; i++) {
+ output += String.fromCharCode(data[i] & 0xFF); // conversion to octet
+ }
+ return output;
+}
+
function SetReadOnlyProperty(obj, n, v) {
- Object.defineProperty(obj, n, {
- value: v,
- writable: false
- });
+ Object.defineProperty(obj, n, {value: v, writable: false});
}
-var FileSystemStorageType = {
- INTERNAL: 'INTERNAL',
- EXTERNAL: 'EXTERNAL'
-};
+var FileSystemStorageType = {INTERNAL: 'INTERNAL', EXTERNAL: 'EXTERNAL'};
var FileSystemStorageState = {
MOUNTED: 'MOUNTED',
UNMOUNTABLE: 'UNMOUNTABLE'
};
-var FileMode = {
- r: 'r',
- rw: 'rw',
- w: 'w',
- a: 'a'
-};
+var FileMode = {a: 'a', r: 'r', rw: 'rw', rwo: 'rwo', w: 'w'};
+
+var BaseSeekPosition = {BEGIN: 'BEGIN', CURRENT: 'CURRENT', END: 'END'};
-var tizen24home = "/opt/usr/media";
+var tizen24home = '/opt/usr/media';
-//this variable need to match same variable in common/filesystem/filesystem_provider_storage.cc
-var kVirtualRootImages = "images";
+// this variable need to match same variable in
+// common/filesystem/filesystem_provider_storage.cc
+var kVirtualRootImages = 'images';
var commonFS_ = (function() {
var cacheReady = false;
var uriPrefix = 'file://';
// special condition for previous versions paths
// (global paths usage issue workaround)
- var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan("3.0");
+ var isAppForEarlierVersion = privUtils_.isAppVersionEarlierThan('3.0');
var homeDir = undefined;
function clearCache() {
}
var imagesPath = cacheVirtualToReal[kVirtualRootImages].path;
- if (imagesPath[imagesPath.length-1] === "/") {
- homeDir = imagesPath.split("/").slice(0, -2).join("/");
+ if (imagesPath[imagesPath.length - 1] === '/') {
+ homeDir = imagesPath.split('/').slice(0, -2).join('/');
} else {
- homeDir = imagesPath.split("/").slice(0, -1).join("/");
+ homeDir = imagesPath.split('/').slice(0, -1).join('/');
}
}
});
listenerRegistered = true;
} catch (e) {
- privUtils_.log('Failed to register storage change listener, '
- + 'storage information may be corrupted: ' + e.message);
+ privUtils_.log(
+ 'Failed to register storage change listener, ' +
+ 'storage information may be corrupted: ' + e.message);
}
}
}
function removeDotsFromPath(str) {
- if(str === undefined){
- return str;
+ if (str === undefined) {
+ return str;
}
var _pathTokens = str.split('/');
var _fileRealPath = _pathTokens[0];
_correctDir.push(_pathTokens[0]);
for (var i = 1; i < _pathTokens.length; ++i) {
- if(_pathTokens[i] == "..") {
+ if (_pathTokens[i] == '..') {
if (_fileRealPath == '') {
_fileRealPath = undefined;
break;
}
var _lastDir = _correctDir.pop();
- _fileRealPath = _fileRealPath.substring(0, _fileRealPath.length - _lastDir.length - 1);
- } else if(_pathTokens[i] != "."){
+ _fileRealPath =
+ _fileRealPath.substring(0, _fileRealPath.length - _lastDir.length - 1);
+ } else if (_pathTokens[i] != '.') {
_fileRealPath += '/' + _pathTokens[i];
_correctDir.push(_pathTokens[i]);
}
function convertForEarlierVersionPath(aPath) {
if (isAppForEarlierVersion) {
if (aPath && aPath.indexOf(tizen24home) === 0) {
- privUtils_.log("Converting 2.4 style path to 3.0 pattern");
+ privUtils_.log('Converting 2.4 style path to 3.0 pattern');
aPath = homeDir + aPath.substr(tizen24home.length);
}
}
} else {
_fileRealPath = aPath;
}
- // this line makes that '.' and '..' is supported in paths, but each method handle those cases
- // and return error (see commonFS_.checkPathWithoutDots() method)
+ // removeDotsFromPath execution here, results with '.' and '..' beeing supported in
+ // paths, next methods throw an error when getting argument with '.' or '..' in it
+ // (see commonFS_.checkPathWithoutDots() method)
_fileRealPath = removeDotsFromPath(_fileRealPath);
// convert path to be compatibile with previous version of Tizen
// (global paths usage issue workaround)
_result.parent = (secondIter) ? null : _fileParentPath;
} else {
// '/' dir case
- _result.path = _pathTokens[last] + lastToken;;
+ _result.path = _pathTokens[last] + lastToken;
_result.name = '';
_result.parent = (secondIter) ? null : _fileParentPath;
}
}
function toCanonicalPath(path) {
- var result = native_.callSync('FileSystemManager_getCanonicalPath', { "path": path});
+ var result = native_.callSync('FileSystemManager_getCanonicalPath', {'path': path});
if (native_.isFailure(result)) {
throw native_.getErrorObject(result);
}
}
function f_isCorrectRelativePath(relativePath) {
- return ((0 !== relativePath.indexOf('/'))
- && (0 !== relativePath.indexOf('\\'))
- && (-1 === relativePath.indexOf('?'))
- && (-1 === relativePath.indexOf('*'))
- && (-1 === relativePath.indexOf(':'))
- && (-1 === relativePath.indexOf('"'))
- && (-1 === relativePath.indexOf('<')) && (-1 === relativePath
- .indexOf('>')));
+ return (
+ (0 !== relativePath.indexOf('/')) && (0 !== relativePath.indexOf('\\')) &&
+ (-1 === relativePath.indexOf('?')) && (-1 === relativePath.indexOf('*')) &&
+ (-1 === relativePath.indexOf(':')) && (-1 === relativePath.indexOf('"')) &&
+ (-1 === relativePath.indexOf('<')) && (-1 === relativePath.indexOf('>')));
};
function cloneStorage(storage) {
- return {
- label: storage.label,
- type: storage.type,
- state: storage.state
- };
+ return {label: storage.label, type: storage.type, state: storage.state};
}
function getStorage(label) {