| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
| 3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
| 4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 // TODO: Parts of this file are identical to ABP/Chrome, these should be split | 7 // TODO: Parts of this file are identical to ABP/Chrome, these should be split |
| 8 // away into a separate file. | 8 // away into a separate file. |
| 9 | 9 |
| 10 // | 10 // |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 }, | 103 }, |
| 104 application: "opera" | 104 application: "opera" |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // | 107 // |
| 108 // IO module: no direct file system access, using FileSystem API | 108 // IO module: no direct file system access, using FileSystem API |
| 109 // | 109 // |
| 110 | 110 |
| 111 require.scopes.io = | 111 require.scopes.io = |
| 112 { | 112 { |
| 113 IO: { | 113 IO: { |
|
Felix Dahlke
2012/10/10 12:11:22
Opening brace not on its own line?
Felix Dahlke
2012/10/11 07:54:28
Nevermind.
| |
| 114 _getFilePath: function(file) | 114 _getFilePath: function(file) |
| 115 { | 115 { |
| 116 if (file instanceof FakeFile) | 116 if (file instanceof FakeFile) |
| 117 return file.path; | 117 return file.path; |
| 118 else if ("spec" in file) | 118 else if ("spec" in file) |
| 119 return file.spec; | 119 return file.spec; |
| 120 | 120 |
| 121 throw new Error("Unexpected file type"); | 121 throw new Error("Unexpected file type"); |
| 122 }, | 122 }, |
| 123 | 123 |
| 124 _setFileContents: function(path, contents, lastModified) | |
| 125 { | |
| 126 window.localStorage[path] = contents; | |
| 127 window.localStorage[path + "/lastModified"] = lastModified || 0; | |
| 128 }, | |
| 129 | |
| 124 lineBreak: "\n", | 130 lineBreak: "\n", |
| 125 | 131 |
| 126 resolveFilePath: function(path) | 132 resolveFilePath: function(path) |
| 127 { | 133 { |
| 128 return new FakeFile(path); | 134 return new FakeFile(path); |
| 129 }, | 135 }, |
| 130 | 136 |
| 131 readFromFile: function(file, decode, listener, callback, timeLineID) | 137 readFromFile: function(file, decode, listener, callback, timeLineID) |
| 132 { | 138 { |
| 133 if ("spec" in file && /^defaults\b/.test(file.spec)) | |
|
Felix Dahlke
2012/10/10 12:11:22
The first check is not necessary, .test(undefined)
Felix Dahlke
2012/10/11 07:54:28
Nevermind.
Wladimir Palant
2012/10/11 09:36:26
Still, I don't feel comfortable running regular ex
| |
| 134 { | |
| 135 // Code attempts to read the default patterns.ini, we don't have that. | |
| 136 // Make sure to execute first-run actions instead. | |
| 137 callback(null); | |
| 138 executeFirstRunActions(); | |
|
Felix Dahlke
2012/10/11 07:54:28
This function cannot be called from here.
| |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 var path = this._getFilePath(file); | |
| 143 if (!(path in window.localStorage)) | |
| 144 { | |
| 145 callback(new Error("File doesn't exist")) | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 var lines = window.localStorage[path].split(/[\r\n]+/); | |
| 150 | |
| 151 // Fake asynchronous execution | 139 // Fake asynchronous execution |
| 152 setTimeout(function() | 140 setTimeout(function() |
| 153 { | 141 { |
| 142 if ("spec" in file && /^defaults\b/.test(file.spec)) | |
| 143 { | |
| 144 // Code attempts to read the default patterns.ini, we don't have that. | |
| 145 // Make sure to execute first-run actions instead. | |
| 146 callback(null); | |
| 147 executeFirstRunActions(); | |
|
Felix Dahlke
2012/10/11 13:10:02
This function cannot be called from here.
| |
| 148 return; | |
| 149 } | |
| 150 | |
| 151 var path = this._getFilePath(file); | |
| 152 if (!(path in window.localStorage)) | |
| 153 { | |
| 154 callback(new Error("File doesn't exist")) | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 var lines = window.localStorage[path].split(/[\r\n]+/); | |
| 154 for (var i = 0; i < lines.length; i++) | 159 for (var i = 0; i < lines.length; i++) |
| 155 listener.process(lines[i]); | 160 listener.process(lines[i]); |
| 156 listener.process(null); | 161 listener.process(null); |
| 157 callback(null); | 162 callback(null); |
| 158 }.bind(this), 0); | 163 }.bind(this), 0); |
| 159 }, | 164 }, |
| 160 | 165 |
| 161 writeToFile: function(file, encode, data, callback, timeLineID) | 166 writeToFile: function(file, encode, data, callback, timeLineID) |
| 162 { | 167 { |
| 163 var path = this._getFilePath(file); | 168 var path = this._getFilePath(file); |
| 164 window.localStorage[path] = data.join("\n") + "\n"; | 169 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Da te.now()); |
|
Felix Dahlke
2012/10/10 12:11:22
Why not use this.lineBreak?
| |
| 165 window.localStorage[path + "/lastModified"] = Date.now(); | |
| 166 | 170 |
| 167 // Fake asynchronous execution | 171 // Fake asynchronous execution |
| 168 setTimeout(callback.bind(null, null), 0); | 172 setTimeout(callback.bind(null, null), 0); |
| 169 }, | 173 }, |
| 170 | 174 |
| 171 copyFile: function(fromFile, toFile, callback) | 175 copyFile: function(fromFile, toFile, callback) |
| 172 { | 176 { |
| 173 // Simply combine read and write operations | 177 // Simply combine read and write operations |
| 174 var data = []; | 178 var data = []; |
| 175 this.readFromFile(fromFile, false, { | 179 this.readFromFile(fromFile, false, { |
|
Felix Dahlke
2012/10/10 12:11:22
Shouldn't the opening brace be on its own line?
| |
| 176 process: function(line) | 180 process: function(line) |
| 177 { | 181 { |
| 178 if (line !== null) | 182 if (line !== null) |
| 179 data.push(line); | 183 data.push(line); |
| 180 } | 184 } |
| 181 }, function(e) | 185 }, function(e) |
| 182 { | 186 { |
| 183 if (e) | 187 if (e) |
| 184 callback(e); | 188 callback(e); |
| 185 else | 189 else |
| 186 this.writeToFile(toFile, false, data, callback); | 190 this.writeToFile(toFile, false, data, callback); |
| 187 }.bind(this)); | 191 }.bind(this)); |
| 188 }, | 192 }, |
| 189 | 193 |
| 190 renameFile: function(fromFile, newName, callback) | 194 renameFile: function(fromFile, newName, callback) |
| 191 { | 195 { |
| 192 var path = this._getFilePath(fromFile); | 196 var path = this._getFilePath(fromFile); |
| 193 if (!(path in window.localStorage)) | 197 if (!(path in window.localStorage)) |
| 194 { | 198 { |
| 195 callback(new Error("File doesn't exist")) | 199 callback(new Error("File doesn't exist")) |
| 196 return; | 200 return; |
| 197 } | 201 } |
| 198 | 202 |
| 199 window.localStorage[newName] = window.localStorage[path]; | 203 this._setFileContents(newName, window.localStorage[path], window.localStor age[path + "/lastModified"]); |
| 200 window.localStorage[newName + "/lastModified"] = window.localStorage[path + "/lastModified"] || 0; | 204 this.removeFile(fromFile, callback); |
|
Felix Dahlke
2012/10/10 12:11:22
How about a function that sets both localStorage[x
| |
| 201 delete window.localStorage[path]; | |
| 202 delete window.localStorage[path + "/lastModified"]; | |
| 203 callback(null); | |
| 204 }, | 205 }, |
| 205 | 206 |
| 206 removeFile: function(file, callback) | 207 removeFile: function(file, callback) |
| 207 { | 208 { |
| 208 var path = this._getFilePath(file); | 209 var path = this._getFilePath(file); |
| 209 delete window.localStorage[path]; | 210 delete window.localStorage[path]; |
|
Felix Dahlke
2012/10/10 12:11:22
How about a function to delete both localStorage[x
| |
| 210 delete window.localStorage[path + "/lastModified"]; | 211 delete window.localStorage[path + "/lastModified"]; |
| 211 callback(null); | 212 callback(null); |
| 212 }, | 213 }, |
| 213 | 214 |
| 214 statFile: function(file, callback) | 215 statFile: function(file, callback) |
| 215 { | 216 { |
| 216 var path = this._getFilePath(file); | 217 var path = this._getFilePath(file); |
| 217 callback(null, { | 218 callback(null, { |
| 218 exists: path in window.localStorage, | 219 exists: path in window.localStorage, |
| 219 isDirectory: false, | 220 isDirectory: false, |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 status: -1, | 492 status: -1, |
| 492 notificationCallbacks: {}, | 493 notificationCallbacks: {}, |
| 493 loadFlags: 0, | 494 loadFlags: 0, |
| 494 INHIBIT_CACHING: 0, | 495 INHIBIT_CACHING: 0, |
| 495 VALIDATE_ALWAYS: 0, | 496 VALIDATE_ALWAYS: 0, |
| 496 QueryInterface: function() | 497 QueryInterface: function() |
| 497 { | 498 { |
| 498 return this; | 499 return this; |
| 499 } | 500 } |
| 500 }; | 501 }; |
| LEFT | RIGHT |