| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_MIDI_PERMISSION_CONTEXT_H_ |
| 6 #define CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ | 6 #define CHROME_BROWSER_MEDIA_MIDI_PERMISSION_CONTEXT_H_ |
| 7 | 7 |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 10 #include "components/keyed_service/core/keyed_service.h" | 11 #include "components/keyed_service/core/keyed_service.h" |
| 11 #include "content/public/browser/browser_context.h" | |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 class WebContents; | 14 class WebContents; |
| 15 } | 15 } |
| 16 | 16 |
| 17 class GURL; | 17 class GURL; |
| 18 class MidiPermissionRequest; | 18 class MidiPermissionRequest; |
| 19 class PermissionQueueController; | 19 class PermissionQueueController; |
| 20 class PermissionRequestID; | 20 class PermissionRequestID; |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 // This class manages MIDI permissions flow. Used on the UI thread. | 23 // This class manages MIDI permissions flow. Used on the UI thread. |
| 24 class ChromeMidiPermissionContext : public KeyedService { | 24 class MidiPermissionContext : public KeyedService { |
| 25 public: | 25 public: |
| 26 explicit ChromeMidiPermissionContext(Profile* profile); | 26 explicit MidiPermissionContext(Profile* profile); |
| 27 virtual ~ChromeMidiPermissionContext(); | 27 virtual ~MidiPermissionContext(); |
| 28 | 28 |
| 29 // KeyedService methods: | 29 // KeyedService methods: |
| 30 virtual void Shutdown() OVERRIDE; | 30 virtual void Shutdown() OVERRIDE; |
| 31 | 31 |
| 32 // Request to ask users permission about MIDI. | 32 // Request to ask users permission about MIDI. |
| 33 void RequestMidiSysExPermission( | 33 void RequestMidiSysExPermission( |
| 34 int render_process_id, | 34 content::WebContents* web_contents, |
| 35 int render_view_id, | |
| 36 int bridge_id, | 35 int bridge_id, |
| 37 const GURL& requesting_frame, | 36 const GURL& requesting_frame, |
| 38 bool user_gesture, | 37 bool user_gesture, |
| 39 const content::BrowserContext::MidiSysExPermissionCallback& callback); | 38 const base::Callback<void(bool)>& result_callback, |
| 40 | 39 base::Closure* cancel_callback); |
| 41 // Cancel a pending MIDI permission request. | |
| 42 void CancelMidiSysExPermissionRequest(int render_process_id, | |
| 43 int render_view_id, | |
| 44 int bridge_id, | |
| 45 const GURL& requesting_frame); | |
| 46 | 40 |
| 47 // Called when the permission decision is made. If a permissions prompt is | 41 // Called when the permission decision is made. If a permissions prompt is |
| 48 // shown to the user it will be called when the user selects an option | 42 // shown to the user it will be called when the user selects an option |
| 49 // from that prompt. | 43 // from that prompt. |
| 50 void NotifyPermissionSet( | 44 void NotifyPermissionSet( |
| 51 const PermissionRequestID& id, | 45 const PermissionRequestID& id, |
| 52 const GURL& requesting_frame, | 46 const GURL& requesting_frame, |
| 53 const content::BrowserContext::MidiSysExPermissionCallback& callback, | 47 const base::Callback<void(bool)>& callback, |
| 54 bool allowed); | 48 bool allowed); |
| 55 | 49 |
| 56 private: | 50 private: |
| 57 friend class MidiPermissionRequest; | 51 friend class MidiPermissionRequest; |
| 58 | 52 |
| 53 // Cancel a pending MIDI permission request. |
| 54 void CancelMidiSysExPermissionRequest(int render_process_id, |
| 55 int render_view_id, |
| 56 int bridge_id); |
| 57 |
| 59 // Decide whether the permission should be granted. | 58 // Decide whether the permission should be granted. |
| 60 // Calls PermissionDecided if permission can be decided non-interactively, | 59 // Calls PermissionDecided if permission can be decided non-interactively, |
| 61 // or NotifyPermissionSet if permission decided by presenting an infobar. | 60 // or NotifyPermissionSet if permission decided by presenting an infobar. |
| 62 void DecidePermission( | 61 void DecidePermission( |
| 63 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
| 64 const PermissionRequestID& id, | 63 const PermissionRequestID& id, |
| 65 const GURL& requesting_frame, | 64 const GURL& requesting_frame, |
| 66 const GURL& embedder, | 65 const GURL& embedder, |
| 67 bool user_gesture, | 66 bool user_gesture, |
| 68 const content::BrowserContext::MidiSysExPermissionCallback& callback); | 67 const base::Callback<void(bool)>& callback); |
| 69 | 68 |
| 70 // Called when permission is granted without interactively asking the user. | 69 // Called when permission is granted without interactively asking the user. |
| 71 void PermissionDecided( | 70 void PermissionDecided( |
| 72 const PermissionRequestID& id, | 71 const PermissionRequestID& id, |
| 73 const GURL& requesting_frame, | 72 const GURL& requesting_frame, |
| 74 const GURL& embedder, | 73 const GURL& embedder, |
| 75 const content::BrowserContext::MidiSysExPermissionCallback& callback, | 74 const base::Callback<void(bool)>& callback, |
| 76 bool allowed); | 75 bool allowed); |
| 77 | 76 |
| 78 // Return an instance of the infobar queue controller, creating it if needed. | 77 // Return an instance of the infobar queue controller, creating it if needed. |
| 79 PermissionQueueController* GetQueueController(); | 78 PermissionQueueController* GetQueueController(); |
| 80 | 79 |
| 81 // Removes any pending InfoBar request. | 80 // Removes any pending InfoBar request. |
| 82 void CancelPendingInfobarRequest(const PermissionRequestID& id); | 81 void CancelPendingInfobarRequest(const PermissionRequestID& id); |
| 83 | 82 |
| 84 // Notify the context that a particular request object is no longer needed. | 83 // Notify the context that a particular request object is no longer needed. |
| 85 void RequestFinished(MidiPermissionRequest* request); | 84 void RequestFinished(MidiPermissionRequest* request); |
| 86 | 85 |
| 87 Profile* const profile_; | 86 Profile* const profile_; |
| 88 bool shutting_down_; | 87 bool shutting_down_; |
| 89 scoped_ptr<PermissionQueueController> permission_queue_controller_; | 88 scoped_ptr<PermissionQueueController> permission_queue_controller_; |
| 90 | 89 |
| 91 base::ScopedPtrHashMap<std::string, MidiPermissionRequest> pending_requests_; | 90 base::ScopedPtrHashMap<std::string, MidiPermissionRequest> pending_requests_; |
| 92 | 91 |
| 93 DISALLOW_COPY_AND_ASSIGN(ChromeMidiPermissionContext); | 92 base::WeakPtrFactory<MidiPermissionContext> weak_factory_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(MidiPermissionContext); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 #endif // CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_ | 97 #endif // CHROME_BROWSER_MEDIA_MIDI_PERMISSION_CONTEXT_H_ |
| OLD | NEW |