[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 1 | // Copyright 2013 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_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ |
| 6 | #define CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ |
| 7 | |
| 8 | #include "base/memory/scoped_ptr.h" |
[email protected] | 95003d52 | 2014-03-13 20:22:31 | [diff] [blame] | 9 | #include "components/keyed_service/core/keyed_service.h" |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 10 | #include "content/public/browser/browser_context.h" |
| 11 | |
[email protected] | 7babfcbe | 2014-02-12 22:56:38 | [diff] [blame] | 12 | namespace content { |
| 13 | class WebContents; |
| 14 | } |
| 15 | |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 16 | class GURL; |
| 17 | class PermissionQueueController; |
| 18 | class PermissionRequestID; |
| 19 | class Profile; |
| 20 | |
| 21 | // This class manages MIDI permissions flow. Used on the UI thread. |
[email protected] | 95003d52 | 2014-03-13 20:22:31 | [diff] [blame] | 22 | class ChromeMidiPermissionContext : public KeyedService { |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 23 | public: |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 24 | explicit ChromeMidiPermissionContext(Profile* profile); |
| 25 | virtual ~ChromeMidiPermissionContext(); |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 26 | |
[email protected] | 95003d52 | 2014-03-13 20:22:31 | [diff] [blame] | 27 | // KeyedService methods: |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 28 | virtual void Shutdown() OVERRIDE; |
| 29 | |
| 30 | // Request to ask users permission about MIDI. |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 31 | void RequestMidiSysExPermission( |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 32 | int render_process_id, |
| 33 | int render_view_id, |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 34 | int bridge_id, |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 35 | const GURL& requesting_frame, |
[email protected] | 7c6d948 | 2014-03-28 20:19:31 | [diff] [blame^] | 36 | bool user_gesture, |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 37 | const content::BrowserContext::MidiSysExPermissionCallback& callback); |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 38 | |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 39 | // Cancel a pending MIDI permission request. |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 40 | void CancelMidiSysExPermissionRequest(int render_process_id, |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 41 | int render_view_id, |
| 42 | int bridge_id, |
| 43 | const GURL& requesting_frame); |
| 44 | |
[email protected] | 7babfcbe | 2014-02-12 22:56:38 | [diff] [blame] | 45 | // Called when the permission decision is made. If a permissions prompt is |
| 46 | // shown to the user it will be called when the user selects an option |
| 47 | // from that prompt. |
| 48 | void NotifyPermissionSet( |
| 49 | const PermissionRequestID& id, |
| 50 | const GURL& requesting_frame, |
| 51 | const content::BrowserContext::MidiSysExPermissionCallback& callback, |
| 52 | bool allowed); |
| 53 | |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 54 | private: |
| 55 | // Decide whether the permission should be granted. |
| 56 | // Calls PermissionDecided if permission can be decided non-interactively, |
| 57 | // or NotifyPermissionSet if permission decided by presenting an infobar. |
| 58 | void DecidePermission( |
[email protected] | 7babfcbe | 2014-02-12 22:56:38 | [diff] [blame] | 59 | content::WebContents* web_contents, |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 60 | const PermissionRequestID& id, |
| 61 | const GURL& requesting_frame, |
| 62 | const GURL& embedder, |
[email protected] | 7c6d948 | 2014-03-28 20:19:31 | [diff] [blame^] | 63 | bool user_gesture, |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 64 | const content::BrowserContext::MidiSysExPermissionCallback& callback); |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 65 | |
| 66 | // Called when permission is granted without interactively asking the user. |
| 67 | void PermissionDecided( |
| 68 | const PermissionRequestID& id, |
| 69 | const GURL& requesting_frame, |
| 70 | const GURL& embedder, |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 71 | const content::BrowserContext::MidiSysExPermissionCallback& callback, |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 72 | bool allowed); |
| 73 | |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 74 | // Return an instance of the infobar queue controller, creating it if needed. |
| 75 | PermissionQueueController* GetQueueController(); |
| 76 | |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 77 | // Removes any pending InfoBar request. |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 78 | void CancelPendingInfobarRequest(const PermissionRequestID& id); |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 79 | |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 80 | Profile* const profile_; |
| 81 | bool shutting_down_; |
| 82 | scoped_ptr<PermissionQueueController> permission_queue_controller_; |
| 83 | |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(ChromeMidiPermissionContext); |
[email protected] | 44ecb83 | 2013-08-02 09:06:45 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #endif // CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ |