2012-03-16 22:23:28 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
function ContentPermissionPrompt() {}
|
|
|
|
|
|
|
|
ContentPermissionPrompt.prototype = {
|
|
|
|
|
|
|
|
handleExistingPermission: function handleExistingPermission(request) {
|
2012-07-30 14:58:26 +00:00
|
|
|
let result = Services.perms.testExactPermissionFromPrincipal(request.principal, request.type);
|
2012-03-16 22:23:28 +00:00
|
|
|
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
|
|
|
|
request.allow();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (result == Ci.nsIPermissionManager.DENY_ACTION) {
|
|
|
|
request.cancel();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2012-04-11 17:05:35 +00:00
|
|
|
_id: 0,
|
2012-03-16 22:23:28 +00:00
|
|
|
prompt: function(request) {
|
|
|
|
// returns true if the request was handled
|
|
|
|
if (this.handleExistingPermission(request))
|
|
|
|
return;
|
|
|
|
|
2012-04-11 17:05:35 +00:00
|
|
|
let browser = Services.wm.getMostRecentWindow("navigator:browser");
|
2012-07-13 02:28:19 +00:00
|
|
|
let content = browser.getContentWindow();
|
2012-04-11 17:05:35 +00:00
|
|
|
if (!content)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let requestId = this._id++;
|
|
|
|
content.addEventListener("mozContentEvent", function contentEvent(evt) {
|
|
|
|
if (evt.detail.id != requestId)
|
|
|
|
return;
|
2012-07-13 02:28:19 +00:00
|
|
|
evt.target.removeEventListener(evt.type, contentEvent);
|
2012-04-11 17:05:35 +00:00
|
|
|
|
|
|
|
if (evt.detail.type == "permission-allow") {
|
|
|
|
request.allow();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
request.cancel();
|
|
|
|
});
|
|
|
|
|
2012-07-13 02:28:19 +00:00
|
|
|
let details = {
|
|
|
|
"type": "permission-prompt",
|
|
|
|
"permission": request.type,
|
|
|
|
"id": requestId,
|
2012-07-30 14:58:26 +00:00
|
|
|
"url": request.principal.URI.spec
|
2012-07-13 02:28:19 +00:00
|
|
|
};
|
2012-08-19 19:00:19 +00:00
|
|
|
browser.shell.sendChromeEvent(details);
|
2012-03-16 22:23:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{8c719f03-afe0-4aac-91ff-6c215895d467}"),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt])
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//module initialization
|
|
|
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);
|