Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / media / protected_media_identifier_permission_context.h
blob594d2f85f42ae9c8423a44c4b700fc2bd1374847
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_
8 #include "chrome/browser/permissions/permission_context_base.h"
9 #include "chrome/browser/permissions/permission_request_id.h"
11 #if defined(OS_CHROMEOS)
12 #include <map>
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h"
16 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
17 #endif
19 class Profile;
21 namespace views {
22 class Widget;
25 namespace content {
26 class RenderViewHost;
27 class WebContents;
30 namespace user_prefs {
31 class PrefRegistrySyncable;
34 // Manages protected media identifier permissions flow, and delegates UI
35 // handling via PermissionQueueController.
36 class ProtectedMediaIdentifierPermissionContext
37 : public PermissionContextBase {
38 public:
39 explicit ProtectedMediaIdentifierPermissionContext(Profile* profile);
41 // In addition to the base class flow checks that it is only code from
42 // valid iframes. It also adds special logic when called through an extension.
43 void RequestPermission(content::WebContents* web_contents,
44 const PermissionRequestID& id,
45 const GURL& requesting_origin,
46 bool user_gesture,
47 const BrowserPermissionCallback& callback) override;
48 ContentSetting GetPermissionStatus(
49 const GURL& requesting_origin,
50 const GURL& embedding_origin) const override;
51 void CancelPermissionRequest(content::WebContents* web_contents,
52 const PermissionRequestID& id) override;
54 private:
55 ~ProtectedMediaIdentifierPermissionContext() override;
57 void UpdateTabContext(const PermissionRequestID& id,
58 const GURL& requesting_frame,
59 bool allowed) override;
60 bool IsRestrictedToSecureOrigins() const override;
62 // Returns whether "Protected content" is enabled based on factors other
63 // than the protected media identifier content setting itself. For example,
64 // it can be disabled by a master switch in content settings, in incognito or
65 // guest mode, or by the device policy.
66 bool IsProtectedMediaIdentifierEnabled() const;
68 #if defined(OS_CHROMEOS)
69 void OnPlatformVerificationConsentResponse(
70 content::WebContents* web_contents,
71 const PermissionRequestID& id,
72 const GURL& requesting_origin,
73 const GURL& embedding_origin,
74 const BrowserPermissionCallback& callback,
75 chromeos::attestation::PlatformVerificationDialog::ConsentResponse
76 response);
78 // |this| is shared among multiple WebContents, so we could receive multiple
79 // permission requests. This map tracks all pending requests. Note that we
80 // only allow one request per WebContents.
81 typedef std::map<content::WebContents*,
82 std::pair<views::Widget*, PermissionRequestID>>
83 PendingRequestMap;
84 PendingRequestMap pending_requests_;
86 // Must be the last member, to ensure that it will be
87 // destroyed first, which will invalidate weak pointers
88 base::WeakPtrFactory<ProtectedMediaIdentifierPermissionContext> weak_factory_;
89 #endif
91 DISALLOW_COPY_AND_ASSIGN(ProtectedMediaIdentifierPermissionContext);
94 #endif // CHROME_BROWSER_MEDIA_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_CONTEXT_H_