Skip to content

Commit b39f0c3

Browse files
committed
Refactors history and how the database is stored
1 parent 9c59437 commit b39f0c3

File tree

7 files changed

+37
-55
lines changed

7 files changed

+37
-55
lines changed

extensions/firefox/bootstrap.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ function getBoolPref(pref, def) {
4343
}
4444
}
4545

46-
function setStringPref(pref, value) {
47-
var str = Cc['@mozilla.org/supports-string;1']
48-
.createInstance(Ci.nsISupportsString);
49-
str.data = value;
50-
Services.prefs.setComplexValue(pref, Ci.nsISupportsString, str);
51-
}
52-
5346
function log(str) {
5447
if (!getBoolPref(EXT_PREFIX + '.pdfBugEnabled', false)) {
5548
return;
@@ -176,9 +169,10 @@ function shutdown(aData, aReason) {
176169
}
177170

178171
function install(aData, aReason) {
172+
// TODO remove after some time -- cleanup of unused preferences
173+
Services.prefs.clearUserPref(EXT_PREFIX + '.database');
179174
}
180175

181176
function uninstall(aData, aReason) {
182-
setStringPref(EXT_PREFIX + '.database', '{}');
183177
}
184178

extensions/firefox/content/PdfJs.jsm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,19 @@ let PdfJs = {
128128
},
129129

130130
_migrate: function migrate() {
131-
const VERSION = 1;
131+
const VERSION = 2;
132132
var currentVersion = getIntPref(PREF_MIGRATION_VERSION, 0);
133133
if (currentVersion >= VERSION) {
134134
return;
135135
}
136136
// Make pdf.js the default pdf viewer on the first migration.
137-
if (currentVersion < 2) {
137+
if (currentVersion < 1) {
138138
this._becomeHandler();
139139
}
140+
if (currentVersion < 2) {
141+
// cleaning up of unused database preference (see #3994)
142+
Services.prefs.clearUserPref(PREF_PREFIX + '.database');
143+
}
140144
Services.prefs.setIntPref(PREF_MIGRATION_VERSION, VERSION);
141145
},
142146

extensions/firefox/content/PdfStreamConverter.jsm

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const PDFJS_EVENT_ID = 'pdf.js.message';
3232
const PDF_CONTENT_TYPE = 'application/pdf';
3333
const PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX';
3434
const PDF_VIEWER_WEB_PAGE = 'resource://pdf.js/web/viewer.html';
35-
const MAX_DATABASE_LENGTH = 4096;
3635
const MAX_NUMBER_OF_PREFS = 50;
3736
const MAX_STRING_PREF_LENGTH = 128;
3837

@@ -295,19 +294,6 @@ ChromeActions.prototype = {
295294
channel.asyncOpen(listener, null);
296295
});
297296
},
298-
setDatabase: function(data) {
299-
if (this.isInPrivateBrowsing())
300-
return;
301-
// Protect against something sending tons of data to setDatabase.
302-
if (data.length > MAX_DATABASE_LENGTH)
303-
return;
304-
setStringPref(PREF_PREFIX + '.database', data);
305-
},
306-
getDatabase: function() {
307-
if (this.isInPrivateBrowsing())
308-
return '{}';
309-
return getStringPref(PREF_PREFIX + '.database', '{}');
310-
},
311297
getLocale: function() {
312298
return getStringPref('general.useragent.locale', 'en-US');
313299
},

web/compatibility.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,23 @@ if (typeof PDFJS === 'undefined') {
537537
}
538538
}
539539
})();
540+
541+
(function checkStorages() {
542+
// Feature test as per http://diveintohtml5.info/storage.html
543+
// The additional localStorage call is to get around a FF quirk, see
544+
// bug #495747 in bugzilla
545+
try {
546+
if ('localStorage' in window && window['localStorage'] !== null) {
547+
return;
548+
}
549+
} catch (e) { }
550+
window.localStorage = {
551+
data: Object.create(null),
552+
getItem: function (key) {
553+
return this.data[key];
554+
},
555+
setItem: function (key, value) {
556+
this.data[key] = value;
557+
}
558+
};
559+
})();

