Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <map> | |
| 9 #include <set> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback_forward.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "extensions/common/extension_id.h" | |
| 15 #include "extensions/common/permissions/api_permission.h" | |
| 16 | |
| 17 namespace content { | |
| 18 class WebContents; | |
| 19 } | |
| 20 | |
| 21 namespace extensions { | |
| 22 | |
| 23 class Extension; | |
| 24 | |
| 25 class PublicSessionPermissionHelperImpl; | |
| 26 enum PermissionState { | |
|
Devlin
2017/01/25 16:00:32
Let's put this in the class.
Ivan Šandrk
2017/01/26 18:53:22
Removed completely.
| |
| 27 NOT_PROMPTED = 0, | |
| 28 SHOWN_PROMPT, | |
| 29 ALLOWED, | |
| 30 DENIED | |
| 31 }; | |
| 32 using PermissionHelperSet = std::set<APIPermission::ID>; | |
| 33 | |
| 34 class PublicSessionPermissionHelper { | |
| 35 public: | |
| 36 static PublicSessionPermissionHelper& Instance(); | |
| 37 | |
| 38 // Sets up the prompt asking the user for additional permission(s), handles | |
| 39 // the result, caches it, and then runs either success_callback or | |
| 40 // failure_callback depending on all permissions being allowed. | |
| 41 // Supports handling multiple requests for the same permission(s). Only the | |
| 42 // first request causes the prompt to be shown, subsequent ones are just | |
| 43 // enqueued to be called when the permission(s) is resolved. | |
| 44 // Caller must ensure that web_contents is valid. Must be called on UI thread. | |
| 45 // If finer resolving is needed, pass the same function in both callbacks and | |
| 46 // check the individual permissions by calling GetUserChoice inside your | |
| 47 // function. | |
| 48 void HandlePermissionRequest(const Extension* extension, | |
|
Devlin
2017/01/25 16:00:32
nit: it seems like we can have these two functions
Ivan Šandrk
2017/01/26 18:53:22
Done.
| |
| 49 PermissionHelperSet requested_permissions, | |
| 50 content::WebContents* web_contents, | |
| 51 const base::Closure& success_callback, | |
| 52 const base::Closure& failure_callback); | |
| 53 | |
| 54 PermissionState GetUserChoice(ExtensionId extension_id, | |
| 55 APIPermission::ID permission_id); | |
| 56 | |
| 57 private: | |
| 58 PublicSessionPermissionHelper(); | |
| 59 ~PublicSessionPermissionHelper(); | |
| 60 | |
| 61 std::map<ExtensionId, PublicSessionPermissionHelperImpl> impl_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(PublicSessionPermissionHelper); | |
| 64 }; | |
| 65 | |
| 66 } // namespace extensions | |
| 67 | |
| 68 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_PUBLIC_SESSION_PERMISSION_HELPER_H _ | |
| OLD | NEW |