Allow script to request durable storage permission (chrome side)
[chromium-blink-merge.git] / ppapi / shared_impl / ppapi_permissions.cc
bloba2d252184dd0580d242b7d02d6817a03a673683f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/ppapi_permissions.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "ppapi/shared_impl/ppapi_switches.h"
11 namespace ppapi {
13 PpapiPermissions::PpapiPermissions() : permissions_(0) {}
15 PpapiPermissions::PpapiPermissions(uint32 perms) : permissions_(perms) {}
17 PpapiPermissions::~PpapiPermissions() {}
19 // static
20 PpapiPermissions PpapiPermissions::AllPermissions() {
21 return PpapiPermissions(PERMISSION_ALL_BITS);
24 // static
25 PpapiPermissions PpapiPermissions::GetForCommandLine(uint32 base_perms) {
26 uint32 additional_permissions = 0;
28 #if !defined(OS_NACL)
29 // Testing permissions. The testing flag implies all permissions since the
30 // test plugin needs to test all interfaces.
31 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kEnablePepperTesting))
33 additional_permissions |= ppapi::PERMISSION_ALL_BITS;
34 #endif
36 return PpapiPermissions(base_perms | additional_permissions);
39 bool PpapiPermissions::HasPermission(Permission perm) const {
40 // Check that "perm" is a power of two to make sure the caller didn't set
41 // more than one permission bit. We may want to change how permissions are
42 // represented in the future so don't want callers making assumptions about
43 // bits.
44 uint32 perm_int = static_cast<uint32>(perm);
45 if (!perm_int)
46 return true; // You always have "no permission".
47 DCHECK((perm_int & (perm_int - 1)) == 0);
48 return !!(permissions_ & perm_int);
51 } // namespace ppapi