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