Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/websql/io.js

Issue 16067002: Added Safari Support (Closed)
Left Patch Set: Created Nov. 9, 2013, 6:45 p.m.
Right Patch Set: Bugfixes Created Nov. 15, 2013, 8:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/utils.js ('k') | metadata.chrome » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 13 matching lines...) Expand all
24 _db: null, 24 _db: null,
25 lineBreak: "\n", 25 lineBreak: "\n",
26 26
27 _transaction: function(callback) 27 _transaction: function(callback)
28 { 28 {
29 var dbCreated = false; 29 var dbCreated = false;
30 if (!this._db) 30 if (!this._db)
31 this._db = openDatabase("adblockplus", "1.0", "", 102400, function() { dbC reated = true; }); 31 this._db = openDatabase("adblockplus", "1.0", "", 102400, function() { dbC reated = true; });
32 32
33 this._db.transaction(function(tx) 33 this._db.transaction(function(tx)
34 » { 34 {
35 if (dbCreated) 35 if (dbCreated)
36 tx.executeSql("CREATE TABLE files (path unique, last_modified, content)" ); 36 tx.executeSql("CREATE TABLE files (path unique, last_modified, content)" );
37 37
38 callback(tx); 38 callback(tx);
39 }); 39 });
40 }, 40 },
41 _getFilePath: function(file) 41 _getFilePath: function(file)
42 { 42 {
43 if (file instanceof FakeFile) 43 if (file instanceof FakeFile)
44 return file.path; 44 return file.path;
45 if ("spec" in file) 45 if ("spec" in file)
46 return file.spec; 46 return file.spec;
47 47
48 throw new Error("Unexpected file type"); 48 throw new Error("Unexpected file type");
49 }, 49 },
50 resolveFilePath: function(path) 50 resolveFilePath: function(path)
51 { 51 {
52 return new FakeFile(path); 52 return new FakeFile(path);
53 }, 53 },
54 readFromFile: function(file, decode, listener, callback, timeLineID) 54 readFromFile: function(file, decode, listener, callback, timeLineID)
55 { 55 {
56 if ("spec" in file && /^defaults\b/.test(file.spec)) 56 if ("spec" in file && /^defaults\b/.test(file.spec))
57 » { 57 {
58 // Code attempts to read the default patterns.ini, we don't have that. 58 // Code attempts to read the default patterns.ini, we don't have that.
59 // Make sure to execute first-run actions instead. 59 // Make sure to execute first-run actions instead.
60 callback(null); 60 callback(null);
61 if (localStorage.currentVersion) 61 if (localStorage.currentVersion)
62 seenDataCorruption = true; 62 seenDataCorruption = true;
63 delete localStorage.currentVersion; 63 delete localStorage.currentVersion;
64 return; 64 return;
65 } 65 }
66 66
67 var path = this._getFilePath(file); 67 var path = this._getFilePath(file);
68 var runAsync = require("utils").Utils.runAsync; 68 var runAsync = require("utils").Utils.runAsync;
69 69
70 this._transaction(function(tx) 70 this._transaction(function(tx)
71 » { 71 {
72 tx.executeSql( 72 tx.executeSql(
73 "SELECT content FROM files WHERE path = ?", 73 "SELECT content FROM files WHERE path = ?",
74 [path], 74 [path],
75 function(tx, results) 75 function(tx, results)
76 » » { 76 {
77 if (results.rows.length == 0) 77 if (results.rows.length == 0)
78 » » { 78 {
79 runAsync(callback, null, new Error("File doesn't exist")); 79 runAsync(callback, null, new Error("File doesn't exist"));
80 return; 80 return;
81 } 81 }
82 82
83 var lines = results.rows.item(0).content.split(/[\r\n]+/); 83 var lines = results.rows.item(0).content.split(/[\r\n]+/);
84 runAsync(function() 84 runAsync(function()
85 » » { 85 {
86 for (var i = 0; i < lines.length; i++) 86 for (var i = 0; i < lines.length; i++)
87 listener.process(lines[i]); 87 listener.process(lines[i]);
88 listener.process(null); 88 listener.process(null);
89 callback(null); 89 callback(null);
90 }); 90 });
91 } 91 }
92 ); 92 );
93 }); 93 });
94 }, 94 },
95 writeToFile: function(file, encode, data, callback, timeLineID) 95 writeToFile: function(file, encode, data, callback, timeLineID)
96 { 96 {
97 var path = this._getFilePath(file); 97 var path = this._getFilePath(file);
98 var lnbr = this.lineBreak; 98 var lnbr = this.lineBreak;
99 var runAsync = require("utils").Utils.runAsync; 99 var runAsync = require("utils").Utils.runAsync;
100 100
101 this._transaction(function(tx) 101 this._transaction(function(tx)
102 » { 102 {
103 tx.executeSql( 103 tx.executeSql(
104 "INSERT OR REPLACE INTO files VALUES (?, ?, ?)", 104 "INSERT OR REPLACE INTO files VALUES (?, ?, ?)",
105 [path, Date.now(), data.join(lnbr) + lnbr], 105 [path, Date.now(), data.join(lnbr) + lnbr],
106 function() { runAsync(callback, null, null); } 106 function() { runAsync(callback, null, null); }
107 ); 107 );
108 }); 108 });
109 }, 109 },
110 copyFile: function(fromFile, toFile, callback) 110 copyFile: function(fromFile, toFile, callback)
111 { 111 {
112 var fromPath = this._getFilePath(fromFile); 112 var fromPath = this._getFilePath(fromFile);
113 var toPath = this._getFilePath(toFile); 113 var toPath = this._getFilePath(toFile);
114 var runAsync = require("utils").Utils.runAsync; 114 var runAsync = require("utils").Utils.runAsync;
115 115
116 this._transaction(function(tx) 116 this._transaction(function(tx)
117 » { 117 {
118 tx.executeSql( 118 tx.executeSql(
119 "INSERT OR REPLACE INTO files SELECT ?, ?, content FROM files WHERE path = ?", 119 "INSERT OR REPLACE INTO files SELECT ?, ?, content FROM files WHERE path = ?",
120 [toPath, Date.now(), fromPath], 120 [toPath, Date.now(), fromPath],
121 function(tx, results) 121 function(tx, results)
122 » » { 122 {
123 if (results.rowsAffected == 0) 123 if (results.rowsAffected == 0)
124 runAsync(callback, null, new Error("File doesn't exist")); 124 runAsync(callback, null, new Error("File doesn't exist"));
125 else 125 else
126 runAsync(callback, null, null); 126 runAsync(callback, null, null);
127 } 127 }
128 ); 128 );
129 }); 129 });
130 }, 130 },
131 renameFile: function(fromFile, newName, callback) 131 renameFile: function(fromFile, newName, callback)
132 { 132 {
133 var path = this._getFilePath(fromFile); 133 var path = this._getFilePath(fromFile);
134 var runAsync = require("utils").Utils.runAsync; 134 var runAsync = require("utils").Utils.runAsync;
135 135
136 this._transaction(function(tx) 136 this._transaction(function(tx)
137 » { 137 {
138 tx.executeSql( 138 tx.executeSql(
139 "UPDATE files SET path = ? WHERE path = ?", 139 "UPDATE files SET path = ? WHERE path = ?",
140 [newName, path], 140 [newName, path],
141 function(tx, results) 141 function(tx, results)
142 » » { 142 {
143 if (results.rowsAffected == 0) 143 if (results.rowsAffected == 0)
144 runAsync(callback, null, new Error("File doesn't exist")); 144 runAsync(callback, null, new Error("File doesn't exist"));
145 else 145 else
146 runAsync(callback, null, null); 146 runAsync(callback, null, null);
147 } 147 }
148 ); 148 );
149 }); 149 });
150 }, 150 },
151 removeFile: function(file, callback) 151 removeFile: function(file, callback)
152 { 152 {
153 var path = this._getFilePath(file); 153 var path = this._getFilePath(file);
154 var runAsync = require("utils").Utils.runAsync; 154 var runAsync = require("utils").Utils.runAsync;
155 155
156 this._transaction(function(tx) 156 this._transaction(function(tx)
157 » { 157 {
158 tx.executeSql( 158 tx.executeSql(
159 "DELETE FROM files WHERE path = ?", 159 "DELETE FROM files WHERE path = ?",
160 [path], 160 [path],
161 function() { runAsync(callback, null, null); } 161 function() { runAsync(callback, null, null); }
162 ); 162 );
163 }); 163 });
164 }, 164 },
165 statFile: function(file, callback) 165 statFile: function(file, callback)
166 { 166 {
167 var path = this._getFilePath(file); 167 var path = this._getFilePath(file);
168 var runAsync = require("utils").Utils.runAsync; 168 var runAsync = require("utils").Utils.runAsync;
169 169
170 this._transaction(function(tx) 170 this._transaction(function(tx)
171 » { 171 {
172 tx.executeSql( 172 tx.executeSql(
173 "SELECT last_modified FROM files WHERE path = ?", 173 "SELECT last_modified FROM files WHERE path = ?",
174 [path], 174 [path],
175 function(tx, results) 175 function(tx, results)
176 » » { 176 {
177 if (results.rows.length == 0) 177 if (results.rows.length == 0)
178 runAsync(callback, null, null, { 178 runAsync(callback, null, null, {
179 exists: false, 179 exists: false,
180 isDirectory: false, 180 isDirectory: false,
181 isFile: false, 181 isFile: false,
182 lastModified: 0 182 lastModified: 0
183 }); 183 });
184 else 184 else
185 runAsync(callback, null, null, { 185 runAsync(callback, null, null, {
186 exists: true, 186 exists: true,
187 isDirectory: false, 187 isDirectory: false,
188 isFile: true, 188 isFile: true,
189 lastModified: results.rows.item(0).last_modified 189 lastModified: results.rows.item(0).last_modified
190 }); 190 });
191 } 191 }
192 ); 192 );
193 }); 193 });
194 } 194 }
195 }; 195 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld