Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Refactors private browsing logic #2481

Merged
merged 1 commit into from

4 participants

@yurydelendik

Followup on #2471

@yurydelendik

/botio-windows lint
/botio-linux preview

@pdfjsbot
Collaborator

From: Bot.io (Windows)


Received

Command cmd_lint from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/0225919d4587bdd/output.txt

@pdfjsbot
Collaborator

From: Bot.io (Linux)


Received

Command cmd_preview from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/61d9c60b45ce27c/output.txt

@pdfjsbot
Collaborator

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/0225919d4587bdd/output.txt

Total script time: 1.26 mins

  • Lint: Passed
extensions/firefox/components/PdfStreamConverter.js
@@ -219,6 +205,34 @@ function ChromeActions(domWindow, dataListener) {
}
ChromeActions.prototype = {
+ isInPrivateBrowsing: function() {
+ let docIsPrivate;
+ try {
+ docIsPrivate = this.domWindow
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsILoadContext)
+ .usePrivateBrowsing;
+ } catch (x) {
+ // unable to get nsILoadContext
+ }
+ if (typeof docIsPrivate === 'undefined') {
@ehsan
ehsan added a note

The usePrivateBrowsing attribute has been supported for quite a while, and it's currently supported in Firefox 17 (release), Aurora, Beta and Nightly (it was introduced in Firefox 13). In builds without per-window private browsing support (anything less than Firefox 20) this value is kept in sync with nsIPrivateBrowsingService.privateBrowsingEnabled, which means that you can just drop this whole if block and everything will work correctly in both types of builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
extensions/firefox/components/PdfStreamConverter.js
@@ -219,6 +205,34 @@ function ChromeActions(domWindow, dataListener) {
}
ChromeActions.prototype = {
+ isInPrivateBrowsing: function() {
+ let docIsPrivate;
+ try {
+ docIsPrivate = this.domWindow
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIWebNavigation)
+ .QueryInterface(Ci.nsILoadContext)
+ .usePrivateBrowsing;
@ehsan
ehsan added a note

Please use PrivateBrowsingUtils.isWindowPrivate instead of using the usePrivateBrowsing attribute directly. See http://mxr.mozilla.org/mozilla-central/source/toolkit/content/PrivateBrowsingUtils.jsm. Basically this needs to look like:

let docIsPrivate = PrivateBrowsingUtils.isWindowPrivate(this.domWindow);

Also, no need for the try/catch block as nothing here can throw as long as this.domWindow is really a DOM window object.

@yurydelendik Owner

This code is also running in the pdf.js add-on and we are trying to support Firefox 10ESR and other things that are using Gecko (e.g. Seamonkey) for now. We will be keeping the try/catch-es -- I added related comments in case if somebody decide to cleanup later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ehsan

I commented on the patch, but this is basically on the right track. Thanks!

@yurydelendik

/botio-linux preview
/botio-windows lint

@pdfjsbot
Collaborator

From: Bot.io (Windows)


Received

Command cmd_lint from @yurydelendik received. Current queue size: 0

Live output at: http://107.22.172.223:8877/4f81aa84ae51e9a/output.txt

@pdfjsbot
Collaborator

From: Bot.io (Linux)


Received

Command cmd_preview from @yurydelendik received. Current queue size: 0

Live output at: http://107.21.233.14:8877/d5fe5372dd0df74/output.txt

@pdfjsbot
Collaborator

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/4f81aa84ae51e9a/output.txt

Total script time: 1.22 mins

  • Lint: Passed
@brendandahl brendandahl merged commit 4b4601d into mozilla:master
@ehsan

How can we get this landed on m-c? Is it OK if I just port this patch on m-c while we're waiting for the next pdf.js merge?

@ehsan

(I submitted #2498 to address my comments here).

@brendandahl
Owner

@ehsan I pinged Ryan VanderMeulen and he plans to update pdf.js before the next uplift date.

@yurydelendik yurydelendik deleted the yurydelendik:rm-global-pb branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2012
  1. @yurydelendik
This page is out of date. Refresh to see the latest.
Showing with 29 additions and 26 deletions.
  1. +29 −26 extensions/firefox/components/PdfStreamConverter.js
View
55 extensions/firefox/components/PdfStreamConverter.js
@@ -30,31 +30,19 @@ const PDF_CONTENT_TYPE = 'application/pdf';
const PREF_PREFIX = 'PDFJSSCRIPT_PREF_PREFIX';
const PDF_VIEWER_WEB_PAGE = 'resource://pdf.js/web/viewer.html';
const MAX_DATABASE_LENGTH = 4096;
-const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}';
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/NetUtil.jsm');
+XPCOMUtils.defineLazyModuleGetter(this, 'PrivateBrowsingUtils',
+ 'resource://gre/modules/PrivateBrowsingUtils.jsm');
-let appInfo = Cc['@mozilla.org/xre/app-info;1']
- .getService(Ci.nsIXULAppInfo);
let Svc = {};
XPCOMUtils.defineLazyServiceGetter(Svc, 'mime',
'@mozilla.org/mime;1',
'nsIMIMEService');
-let isInPrivateBrowsing;
-if (appInfo.ID === FIREFOX_ID) {
- let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
- .getService(Ci.nsIPrivateBrowsingService);
- isInPrivateBrowsing = function getInPrivateBrowsing() {
- return privateBrowsing.privateBrowsingEnabled;
- };
-} else {
- isInPrivateBrowsing = function() { return false; };
-}
-
function getChromeWindow(domWindow) {
var containingBrowser = domWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
@@ -219,6 +207,30 @@ function ChromeActions(domWindow, dataListener) {
}
ChromeActions.prototype = {
+ isInPrivateBrowsing: function() {
+ let docIsPrivate;
+ try {
+ docIsPrivate = PrivateBrowsingUtils.isWindowPrivate(this.domWindow);
+ } catch (x) {
+ // unable to use PrivateBrowsingUtils, e.g. FF15
+ }
+ if (typeof docIsPrivate === 'undefined') {
+ // per-window Private Browsing is not supported, trying global service
+ try {
+ let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
+ .getService(Ci.nsIPrivateBrowsingService);
+ docIsPrivate = privateBrowsing.privateBrowsingEnabled;
+ } catch (x) {
+ // unable to get nsIPrivateBrowsingService (e.g. not Firefox)
+ docIsPrivate = false;
+ }
+ }
+ // caching the result
+ this.isInPrivateBrowsing = function isInPrivateBrowsingCached() {
+ return docIsPrivate;
+ };
+ return docIsPrivate;
+ },
download: function(data, sendResponse) {
var originalUrl = data.originalUrl;
// The data may not be downloaded so we need just retry getting the pdf with
@@ -231,16 +243,7 @@ ChromeActions.prototype = {
var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1'].
getService(Ci.nsIWindowWatcher).activeWindow;
- let docIsPrivate = false;
- try {
- docIsPrivate = this.domWindow
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIWebNavigation)
- .QueryInterface(Ci.nsILoadContext)
- .usePrivateBrowsing;
- } catch (x) {
- }
-
+ let docIsPrivate = this.isInPrivateBrowsing();
let netChannel = NetUtil.newChannel(blobUri);
if ('nsIPrivateBrowsingChannel' in Ci &&
netChannel instanceof Ci.nsIPrivateBrowsingChannel) {
@@ -289,7 +292,7 @@ ChromeActions.prototype = {
});
},
setDatabase: function(data) {
- if (isInPrivateBrowsing())
+ if (this.isInPrivateBrowsing())
return;
// Protect against something sending tons of data to setDatabase.
if (data.length > MAX_DATABASE_LENGTH)
@@ -297,7 +300,7 @@ ChromeActions.prototype = {
setStringPref(PREF_PREFIX + '.database', data);
},
getDatabase: function() {
- if (isInPrivateBrowsing())
+ if (this.isInPrivateBrowsing())
return '{}';
return getStringPref(PREF_PREFIX + '.database', '{}');
},
Something went wrong with that request. Please try again.