Bug 884897 - Add permission check to navigator.push load. r=bz

This commit is contained in:
Nikhil Marathe 2013-08-07 08:04:10 -07:00
parent f682cecd3d
commit 5552b135d1
4 changed files with 14 additions and 18 deletions

View File

@ -1736,6 +1736,14 @@ bool Navigator::HasUserMediaSupport(JSContext* /* unused */,
}
#endif // MOZ_MEDIA_NAVIGATOR
/* static */
bool Navigator::HasPushNotificationsSupport(JSContext* /* unused */,
JSObject* aGlobal)
{
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(aGlobal);
return win && Preferences::GetBool("services.push.enabled", false) && CheckPermission(win, "push");
}
/* static */
already_AddRefed<nsPIDOMWindow>
Navigator::GetWindowFromGlobal(JSObject* aGlobal)

View File

@ -283,6 +283,9 @@ public:
JSObject* /* unused */);
#endif // MOZ_MEDIA_NAVIGATOR
static bool HasPushNotificationsSupport(JSContext* /* unused */,
JSObject* aGlobal);
nsPIDOMWindow* GetParentObject() const
{
return GetWindow();

View File

@ -42,26 +42,11 @@ Push.prototype = {
debug("init()");
let principal = aWindow.document.nodePrincipal;
this._pageURL = principal.URI;
let appsService = Cc["@mozilla.org/AppsService;1"]
.getService(Ci.nsIAppsService);
this._app = appsService.getAppByLocalId(principal.appId);
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
if (!this._manifestURL) {
// Now what? XXXbz should this be tested in a Func for this
// interface so it wouldn't appear at all?
return;
}
let perm = Services.perms.testExactPermissionFromPrincipal(principal,
"push");
if (perm != Ci.nsIPermissionManager.ALLOW_ACTION) {
// Now what? XXXbz should this be tested in a Func for this
// interface so it wouldn't appear at all?
return;
}
this._manifestURL = appsService.getManifestURLByLocalId(principal.appId);
this._pageURL = principal.URI;
this.initDOMRequestHelper(aWindow, [
"PushService:Register:OK",

View File

@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
[NoInterfaceObject, NavigatorProperty="push", JSImplementation="@mozilla.org/push/PushManager;1", Pref="services.push.enabled"]
[NoInterfaceObject, NavigatorProperty="push", JSImplementation="@mozilla.org/push/PushManager;1", Func="Navigator::HasPushNotificationsSupport"]
interface PushManager {
DOMRequest register();
DOMRequest unregister(DOMString pushEndpoint);