Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / media / protected_media_identifier_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_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_
6 #define CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/content_settings/permission_queue_controller.h"
14
15 class PermissionRequestID;
16 class Profile;
17
18 namespace content {
19 class RenderViewHost;
20 class WebContents;
21 }
22
23 // Manages protected media identifier permissions flow, and delegates UI
24 // handling via PermissionQueueController.
25 class ProtectedMediaIdentifierPermissionContext
26     : public base::RefCountedThreadSafe<
27         ProtectedMediaIdentifierPermissionContext> {
28  public:
29   explicit ProtectedMediaIdentifierPermissionContext(Profile* profile);
30
31   void RequestProtectedMediaIdentifierPermission(
32       content::WebContents* web_contents,
33       const GURL& origin,
34       base::Callback<void(bool)> result_callback);
35
36   void CancelProtectedMediaIdentifierPermissionRequests(int render_process_id,
37                                                         int render_view_id,
38                                                         const GURL& origin);
39
40   // Called on the UI thread when the profile is about to be destroyed.
41   void ShutdownOnUIThread();
42
43  private:
44   friend class base::RefCountedThreadSafe<
45       ProtectedMediaIdentifierPermissionContext>;
46   ~ProtectedMediaIdentifierPermissionContext();
47
48   Profile* profile() const { return profile_; }
49
50   // Return an instance of the infobar queue controller, creating it
51   // if necessary.
52   PermissionQueueController* QueueController();
53
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,
58                            const GURL& origin,
59                            const base::Callback<void(bool)>& callback,
60                            bool allowed);
61
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,
67                         const GURL& origin,
68                         const GURL& embedder,
69                         content::RenderViewHost* rvh,
70                         const base::Callback<void(bool)>& callback);
71
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,
77                          const GURL& origin,
78                          const GURL& embedder,
79                          const base::Callback<void(bool)>& callback,
80                          bool allowed);
81
82   // Create an PermissionQueueController. overridden in derived classes to
83   // provide additional UI flow.  Called on the UI thread.
84   PermissionQueueController* CreateQueueController();
85
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,
89                                     int render_view_id,
90                                     const GURL& origin);
91
92   // These must only be accessed from the UI thread.
93   Profile* const profile_;
94   bool shutting_down_;
95   scoped_ptr<PermissionQueueController> permission_queue_controller_;
96
97   DISALLOW_COPY_AND_ASSIGN(ProtectedMediaIdentifierPermissionContext);
98 };
99
100 #endif  // CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_