mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 884897 - Add permission check to navigator.push load. r=bz
This commit is contained in:
parent
f682cecd3d
commit
5552b135d1
@ -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)
|
||||
|
@ -283,6 +283,9 @@ public:
|
||||
JSObject* /* unused */);
|
||||
#endif // MOZ_MEDIA_NAVIGATOR
|
||||
|
||||
static bool HasPushNotificationsSupport(JSContext* /* unused */,
|
||||
JSObject* aGlobal);
|
||||
|
||||
nsPIDOMWindow* GetParentObject() const
|
||||
{
|
||||
return GetWindow();
|
||||
|
@ -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",
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user