@@ -30,31 +30,19 @@ const PDF_CONTENT_TYPE = 'application/pdf';
30
30
const PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX' ;
31
31
const PDF_VIEWER_WEB_PAGE = 'resource://pdf.js/web/viewer.html' ;
32
32
const MAX_DATABASE_LENGTH = 4096 ;
33
- const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}' ;
34
33
35
34
Cu .import ('resource://gre/modules/XPCOMUtils.jsm' );
36
35
Cu .import ('resource://gre/modules/Services.jsm' );
37
36
Cu .import ('resource://gre/modules/NetUtil.jsm' );
38
37
38
+ XPCOMUtils .defineLazyModuleGetter (this , 'PrivateBrowsingUtils' ,
39
+ 'resource://gre/modules/PrivateBrowsingUtils.jsm' );
39
40
40
- let appInfo = Cc ['@mozilla.org/xre/app-info;1' ]
41
- .getService (Ci .nsIXULAppInfo );
42
41
let Svc = {};
43
42
XPCOMUtils .defineLazyServiceGetter (Svc , 'mime' ,
44
43
'@mozilla.org/mime;1' ,
45
44
'nsIMIMEService' );
46
45
47
- let isInPrivateBrowsing ;
48
- if (appInfo .ID === FIREFOX_ID ) {
49
- let privateBrowsing = Cc ['@mozilla.org/privatebrowsing;1' ]
50
- .getService (Ci .nsIPrivateBrowsingService );
51
- isInPrivateBrowsing = function getInPrivateBrowsing () {
52
- return privateBrowsing .privateBrowsingEnabled ;
53
- };
54
- } else {
55
- isInPrivateBrowsing = function () { return false ; };
56
- }
57
-
58
46
function getChromeWindow (domWindow ) {
59
47
var containingBrowser = domWindow .QueryInterface (Ci .nsIInterfaceRequestor )
60
48
.getInterface (Ci .nsIWebNavigation )
@@ -219,6 +207,30 @@ function ChromeActions(domWindow, dataListener) {
219
207
}
220
208
221
209
ChromeActions .prototype = {
210
+ isInPrivateBrowsing : function () {
211
+ let docIsPrivate ;
212
+ try {
213
+ docIsPrivate = PrivateBrowsingUtils .isWindowPrivate (this .domWindow );
214
+ } catch (x ) {
215
+ // unable to use PrivateBrowsingUtils, e.g. FF15
216
+ }
217
+ if (typeof docIsPrivate === 'undefined' ) {
218
+ // per-window Private Browsing is not supported, trying global service
219
+ try {
220
+ let privateBrowsing = Cc ['@mozilla.org/privatebrowsing;1' ]
221
+ .getService (Ci .nsIPrivateBrowsingService );
222
+ docIsPrivate = privateBrowsing .privateBrowsingEnabled ;
223
+ } catch (x ) {
224
+ // unable to get nsIPrivateBrowsingService (e.g. not Firefox)
225
+ docIsPrivate = false ;
226
+ }
227
+ }
228
+ // caching the result
229
+ this .isInPrivateBrowsing = function isInPrivateBrowsingCached () {
230
+ return docIsPrivate ;
231
+ };
232
+ return docIsPrivate ;
233
+ },
222
234
download : function (data , sendResponse ) {
223
235
var originalUrl = data .originalUrl ;
224
236
// The data may not be downloaded so we need just retry getting the pdf with
@@ -231,16 +243,7 @@ ChromeActions.prototype = {
231
243
var frontWindow = Cc ['@mozilla.org/embedcomp/window-watcher;1' ].
232
244
getService (Ci .nsIWindowWatcher ).activeWindow ;
233
245
234
- let docIsPrivate = false ;
235
- try {
236
- docIsPrivate = this .domWindow
237
- .QueryInterface (Ci .nsIInterfaceRequestor )
238
- .getInterface (Ci .nsIWebNavigation )
239
- .QueryInterface (Ci .nsILoadContext )
240
- .usePrivateBrowsing ;
241
- } catch (x ) {
242
- }
243
-
246
+ let docIsPrivate = this .isInPrivateBrowsing ();
244
247
let netChannel = NetUtil .newChannel (blobUri );
245
248
if ('nsIPrivateBrowsingChannel' in Ci &&
246
249
netChannel instanceof Ci .nsIPrivateBrowsingChannel ) {
@@ -289,15 +292,15 @@ ChromeActions.prototype = {
289
292
});
290
293
},
291
294
setDatabase : function (data ) {
292
- if (isInPrivateBrowsing ())
295
+ if (this . isInPrivateBrowsing ())
293
296
return ;
294
297
// Protect against something sending tons of data to setDatabase.
295
298
if (data .length > MAX_DATABASE_LENGTH )
296
299
return ;
297
300
setStringPref (PREF_PREFIX + '.database' , data );
298
301
},
299
302
getDatabase : function () {
300
- if (isInPrivateBrowsing ())
303
+ if (this . isInPrivateBrowsing ())
301
304
return '{}' ;
302
305
return getStringPref (PREF_PREFIX + '.database' , '{}' );
303
306
},
0 commit comments