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 #include "chrome/browser/media/protected_media_identifier_permission_context.h" | 5 #include "chrome/browser/media/protected_media_identifier_permission_context.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "components/content_settings/core/common/permission_request_id.h" | 11 #include "components/content_settings/core/common/permission_request_id.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 | 14 |
15 #if defined(OS_CHROMEOS) | 15 #if defined(OS_CHROMEOS) |
16 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "chromeos/settings/cros_settings_names.h" | 18 #include "chromeos/settings/cros_settings_names.h" |
19 #include "ui/views/widget/widget.h" | |
20 | |
21 using chromeos::attestation::PlatformVerificationDialog; | |
22 using chromeos::attestation::PlatformVerificationFlow; | |
23 #endif | |
24 | |
25 #if defined(OS_CHROMEOS) | |
26 namespace { | |
27 PermissionRequestID GetInvalidPendingId() { | |
28 return PermissionRequestID(-1, -1, -1, GURL()); | |
29 } | |
30 } | |
18 #endif | 31 #endif |
19 | 32 |
20 ProtectedMediaIdentifierPermissionContext:: | 33 ProtectedMediaIdentifierPermissionContext:: |
21 ProtectedMediaIdentifierPermissionContext(Profile* profile) | 34 ProtectedMediaIdentifierPermissionContext(Profile* profile) |
22 : PermissionContextBase(profile, | 35 : PermissionContextBase(profile, |
23 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | 36 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) |
37 #if defined(OS_CHROMEOS) | |
38 , | |
39 pending_id_(GetInvalidPendingId()), | |
40 widget_(nullptr), | |
41 weak_factory_(this) | |
42 #endif | |
43 { | |
24 } | 44 } |
25 | 45 |
26 ProtectedMediaIdentifierPermissionContext:: | 46 ProtectedMediaIdentifierPermissionContext:: |
27 ~ProtectedMediaIdentifierPermissionContext() { | 47 ~ProtectedMediaIdentifierPermissionContext() { |
28 } | 48 } |
29 | 49 |
30 void ProtectedMediaIdentifierPermissionContext::RequestPermission( | 50 void ProtectedMediaIdentifierPermissionContext::RequestPermission( |
31 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
32 const PermissionRequestID& id, | 52 const PermissionRequestID& id, |
33 const GURL& requesting_frame_origin, | 53 const GURL& requesting_origin, |
34 bool user_gesture, | 54 bool user_gesture, |
35 const BrowserPermissionCallback& callback) { | 55 const BrowserPermissionCallback& callback) { |
36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
37 | 57 |
38 if (!IsProtectedMediaIdentifierEnabled()) { | 58 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
39 NotifyPermissionSet(id, | 59 |
40 requesting_frame_origin, | 60 if (!requesting_origin.is_valid() || !embedding_origin.is_valid() || |
41 web_contents->GetLastCommittedURL().GetOrigin(), | 61 !IsProtectedMediaIdentifierEnabled()) { |
42 callback, false, false); | 62 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
63 false /* persist */, false /* granted */); | |
43 return; | 64 return; |
44 } | 65 } |
45 | 66 |
46 PermissionContextBase::RequestPermission(web_contents, id, | 67 #if defined(OS_CHROMEOS) |
47 requesting_frame_origin, | 68 // On ChromeOS, we don't use PermissionContextBase::RequestPermission() which |
48 user_gesture, | 69 // uses the standard permission infobar/bubble UI. See http://crbug.com/454847 |
49 callback); | 70 // Instead, we check the content setting and show the existing platform |
71 // verification UI. | |
72 // TODO(xhwang): Remove when http://crbug.com/454847 is fixed. | |
73 ContentSetting content_setting = | |
74 GetPermissionStatus(requesting_origin, embedding_origin); | |
75 | |
76 switch (content_setting) { | |
77 case CONTENT_SETTING_BLOCK: | |
78 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
79 false /* persist */, false /* granted */); | |
80 return; | |
81 case CONTENT_SETTING_ALLOW: | |
82 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
83 false /* persist */, true /* granted */); | |
84 return; | |
85 default: | |
86 break; | |
87 } | |
88 | |
89 // We only support one prompt and one pending permission request. | |
90 // Reject the new one if there is already one pending. See | |
91 // http://crbug.com/447005 | |
92 if (!pending_id_.Equals(GetInvalidPendingId())) { | |
93 callback.Run(false); | |
94 return; | |
95 } | |
96 | |
97 pending_id_ = id; | |
98 widget_ = PlatformVerificationDialog::ShowDialog( | |
99 web_contents, requesting_origin, | |
100 base::Bind(&ProtectedMediaIdentifierPermissionContext:: | |
101 OnPlatformVerificationResult, | |
102 weak_factory_.GetWeakPtr(), id, requesting_origin, | |
103 embedding_origin, callback)); | |
104 #elif | |
ddorwin
2015/02/05 03:25:27
#else
xhwang
2015/02/05 05:46:51
Done.
| |
105 PermissionContextBase::RequestPermission(web_contents, id, requesting_origin, | |
106 user_gesture, callback); | |
107 #endif | |
50 } | 108 } |
51 | 109 |
52 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( | 110 ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus( |
53 const GURL& requesting_origin, | 111 const GURL& requesting_origin, |
54 const GURL& embedding_origin) const { | 112 const GURL& embedding_origin) const { |
55 if (!IsProtectedMediaIdentifierEnabled()) | 113 if (!IsProtectedMediaIdentifierEnabled()) |
56 return CONTENT_SETTING_BLOCK; | 114 return CONTENT_SETTING_BLOCK; |
57 | 115 |
58 return PermissionContextBase::GetPermissionStatus(requesting_origin, | 116 return PermissionContextBase::GetPermissionStatus(requesting_origin, |
59 embedding_origin); | 117 embedding_origin); |
60 } | 118 } |
61 | 119 |
120 void ProtectedMediaIdentifierPermissionContext::CancelPermissionRequest( | |
121 content::WebContents* web_contents, | |
122 const PermissionRequestID& id) { | |
123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
124 | |
125 #if defined(OS_CHROMEOS) | |
126 if (!widget_ || !pending_id_.Equals(id)) | |
127 return; | |
128 | |
129 // Close the |widget_|. OnPlatformVerificationResult() will be fired | |
130 // during this process, but since |pending_id_| is cleared, the callback will | |
131 // be dropped. | |
132 pending_id_ = GetInvalidPendingId(); | |
133 widget_->Close(); | |
134 return; | |
135 #elif | |
ddorwin
2015/02/05 03:25:26
ditto
xhwang
2015/02/05 05:46:51
Done.
| |
136 PermissionContextBase::CancelPermissionRequest(web_contents, id); | |
137 #endif | |
138 } | |
139 | |
62 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( | 140 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext( |
63 const PermissionRequestID& id, | 141 const PermissionRequestID& id, |
64 const GURL& requesting_frame, | 142 const GURL& requesting_frame, |
65 bool allowed) { | 143 bool allowed) { |
66 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
67 | 145 |
68 // WebContents may have gone away. | 146 // WebContents may have gone away. |
69 TabSpecificContentSettings* content_settings = | 147 TabSpecificContentSettings* content_settings = |
70 TabSpecificContentSettings::Get(id.render_process_id(), | 148 TabSpecificContentSettings::Get(id.render_process_id(), |
71 id.render_view_id()); | 149 id.render_view_id()); |
72 if (content_settings) { | 150 if (content_settings) { |
73 content_settings->OnProtectedMediaIdentifierPermissionSet( | 151 content_settings->OnProtectedMediaIdentifierPermissionSet( |
74 requesting_frame.GetOrigin(), allowed); | 152 requesting_frame.GetOrigin(), allowed); |
75 } | 153 } |
76 | |
77 } | 154 } |
78 | 155 |
79 // TODO(xhwang): We should consolidate the "protected content" related pref | 156 // TODO(xhwang): We should consolidate the "protected content" related pref |
80 // across platforms. | 157 // across platforms. |
81 bool ProtectedMediaIdentifierPermissionContext:: | 158 bool ProtectedMediaIdentifierPermissionContext:: |
82 IsProtectedMediaIdentifierEnabled() const { | 159 IsProtectedMediaIdentifierEnabled() const { |
83 bool enabled = false; | 160 bool enabled = false; |
84 | 161 |
85 #if defined(OS_ANDROID) | 162 #if defined(OS_ANDROID) |
86 enabled = profile()->GetPrefs()->GetBoolean( | 163 enabled = profile()->GetPrefs()->GetBoolean( |
87 prefs::kProtectedMediaIdentifierEnabled); | 164 prefs::kProtectedMediaIdentifierEnabled); |
88 #endif | 165 #endif |
89 | 166 |
90 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
91 // This could be disabled by the device policy. | 168 // This could be disabled by the device policy. |
92 bool enabled_for_device = false; | 169 bool enabled_for_device = false; |
93 enabled = chromeos::CrosSettings::Get()->GetBoolean( | 170 enabled = chromeos::CrosSettings::Get()->GetBoolean( |
94 chromeos::kAttestationForContentProtectionEnabled, | 171 chromeos::kAttestationForContentProtectionEnabled, |
95 &enabled_for_device) && | 172 &enabled_for_device) && |
96 enabled_for_device && | 173 enabled_for_device && |
97 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); | 174 profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM); |
98 #endif | 175 #endif |
99 | 176 |
100 DVLOG_IF(1, !enabled) | 177 DVLOG_IF(1, !enabled) |
101 << "Protected media identifier disabled by the user or by device policy."; | 178 << "Protected media identifier disabled by the user or by device policy."; |
102 return enabled; | 179 return enabled; |
103 } | 180 } |
181 | |
182 #if defined(OS_CHROMEOS) | |
183 void ProtectedMediaIdentifierPermissionContext::OnPlatformVerificationResult( | |
184 const PermissionRequestID& id, | |
185 const GURL& requesting_origin, | |
186 const GURL& embedding_origin, | |
187 const BrowserPermissionCallback& callback, | |
188 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | |
189 DCHECK(widget_); | |
190 widget_ = nullptr; | |
191 | |
192 // The request may have been canceled. Drop the callback here. | |
193 if (!pending_id_.Equals(id)) | |
194 return; | |
195 | |
196 pending_id_ = GetInvalidPendingId(); | |
197 | |
198 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { | |
199 // Deny request and do not save to content settings. | |
200 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | |
201 false, // Do not save to content settings. | |
202 false); // Do not allow the permission. | |
203 return; | |
204 } | |
205 | |
206 NotifyPermissionSet( | |
207 id, requesting_origin, embedding_origin, callback, | |
208 true, // Save to content settings. | |
209 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | |
210 } | |
211 #endif | |
OLD | NEW |