Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
5
* You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_indexeddb_permissionrequestbase_h__
8
#define mozilla_dom_indexeddb_permissionrequestbase_h__
9
10
#include "mozilla/Attributes.h"
11
#include "nsCOMPtr.h"
12
#include "nsIIDBPermissionsRequest.h"
13
#include "nsIObserver.h"
14
#include "nsIPermissionManager.h"
15
#include "nsISupportsImpl.h"
16
#include "nsString.h"
17
18
class nsIPrincipal;
19
20
namespace mozilla {
21
namespace dom {
22
23
class Element;
24
25
namespace indexedDB {
26
27
class PermissionRequestBase : public nsIObserver,
28
public nsIIDBPermissionsRequest {
29
nsCOMPtr<Element> mOwnerElement;
30
nsCOMPtr<nsIPrincipal> mPrincipal;
31
32
public:
33
enum PermissionValue {
34
kPermissionAllowed = nsIPermissionManager::ALLOW_ACTION,
35
kPermissionDenied = nsIPermissionManager::DENY_ACTION,
36
kPermissionPrompt = nsIPermissionManager::PROMPT_ACTION
37
};
38
39
NS_DECL_ISUPPORTS
40
41
// This function will not actually prompt. It will never return
42
// kPermissionDefault but will instead translate the permission manager value
43
// into the correct value for the given type.
44
static nsresult GetCurrentPermission(nsIPrincipal* aPrincipal,
45
PermissionValue* aCurrentValue);
46
47
static PermissionValue PermissionValueForIntPermission(
48
uint32_t aIntPermission);
49
50
// This function will prompt if needed. It may only be called once.
51
nsresult PromptIfNeeded(PermissionValue* aCurrentValue);
52
53
protected:
54
PermissionRequestBase(Element* aOwnerElement, nsIPrincipal* aPrincipal);
55
56
// Reference counted.
57
virtual ~PermissionRequestBase();
58
59
virtual void OnPromptComplete(PermissionValue aPermissionValue) = 0;
60
61
private:
62
void SetExplicitPermission(nsIPrincipal* aPrincipal, uint32_t aIntPermission);
63
64
NS_DECL_NSIOBSERVER
65
NS_DECL_NSIIDBPERMISSIONSREQUEST
66
};
67
68
} // namespace indexedDB
69
} // namespace dom
70
} // namespace mozilla
71
72
#endif // mozilla_dom_indexeddb_permissionrequestbase_h__