Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/chromeos/extensions/public_session_permission_helper.h

Issue 2552203007: Public Sessions - prompt the user for pageCapture requests (Closed)
Patch Set: Removed _impl.cc/h Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_H_
7
8 #include <memory>
9 #include <set>
10 #include <vector>
11
12 #include "base/callback_forward.h"
13 #include "base/macros.h"
14 #include "chrome/browser/extensions/extension_install_prompt.h"
15 #include "extensions/common/extension_id.h"
16 #include "extensions/common/permissions/api_permission.h"
17 #include "extensions/common/permissions/api_permission_set.h"
18
19 namespace content {
20 class WebContents;
21 }
22
23 namespace extensions {
24
25 class Extension;
26
27 // In Public Sessions, extensions (and apps) are force-installed by admin policy
28 // so the user does not get a chance to review the permissions for these
29 // extensions. This is not acceptable from a security/privacy standpoint, so
30 // when an extension uses one of the sensitive APIs for the first time, we show
31 // the user a dialog where they can choose whether to allow the extension access
32 // to the API.
33 //
34 // This class encapsulates the common functionality needed to show permission
35 // requests to the user and to cache the user choices. The interface exposes two
36 // functions which are used to request additional permissions, or to query the
37 // currently granted permissions.
38 class PublicSessionPermissionHelper {
39 private:
40 // ContainsAnyID function accepts only std::set<APIPermission::ID> argument,
Devlin 2017/01/30 17:04:17 nitty nit: PermissionIDSet::ContainsAnyID()
Ivan Šandrk 2017/01/30 18:14:20 Done.
41 // therefore PermissionHelperSet is used in this class.
42 using PermissionHelperSet = std::set<APIPermission::ID>;
43
44 public:
45 // Sets up the prompt asking the user for additional permission(s), handles
46 // the result, caches it, and then runs either success_callback or
47 // failure_callback depending on all permissions being allowed.
48 //
49 // Supports handling multiple requests for the same permission(s). Only the
50 // first request causes the prompt to be shown, subsequent ones are just
51 // enqueued to be called when the permission(s) is resolved.
52 //
53 // Caller must ensure that web_contents is valid. Must be called on UI thread.
54 //
55 // If finer resolving is needed, pass the same function in both callbacks and
56 // check the individual permissions by calling PermissionAllowed inside your
57 // function.
58 static void HandlePermissionRequest(const Extension& extension,
59 PermissionHelperSet requested_permissions,
60 content::WebContents* web_contents,
61 const base::Closure& success_callback,
62 const base::Closure& failure_callback);
63
64 // Used to check whether a certain permission is allowed. Useful only if
65 // called inside success/failure callbacks.
66 static bool PermissionAllowed(ExtensionId extension_id,
67 APIPermission::ID permission_id);
68
69 PublicSessionPermissionHelper();
70 PublicSessionPermissionHelper(PublicSessionPermissionHelper&& other);
71 ~PublicSessionPermissionHelper();
72
73 private:
74 void HandlePermissionRequestImpl(const Extension& extension,
75 PermissionHelperSet requested_permissions,
76 content::WebContents* web_contents,
77 const base::Closure& success_callback,
78 const base::Closure& failure_callback);
79
80 bool PermissionAllowedImpl(APIPermission::ID permission_id);
81
82 void ResolvePermissionPrompt(
83 const std::unique_ptr<ExtensionInstallPrompt>* prompt,
84 PermissionIDSet unprompted_permissions,
85 ExtensionInstallPrompt::Result prompt_result);
86
87 struct RequestCallback {
88 RequestCallback(const base::Closure& success_callback,
89 const base::Closure& failure_callback,
90 const PermissionHelperSet& permission_list);
91 RequestCallback(const RequestCallback& other);
92 ~RequestCallback();
93 base::Closure success_callback;
94 base::Closure failure_callback;
95 PermissionHelperSet permission_list;
96 };
97 using RequestCallbackList = std::vector<RequestCallback>;
98
99 std::set<std::unique_ptr<ExtensionInstallPrompt>> prompts_;
100 PermissionIDSet prompted_permission_set_;
101 PermissionIDSet allowed_permission_set_;
102 PermissionIDSet denied_permission_set_;
103 RequestCallbackList callbacks_;
104
105 DISALLOW_COPY_AND_ASSIGN(PublicSessionPermissionHelper);
106 };
107
108 } // namespace extensions
109
110 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698