Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / chrome_midi_permission_context.h
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"
9 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
10 #include "content/public/browser/browser_context.h"
11
12 namespace content {
13 class WebContents;
14 }
15
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.
22 class ChromeMidiPermissionContext : public BrowserContextKeyedService {
23  public:
24   explicit ChromeMidiPermissionContext(Profile* profile);
25   virtual ~ChromeMidiPermissionContext();
26
27   // BrowserContextKeyedService methods:
28   virtual void Shutdown() OVERRIDE;
29
30   // Request to ask users permission about MIDI.
31   void RequestMidiSysExPermission(
32       int render_process_id,
33       int render_view_id,
34       int bridge_id,
35       const GURL& requesting_frame,
36       const content::BrowserContext::MidiSysExPermissionCallback& callback);
37
38   // Cancel a pending MIDI permission request.
39   void CancelMidiSysExPermissionRequest(int render_process_id,
40                                         int render_view_id,
41                                         int bridge_id,
42                                         const GURL& requesting_frame);
43
44   // Called when the permission decision is made. If a permissions prompt is
45   // shown to the user it will be called when the user selects an option
46   // from that prompt.
47   void NotifyPermissionSet(
48       const PermissionRequestID& id,
49       const GURL& requesting_frame,
50       const content::BrowserContext::MidiSysExPermissionCallback& callback,
51       bool allowed);
52
53  private:
54   // Decide whether the permission should be granted.
55   // Calls PermissionDecided if permission can be decided non-interactively,
56   // or NotifyPermissionSet if permission decided by presenting an infobar.
57   void DecidePermission(
58       content::WebContents* web_contents,
59       const PermissionRequestID& id,
60       const GURL& requesting_frame,
61       const GURL& embedder,
62       const content::BrowserContext::MidiSysExPermissionCallback& callback);
63
64   // Called when permission is granted without interactively asking the user.
65   void PermissionDecided(
66       const PermissionRequestID& id,
67       const GURL& requesting_frame,
68       const GURL& embedder,
69       const content::BrowserContext::MidiSysExPermissionCallback& callback,
70       bool allowed);
71
72   // Return an instance of the infobar queue controller, creating it if needed.
73   PermissionQueueController* GetQueueController();
74
75   // Removes any pending InfoBar request.
76   void CancelPendingInfobarRequest(const PermissionRequestID& id);
77
78   Profile* const profile_;
79   bool shutting_down_;
80   scoped_ptr<PermissionQueueController> permission_queue_controller_;
81
82   DISALLOW_COPY_AND_ASSIGN(ChromeMidiPermissionContext);
83 };
84
85 #endif  // CHROME_BROWSER_MEDIA_CHROME_MIDI_PERMISSION_CONTEXT_H_