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

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: More nits 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:
Andrew T Wilson (Slow) 2017/01/31 16:22:24 Why is this private section up here at the top?
Ivan Šandrk 2017/02/01 18:11:29 I wanted to define PermissionHelperSet as private
40 // PermissionIDSet::ContainsAnyID() function accepts only
41 // std::set<APIPermission::ID> argument, therefore PermissionHelperSet is
42 // used in this class.
Andrew T Wilson (Slow) 2017/01/31 16:22:25 nit: this naming is weird - PermissionHelperSet is
Ivan Šandrk 2017/02/01 18:11:29 APIPermissionSet already exists. So does Permissio
43 using PermissionHelperSet = std::set<APIPermission::ID>;
44
45 public:
46 // Sets up the prompt asking the user for additional permission(s), handles
47 // the result, caches it, and then runs either success_callback or
48 // failure_callback depending on all permissions being allowed.
Andrew T Wilson (Slow) 2017/01/31 16:22:24 So failure_callback is invoked if *any* permission
Ivan Šandrk 2017/02/01 18:11:29 Done.
49 //
50 // Supports handling multiple requests for the same permission(s). Only the
51 // first request causes the prompt to be shown, subsequent ones are just
52 // enqueued to be called when the permission(s) is resolved.
Andrew T Wilson (Slow) 2017/01/31 16:22:24 Are you saying that the user will be prompted mult
Ivan Šandrk 2017/02/01 18:11:29 User will be prompted only once per permission; th
53 //
54 // Caller must ensure that web_contents is valid. Must be called on UI thread.
55 //
56 // If finer resolving is needed, pass the same function in both callbacks and
57 // check the individual permissions by calling PermissionAllowed inside your
58 // function.
59 static void HandlePermissionRequest(const Extension& extension,
60 PermissionHelperSet requested_permissions,
61 content::WebContents* web_contents,
62 const base::Closure& success_callback,
63 const base::Closure& failure_callback);
64
65 // Used to check whether a certain permission is allowed. Useful only if
66 // called inside success/failure callbacks.
Andrew T Wilson (Slow) 2017/01/31 16:22:24 Why is it only useful inside a callback? Why don't
Ivan Šandrk 2017/02/01 18:11:29 The function should be called only after the permi
67 static bool PermissionAllowed(ExtensionId extension_id,
68 APIPermission::ID permission_id);
69
70 PublicSessionPermissionHelper();
Andrew T Wilson (Slow) 2017/01/31 16:22:24 Why do we have public constructors when all APIs a
Ivan Šandrk 2017/02/01 18:11:29 Good point. Done.
71 PublicSessionPermissionHelper(PublicSessionPermissionHelper&& other);
72 ~PublicSessionPermissionHelper();
73
74 private:
75 void HandlePermissionRequestImpl(const Extension& extension,
76 PermissionHelperSet requested_permissions,
77 content::WebContents* web_contents,
78 const base::Closure& success_callback,
79 const base::Closure& failure_callback);
80
81 bool PermissionAllowedImpl(APIPermission::ID permission_id);
82
83 void ResolvePermissionPrompt(
84 const std::unique_ptr<ExtensionInstallPrompt>* prompt,
85 const PermissionIDSet& unprompted_permissions,
86 ExtensionInstallPrompt::Result prompt_result);
87
88 struct RequestCallback {
89 RequestCallback(const base::Closure& success_callback,
90 const base::Closure& failure_callback,
91 const PermissionHelperSet& permission_list);
92 RequestCallback(const RequestCallback& other);
93 ~RequestCallback();
94 base::Closure success_callback;
95 base::Closure failure_callback;
96 PermissionHelperSet permission_list;
97 };
98 using RequestCallbackList = std::vector<RequestCallback>;
99
100 std::set<std::unique_ptr<ExtensionInstallPrompt>> prompts_;
101 PermissionIDSet prompted_permission_set_;
102 PermissionIDSet allowed_permission_set_;
103 PermissionIDSet denied_permission_set_;
104 RequestCallbackList callbacks_;
105
106 DISALLOW_COPY_AND_ASSIGN(PublicSessionPermissionHelper);
107 };
108
109 } // namespace extensions
110
111 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698