Bug 1105827 - Part 2: Add stub Permissions implementation. r=baku

This commit is contained in:
Birunthan Mohanathas 2015-07-28 06:33:46 -07:00
parent 3cebf1a295
commit bd698632d1
6 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,62 @@
/* -*- 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 "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);
}
already_AddRefed<Promise>
Permissions::Query(const PermissionDescriptor& aPermission)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
if (!global) {
return nullptr;
}
ErrorResult aRv;
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
promise->MaybeReject(NS_ERROR_NOT_IMPLEMENTED);
return promise.forget();
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,46 @@
/* -*- 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/. */
#ifndef mozilla_dom_Permissions_h_
#define mozilla_dom_Permissions_h_
#include "nsISupports.h"
#include "nsPIDOMWindow.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
struct PermissionDescriptor;
class Promise;
class Permissions final
: public nsISupports
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Permissions)
explicit Permissions(nsPIDOMWindow* aWindow);
nsPIDOMWindow* GetParentObject() const { return mWindow; }
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
already_AddRefed<Promise> Query(const PermissionDescriptor& aPermission);
private:
~Permissions();
nsCOMPtr<nsPIDOMWindow> mWindow;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_permissions_h_

View File

@ -5,10 +5,12 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXPORTS.mozilla.dom += [
'Permissions.h',
'PermissionStatus.h',
]
UNIFIED_SOURCES += [
'Permissions.cpp',
'PermissionStatus.cpp',
]

View File

@ -891,6 +891,8 @@ var interfaceNamesInGlobalScope =
"PerformanceTiming",
// IMPORTANT: Do not change this list without review from a DOM peer!
"PeriodicWave",
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "Permissions", nightly: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "PermissionSettings", b2g: true, permission: ["permissions"]},
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -0,0 +1,25 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* https://w3c.github.io/permissions/#permissions-interface
*/
enum PermissionName {
"geolocation",
"notifications",
"push",
"midi"
};
dictionary PermissionDescriptor {
required PermissionName name;
};
[Exposed=(Window),
Pref="dom.permissions.enabled"]
interface Permissions {
Promise<PermissionStatus> query(PermissionDescriptor permission);
};

View File

@ -354,6 +354,7 @@ WEBIDL_FILES = [
'PerformanceResourceTiming.webidl',
'PerformanceTiming.webidl',
'PeriodicWave.webidl',
'Permissions.webidl',
'PermissionSettings.webidl',
'PermissionStatus.webidl',
'PhoneNumberService.webidl',