-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
138 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resource fileblock modules/ | ||
component {cbea9627-60c0-4718-8545-72a6c3c4b8a3} components/fileBlockService.js | ||
contract @kaply.com/fileblock-service;1 {cbea9627-60c0-4718-8545-72a6c3c4b8a3} | ||
category content-policy policy @kaply.com/fileblock-service;1 | ||
category profile-after-change FileBlock @kaply.com/fileblock-service;1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,56 @@ | ||
var gPathWhitelist = []; | ||
var gExtensionWhitelist = []; | ||
|
||
var gHideAddon = false; | ||
|
||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components; | ||
|
||
Cu.import("resource://gre/modules/Services.jsm"); | ||
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||
|
||
function FileBlock() {} | ||
|
||
FileBlock.prototype = { | ||
appDir: null, | ||
profileDir: null, | ||
tempDir: null, | ||
shouldLoad: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) { | ||
if (!this.appDir) { | ||
this.appDir = Services.io.newFileURI(Services.dirsvc.get("CurProcD", Ci.nsIFile)).spec; | ||
this.profileDir = Services.io.newFileURI(Services.dirsvc.get("ProfD", Ci.nsIFile)).spec; | ||
this.tempDir = Services.io.newFileURI(Services.dirsvc.get("TmpD", Ci.nsIFile)).spec; | ||
var userDir = Services.dirsvc.get("Home", Ci.nsIFile); | ||
for (var i=0; i < gPathWhitelist.length; i++) { | ||
gPathWhitelist[i] = gPathWhitelist[i].replace("~", userDir.path); | ||
} | ||
} | ||
// We need to allow access to any files in the profile directory, | ||
// application directory or the temporary directory. Without these, | ||
// Firefox won't start | ||
if (aContentLocation.spec.match(this.profileDir) || | ||
aContentLocation.spec.match(this.appDir) || | ||
aContentLocation.spec.match(this.tempDir)) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
} | ||
// Deny all files except those on the whitelists | ||
if (aContentLocation.scheme == "file") { | ||
var file = aContentLocation.QueryInterface(Components.interfaces.nsIFileURL).file; | ||
for (var i=0; i< gPathWhitelist.length; i++) { | ||
if (file.path.toLowerCase().indexOf(gPathWhitelist[i].toLowerCase()) == 0) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
} | ||
} | ||
for (var i=0; i< gExtensionWhitelist.length; i++) { | ||
var filename = file.leafName.toLowerCase(); | ||
var extension = "." + gExtensionWhitelist[i].toLowerCase(); | ||
if (filename.indexOf(extension, filename.length - extension.length) !== -1) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
} | ||
} | ||
return Ci.nsIContentPolicy.REJECT_REQUEST; | ||
} | ||
// Allow everything else | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
}, | ||
shouldProcess: function(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
}, | ||
observe: function(aSubject, aTopic, aData) { | ||
switch(aTopic) { | ||
case "profile-after-change": | ||
Services.obs.addObserver(documentObserver, "chrome-document-global-created", false); | ||
Services.obs.addObserver(FileBlock, "profile-before-change", false); | ||
break; | ||
case "profile-before-change": | ||
Services.obs.removeObserver(FileBlock, "profile-before-change", false); | ||
Services.obs.removeObserver(documentObserver, "chrome-document-global-created", false); | ||
break; | ||
} | ||
}, | ||
classDescription: "FileBlock Service", | ||
contractID: "@kaply.com/fileblock-service;1", | ||
classID: Components.ID('{cbea9627-60c0-4718-8545-72a6c3c4b8a3}'), | ||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIObserver]) | ||
} | ||
|
||
var documentObserver = { | ||
observe: function(aSubject, aTopic, aData) { | ||
switch(aTopic) { | ||
case "chrome-document-global-created": | ||
if (!(aSubject instanceof Ci.nsIDOMWindow)) { | ||
return; | ||
} | ||
var win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); | ||
win.addEventListener("load", function(event) { | ||
win.removeEventListener("load", arguments.callee, false); | ||
var doc = event.target; | ||
var url = doc.location.href.split("?")[0].split("#")[0]; | ||
switch (url) { | ||
case "chrome://browser/content/browser.xul": | ||
try { | ||
doc.getElementById("menu_openFile").hidden = true; | ||
} catch (e) {} | ||
try { | ||
doc.getElementById("appmenu_openFile").hidden = true; | ||
} catch (e) {} | ||
try { | ||
var keyset = doc.getElementById("openFileKb").removeAttribute("command"); | ||
} catch (e) {} | ||
try { | ||
Components.utils.import("resource:///modules/CustomizableUI.jsm"); | ||
CustomizableUI.destroyWidget("open-file-button") | ||
} catch (e) {} | ||
break; | ||
case "chrome://mozapps/content/extensions/extensions.xul": | ||
case "about:addons": | ||
if (!gHideAddon) { | ||
return; | ||
} | ||
try { | ||
doc.querySelector("richlistitem[value='fileblock@kaply.com']").hidden = true; | ||
} catch (e) {} | ||
win.addEventListener("ViewChanged", function() { | ||
try { | ||
doc.querySelector("richlistitem[value='fileblock@kaply.com']").hidden = true; | ||
} catch (e) {} | ||
} , false) | ||
} | ||
}, false); | ||
} | ||
} | ||
} | ||
|
||
if (XPCOMUtils.generateNSGetFactory) { | ||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([FileBlock]); | ||
} else { | ||
var NSGetModule = XPCOMUtils.generateNSGetModule([FileBlock]); | ||
} | ||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components; | ||
|
||
Cu.import("resource://gre/modules/Services.jsm"); | ||
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||
|
||
function FileBlock() {} | ||
|
||
FileBlock.prototype = { | ||
observe: function(aSubject, aTopic, aData) { | ||
switch(aTopic) { | ||
case "profile-after-change": | ||
Services.ppmm.loadProcessScript("resource://fileblock/fileBlockModule.js", true); | ||
Services.obs.addObserver(FileBlock, "profile-before-change", false); | ||
Services.obs.addObserver(documentObserver, "browser-window-before-show", false); | ||
break; | ||
case "profile-before-change": | ||
Services.obs.removeObserver(FileBlock, "profile-before-change", false); | ||
Services.obs.removeObserver(documentObserver, "browser-window-before-show", false); | ||
break; | ||
} | ||
}, | ||
classDescription: "FileBlock Service", | ||
contractID: "@kaply.com/fileblock-service;1", | ||
classID: Components.ID('{cbea9627-60c0-4718-8545-72a6c3c4b8a3}'), | ||
QueryInterface: ("generateQI" in XPCOMUtils) ? XPCOMUtils.generateQI([Ci.nsIObserver]) : ChromeUtils.generateQI([Ci.nsIObserver]), | ||
} | ||
|
||
var documentObserver = { | ||
observe: function(aSubject, aTopic, aData) { | ||
switch(aTopic) { | ||
case "browser-window-before-show": | ||
var win = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); | ||
let doc = win.document; | ||
try { | ||
doc.getElementById("menu_openFile").hidden = true; | ||
} catch (e) {} | ||
try { | ||
doc.getElementById("appMenu-open-file-button").hidden = true; | ||
} catch (e) {} | ||
try { | ||
var keyset = doc.getElementById("openFileKb").removeAttribute("command"); | ||
} catch (e) {} | ||
try { | ||
Components.utils.import("resource:///modules/CustomizableUI.jsm"); | ||
CustomizableUI.destroyWidget("open-file-button") | ||
} catch (e) {} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (XPCOMUtils.generateNSGetFactory) { | ||
var NSGetFactory = XPCOMUtils.generateNSGetFactory([FileBlock]); | ||
} else { | ||
var NSGetModule = XPCOMUtils.generateNSGetModule([FileBlock]); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components; | ||
|
||
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | ||
Cu.import("resource://gre/modules/Services.jsm"); | ||
Cu.import('resource://gre/modules/Timer.jsm'); | ||
|
||
let LocalFileBlockPolicy = { | ||
appDir: null, | ||
profileDir: null, | ||
tempDir: null, | ||
fileExtensionsBlackList: [], | ||
shouldLoad(contentLocation, loadInfo, mimeTypeGuess) { | ||
if (!this.appDir) { | ||
try { | ||
this.appDir = Services.io.newFileURI(Services.dirsvc.get("CurProcD", Ci.nsIFile)).spec; | ||
} catch (e) {} | ||
} | ||
if (!this.profileDir) { | ||
try { | ||
this.profileDir = Services.io.newFileURI(Services.dirsvc.get("ProfD", Ci.nsIFile)).spec; | ||
} catch (e) {} | ||
} | ||
if (!this.tempDir) { | ||
try { | ||
this.tempDir = Services.io.newFileURI(Services.dirsvc.get("TmpD", Ci.nsIFile)).spec; | ||
} catch (e) {} | ||
} | ||
if (!this.fileExtensionsBlackList.length) { | ||
try { | ||
this.fileExtensionsBlackList = Services.prefs.getCharPref("fileExtensions.blacklist").split(","); | ||
} catch (e) {} | ||
} | ||
// We need to allow access to any files in the profile directory, | ||
// application directory or the temporary directory. Without these, | ||
// Firefox won't start | ||
if (contentLocation.spec.match(this.profileDir) || | ||
contentLocation.spec.match(this.appDir) || | ||
contentLocation.spec.match(this.tempDir)) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
} | ||
if (contentLocation.scheme == "file") { | ||
let contentType = loadInfo.externalContentPolicyType; | ||
if (contentType == Ci.nsIContentPolicy.TYPE_DOCUMENT) { | ||
setTimeout(function() { | ||
Services.ww.activeWindow.location.href = "about:blank"; | ||
}, 0); | ||
} | ||
return Ci.nsIContentPolicy.REJECT_REQUEST; | ||
} | ||
try { | ||
// Might not be an nsIURL | ||
if (this.fileExtensionsBlackList.includes(contentLocation.QueryInterface(Ci.nsIURL).fileExtension)) { | ||
return Ci.nsIContentPolicy.REJECT_REQUEST; | ||
} | ||
} catch (e) {} | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
}, | ||
shouldProcess(contentLocation, loadInfo, mimeTypeGuess) { | ||
return Ci.nsIContentPolicy.ACCEPT; | ||
}, | ||
classDescription: "FileBlock Content Service", | ||
contractID: "@kaply.com/fileblock-content-service;1", | ||
classID: Components.ID('{d85791cf-3ae5-45e3-bebe-b567df75c7f4}'), | ||
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentPolicy]), | ||
createInstance(outer, iid) { | ||
return this.QueryInterface(iid); | ||
} | ||
}; | ||
|
||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | ||
registrar.registerFactory(LocalFileBlockPolicy.classID, | ||
LocalFileBlockPolicy.classDescription, | ||
LocalFileBlockPolicy.contractID, | ||
LocalFileBlockPolicy); | ||
|
||
let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager); | ||
cm.addCategoryEntry("content-policy", LocalFileBlockPolicy.contractID, LocalFileBlockPolicy.contractID, false, true); |