Files
palemoon27/dom/permission/Permissions.cpp
T
roytam1 817a8eed36 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1248105 - Move CSSPseudoElement::GetParentObject out of header, r=boris (b851c3806d)
- Bug 1248581 - Fix build bustage on WakeLock.h and CSSPseudoElement.h. r=khuey (fb47a96889)
- Bug 1249230 - Prepend an extra colon to the pseudo type string. r=birtles (6af63f00de)
- fix build on Mac > 10.5 (1ae9402eaf)
- Bug 1241118 - Add gc = GetGeneralCategory(ch) when sc == MOZ_SCRIPT_COMMON. r=jfkthame (51dfbede47)
- minor crash rep (1e7e5bc97e)
- Bug 1240904 - Remove ParamTraits for NPString and NPVariant. r=bsmedberg (1850d10374)
- bug 1170584 - fix PluginMessageUtils on iOS. r=jimm (c624cbe92d)
- Bug 1170343 - Use release-mode asserts when plugins making NPAPI calls on the wrong thread, r=mccr8 (15c71250f4)
- Bug 1239525 - Make sure async plugin initialization is off if e10s is on. r=aklotz (07e73ce74d)
- Bug 1128454 - When plugin bridging fails, propagate the error back to the content process without aborting tabs. r=billm (e1547c00ab)
- Bug 1222169 - remove unused function from PluginProcessChild.cpp; r=aklotz (11a8fc32e1)
- Bug 1239749 - Remove extra space from PermissionSettings.js debug message. r=gwagner (abe2ac7574)
- Bug 1221104 - Revoke 'midi' permission queries with TypeError. r=baku (cce673498f)
- Bug 1221104 - Throw NS_ERROR_NOT_IMPLEMENTED instead of NS_ERROR_UNEXPECTED for PushPermissionDescriptor.userVisible. r=baku (face32ed7b)
- Bug 1228723 - Avoid a promise worker proxy deadlock caused by synchronous Push callbacks. r=catalinb (bd564a0483)
- Bug 1191931, Part 1 - Use tasks in the Push subscription tests. r=mt (3109fdf2af)
- Bug 1191931, Part 2 - Test resubscribing from a worker. r=m (9527fa2672)
- Bug 1243781 - Push methods called from a worker should reject with a `DOMException`. r=mt (f66818b161)
- Bug 1219064 - Add test for extendable pushsubscriptionchange event. r=mt (12af4b59dd)
- Bug 1176449 - Enter an update here to avoid assertions on startup. r=dbaron (1109cce81d)
- Bug 1239743: Do not allow windows to be resized to sizes above the maximum texture size. We don't know how to draw to these anyway. r=jimm (694dafd544)
- Remove some static_casting in CompositorParent. (bug 1245765 part 5, r=mattwoodrow) (4c7f39b18e)
- Bug 1133615 - Don't assert about the contents of RestyleData::mDescendants when in a full style rebuild. r=dbaron (2b071b90d2)
- Bug 1237902 (part 1) - Remove unneeded gfxContext ops in DrawTableBorderSegment(). r=roc. (8490ab67ca)
- Bug 1237902 (part 2) - Pass a DrawTarget to DrawTableBorderSegment(). r=roc. (c602535af0)
- Bug 1237902 (part 3) - Change the gfxContextMatrixAutoSaveRestore in PaintTableBorderBackground() to an AutoRestoreTransform. r=roc. (0b2412e7d6)
- Bug 1242164 - Remove the implementation of colspan=0 (which is now dead code). r=dbaron (88555a04a4)
- Bug 1235478 - Part 1: Rename eAdjustingTimer to eForceAdjustTimer. r=mchang (113a98fa28)
- Bug 1235478 - Part 2: Don't update mMostRecentRefresh when nsRefreshDriver::ScheduleViewManagerFlush is called. r=mchang (7fd8599b7b)
- Bug 1235478 - Part 3: Make weightmapping-12579.html fuzzy on MacOS 10.10. r=jdaggett (559683f95d)
- Bug 1234049 - Ensure we always invalidate new PresShells that are created for an inactive DocShell upon reactivating them. r=smaug (aeca3e08d9)
- Re-backout c216ff19d690 (bug 1059014 part 3) because the removed code is less dead than it first appears. (2cce434c50)
2024-01-23 13:49:53 +08:00

161 lines
4.1 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include "mozilla/dom/Permissions.h"
#include "mozilla/dom/PermissionsBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/Services.h"
#include "nsIPermissionManager.h"
namespace mozilla {
namespace dom {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Permissions)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(Permissions)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Permissions)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Permissions, mWindow)
Permissions::Permissions(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
{
}
Permissions::~Permissions()
{
}
JSObject*
Permissions::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return PermissionsBinding::Wrap(aCx, this, aGivenProto);
}
namespace {
PermissionState
ActionToPermissionState(uint32_t aAction)
{
switch (aAction) {
case nsIPermissionManager::ALLOW_ACTION:
return PermissionState::Granted;
case nsIPermissionManager::DENY_ACTION:
return PermissionState::Denied;
default:
case nsIPermissionManager::PROMPT_ACTION:
return PermissionState::Prompt;
}
}
nsresult
CheckPermission(const char* aName,
nsPIDOMWindow* aWindow,
PermissionState& aResult)
{
MOZ_ASSERT(aName);
MOZ_ASSERT(aWindow);
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
if (NS_WARN_IF(!permMgr)) {
return NS_ERROR_FAILURE;
}
uint32_t action = nsIPermissionManager::DENY_ACTION;
nsresult rv = permMgr->TestPermissionFromWindow(aWindow, aName, &action);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_FAILURE;
}
aResult = ActionToPermissionState(action);
return NS_OK;
}
nsresult
CheckPushPermission(JSContext* aCx,
JS::Handle<JSObject*> aPermission,
nsPIDOMWindow* aWindow,
PermissionState& aResult)
{
PushPermissionDescriptor permission;
JS::Rooted<JS::Value> value(aCx, JS::ObjectOrNullValue(aPermission));
if (NS_WARN_IF(!permission.Init(aCx, value))) {
return NS_ERROR_UNEXPECTED;
}
if (permission.mUserVisible) {
return NS_ERROR_NOT_IMPLEMENTED;
}
return CheckPermission("push", aWindow, aResult);
}
nsresult
CheckPermission(JSContext* aCx,
JS::Handle<JSObject*> aPermission,
nsPIDOMWindow* aWindow,
PermissionState& aResult)
{
PermissionDescriptor permission;
JS::Rooted<JS::Value> value(aCx, JS::ObjectOrNullValue(aPermission));
if (NS_WARN_IF(!permission.Init(aCx, value))) {
return NS_ERROR_UNEXPECTED;
}
switch (permission.mName) {
case PermissionName::Geolocation:
return CheckPermission("geo", aWindow, aResult);
case PermissionName::Notifications:
return CheckPermission("desktop-notification", aWindow, aResult);
case PermissionName::Push:
return CheckPushPermission(aCx, aPermission, aWindow, aResult);
default:
MOZ_ASSERT_UNREACHABLE("Unhandled type");
return NS_ERROR_NOT_IMPLEMENTED;
}
}
} // namespace
already_AddRefed<Promise>
Permissions::Query(JSContext* aCx,
JS::Handle<JSObject*> aPermission,
ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
if (!global) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
PermissionState state = PermissionState::Denied;
nsresult rv = CheckPermission(aCx, aPermission, mWindow, state);
if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(rv);
} else {
promise->MaybeResolve(new PermissionStatus(mWindow, state));
}
return promise.forget();
}
} // namespace dom
} // namespace mozilla