aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/chromeapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/chromeapi.js')
-rw-r--r--js/io/system/chromeapi.js377
1 files changed, 189 insertions, 188 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
index 0650385f..e46894d3 100644
--- a/js/io/system/chromeapi.js
+++ b/js/io/system/chromeapi.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -32,9 +33,9 @@ POSSIBILITY OF SUCH DAMAGE.
32//////////////////////////////////////////////////////////////////////// 33////////////////////////////////////////////////////////////////////////
33NOTES: 34NOTES:
34 35
35 The init function starts up the file system API, and a size must be 36 The init function starts up the file system API, and a size must be
36 set, no unlimited available as of now. 37 set, no unlimited available as of now.
37 38
38//////////////////////////////////////////////////////////////////////// 39////////////////////////////////////////////////////////////////////////
39///////////////////////////////////////////////////////////////////// */ 40///////////////////////////////////////////////////////////////////// */
40// 41//
@@ -42,31 +43,31 @@ var Montage = require("montage/core/core").Montage;
42//////////////////////////////////////////////////////////////////////// 43////////////////////////////////////////////////////////////////////////
43// 44//
44exports.ChromeApi = Montage.create(Object.prototype, { 45exports.ChromeApi = Montage.create(Object.prototype, {
45 //////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////
46 //Needs size in MBs for fileSystem init 47 //Needs size in MBs for fileSystem init
47 init: { 48 init: {
48 enumerable: true, 49 enumerable: true,
49 value: function(size) { 50 value: function(size) {
50 // 51 //
51 if (window.webkitRequestFileSystem) { 52 if (window.webkitRequestFileSystem) {
52 //Current way to init Chrome's fileSystem API 53 //Current way to init Chrome's fileSystem API
53 window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) { 54 window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) {
54 //Storing reference to instance 55 //Storing reference to instance
55 this.fileSystem = fs; 56 this.fileSystem = fs;
56 //Dispatching action ready event 57 //Dispatching action ready event
57 var readyEvent = document.createEvent("CustomEvent"); 58 var readyEvent = document.createEvent("CustomEvent");
58 readyEvent.initEvent('ready', true, true); 59 readyEvent.initEvent('ready', true, true);
59 this.dispatchEvent(readyEvent); 60 this.dispatchEvent(readyEvent);
60 //Building data of local Ninja Library 61 //Building data of local Ninja Library
61 this._listNinjaChromeLibrary(); 62 this._listNinjaChromeLibrary();
62 }.bind(this), function (e) {return false}); //Returns false on error (not able to init) 63 }.bind(this), function (e) {return false}); //Returns false on error (not able to init)
63 // 64 //
64 return true; 65 return true;
65 } else { 66 } else {
66 //No fileSystem API 67 //No fileSystem API
67 return false; 68 return false;
68 } 69 }
69 } 70 }
70 }, 71 },
71 //////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////
72 // 73 //
@@ -77,217 +78,217 @@ exports.ChromeApi = Montage.create(Object.prototype, {
77 //////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////
78 // 79 //
79 fileSystem: { 80 fileSystem: {
80 enumerable: false, 81 enumerable: false,
81 get: function() { 82 get: function() {
82 return this._fileSystem; 83 return this._fileSystem;
83 }, 84 },
84 set: function(value) { 85 set: function(value) {
85 this._fileSystem = value; 86 this._fileSystem = value;
86 } 87 }
87 }, 88 },
88 //////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////
89 // 90 //
90 fileNew: { 91 fileNew: {
91 enumerable: true, 92 enumerable: true,
92 value: function(filePath, content, callback) { 93 value: function(filePath, content, callback) {
93 // 94 //
94 this.fileSystem.root.getFile(filePath, {create: true}, function(f) { 95 this.fileSystem.root.getFile(filePath, {create: true}, function(f) {
95 // 96 //
96 f.createWriter(function(writer) { 97 f.createWriter(function(writer) {
97 // 98 //
98 var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.'); 99 var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.');
99 type = type[type.length-1]; 100 type = type[type.length-1];
100 switch (type) { 101 switch (type) {
101 case 'bmp': 102 case 'bmp':
102 mime = 'image/bmp'; 103 mime = 'image/bmp';
103 break; 104 break;
104 case 'gif': 105 case 'gif':
105 mime = 'image/gif'; 106 mime = 'image/gif';
106 break; 107 break;
107 case 'jpeg': 108 case 'jpeg':
108 mime = 'image/jpeg'; 109 mime = 'image/jpeg';
109 break; 110 break;
110 case 'jpg': 111 case 'jpg':
111 mime = 'image/jpeg'; 112 mime = 'image/jpeg';
112 break; 113 break;
113 case 'png': 114 case 'png':
114 mime = 'image/png'; 115 mime = 'image/png';
115 break; 116 break;
116 case 'rtf': 117 case 'rtf':
117 mime = 'application/rtf'; 118 mime = 'application/rtf';
118 break; 119 break;
119 case 'tif': 120 case 'tif':
120 mime = 'image/tiff'; 121 mime = 'image/tiff';
121 break; 122 break;
122 case 'tiff': 123 case 'tiff':
123 mime = 'image/tiff'; 124 mime = 'image/tiff';
124 break; 125 break;
125 case 'pdf': 126 case 'pdf':
126 mime = 'application/pdf'; 127 mime = 'application/pdf';
127 break; 128 break;
128 case 'zip': 129 case 'zip':
129 mime = 'application/zip'; 130 mime = 'application/zip';
130 break; 131 break;
131 case 'svg': 132 case 'svg':
132 mime = 'image/svg+xml'; 133 mime = 'image/svg+xml';
133 break; 134 break;
134 default: 135 default:
135 mime = 'text/'+type; 136 mime = 'text/'+type;
136 break; 137 break;
137 } 138 }
138 // 139 //
139 blob.append(content); 140 blob.append(content);
140 writer.write(blob.getBlob(mime)); 141 writer.write(blob.getBlob(mime));
141 // 142 //
142 if (callback) callback(true); 143 if (callback) callback(true);
143 }, function (e) {if (callback) callback(false)}); 144 }, function (e) {if (callback) callback(false)});
144 }, function (e) {if (callback) callback(false)}); 145 }, function (e) {if (callback) callback(false)});
145 } 146 }
146 }, 147 },
147 //////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////
148 // 149 //
149 fileDelete: { 150 fileDelete: {
150 enumerable: true, 151 enumerable: true,
151 value: function(filePath, callback) { 152 value: function(filePath, callback) {
152 this.fileSystem.root.getFile(filePath, {create: false}, function(file) { 153 this.fileSystem.root.getFile(filePath, {create: false}, function(file) {
153 file.remove(function() { 154 file.remove(function() {