web/preferences.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
/* globals DEFAULT_PREFERENCES, isLocalStorageEnabled, Promise */
17+
/* globals DEFAULT_PREFERENCES, Promise */
1818

1919
'use strict';
2020

@@ -174,19 +174,14 @@ var Preferences = {
174174
//#if !(FIREFOX || MOZCENTRAL || B2G)
175175
Preferences._writeToStorage = function (prefObj) {
176176
return new Promise(function (resolve) {
177-
if (isLocalStorageEnabled) {
178-
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
179-
}
177+
localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
180178
resolve();
181179
});
182180
};
183181

184182
Preferences._readFromStorage = function (prefObj) {
185183
return new Promise(function (resolve) {
186-
var readPrefs;
187-
if (isLocalStorageEnabled) {
188-
readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
189-
}
184+
var readPrefs = JSON.parse(localStorage.getItem('pdfjs.preferences'));
190185
resolve(readPrefs);
191186
});
192187
};

web/ui_utils.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,3 @@ var Cache = function cacheCache(size) {
257257
};
258258
};
259259

260-
//#if !(FIREFOX || MOZCENTRAL || B2G)
261-
var isLocalStorageEnabled = (function isLocalStorageEnabledClosure() {
262-
// Feature test as per http://diveintohtml5.info/storage.html
263-
// The additional localStorage call is to get around a FF quirk, see
264-
// bug #495747 in bugzilla
265-
try {
266-
return ('localStorage' in window && window['localStorage'] !== null &&
267-
localStorage);
268-
} catch (e) {
269-
return false;
270-
}
271-
})();
272-
//#endif

web/view_history.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
/* globals PDFJS, VIEW_HISTORY_MEMORY, isLocalStorageEnabled, Promise */
17+
/* globals PDFJS, VIEW_HISTORY_MEMORY, Promise */
1818

1919
'use strict';
2020

@@ -24,7 +24,7 @@
2424
*
2525
* The way that the view parameters are stored depends on how PDF.js is built,
2626
* for 'node make <flag>' the following cases exist:
27-
* - FIREFOX or MOZCENTRAL - uses about:config.
27+
* - FIREFOX or MOZCENTRAL - uses sessionStorage.
2828
* - B2G - uses asyncStorage.
2929
* - GENERIC or CHROME - uses localStorage, if it is available.
3030
*/
@@ -48,13 +48,11 @@ var ViewHistory = (function ViewHistoryClosure() {
4848
//#endif
4949

5050
//#if FIREFOX || MOZCENTRAL
51-
// resolvePromise(FirefoxCom.requestSync('getDatabase', null));
51+
// resolvePromise(sessionStorage.getItem('pdfjsHistory'));
5252
//#endif
5353

5454
//#if !(FIREFOX || MOZCENTRAL || B2G)
55-
if (isLocalStorageEnabled) {
56-
resolvePromise(localStorage.getItem('database'));
57-
}
55+
resolvePromise(localStorage.getItem('database'));
5856
//#endif
5957
}
6058

@@ -95,13 +93,11 @@ var ViewHistory = (function ViewHistoryClosure() {
9593
//#endif
9694

9795
//#if FIREFOX || MOZCENTRAL
98-
// FirefoxCom.requestSync('setDatabase', database);
96+
// sessionStorage.setItem('pdfjsHistory',database);
9997
//#endif
10098

10199
//#if !(FIREFOX || MOZCENTRAL || B2G)
102-
if (isLocalStorageEnabled) {
103-
localStorage.setItem('database', database);
104-
}
100+
localStorage.setItem('database', database);
105101
//#endif
106102
},
107103

0 commit comments

Comments
 (0)