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.
5 #ifndef CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_
6 #define CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/content_settings/permission_queue_controller.h"
15 class PermissionRequestID;
23 // Manages protected media identifier permissions flow, and delegates UI
24 // handling via PermissionQueueController.
25 class ProtectedMediaIdentifierPermissionContext
26 : public base::RefCountedThreadSafe<
27 ProtectedMediaIdentifierPermissionContext> {
29 explicit ProtectedMediaIdentifierPermissionContext(Profile* profile);
31 void RequestProtectedMediaIdentifierPermission(
32 content::WebContents* web_contents,
34 base::Callback<void(bool)> result_callback);
36 void CancelProtectedMediaIdentifierPermissionRequests(int render_process_id,
40 // Called on the UI thread when the profile is about to be destroyed.
41 void ShutdownOnUIThread();
44 friend class base::RefCountedThreadSafe<
45 ProtectedMediaIdentifierPermissionContext>;
46 ~ProtectedMediaIdentifierPermissionContext();
48 Profile* profile() const { return profile_; }
50 // Return an instance of the infobar queue controller, creating it
52 PermissionQueueController* QueueController();
54 // Notifies whether or not the corresponding bridge is allowed to use
55 // protected media identifier via
56 // SetProtectedMediaIdentifierPermissionResponse(). Called on the UI thread.
57 void NotifyPermissionSet(const PermissionRequestID& id,
59 const base::Callback<void(bool)>& callback,
62 // Decide whether the protected media identifier permission should be granted.
63 // Calls PermissionDecided if permission can be decided non-interactively,
64 // or NotifyPermissionSet if permission decided by presenting an
65 // infobar to the user. Called on the UI thread.
66 void DecidePermission(const PermissionRequestID& id,
69 content::RenderViewHost* rvh,
70 const base::Callback<void(bool)>& callback);
72 // Called when permission is granted without interactively asking
73 // the user. Can be overridden to introduce additional UI flow.
74 // Should ultimately ensure that NotifyPermissionSet is called.
75 // Called on the UI thread.
76 void PermissionDecided(const PermissionRequestID& id,
79 const base::Callback<void(bool)>& callback,
82 // Create an PermissionQueueController. overridden in derived classes to
83 // provide additional UI flow. Called on the UI thread.
84 PermissionQueueController* CreateQueueController();
86 // Removes pending InfoBar requests that match |bridge_id| from the tab
87 // given by |render_process_id| and |render_view_id|.
88 void CancelPendingInfobarRequests(int render_process_id,
92 // These must only be accessed from the UI thread.
93 Profile* const profile_;
95 scoped_ptr<PermissionQueueController> permission_queue_controller_;
97 DISALLOW_COPY_AND_ASSIGN(ProtectedMediaIdentifierPermissionContext);
100 #endif // CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_