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

Side by Side Diff: lib/adblockplus_compat.js

Issue 8893047: adblockplusopera: Fix loading race condition (Closed)
Patch Set: Created Nov. 21, 2012, 3:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of the Adblock Plus extension, 2 * This file is part of the Adblock Plus extension,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 lineBreak: "\n", 141 lineBreak: "\n",
142 142
143 resolveFilePath: function(path) 143 resolveFilePath: function(path)
144 { 144 {
145 return new FakeFile(path); 145 return new FakeFile(path);
146 }, 146 },
147 147
148 readFromFile: function(file, decode, listener, callback, timeLineID) 148 readFromFile: function(file, decode, listener, callback, timeLineID)
149 { 149 {
150 // Fake asynchronous execution 150 var Utils = require("utils").Utils;
151 setTimeout(function() 151 Utils.runAsync(function()
152 { 152 {
153 if ("spec" in file && /^defaults\b/.test(file.spec)) 153 if ("spec" in file && /^defaults\b/.test(file.spec))
154 { 154 {
155 // Code attempts to read the default patterns.ini, we don't have that. 155 // Code attempts to read the default patterns.ini, we don't have that.
156 // Make sure to execute first-run actions instead. 156 // Make sure to execute first-run actions instead.
157 callback(null); 157 callback(null);
158 if (localStorage.currentVersion) 158 if (localStorage.currentVersion)
159 seenDataCorruption = true; 159 seenDataCorruption = true;
160 delete localStorage.currentVersion; 160 delete localStorage.currentVersion;
161 return; 161 return;
162 } 162 }
163 163
164 var path = this._getFilePath(file); 164 var path = this._getFilePath(file);
165 if (!(path in window.localStorage)) 165 if (!(path in window.localStorage))
166 { 166 {
167 callback(new Error("File doesn't exist")) 167 callback(new Error("File doesn't exist"))
168 return; 168 return;
169 } 169 }
170 170
171 var lines = window.localStorage[path].split(/[\r\n]+/); 171 var lines = window.localStorage[path].split(/[\r\n]+/);
172 for (var i = 0; i < lines.length; i++) 172 for (var i = 0; i < lines.length; i++)
173 listener.process(lines[i]); 173 listener.process(lines[i]);
174 listener.process(null); 174 listener.process(null);
175 callback(null); 175 callback(null);
176 }.bind(this), 0); 176 }.bind(this));
177 }, 177 },
178 178
179 writeToFile: function(file, encode, data, callback, timeLineID) 179 writeToFile: function(file, encode, data, callback, timeLineID)
180 { 180 {
181 var path = this._getFilePath(file); 181 var path = this._getFilePath(file);
182 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Da te.now()); 182 this._setFileContents(path, data.join(this.lineBreak) + this.lineBreak, Da te.now());
183 183
184 // Fake asynchronous execution 184 var Utils = require("utils").Utils;
185 setTimeout(callback.bind(null, null), 0); 185 Utils.runAsync(callback, null, null);
186 }, 186 },
187 187
188 copyFile: function(fromFile, toFile, callback) 188 copyFile: function(fromFile, toFile, callback)
189 { 189 {
190 // Simply combine read and write operations 190 // Simply combine read and write operations
191 var data = []; 191 var data = [];
192 this.readFromFile(fromFile, false, { 192 this.readFromFile(fromFile, false, {
193 process: function(line) 193 process: function(line)
194 { 194 {
195 if (line !== null) 195 if (line !== null)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 { 301 {
302 Utils: { 302 Utils: {
303 systemPrincipal: null, 303 systemPrincipal: null,
304 getString: function(id) 304 getString: function(id)
305 { 305 {
306 return id; 306 return id;
307 }, 307 },
308 runAsync: function(callback, thisPtr) 308 runAsync: function(callback, thisPtr)
309 { 309 {
310 var params = Array.prototype.slice.call(arguments, 2); 310 var params = Array.prototype.slice.call(arguments, 2);
311 window.setTimeout(function() 311
312 function invokeCallback()
312 { 313 {
313 callback.apply(thisPtr, params); 314 callback.apply(thisPtr, params);
314 }, 0); 315 }
316
317 if (document.readyState === "complete")
318 window.setTimeout(invokeCallback, 0);
319 else
320 window.addEventListener("load", invokeCallback);
315 }, 321 },
316 get appLocale() 322 get appLocale()
317 { 323 {
318 // Note: navigator.language 324 // Note: navigator.language
319 return window.navigator.browserLanguage; 325 return window.navigator.browserLanguage;
320 }, 326 },
321 generateChecksum: function(lines) 327 generateChecksum: function(lines)
322 { 328 {
323 // We cannot calculate MD5 checksums yet :-( 329 // We cannot calculate MD5 checksums yet :-(
324 return null; 330 return null;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 status: -1, 511 status: -1,
506 notificationCallbacks: {}, 512 notificationCallbacks: {},
507 loadFlags: 0, 513 loadFlags: 0,
508 INHIBIT_CACHING: 0, 514 INHIBIT_CACHING: 0,
509 VALIDATE_ALWAYS: 0, 515 VALIDATE_ALWAYS: 0,
510 QueryInterface: function() 516 QueryInterface: function()
511 { 517 {
512 return this; 518 return this;
513 } 519 }
514 }; 520 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld